Size field of message buffers

Hello everyone, I have recently upgraded a project I worked on to FreeRTOS 10. Currently I use queues to send messages between the tasks of my system. All messages are the same structure type containing a 4 byte header and a 4 byte payload. I would like to use a Message Buffer instead of the queue. As some of my messages only require a single or 2 payload bytes, I could reduce the size of some messages in my system. I also have the use case now of handling messages with bigger payloads (up to 250 bytes for example but never above 255). Unfortunately the size field used in the message buffer is 4 bytes long on my ARM Cortex-M0 MCU, so if start using it : a message with 4 bytes of header + 1 byte of payload would actually require 9 bytes of storage in the message buffer where it uses 8 bytes right now ; a 4 byte header + 4 bytes payload would use 12 bytes. As my use case do not require messages bigger than 255 bytes, would it be possible to allow a configurable type for the size field of the message buffer ? Like a config in the freertos config file allowing me to use uint8t instead of the 4 bytes sizet ? I am sure this feature would be useful for others too. Regards, Nathan O.

Size field of message buffers

There is no facility to do this at the moment, but looking at the code it seems it would be a simple update to introduce the capability. I will have a play with it and see.

Size field of message buffers

Try the FreeRTOS.h and message_buffer.c files just checked in. In those I added the following to FreeRTOS.h to ensure backward compatibility:
#ifndef configMESSAGE_BUFFER_LENGTH_TYPE
     /* Defaults to size_t for backward compatibility, but can be overridden
     in FreeRTOSConfig.h if lengths will always be less than the number 
of bytes
     in a size_t. */
     #define configMESSAGE_BUFFER_LENGTH_TYPE size_t
#endif
…and in stream_buffer.c I changed:
#define sbBYTES_TO_STORE_MESSAGE_LENGTH ( sizeof( size_t ) )
to
#define sbBYTES_TO_STORE_MESSAGE_LENGTH ( sizeof( 
configMESSAGE_BUFFER_LENGTH_TYPE ) )
The sizet is still used to hold the message size in the APIs, only the number of bytes used to read and write the message size into the buffer have changed. Therefore sizeof( configMESSAGEBUFFERLENGTHTYPE ) could be less than sizeof( sizet ) – so the sizet variable used to hold the message size read out of the buffer is cleared to zero before it is used (in case only one byte is read into the variable the other bytes must be zero). Now of course the tests are failing because they specifically expect the message length field to be 4 bytes – I will update those when I get a change. https://sourceforge.net/p/freertos/code/HEAD/tree/trunk/ Let me know….

Size field of message buffers

Note having updated the tests I had to fix some regressions in stream_buffer.c, so if you already downloaded the updated version, please do so again.

Size field of message buffers

Thank you very much. This is exactly what I was looking for. I have downloaded the latest trunk 2536, set the configMESSAGEBUFFERLENGTHTYPE in my FreeRTOSConfig file to uint8t and it works great.