ZestCode
 
Loading...
Searching...
No Matches
message_buffer.h
1/*
2 * FreeRTOS Kernel V10.0.1
3 * Copyright (C) 2017 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 msg_buf_send()) 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 )
69extern "C" {
70#endif
71
78typedef void * msg_buf_t;
79
80/*-----------------------------------------------------------*/
81
138#define xMessageBufferCreate( xBufferSizeBytes ) ( msg_buf_t ) xStreamBufferGenericCreate( xBufferSizeBytes, ( size_t ) 0, pdTRUE )
139
204#define xMessageBufferCreateStatic( xBufferSizeBytes, pucMessageBufferStorageArea, pxStaticMessageBuffer ) ( msg_buf_t ) xStreamBufferGenericCreateStatic( xBufferSizeBytes, 0, pdTRUE, pucMessageBufferStorageArea, pxStaticMessageBuffer )
205
303#define msg_buf_send( xMessageBuffer, pvTxData, xDataLengthBytes, xTicksToWait ) stream_buf_send( ( stream_buf_t ) xMessageBuffer, pvTxData, xDataLengthBytes, xTicksToWait )
304
407#define xMessageBufferSendFromISR( xMessageBuffer, pvTxData, xDataLengthBytes, pxHigherPriorityTaskWoken ) xStreamBufferSendFromISR( ( stream_buf_t ) xMessageBuffer, pvTxData, xDataLengthBytes, pxHigherPriorityTaskWoken )
408
495#define msg_buf_recv( xMessageBuffer, pvRxData, xBufferLengthBytes, xTicksToWait ) stream_buf_recv( ( stream_buf_t ) xMessageBuffer, pvRxData, xBufferLengthBytes, xTicksToWait )
496
497
596#define xMessageBufferReceiveFromISR( xMessageBuffer, pvRxData, xBufferLengthBytes, pxHigherPriorityTaskWoken ) xStreamBufferReceiveFromISR( ( stream_buf_t ) xMessageBuffer, pvRxData, xBufferLengthBytes, pxHigherPriorityTaskWoken )
597
616#define vMessageBufferDelete( xMessageBuffer ) vStreamBufferDelete( ( stream_buf_t ) xMessageBuffer )
617
633#define msg_buf_is_full( xMessageBuffer ) stream_buf_is_full( ( stream_buf_t ) xMessageBuffer )
634
649#define msg_buf_is_empty( xMessageBuffer ) stream_buf_is_empty( ( stream_buf_t ) xMessageBuffer )
650
672#define msg_buf_reset( xMessageBuffer ) stream_buf_reset( ( stream_buf_t ) xMessageBuffer )
673
674
694#define xMessageBufferSpaceAvailable( xMessageBuffer ) stream_buf_get_unused( ( stream_buf_t ) xMessageBuffer )
695
733#define xMessageBufferSendCompletedFromISR( xMessageBuffer, pxHigherPriorityTaskWoken ) xStreamBufferSendCompletedFromISR( ( stream_buf_t ) xMessageBuffer, pxHigherPriorityTaskWoken )
734
773#define xMessageBufferReceiveCompletedFromISR( xMessageBuffer, pxHigherPriorityTaskWoken ) xStreamBufferReceiveCompletedFromISR( ( stream_buf_t ) xMessageBuffer, pxHigherPriorityTaskWoken )
774
775#if defined( __cplusplus )
776} /* extern "C" */
777#endif
778
779#endif /* !defined( FREERTOS_MESSAGE_BUFFER_H ) */