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 uint8_t instead of the 4 bytes size_t ?
I am sure this feature would be useful for others too.
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.
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
The size_t 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( configMESSAGE_BUFFER_LENGTH_TYPE )
could be less than sizeof( size_t ) - so the size_t 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.