Is it possible to discard a message in a message buffer?

Hi,

I encountered a situation in my code where a message was written to a message buffer that was longer than the count specified in the call to xMessageBufferReceive. As documented, this caused the return value to be 0 and the message to be left in the buffer. While I will make changes to my code to prevent the too long message from being written, I was wondering if there is a way to discard a message in the message buffer, short of doing xMessageBufferReset. It seems like this would be useful in some error recovery situations.

thanks,
galen

I don’t think that should happen in the first place.

Which version of FreeRTOS are you using?
Are you writing to the message buffer from more than one task or from tasks and interrupts?
If 0 was returned, what makes you think the message was left in the buffer.
Which documentation are you referring to?

Re-reading my message, perhaps I wasn’t clear. A long message is written using xMessageBufferSendFromISR. The receiving task is not expecting a message of this length, so the call to xMessageBufferReceive returns 0, and the message is left in the message buffer.

FreeRTOS V10.3.1

No, messages are sent from a single place in an interrupt routine using xMessageBufferSendFromISR.

https://www.freertos.org/xMessageBufferReceive.html

If xBufferLengthBytes is too small to hold the next message then the message will be left in the message buffer and 0 will be returned.

galen

Ah, I understand. So if you can’t provide a buffer large enough you need a method of removing the message. Please use this link to add the feature request.

Thanks for the feedback. I’ve created an issue suggesting this feature.