hello friends i have written the code for ARM RTOS, i have used same priority for all of my 4 task, its working fine
my problem is when i change the priority in the code then all task's are not executing simultaneously.... please any one help
Thank you per
if i set the flag 1 in task1 , it means that i should wait for that perticular flag(flag 1) in task2?
example:
__task void task1 (void){ /* Obtain own system task identification number */ id1 = os_tsk_self(); os_tsk_prio_self(1); /* Create task2 and obtain its task identification number */ id2 = os_tsk_create (task2, 2); for (;;) { /* Signal to task2 that task1 has compelted */ os_evt_set(0x0004, id2); setting the flag here /* Wait for completion of task2 activity. */ /* 0xFFFF makes it wait without timeout. */ os_evt_wait_or(0x0003, 0xFFFF); } } __task void task2 (void) { for (;;) { /* Wait for completion of task1 activity. */ /* 0xFFFF makes it wait without timeout. */ /* 0x0004 represents bit 2. */ os_evt_wait_or(0x0004, 0xFFFF); should i wait here for same flag? /* Signal to task1 that task1 has compelted */ os_evt_set(0x0003, id1); } }
"if i set the flag 1 in task1 , it means that i should wait for that perticular flag(flag 1) in task2?"
That obviously depends on if your goal is that task 1 should activate task 2.
If task 2 have (at least) same priority unless you put task 1 to sleep after having set the event. As usual, the OS will sort all runnable (not waiting for a delay to end or waiting for event, mail,...) on priority and only look at the threads that have the highest priority among the threads that are running. Threads with lower priority gets ignored. Threads still waiting for something that haven't happened (no timeout , no event, no mail, ...) gets ignored.
Thank you so much per.....
now i resided to change my project procedure
i want ADC to read the value for some time and display it on the LCD as well as Hyper terminal(using SCI protocol), buzzer should be turned ON and OFF according to events(as you mentioned earlier) is it possible?? and what about the SPI() function where shall i put? and for what reason? OR should i develop it in different way? if so please suggest me..
Excuse me, but I believe most of us here are working right now. Can't you find a consultant (=pay) to do your homework for you?
in the below program its switching from tsk1 to tsk2 and tsk2 to tsk3 but its again not going back to the tsk1 where tsk2 is going in to wait state.... can anyone tell me why tsk3 is not going to the wait state?
__task void task1 (void){ /* Obtain own system task identification number */ id1 = os_tsk_self(); os_tsk_prio_self(1); /* Create task2 and obtain its task identification number */ id2 = os_tsk_create (task2, 2); id3 = os_tsk_create (task3, 3); for (;;) { buzzer();/* ... place code for task1 activity here ... */ os_evt_set(0x0002,id2); /* Signal to task2 that task1 has compelted */ os_evt_wait_or(0x0001,0xffff); } } __task void task2 (void) { for (;;) { ADC();/* ... place code for task2 activity here ... */ //os_evt_set(0x0003, id3); os_evt_wait_or(0x0002, 0xFFFF); //os_dly_wait(10); } } __task void task3(void) { for(;;) { SPI(); /* Signal to task1 that task1 has compelted */ os_evt_set(0x0001, id1); os_evt_wait_or(0x0003,0xffff); os_dly_wait(15); } } int main (void) { /* Start the RTX kernel, and then create and execute task1. */ os_sys_init(task1); }
We don't even know if buzzer(), ADC() or SPI() takes long time in relation to os_dly_wait(15).
You have done some debugging, haven't you? What happens when you singlestep the three threads?
By the way - task 3 is waiting for os_evt_wait_or(0x0003,0xffff). But who is sending any event 0x0001 or 0x0002 to this thread? How long do you think the wait will be if the thread don't get anyone to set one or both of the events?
Another thing - is there are reason why task 3 listens to two flags?
It looks a little as if the OP is copy-pasting pieces of code he finds in example programs without really understanding their impact (and then stumping with his foot: "it is not working!").
sorry sir i was commented it while posting.......
after dumping the program its working i.e, it its going to task 1(buzzer is functioning ) and one more doubt i have sir .... i am not able to find it in manual i.e,
is it possible to run only one task for specific time out of 4 task??
Yes, if a task calls "tsk_lock". Don't forget to call "tsk_unlock" to allocw the scheduler to operate normally again. Are you sure you read the manual? You clearly did not understand much (no offense!)
You normally never do force a single task to run for a specific time by trying to block the scheduler - it is more something used when having the simplest form of round-robin interaction or when something very special happens like a communication thread that instead of normal communication gets a new firmware where the real-time requirements gets dropped until the device have rebooted after the firmware update.
Different tasks are created to solve different problems. Different problems that often have different priorities, where the priority can be used to avoid bad interaction from other threads. And real-time systems are normally designed to perform all prioritized tasks as short bursts before leaving the CPU capacity to lower-prioritized tasks. Often with lots of interrupt processing to allow high-prio tasks to sleep until the hardware detects special conditions.
So you assign task priorities based on the importance of the work to be done. If the buzzer is the most important thing to do, then you may decide to give the buzzer task the highest priority. Then no other task will interfere with the buzzer task until the buzzer task performs a wait statement, waiting either a fixed time or waiting for an event or mail.
Next thing - if you think about it - is that if that buzzer is a piezo, then you don't have to generate any wave frequency to get it to sound. You only have to turn on the power. Then you can have your processor busy doing other things while waiting until it's time to turn off the power.
Didn't you read my previous post about writing down your different things you need to do, and figure out what priorities they should have and what things may be done concurrently and when a higher priority task should be performed in full before a lower prio task gets reactivated?
You can't just program by random copy/paste of wait, set_event, ...
When you do know what tasks to solve, and how they _need_ to interact, then it is easy to figure out what OS function calls you need to add to the different tasks - and where - to get that specific interaction.
I stumbled across this thread and figured that I could write something that was more constructive and more useful than just a straight forum post. So I wrote this...
nohauuk.blogspot.com/.../fundamental-rtos-co-operative.html
If you think it is useful then let me know and I will write more.