Hi ,
I am checking the page34 of«rl-arm_gs» and find below description :
Signaling Synchronizing the execution of two tasks is the simplest use of a semaphore:
os_sem semB; __task void task1 (void) { os_sem_init (semB, 0); while (1) { os_sem_send (semB); FuncA(); } } __task void task2 (void) { while (1) { os_sem_wait (semB, 0xFFFF); FuncB(); } }
In this case, the semaphore is used to ensure that the code in FuncA() is executed before the code in FuncB().
My questions is,
when the task1 will be suspended and the scheduler will start task2? I add above codes into one keil project and find actually task2 will not start for ever.
I think that such description above in italics is incorrect, isn't it?
here are my codes:
#include <RTL.h> /* RTX kernel functions & defines */ #include <LPC21xx.H> /* LPC21xx definitions */ #include <stdio.h> OS_TID tsk1, tsk2; OS_SEM semB; int counter1=0; int counter2=0; __task void task1 (void) { os_sem_init (semB, 0); while (1) { os_sem_send (semB); counter1 ++ ; } } __task void task2 (void) { while(1){ os_sem_wait (semB, 0xFFFF); counter2++; } } __task void init (void) { tsk1 = os_tsk_create (task1, 10); tsk2 = os_tsk_create (task2, 10); os_tsk_delete_self (); } int main (void) { os_sys_init (init); }
even round-robin option in config wizard is checked, task2 never starts, either.
Looking forward to help. thanks
BR,
fisher
What do you mean task 2 won't start "for ever"? That Task 2 never executes, or that the counter in task 1 gets really high before the switch?
Do you have round-robin multitasking enabled? If not, you are responsible for calling os_dly_wait() and os_tsk_pass().
If round-robin is enabled, and your Task 2 does execute, the default round-robin context switch is 10ms. Since both tasks have the same priority, Task 1 will run for the full 10ms. The while loop in task 1 will execute quite a few times in 10ms. Running the CPU at 60MHz, I'd guess that the counter would get over 5800 (~1.7uS/send semaphore).