firmware
IEM Firmware Documentation
Loading...
Searching...
No Matches
message_buffer.h
Go to the documentation of this file.
1/*
2 * FreeRTOS Kernel V11.1.0
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
26 *
27 */
28
29
30/*
31 * Message buffers build functionality on top of FreeRTOS stream buffers.
32 * Whereas stream buffers are used to send a continuous stream of data from one
33 * task or interrupt to another, message buffers are used to send variable
34 * length discrete messages from one task or interrupt to another. Their
35 * implementation is light weight, making them particularly suited for interrupt
36 * to task and core to core communication scenarios.
37 *
38 * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
39 * implementation (so also the message buffer implementation, as message buffers
40 * are built on top of stream buffers) assumes there is only one task or
41 * interrupt that will write to the buffer (the writer), and only one task or
42 * interrupt that will read from the buffer (the reader). It is safe for the
43 * writer and reader to be different tasks or interrupts, but, unlike other
44 * FreeRTOS objects, it is not safe to have multiple different writers or
45 * multiple different readers. If there are to be multiple different writers
46 * then the application writer must place each call to a writing API function
47 * (such as xMessageBufferSend()) inside a critical section and set the send
48 * block time to 0. Likewise, if there are to be multiple different readers
49 * then the application writer must place each call to a reading API function
50 * (such as xMessageBufferRead()) inside a critical section and set the receive
51 * timeout to 0.
52 *
53 * Message buffers hold variable length messages. To enable that, when a
54 * message is written to the message buffer an additional sizeof( size_t ) bytes
55 * are also written to store the message's length (that happens internally, with
56 * the API function). sizeof( size_t ) is typically 4 bytes on a 32-bit
57 * architecture, so writing a 10 byte message to a message buffer on a 32-bit
58 * architecture will actually reduce the available space in the message buffer
59 * by 14 bytes (10 byte are used by the message, and 4 bytes to hold the length
60 * of the message).
61 */
62
63#ifndef FREERTOS_MESSAGE_BUFFER_H
64#define FREERTOS_MESSAGE_BUFFER_H
65
66#ifndef INC_FREERTOS_H
67 #error "include FreeRTOS.h must appear in source files before include message_buffer.h"
68#endif
69
70/* Message buffers are built onto of stream buffers. */
71#include "stream_buffer.h"
72
73/* *INDENT-OFF* */
74#if defined( __cplusplus )
75 extern "C" {
76#endif
77/* *INDENT-ON* */
78
87
88/*-----------------------------------------------------------*/
89
160#define xMessageBufferCreate( xBufferSizeBytes ) \
161 xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( size_t ) 0, sbTYPE_MESSAGE_BUFFER, NULL, NULL )
162
163#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
164 #define xMessageBufferCreateWithCallback( xBufferSizeBytes, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
165 xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( size_t ) 0, sbTYPE_MESSAGE_BUFFER, ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) )
166#endif
167
245#define xMessageBufferCreateStatic( xBufferSizeBytes, pucMessageBufferStorageArea, pxStaticMessageBuffer ) \
246 xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), 0, sbTYPE_MESSAGE_BUFFER, ( pucMessageBufferStorageArea ), ( pxStaticMessageBuffer ), NULL, NULL )
247
248#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
249 #define xMessageBufferCreateStaticWithCallback( xBufferSizeBytes, pucMessageBufferStorageArea, pxStaticMessageBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
250 xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), 0, sbTYPE_MESSAGE_BUFFER, ( pucMessageBufferStorageArea ), ( pxStaticMessageBuffer ), ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) )
251#endif
252
282#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
283 #define xMessageBufferGetStaticBuffers( xMessageBuffer, ppucMessageBufferStorageArea, ppxStaticMessageBuffer ) \
284 xStreamBufferGetStaticBuffers( ( xMessageBuffer ), ( ppucMessageBufferStorageArea ), ( ppxStaticMessageBuffer ) )
285#endif /* configSUPPORT_STATIC_ALLOCATION */
286
387#define xMessageBufferSend( xMessageBuffer, pvTxData, xDataLengthBytes, xTicksToWait ) \
388 xStreamBufferSend( ( xMessageBuffer ), ( pvTxData ), ( xDataLengthBytes ), ( xTicksToWait ) )
389
495#define xMessageBufferSendFromISR( xMessageBuffer, pvTxData, xDataLengthBytes, pxHigherPriorityTaskWoken ) \
496 xStreamBufferSendFromISR( ( xMessageBuffer ), ( pvTxData ), ( xDataLengthBytes ), ( pxHigherPriorityTaskWoken ) )
497
587#define xMessageBufferReceive( xMessageBuffer, pvRxData, xBufferLengthBytes, xTicksToWait ) \
588 xStreamBufferReceive( ( xMessageBuffer ), ( pvRxData ), ( xBufferLengthBytes ), ( xTicksToWait ) )
589
590
692#define xMessageBufferReceiveFromISR( xMessageBuffer, pvRxData, xBufferLengthBytes, pxHigherPriorityTaskWoken ) \
693 xStreamBufferReceiveFromISR( ( xMessageBuffer ), ( pvRxData ), ( xBufferLengthBytes ), ( pxHigherPriorityTaskWoken ) )
694
716#define vMessageBufferDelete( xMessageBuffer ) \
717 vStreamBufferDelete( xMessageBuffer )
718
737#define xMessageBufferIsFull( xMessageBuffer ) \
738 xStreamBufferIsFull( xMessageBuffer )
739
757#define xMessageBufferIsEmpty( xMessageBuffer ) \
758 xStreamBufferIsEmpty( xMessageBuffer )
759
788#define xMessageBufferReset( xMessageBuffer ) \
789 xStreamBufferReset( xMessageBuffer )
790
791
821#define xMessageBufferResetFromISR( xMessageBuffer ) \
822 xStreamBufferResetFromISR( xMessageBuffer )
823
846#define xMessageBufferSpaceAvailable( xMessageBuffer ) \
847 xStreamBufferSpacesAvailable( xMessageBuffer )
848#define xMessageBufferSpacesAvailable( xMessageBuffer ) \
849 xStreamBufferSpacesAvailable( xMessageBuffer ) /* Corrects typo in original macro name. */
850
871#define xMessageBufferNextLengthBytes( xMessageBuffer ) \
872 xStreamBufferNextMessageLengthBytes( xMessageBuffer )
873
914#define xMessageBufferSendCompletedFromISR( xMessageBuffer, pxHigherPriorityTaskWoken ) \
915 xStreamBufferSendCompletedFromISR( ( xMessageBuffer ), ( pxHigherPriorityTaskWoken ) )
916
958#define xMessageBufferReceiveCompletedFromISR( xMessageBuffer, pxHigherPriorityTaskWoken ) \
959 xStreamBufferReceiveCompletedFromISR( ( xMessageBuffer ), ( pxHigherPriorityTaskWoken ) )
960
961/* *INDENT-OFF* */
962#if defined( __cplusplus )
963 } /* extern "C" */
964#endif
965/* *INDENT-ON* */
966
967#endif /* !defined( FREERTOS_MESSAGE_BUFFER_H ) */
StreamBufferHandle_t MessageBufferHandle_t
Definition message_buffer.h:86
struct StreamBufferDef_t * StreamBufferHandle_t
Definition stream_buffer.h:79