Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem

[RTOS Message Buffer API]


MessageBufferHandle_t xMessageBufferCreateStatic(
                                          size_t xBufferSizeBytes,
                                          uint8_t *pucMessageBufferStorageArea,
                                          StaticMessageBuffer_t *pxStaticMessageBuffer );

Creates a new message buffer using statically allocated memory. See xMessageBufferCreate() for a version that uses dynamically allocated memory.

configSUPPORT_STATIC_ALLOCATION must be set to 1 in FreeRTOSConfig.h for xMessageBufferCreateStatic() to be available.

Message buffer functionality is enabled by including the FreeRTOS/source/stream_buffer.c source file in the build (as message buffers use stream buffers).

xBufferSizeBytes   The size, in bytes, of the buffer pointed to by the pucMessageBufferStorageArea parameter. When a message is written to the message buffer an additional sizeof( size_t ) bytes are also written to store the message's length. sizeof( size_t ) is typically 4 bytes on a 32-bit architecture, so on most 32-bit architecture a 10 byte message will take up 14 bytes of message buffer space. The maximum number of bytes that can be stored in the message buffer is actually (xBufferSizeBytes - 1).
pucMessageBufferStorageArea   Must point to a uint8_t array that is at least xBufferSizeBytes + 1 big. This is the array to which messages are copied when they are written to the message buffer.
pxStaticMessageBuffer   Must point to a variable of type StaticMessageBuffer_t, which will be used to hold the message buffer's data structure.
If the message buffer is created successfully then a handle to the created message buffer is returned. If either pucMessageBufferStorageArea or pxStaticMessageBuffer are NULL then NULL is returned.

Example usage:

/* Used to dimension the array used to hold the messages.  The available space
will actually be one less than this, so 999. */

/* Defines the memory that will actually hold the messages within the message
buffer.  Should be one more than the value passed in the xBufferSizeBytes
parameter. */
static uint8_t ucStorageBuffer[ STORAGE_SIZE_BYTES ];

/* The variable used to hold the message buffer structure. */
StaticMessageBuffer_t xMessageBufferStruct;

void MyFunction( void )
MessageBufferHandle_t xMessageBuffer;

    xMessageBuffer = xMessageBufferCreateStatic( sizeof( ucStoragegBuffer ),
                                                 &xMessageBufferStruct );

    /* As neither the pucMessageBufferStorageArea or pxStaticMessageBuffer
    parameters were NULL, xMessageBuffer will not be NULL, and can be used to
    reference the created message buffer in other message buffer API calls. */

    /* Other code that uses the message buffer can go here. */

[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

Meet us at Embedded World. Hall 3A-525.

Hear from Richard Barry at Embedded World. Feb 28, 16:00, Hall 4-428.

Video: Watch James Gosling & Richard Barry at re:Invent, Las Vegas 2017.

FreeRTOS kernel V10.0.1 is available for immediate download. Now MIT licensed.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS