mTower
message_buffer.h
1 /*
2  * FreeRTOS Kernel V10.1.1
3  * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * http://www.FreeRTOS.org
23  * http://aws.amazon.com/freertos
24  *
25  * 1 tab == 4 spaces!
26  */
27 
28 
29 /*
30  * Message buffers build functionality on top of FreeRTOS stream buffers.
31  * Whereas stream buffers are used to send a continuous stream of data from one
32  * task or interrupt to another, message buffers are used to send variable
33  * length discrete messages from one task or interrupt to another. Their
34  * implementation is light weight, making them particularly suited for interrupt
35  * to task and core to core communication scenarios.
36  *
37  * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
38  * implementation (so also the message buffer implementation, as message buffers
39  * are built on top of stream buffers) assumes there is only one task or
40  * interrupt that will write to the buffer (the writer), and only one task or
41  * interrupt that will read from the buffer (the reader). It is safe for the
42  * writer and reader to be different tasks or interrupts, but, unlike other
43  * FreeRTOS objects, it is not safe to have multiple different writers or
44  * multiple different readers. If there are to be multiple different writers
45  * then the application writer must place each call to a writing API function
46  * (such as xMessageBufferSend()) inside a critical section and set the send
47  * block time to 0. Likewise, if there are to be multiple different readers
48  * then the application writer must place each call to a reading API function
49  * (such as xMessageBufferRead()) inside a critical section and set the receive
50  * timeout to 0.
51  *
52  * Message buffers hold variable length messages. To enable that, when a
53  * message is written to the message buffer an additional sizeof( size_t ) bytes
54  * are also written to store the message's length (that happens internally, with
55  * the API function). sizeof( size_t ) is typically 4 bytes on a 32-bit
56  * architecture, so writing a 10 byte message to a message buffer on a 32-bit
57  * architecture will actually reduce the available space in the message buffer
58  * by 14 bytes (10 byte are used by the message, and 4 bytes to hold the length
59  * of the message).
60  */
61 
62 #ifndef FREERTOS_MESSAGE_BUFFER_H
63 #define FREERTOS_MESSAGE_BUFFER_H
64 
65 /* Message buffers are built onto of stream buffers. */
66 #include "stream_buffer.h"
67 
68 #if defined( __cplusplus )
69 extern "C" {
70 #endif
71 
78 typedef void * MessageBufferHandle_t;
79 
80 /*-----------------------------------------------------------*/
81 
138 #define xMessageBufferCreate( xBufferSizeBytes ) ( MessageBufferHandle_t ) xStreamBufferGenericCreate( xBufferSizeBytes, ( size_t ) 0, pdTRUE )
139 
204 #define xMessageBufferCreateStatic( xBufferSizeBytes, pucMessageBufferStorageArea, pxStaticMessageBuffer ) ( MessageBufferHandle_t ) xStreamBufferGenericCreateStatic( xBufferSizeBytes, 0, pdTRUE, pucMessageBufferStorageArea, pxStaticMessageBuffer )
205 
303 #define xMessageBufferSend( xMessageBuffer, pvTxData, xDataLengthBytes, xTicksToWait ) xStreamBufferSend( ( StreamBufferHandle_t ) xMessageBuffer, pvTxData, xDataLengthBytes, xTicksToWait )
304 
407 #define xMessageBufferSendFromISR( xMessageBuffer, pvTxData, xDataLengthBytes, pxHigherPriorityTaskWoken ) xStreamBufferSendFromISR( ( StreamBufferHandle_t ) xMessageBuffer, pvTxData, xDataLengthBytes, pxHigherPriorityTaskWoken )
408 
495 #define xMessageBufferReceive( xMessageBuffer, pvRxData, xBufferLengthBytes, xTicksToWait ) xStreamBufferReceive( ( StreamBufferHandle_t ) xMessageBuffer, pvRxData, xBufferLengthBytes, xTicksToWait )
496 
497 
596 #define xMessageBufferReceiveFromISR( xMessageBuffer, pvRxData, xBufferLengthBytes, pxHigherPriorityTaskWoken ) xStreamBufferReceiveFromISR( ( StreamBufferHandle_t ) xMessageBuffer, pvRxData, xBufferLengthBytes, pxHigherPriorityTaskWoken )
597 
616 #define vMessageBufferDelete( xMessageBuffer ) vStreamBufferDelete( ( StreamBufferHandle_t ) xMessageBuffer )
617 
633 #define xMessageBufferIsFull( xMessageBuffer ) xStreamBufferIsFull( ( StreamBufferHandle_t ) xMessageBuffer )
634 
649 #define xMessageBufferIsEmpty( xMessageBuffer ) xStreamBufferIsEmpty( ( StreamBufferHandle_t ) xMessageBuffer )
650 
672 #define xMessageBufferReset( xMessageBuffer ) xStreamBufferReset( ( StreamBufferHandle_t ) xMessageBuffer )
673 
674 
694 #define xMessageBufferSpaceAvailable( xMessageBuffer ) xStreamBufferSpacesAvailable( ( StreamBufferHandle_t ) xMessageBuffer )
695 
713 #define xMessageBufferNextLengthBytes( xMessageBuffer ) xStreamBufferNextMessageLengthBytes( ( StreamBufferHandle_t ) xMessageBuffer ) PRIVILEGED_FUNCTION;
714 
752 #define xMessageBufferSendCompletedFromISR( xMessageBuffer, pxHigherPriorityTaskWoken ) xStreamBufferSendCompletedFromISR( ( StreamBufferHandle_t ) xMessageBuffer, pxHigherPriorityTaskWoken )
753 
792 #define xMessageBufferReceiveCompletedFromISR( xMessageBuffer, pxHigherPriorityTaskWoken ) xStreamBufferReceiveCompletedFromISR( ( StreamBufferHandle_t ) xMessageBuffer, pxHigherPriorityTaskWoken )
793 
794 #if defined( __cplusplus )
795 } /* extern "C" */
796 #endif
797 
798 #endif /* !defined( FREERTOS_MESSAGE_BUFFER_H ) */