lpmay wrote on Friday, May 18, 2018:
Hi,
I think I may have stumbled into a bug with xStreamBufferReset
, and how it interacts with xStreamBufferSendFromISR
. Perhaps it’s just a misunderstanding on my, part and if so I think the documentation could probably be a little more clear.
Basically, I thought it was always safe to call xStreamBufferReset
, but in fact if FromISR
functions are used it is not safe, unless interrupts are disabled. Since xStreamBufferReset
ultimately clears the underlying stream structure and then re-populates it with interrupts enabled, it is possible for an interrupt to fire while the structure is not in a valid state. If that interrupt tries to access the StreamBuffer, even with one of the fromISR
functions that access will fail (and configASSERT
).
In pseudo-code, my setup is something like this:
:::c
void ISR(void)
{
...
xStreamBufferSendFromISR(/* new byte */);
...
}
void process_bytes(void)
{
while(1){
/* start with a fresh stream */
xStreamBufferReset();
/*
... receive from stream multiple times, continue if error encountered
*/
return;
}
In my opinion, there should be a specific note in the documenation that xStreamBufferReset
is not safe to use with the FromISR
functions, or better yet the implementation should be changed such that xStreamBufferReset
is safe to use with the FromISR
functions.
Am I missing something more fundamental? Should I open a support ticket? Thanks for any help!