This is a silly comment only for updating the official documentation. While xQueueSend() returns errQUEUE_FULL if the queue was full, the function xQueueReceive() returns pdFALSE:
Returns:
pdTRUE if an item was successfully received from the queue, otherwise pdFALSE.
Yes, errQUEUE_EMPTY and errQUEUE_FULL have the same value. My point is to be consistent all along the code: while in some places one tests against errQUEUE_FULL, in others one tests against pdFALSE. Thatâs weird and inconsistent.
Any reason to use pdFALSE instead of errQUEUE_EMPTY. A workaround is to test always against pdTRUE and all problems are gone.
I think the idea is that for a xQueueReceive() you could check for a âgenericâ failure with pdFAIL, or check for the type of error that would actual occur with errQUEUE_EMPTY to document what the error was. And for a send, the actual error would be errQUEUE_FULL
If you see that, both defines using for error detection, in this case, if you want to receive something from queue, but itâs EMPTY you canât get any of data â so itâs error (0).
If you want to write into the queue and itâs full, itâs FULL so you canât write any data â so itâs error (0).
There is no sense to know queue is full when you want to read, because itâs canât cause any of errors.
If you want to get number of items, you could use functions like: uxQueueMessagesWaiting().
Regards.
I mean detecting an error without implying the type (which will only be the queue was empty/full).
You can read and test for âany errorâ or you can read and test if you got a âqueue emptyâ error. They both are the same error code as that is the only error there is.
Yes, I already know that. My point here is TO BE CONSISTENT! For Richard Barry the naming is very important (although the prefix âxâ is meaningless in so many situations). If I test against errQUEUE_FULL when using xQueueSend(), then it would be logical to test against errQUEUE_EMPTY when using xQueueReceive(), THATâS CONSISTENCY!
What is the error code when you pass the wrong handler?
if( xQueueReceive( handler, &data, ( TickType_t ) 10 ) == pdFALSE)
{
// Are we here for a timeout or for something else?
// How do you know what is that "something else"?
}
else
{
// process the incoming data
}
Yes, consistancy would be to use pdFAIL everywhere or errQUEUE_FULL / errQUEUE_EMPTY. My guess is that the documentation is old (but still accurate) and some has been updated to more current practices.
Personally, I just use if(xQueueReceive(âŚ)) { âŚ
That question of my own was following this comment:
You canât set the same value to different errors; an empty queue is one thing, and passing the wrong handler is other thing, so you canât use the value 0 for both. Thatâs what I wanted to point out. By the way the wrong handler former canât be catched by configAssert() if the handler is assigned to a very different object (like a semaphore or timer) but itâs not NULL.