Vous êtes sur la page 1sur 8

RTOS LAB REPORT First step: Loading the project on the Coldfire board. 1.

How many tasks are usable in this application? #define OS_MAX_TASKS >= 2 */ So its 10 tasks. 2. What timer is used for ticks generating? PIT0 3. How much is the timer work frequency? How much is the tick duration? Verify the coherency between the two values. OS_TICKS_PER_SEC 100u 10u /* Max. number of tasks in your application, MUST be

4. Lines of Code added: MCF_PIT0_PMR = 30000; MCF_PIT0_PCSR=(MCF_PIT_PCSR_EN|MCF_PIT_PCSR_RLD|MCF_PIT_PCSR_PIF|MCF_PIT_PC SR_PIE|MCF_PIT_PCSR_PRE(3)); MCF_PIT0_PCSR&=~ (MCF_PIT_PCSR_OVW|MCF_PIT_PCSR_DBG|MCF_PIT_PCSR_DOZE); 5. Put a breakpoint in My_Task1() on the var++ line; Run several time, what do you see ? The breakpoint is reached every second in the given program so the program runs fine until the breakpoint is reached. We can see the value at the breakpoint. 6. The following code was added in the program to get the hyperlink network : INT8U retval; uart_init( 0, 48000,19200); uart_outstring(0,"Bonjour "); 7. The code for the counter is : int X; char buffer1[20]; X = sprintf(buffer1, "\r Count is %d", var); uart_outstring(0,buffer1);

8. To kill the ticks, the code was changed as follows : MCF_PIT0_PCSR|=(MCF_PIT_PCSR_EN|MCF_PIT_PCSR_RLD|MCF_PIT_PCSR_PIF|MCF_PIT_P CSR_PRE(3));

MCF_PIT0_PCSR&=~(MCF_PIT_PCSR_OVW|MCF_PIT_PCSR_DBG|MCF_PIT_PCSR_DOZE|MCF _PIT_PCSR_PIE); At first, the scheduler tries to find the next highest priority task ready to run but finds none as the only task (MyTask1()) is blocked by the OSTimeDlyHMSM(). Later the scheduler ends up calling the idle task which calls the Idle Hook indefinitely in an endless loop. 9. In order to calculate the context switching time, following changes were made in the program: MCF_GPIO_PORTTC |= 0x02; Was added in myTask1() before the Dly function. All the other tasks were suppressed. In the Idle Hook function the following line was uncommented: MCF_GPIO_PORTTC &=~ 0x02; Then using logicport the context switching time was calculated. It came out to be 11.62s

Second step: Project modification on the Coldfire board. 1. Modify the program to blink the PTA0 led of the Coldfire in place of increase a variable. static void myTask1(void *pdata) { INT8U retval; pdata=pdata; while (TRUE) {

/* dummy usage to avoid compiler warning */ /* Task body, ALWAYS written as an infinite loop */

// MCF_GPIO_PORTTC |= 0x02; retval=OSTimeDlyHMSM(0,0,2,0); /* Delay for hr,min,sec,ms

*/

MCF_GPIO_PORTTA ^= 0x01; /* var++;*/

} /* end while */ } /* end myTask1() */

2. MyTask1() tval=OSTimeDlyHMSM(0,0,0,500); MyTask2() tval=OSTimeDlyHMSM(0,0,2,0); MyTask3() TimeDly(20); Is it possible to place a task at the priority 20? Why? No, because the lowest allowed priority is 15. #define OS_LOWEST_PRIO assigned... */ /* ... MUST NEVER be higher than 254! 15u /* Defines the lowest priority that can be

*/

Q. Put the OSSchedLock() function in the less priority task. What happens? Why? Suppress the function. The function OSSchedLock() will prevent task rescheduling until its counterpart, even though other higher priority tasks are ready to run . So in this case, task1 and task 2 which have higher priority cannot take the CPU until scheduling is enabled once again by OSSchedUnlock().

3. Modify the third task for periodically displaying a 20 characters message in the Hyperterminal window.

static void myTask3(void *pdata)

char ch;

int i; uart_init( 0, 48000,19200); pdata=pdata; while (TRUE) { ch='a'; MCF_GPIO_PORTTA ^= 0x04; for(i=0;i<20;i++) { uart_putchar(0,ch); ch++; uart_putchar(0,' '); /* dummy usage to avoid compiler warning */ /* Task body, ALWAYS written as an infinite loop */

} OSTimeDly(20); var++; } /* end while */ }

4. Change the transmit baudrate in the UART initialization as in the Hyperterminal connexion for working at 110 bauds. Launch the application. What happens? Why?

The transmission rate is very slow so we get jargon.

5. The program code was changed as follows: static void myTask2(void *pdata) { INT8U retval; uart_init( 0, 48000,19200);

pdata=pdata;

/* dummy usage to avoid compiler warning */

while (TRUE) /* Task body, ALWAYS written as an infinite loop */ { uart_outstring(0,"This is String 1 "); retval=OSTimeDlyHMSM(0,0,1,0); /* Delay for hr,min,sec,ms */ uart_outstring(0,"This is String 2 "); retval=OSTimeDlyHMSM(0,0,1,0); MCF_GPIO_PORTTA ^= 0x02;

} /* end while */ } static void myTask3(void *pdata) { INT8U retval; uart_init( 0, 48000,19200); pdata=pdata; /* dummy usage to avoid compiler warning */

while (TRUE) {

/* Task body, ALWAYS written as an infinite loop */

MCF_GPIO_PORTTA ^= 0x04; uart_outstring(0,"This is String 3 "); retval=OSTimeDlyHMSM(0,0,1,0); uart_outstring(0,"This is String 4 "); retval=OSTimeDlyHMSM(0,0,1,0);

OSTimeDly(20); var++;

} /* end while */

The following output was obtained:

Inference: Task 2 is run, once delay is encountered the next high priority task, i.e., Task 3 is run. When the OS Tick is encountered the tasks go back to the original priority and Task 2 is executed and this goes on. The lines of code added to make the semaphore work are as follows: OS_EVENT *sem; OS_EVENT *sem1; Task 2: OSSemPend(sem1,0,0); uart_outstring(0,"This is String 1 "); retval=OSTimeDlyHMSM(0,0,1,0); /* Delay for hr,min,sec,ms uart_outstring(0,"This is String 2 "); retval=OSTimeDlyHMSM(0,0,1,0); OSSemPost(sem);

*/

Task 3: OSSemPend(sem,0,0); uart_outstring(0,"This is String 3 "); retval=OSTimeDlyHMSM(0,0,1,0); uart_outstring(0,"This is String 4 "); retval=OSTimeDlyHMSM(0,0,1,0); OSSemPost(sem1); sem=OSSemCreate(0); sem1=OSSemCreate(1); The output obtained is as below:

Third step: Interrupt control with MicroC.

Vous aimerez peut-être aussi