Hi,
I'm developping on ARM7 chip with ARTX OS and I would like to implement periodic task. My software is based onto the example you can find at the following link : http://www.keil.com/support/docs/3008.htm
During my tests, I've detected some troubles with os_evt_set() an os_evt_wait_or() functions.
If a high task priority post two event before the low task take event with os_evt_wait_or(), sometimes this task is waking-up twice as the event have been store !
I don't understand. Could you help me ?
Thanks for all
The code you have posted SHOULD return OS_R_TMO on the second call to os_wait_evt_or(); If it is not there is something wrong. If this is what you are seeing (and I believe you are) then the event system is working properly.
Actually there may be another issue. It is not a good idea to call os_set_evt() while you have interrupts disabled. os_set_evt() MAY dispatch a task other than the currently running task, this has a side effect of causing interrupts to be reenabled at that point in time. (It should only do it if the task you are sending it to is waiting for it and a higher priority) I am not sure, but isr_set_evt() might work better.
tsk_lock and tsk_unlock are not the problem. If I remove them the same problem occured, the code return OS_R_EVT on the second call to os_evt_wait_or...
thanks
OK. I can replicate and explain what it is doing. It is debatable if it is actaully a bug (I would not submit it as a bug, but that is because it is not causing me any problems)
Task2 is WAITING for an event.
Task1 sets the event for Task2.
In the context of Task1, Task2 is set READY to run. The event that caused the wakeup is set. (for os_get_evt) The event(s) that caused the wakeup is cleared.
Task1 continues to run and sets the event again.
Task2 actaully returns from the first wait and runs.
Task2 does a 0 time wait on the event, and finds that it is set and returns it.
Knowing this, you may want to change your logic accordingly. (maybe you should use a mailbox instead of an event)
I've arrived at the same point, but instead using mailbox to fix the problem I would like to use something easier such a flag. I think that it is a bug. The event would be clear by the waiting task when it's running. In my example, the waiting task were never running (low priority task). The scheduler reset the event flag not propaly before waiting task running
Do you have some idea ?
Thanks for all !
You will need to put together code that gives you the behavior that you desire. A "simple" solution that does not do what you want is not a good choice. I do not believe the Keil will be changing the way events work any time soon (if at all) so you will need to either add a flag to your code or use some other technique. It is not clear exactly what you are trying to do so what I did was explain what the event system was doing. If it does not do what you want, then use something that does do what you want.