I am using KEIL CMSIS RTOS v2 with the FreeRTOS implementation underneath
I have some I2C code (not in an ISR) that kicks off a transfer and then calls:
osFlags = osEventFlagsWait(event_id, 0x00000001, osFlagsWaitAny, 10000);
Then, at the end of the ISR, it does the following:
osFlags = osEventFlagsSet(event_id, 0x00000001);
This results in the wait call waking up, and all works well. Except when it doesn't. Occasionally, I see the I2C transfer complete, and then the ISR completes and the EventFlagSet gets called, but the EventFlagsWait times out. And once that happens, it just continues to time out on every other transfer.
Now for the fun part ... I replaced the wait with a wait on ANY flag:
osFlags = osEventFlagsWait(event_id, 0xFFFFFFFF, osFlagsWaitAny, 10000);
And in the ISR, I did the following:
for (i = 0; i < 32; i++) { osFlags = osEventFlagsSet(event_id, 1 << i);
}
And this seems to work consistently. So - I wondered what would happen if I did it all at once ...
osFlags = osEventFlagsSet(event_id, 0xFFFFFFFF);
And that also seems to work consistently. I even went back and checked the wait with osFlagsWaitAll - and that seems to work as well. So - I Went all the way back and did the original with just the one bit. ... and sure enough, it fails after a few good transfers .
Finally - to be thorough, I went back to the loop just do 2 bits - and that worked, and then I changed it to where the osFlagsSet was to 0x00000003 .. rather than 1.
This also worked. What??!??!?
3 questions ..
1) Am I doing these calls correctly? The initial version "should" work, shouldn't it?
2) Any clue at all what might be causing this problem?
3) Are there any negatives to just setting all the bits and doing a wait on any?
I appreciate the response. I don't see any evidence of that - and that wouldn't explain (I don't think) why it works when I set 2 bits in the Event rather than just 1. I have decided to just take out all of the events and use semaphores instead. That seems to be working much better. And seems to be better supported by FreeRTOS underneath.