2 * FreeRTOS Kernel V10.4.4
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: MIT
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:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
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.
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
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.
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
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
63 #ifndef FREERTOS_MESSAGE_BUFFER_H
64 #define FREERTOS_MESSAGE_BUFFER_H
66 #ifndef INC_FREERTOS_H
67 #error "include FreeRTOS.h must appear in source files before include message_buffer.h"
70 /* Message buffers are built onto of stream buffers. */
71 #include "stream_buffer.h"
74 #if defined( __cplusplus )
80 * Type by which message buffers are referenced. For example, a call to
81 * xMessageBufferCreate() returns an MessageBufferHandle_t variable that can
82 * then be used as a parameter to xMessageBufferSend(), xMessageBufferReceive(),
85 typedef void * MessageBufferHandle_t;
87 /*-----------------------------------------------------------*/
93 * MessageBufferHandle_t xMessageBufferCreate( size_t xBufferSizeBytes );
96 * Creates a new message buffer using dynamically allocated memory. See
97 * xMessageBufferCreateStatic() for a version that uses statically allocated
98 * memory (memory that is allocated at compile time).
100 * configSUPPORT_DYNAMIC_ALLOCATION must be set to 1 or left undefined in
101 * FreeRTOSConfig.h for xMessageBufferCreate() to be available.
103 * @param xBufferSizeBytes The total number of bytes (not messages) the message
104 * buffer will be able to hold at any one time. When a message is written to
105 * the message buffer an additional sizeof( size_t ) bytes are also written to
106 * store the message's length. sizeof( size_t ) is typically 4 bytes on a
107 * 32-bit architecture, so on most 32-bit architectures a 10 byte message will
108 * take up 14 bytes of message buffer space.
110 * @return If NULL is returned, then the message buffer cannot be created
111 * because there is insufficient heap memory available for FreeRTOS to allocate
112 * the message buffer data structures and storage area. A non-NULL value being
113 * returned indicates that the message buffer has been created successfully -
114 * the returned value should be stored as the handle to the created message
120 * void vAFunction( void )
122 * MessageBufferHandle_t xMessageBuffer;
123 * const size_t xMessageBufferSizeBytes = 100;
125 * // Create a message buffer that can hold 100 bytes. The memory used to hold
126 * // both the message buffer structure and the messages themselves is allocated
127 * // dynamically. Each message added to the buffer consumes an additional 4
128 * // bytes which are used to hold the lengh of the message.
129 * xMessageBuffer = xMessageBufferCreate( xMessageBufferSizeBytes );
131 * if( xMessageBuffer == NULL )
133 * // There was not enough heap memory space available to create the
138 * // The message buffer was created successfully and can now be used.
142 * \defgroup xMessageBufferCreate xMessageBufferCreate
143 * \ingroup MessageBufferManagement
145 #define xMessageBufferCreate( xBufferSizeBytes ) \
146 ( MessageBufferHandle_t ) xStreamBufferGenericCreate( xBufferSizeBytes, ( size_t ) 0, pdTRUE )
152 * MessageBufferHandle_t xMessageBufferCreateStatic( size_t xBufferSizeBytes,
153 * uint8_t *pucMessageBufferStorageArea,
154 * StaticMessageBuffer_t *pxStaticMessageBuffer );
156 * Creates a new message buffer using statically allocated memory. See
157 * xMessageBufferCreate() for a version that uses dynamically allocated memory.
159 * @param xBufferSizeBytes The size, in bytes, of the buffer pointed to by the
160 * pucMessageBufferStorageArea parameter. When a message is written to the
161 * message buffer an additional sizeof( size_t ) bytes are also written to store
162 * the message's length. sizeof( size_t ) is typically 4 bytes on a 32-bit
163 * architecture, so on most 32-bit architecture a 10 byte message will take up
164 * 14 bytes of message buffer space. The maximum number of bytes that can be
165 * stored in the message buffer is actually (xBufferSizeBytes - 1).
167 * @param pucMessageBufferStorageArea Must point to a uint8_t array that is at
168 * least xBufferSizeBytes + 1 big. This is the array to which messages are
169 * copied when they are written to the message buffer.
171 * @param pxStaticMessageBuffer Must point to a variable of type
172 * StaticMessageBuffer_t, which will be used to hold the message buffer's data
175 * @return If the message buffer is created successfully then a handle to the
176 * created message buffer is returned. If either pucMessageBufferStorageArea or
177 * pxStaticmessageBuffer are NULL then NULL is returned.
182 * // Used to dimension the array used to hold the messages. The available space
183 * // will actually be one less than this, so 999.
184 #define STORAGE_SIZE_BYTES 1000
186 * // Defines the memory that will actually hold the messages within the message
188 * static uint8_t ucStorageBuffer[ STORAGE_SIZE_BYTES ];
190 * // The variable used to hold the message buffer structure.
191 * StaticMessageBuffer_t xMessageBufferStruct;
193 * void MyFunction( void )
195 * MessageBufferHandle_t xMessageBuffer;
197 * xMessageBuffer = xMessageBufferCreateStatic( sizeof( ucBufferStorage ),
199 * &xMessageBufferStruct );
201 * // As neither the pucMessageBufferStorageArea or pxStaticMessageBuffer
202 * // parameters were NULL, xMessageBuffer will not be NULL, and can be used to
203 * // reference the created message buffer in other message buffer API calls.
205 * // Other code that uses the message buffer can go here.
209 * \defgroup xMessageBufferCreateStatic xMessageBufferCreateStatic
210 * \ingroup MessageBufferManagement
212 #define xMessageBufferCreateStatic( xBufferSizeBytes, pucMessageBufferStorageArea, pxStaticMessageBuffer ) \
213 ( MessageBufferHandle_t ) xStreamBufferGenericCreateStatic( xBufferSizeBytes, 0, pdTRUE, pucMessageBufferStorageArea, pxStaticMessageBuffer )
219 * size_t xMessageBufferSend( MessageBufferHandle_t xMessageBuffer,
220 * const void *pvTxData,
221 * size_t xDataLengthBytes,
222 * TickType_t xTicksToWait );
225 * Sends a discrete message to the message buffer. The message can be any
226 * length that fits within the buffer's free space, and is copied into the
229 * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
230 * implementation (so also the message buffer implementation, as message buffers
231 * are built on top of stream buffers) assumes there is only one task or
232 * interrupt that will write to the buffer (the writer), and only one task or
233 * interrupt that will read from the buffer (the reader). It is safe for the
234 * writer and reader to be different tasks or interrupts, but, unlike other
235 * FreeRTOS objects, it is not safe to have multiple different writers or
236 * multiple different readers. If there are to be multiple different writers
237 * then the application writer must place each call to a writing API function
238 * (such as xMessageBufferSend()) inside a critical section and set the send
239 * block time to 0. Likewise, if there are to be multiple different readers
240 * then the application writer must place each call to a reading API function
241 * (such as xMessageBufferRead()) inside a critical section and set the receive
244 * Use xMessageBufferSend() to write to a message buffer from a task. Use
245 * xMessageBufferSendFromISR() to write to a message buffer from an interrupt
246 * service routine (ISR).
248 * @param xMessageBuffer The handle of the message buffer to which a message is
251 * @param pvTxData A pointer to the message that is to be copied into the
254 * @param xDataLengthBytes The length of the message. That is, the number of
255 * bytes to copy from pvTxData into the message buffer. When a message is
256 * written to the message buffer an additional sizeof( size_t ) bytes are also
257 * written to store the message's length. sizeof( size_t ) is typically 4 bytes
258 * on a 32-bit architecture, so on most 32-bit architecture setting
259 * xDataLengthBytes to 20 will reduce the free space in the message buffer by 24
260 * bytes (20 bytes of message data and 4 bytes to hold the message length).
262 * @param xTicksToWait The maximum amount of time the calling task should remain
263 * in the Blocked state to wait for enough space to become available in the
264 * message buffer, should the message buffer have insufficient space when
265 * xMessageBufferSend() is called. The calling task will never block if
266 * xTicksToWait is zero. The block time is specified in tick periods, so the
267 * absolute time it represents is dependent on the tick frequency. The macro
268 * pdMS_TO_TICKS() can be used to convert a time specified in milliseconds into
269 * a time specified in ticks. Setting xTicksToWait to portMAX_DELAY will cause
270 * the task to wait indefinitely (without timing out), provided
271 * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. Tasks do not use any
272 * CPU time when they are in the Blocked state.
274 * @return The number of bytes written to the message buffer. If the call to
275 * xMessageBufferSend() times out before there was enough space to write the
276 * message into the message buffer then zero is returned. If the call did not
277 * time out then xDataLengthBytes is returned.
281 * void vAFunction( MessageBufferHandle_t xMessageBuffer )
284 * uint8_t ucArrayToSend[] = { 0, 1, 2, 3 };
285 * char *pcStringToSend = "String to send";
286 * const TickType_t x100ms = pdMS_TO_TICKS( 100 );
288 * // Send an array to the message buffer, blocking for a maximum of 100ms to
289 * // wait for enough space to be available in the message buffer.
290 * xBytesSent = xMessageBufferSend( xMessageBuffer, ( void * ) ucArrayToSend, sizeof( ucArrayToSend ), x100ms );
292 * if( xBytesSent != sizeof( ucArrayToSend ) )
294 * // The call to xMessageBufferSend() times out before there was enough
295 * // space in the buffer for the data to be written.
298 * // Send the string to the message buffer. Return immediately if there is
299 * // not enough space in the buffer.
300 * xBytesSent = xMessageBufferSend( xMessageBuffer, ( void * ) pcStringToSend, strlen( pcStringToSend ), 0 );
302 * if( xBytesSent != strlen( pcStringToSend ) )
304 * // The string could not be added to the message buffer because there was
305 * // not enough free space in the buffer.
309 * \defgroup xMessageBufferSend xMessageBufferSend
310 * \ingroup MessageBufferManagement
312 #define xMessageBufferSend( xMessageBuffer, pvTxData, xDataLengthBytes, xTicksToWait ) \
313 xStreamBufferSend( ( StreamBufferHandle_t ) xMessageBuffer, pvTxData, xDataLengthBytes, xTicksToWait )
319 * size_t xMessageBufferSendFromISR( MessageBufferHandle_t xMessageBuffer,
320 * const void *pvTxData,
321 * size_t xDataLengthBytes,
322 * BaseType_t *pxHigherPriorityTaskWoken );
325 * Interrupt safe version of the API function that sends a discrete message to
326 * the message buffer. The message can be any length that fits within the
327 * buffer's free space, and is copied into the buffer.
329 * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
330 * implementation (so also the message buffer implementation, as message buffers
331 * are built on top of stream buffers) assumes there is only one task or
332 * interrupt that will write to the buffer (the writer), and only one task or
333 * interrupt that will read from the buffer (the reader). It is safe for the
334 * writer and reader to be different tasks or interrupts, but, unlike other
335 * FreeRTOS objects, it is not safe to have multiple different writers or
336 * multiple different readers. If there are to be multiple different writers
337 * then the application writer must place each call to a writing API function
338 * (such as xMessageBufferSend()) inside a critical section and set the send
339 * block time to 0. Likewise, if there are to be multiple different readers
340 * then the application writer must place each call to a reading API function
341 * (such as xMessageBufferRead()) inside a critical section and set the receive
344 * Use xMessageBufferSend() to write to a message buffer from a task. Use
345 * xMessageBufferSendFromISR() to write to a message buffer from an interrupt
346 * service routine (ISR).
348 * @param xMessageBuffer The handle of the message buffer to which a message is
351 * @param pvTxData A pointer to the message that is to be copied into the
354 * @param xDataLengthBytes The length of the message. That is, the number of
355 * bytes to copy from pvTxData into the message buffer. When a message is
356 * written to the message buffer an additional sizeof( size_t ) bytes are also
357 * written to store the message's length. sizeof( size_t ) is typically 4 bytes
358 * on a 32-bit architecture, so on most 32-bit architecture setting
359 * xDataLengthBytes to 20 will reduce the free space in the message buffer by 24
360 * bytes (20 bytes of message data and 4 bytes to hold the message length).
362 * @param pxHigherPriorityTaskWoken It is possible that a message buffer will
363 * have a task blocked on it waiting for data. Calling
364 * xMessageBufferSendFromISR() can make data available, and so cause a task that
365 * was waiting for data to leave the Blocked state. If calling
366 * xMessageBufferSendFromISR() causes a task to leave the Blocked state, and the
367 * unblocked task has a priority higher than the currently executing task (the
368 * task that was interrupted), then, internally, xMessageBufferSendFromISR()
369 * will set *pxHigherPriorityTaskWoken to pdTRUE. If
370 * xMessageBufferSendFromISR() sets this value to pdTRUE, then normally a
371 * context switch should be performed before the interrupt is exited. This will
372 * ensure that the interrupt returns directly to the highest priority Ready
373 * state task. *pxHigherPriorityTaskWoken should be set to pdFALSE before it
374 * is passed into the function. See the code example below for an example.
376 * @return The number of bytes actually written to the message buffer. If the
377 * message buffer didn't have enough free space for the message to be stored
378 * then 0 is returned, otherwise xDataLengthBytes is returned.
382 * // A message buffer that has already been created.
383 * MessageBufferHandle_t xMessageBuffer;
385 * void vAnInterruptServiceRoutine( void )
388 * char *pcStringToSend = "String to send";
389 * BaseType_t xHigherPriorityTaskWoken = pdFALSE; // Initialised to pdFALSE.
391 * // Attempt to send the string to the message buffer.
392 * xBytesSent = xMessageBufferSendFromISR( xMessageBuffer,
393 * ( void * ) pcStringToSend,
394 * strlen( pcStringToSend ),
395 * &xHigherPriorityTaskWoken );
397 * if( xBytesSent != strlen( pcStringToSend ) )
399 * // The string could not be added to the message buffer because there was
400 * // not enough free space in the buffer.
403 * // If xHigherPriorityTaskWoken was set to pdTRUE inside
404 * // xMessageBufferSendFromISR() then a task that has a priority above the
405 * // priority of the currently executing task was unblocked and a context
406 * // switch should be performed to ensure the ISR returns to the unblocked
407 * // task. In most FreeRTOS ports this is done by simply passing
408 * // xHigherPriorityTaskWoken into portYIELD_FROM_ISR(), which will test the
409 * // variables value, and perform the context switch if necessary. Check the
410 * // documentation for the port in use for port specific instructions.
411 * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
414 * \defgroup xMessageBufferSendFromISR xMessageBufferSendFromISR
415 * \ingroup MessageBufferManagement
417 #define xMessageBufferSendFromISR( xMessageBuffer, pvTxData, xDataLengthBytes, pxHigherPriorityTaskWoken ) \
418 xStreamBufferSendFromISR( ( StreamBufferHandle_t ) xMessageBuffer, pvTxData, xDataLengthBytes, pxHigherPriorityTaskWoken )
424 * size_t xMessageBufferReceive( MessageBufferHandle_t xMessageBuffer,
426 * size_t xBufferLengthBytes,
427 * TickType_t xTicksToWait );
430 * Receives a discrete message from a message buffer. Messages can be of
431 * variable length and are copied out of the buffer.
433 * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
434 * implementation (so also the message buffer implementation, as message buffers
435 * are built on top of stream buffers) assumes there is only one task or
436 * interrupt that will write to the buffer (the writer), and only one task or
437 * interrupt that will read from the buffer (the reader). It is safe for the
438 * writer and reader to be different tasks or interrupts, but, unlike other
439 * FreeRTOS objects, it is not safe to have multiple different writers or
440 * multiple different readers. If there are to be multiple different writers
441 * then the application writer must place each call to a writing API function
442 * (such as xMessageBufferSend()) inside a critical section and set the send
443 * block time to 0. Likewise, if there are to be multiple different readers
444 * then the application writer must place each call to a reading API function
445 * (such as xMessageBufferRead()) inside a critical section and set the receive
448 * Use xMessageBufferReceive() to read from a message buffer from a task. Use
449 * xMessageBufferReceiveFromISR() to read from a message buffer from an
450 * interrupt service routine (ISR).
452 * @param xMessageBuffer The handle of the message buffer from which a message
455 * @param pvRxData A pointer to the buffer into which the received message is
458 * @param xBufferLengthBytes The length of the buffer pointed to by the pvRxData
459 * parameter. This sets the maximum length of the message that can be received.
460 * If xBufferLengthBytes is too small to hold the next message then the message
461 * will be left in the message buffer and 0 will be returned.
463 * @param xTicksToWait The maximum amount of time the task should remain in the
464 * Blocked state to wait for a message, should the message buffer be empty.
465 * xMessageBufferReceive() will return immediately if xTicksToWait is zero and
466 * the message buffer is empty. The block time is specified in tick periods, so
467 * the absolute time it represents is dependent on the tick frequency. The
468 * macro pdMS_TO_TICKS() can be used to convert a time specified in milliseconds
469 * into a time specified in ticks. Setting xTicksToWait to portMAX_DELAY will
470 * cause the task to wait indefinitely (without timing out), provided
471 * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. Tasks do not use any
472 * CPU time when they are in the Blocked state.
474 * @return The length, in bytes, of the message read from the message buffer, if
475 * any. If xMessageBufferReceive() times out before a message became available
476 * then zero is returned. If the length of the message is greater than
477 * xBufferLengthBytes then the message will be left in the message buffer and
482 * void vAFunction( MessageBuffer_t xMessageBuffer )
484 * uint8_t ucRxData[ 20 ];
485 * size_t xReceivedBytes;
486 * const TickType_t xBlockTime = pdMS_TO_TICKS( 20 );
488 * // Receive the next message from the message buffer. Wait in the Blocked
489 * // state (so not using any CPU processing time) for a maximum of 100ms for
490 * // a message to become available.
491 * xReceivedBytes = xMessageBufferReceive( xMessageBuffer,
492 * ( void * ) ucRxData,
493 * sizeof( ucRxData ),
496 * if( xReceivedBytes > 0 )
498 * // A ucRxData contains a message that is xReceivedBytes long. Process
499 * // the message here....
503 * \defgroup xMessageBufferReceive xMessageBufferReceive
504 * \ingroup MessageBufferManagement
506 #define xMessageBufferReceive( xMessageBuffer, pvRxData, xBufferLengthBytes, xTicksToWait ) \
507 xStreamBufferReceive( ( StreamBufferHandle_t ) xMessageBuffer, pvRxData, xBufferLengthBytes, xTicksToWait )
514 * size_t xMessageBufferReceiveFromISR( MessageBufferHandle_t xMessageBuffer,
516 * size_t xBufferLengthBytes,
517 * BaseType_t *pxHigherPriorityTaskWoken );
520 * An interrupt safe version of the API function that receives a discrete
521 * message from a message buffer. Messages can be of variable length and are
522 * copied out of the buffer.
524 * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
525 * implementation (so also the message buffer implementation, as message buffers
526 * are built on top of stream buffers) assumes there is only one task or
527 * interrupt that will write to the buffer (the writer), and only one task or
528 * interrupt that will read from the buffer (the reader). It is safe for the
529 * writer and reader to be different tasks or interrupts, but, unlike other
530 * FreeRTOS objects, it is not safe to have multiple different writers or
531 * multiple different readers. If there are to be multiple different writers
532 * then the application writer must place each call to a writing API function
533 * (such as xMessageBufferSend()) inside a critical section and set the send
534 * block time to 0. Likewise, if there are to be multiple different readers
535 * then the application writer must place each call to a reading API function
536 * (such as xMessageBufferRead()) inside a critical section and set the receive
539 * Use xMessageBufferReceive() to read from a message buffer from a task. Use
540 * xMessageBufferReceiveFromISR() to read from a message buffer from an
541 * interrupt service routine (ISR).
543 * @param xMessageBuffer The handle of the message buffer from which a message
546 * @param pvRxData A pointer to the buffer into which the received message is
549 * @param xBufferLengthBytes The length of the buffer pointed to by the pvRxData
550 * parameter. This sets the maximum length of the message that can be received.
551 * If xBufferLengthBytes is too small to hold the next message then the message
552 * will be left in the message buffer and 0 will be returned.
554 * @param pxHigherPriorityTaskWoken It is possible that a message buffer will
555 * have a task blocked on it waiting for space to become available. Calling
556 * xMessageBufferReceiveFromISR() can make space available, and so cause a task
557 * that is waiting for space to leave the Blocked state. If calling
558 * xMessageBufferReceiveFromISR() causes a task to leave the Blocked state, and
559 * the unblocked task has a priority higher than the currently executing task
560 * (the task that was interrupted), then, internally,
561 * xMessageBufferReceiveFromISR() will set *pxHigherPriorityTaskWoken to pdTRUE.
562 * If xMessageBufferReceiveFromISR() sets this value to pdTRUE, then normally a
563 * context switch should be performed before the interrupt is exited. That will
564 * ensure the interrupt returns directly to the highest priority Ready state
565 * task. *pxHigherPriorityTaskWoken should be set to pdFALSE before it is
566 * passed into the function. See the code example below for an example.
568 * @return The length, in bytes, of the message read from the message buffer, if
573 * // A message buffer that has already been created.
574 * MessageBuffer_t xMessageBuffer;
576 * void vAnInterruptServiceRoutine( void )
578 * uint8_t ucRxData[ 20 ];
579 * size_t xReceivedBytes;
580 * BaseType_t xHigherPriorityTaskWoken = pdFALSE; // Initialised to pdFALSE.
582 * // Receive the next message from the message buffer.
583 * xReceivedBytes = xMessageBufferReceiveFromISR( xMessageBuffer,
584 * ( void * ) ucRxData,
585 * sizeof( ucRxData ),
586 * &xHigherPriorityTaskWoken );
588 * if( xReceivedBytes > 0 )
590 * // A ucRxData contains a message that is xReceivedBytes long. Process
591 * // the message here....
594 * // If xHigherPriorityTaskWoken was set to pdTRUE inside
595 * // xMessageBufferReceiveFromISR() then a task that has a priority above the
596 * // priority of the currently executing task was unblocked and a context
597 * // switch should be performed to ensure the ISR returns to the unblocked
598 * // task. In most FreeRTOS ports this is done by simply passing
599 * // xHigherPriorityTaskWoken into portYIELD_FROM_ISR(), which will test the
600 * // variables value, and perform the context switch if necessary. Check the
601 * // documentation for the port in use for port specific instructions.
602 * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
605 * \defgroup xMessageBufferReceiveFromISR xMessageBufferReceiveFromISR
606 * \ingroup MessageBufferManagement
608 #define xMessageBufferReceiveFromISR( xMessageBuffer, pvRxData, xBufferLengthBytes, pxHigherPriorityTaskWoken ) \
609 xStreamBufferReceiveFromISR( ( StreamBufferHandle_t ) xMessageBuffer, pvRxData, xBufferLengthBytes, pxHigherPriorityTaskWoken )
615 * void vMessageBufferDelete( MessageBufferHandle_t xMessageBuffer );
618 * Deletes a message buffer that was previously created using a call to
619 * xMessageBufferCreate() or xMessageBufferCreateStatic(). If the message
620 * buffer was created using dynamic memory (that is, by xMessageBufferCreate()),
621 * then the allocated memory is freed.
623 * A message buffer handle must not be used after the message buffer has been
626 * @param xMessageBuffer The handle of the message buffer to be deleted.
629 #define vMessageBufferDelete( xMessageBuffer ) \
630 vStreamBufferDelete( ( StreamBufferHandle_t ) xMessageBuffer )
635 * BaseType_t xMessageBufferIsFull( MessageBufferHandle_t xMessageBuffer );
638 * Tests to see if a message buffer is full. A message buffer is full if it
639 * cannot accept any more messages, of any size, until space is made available
640 * by a message being removed from the message buffer.
642 * @param xMessageBuffer The handle of the message buffer being queried.
644 * @return If the message buffer referenced by xMessageBuffer is full then
645 * pdTRUE is returned. Otherwise pdFALSE is returned.
647 #define xMessageBufferIsFull( xMessageBuffer ) \
648 xStreamBufferIsFull( ( StreamBufferHandle_t ) xMessageBuffer )
653 * BaseType_t xMessageBufferIsEmpty( MessageBufferHandle_t xMessageBuffer );
656 * Tests to see if a message buffer is empty (does not contain any messages).
658 * @param xMessageBuffer The handle of the message buffer being queried.
660 * @return If the message buffer referenced by xMessageBuffer is empty then
661 * pdTRUE is returned. Otherwise pdFALSE is returned.
664 #define xMessageBufferIsEmpty( xMessageBuffer ) \
665 xStreamBufferIsEmpty( ( StreamBufferHandle_t ) xMessageBuffer )
670 * BaseType_t xMessageBufferReset( MessageBufferHandle_t xMessageBuffer );
673 * Resets a message buffer to its initial empty state, discarding any message it
676 * A message buffer can only be reset if there are no tasks blocked on it.
678 * @param xMessageBuffer The handle of the message buffer being reset.
680 * @return If the message buffer was reset then pdPASS is returned. If the
681 * message buffer could not be reset because either there was a task blocked on
682 * the message queue to wait for space to become available, or to wait for a
683 * a message to be available, then pdFAIL is returned.
685 * \defgroup xMessageBufferReset xMessageBufferReset
686 * \ingroup MessageBufferManagement
688 #define xMessageBufferReset( xMessageBuffer ) \
689 xStreamBufferReset( ( StreamBufferHandle_t ) xMessageBuffer )
695 * size_t xMessageBufferSpaceAvailable( MessageBufferHandle_t xMessageBuffer );
697 * Returns the number of bytes of free space in the message buffer.
699 * @param xMessageBuffer The handle of the message buffer being queried.
701 * @return The number of bytes that can be written to the message buffer before
702 * the message buffer would be full. When a message is written to the message
703 * buffer an additional sizeof( size_t ) bytes are also written to store the
704 * message's length. sizeof( size_t ) is typically 4 bytes on a 32-bit
705 * architecture, so if xMessageBufferSpacesAvailable() returns 10, then the size
706 * of the largest message that can be written to the message buffer is 6 bytes.
708 * \defgroup xMessageBufferSpaceAvailable xMessageBufferSpaceAvailable
709 * \ingroup MessageBufferManagement
711 #define xMessageBufferSpaceAvailable( xMessageBuffer ) \
712 xStreamBufferSpacesAvailable( ( StreamBufferHandle_t ) xMessageBuffer )
713 #define xMessageBufferSpacesAvailable( xMessageBuffer ) \
714 xStreamBufferSpacesAvailable( ( StreamBufferHandle_t ) xMessageBuffer ) /* Corrects typo in original macro name. */
719 * size_t xMessageBufferNextLengthBytes( MessageBufferHandle_t xMessageBuffer );
721 * Returns the length (in bytes) of the next message in a message buffer.
722 * Useful if xMessageBufferReceive() returned 0 because the size of the buffer
723 * passed into xMessageBufferReceive() was too small to hold the next message.
725 * @param xMessageBuffer The handle of the message buffer being queried.
727 * @return The length (in bytes) of the next message in the message buffer, or 0
728 * if the message buffer is empty.
730 * \defgroup xMessageBufferNextLengthBytes xMessageBufferNextLengthBytes
731 * \ingroup MessageBufferManagement
733 #define xMessageBufferNextLengthBytes( xMessageBuffer ) \
734 xStreamBufferNextMessageLengthBytes( ( StreamBufferHandle_t ) xMessageBuffer ) PRIVILEGED_FUNCTION;
740 * BaseType_t xMessageBufferSendCompletedFromISR( MessageBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken );
743 * For advanced users only.
745 * The sbSEND_COMPLETED() macro is called from within the FreeRTOS APIs when
746 * data is sent to a message buffer or stream buffer. If there was a task that
747 * was blocked on the message or stream buffer waiting for data to arrive then
748 * the sbSEND_COMPLETED() macro sends a notification to the task to remove it
749 * from the Blocked state. xMessageBufferSendCompletedFromISR() does the same
750 * thing. It is provided to enable application writers to implement their own
751 * version of sbSEND_COMPLETED(), and MUST NOT BE USED AT ANY OTHER TIME.
753 * See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for
754 * additional information.
756 * @param xStreamBuffer The handle of the stream buffer to which data was
759 * @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be
760 * initialised to pdFALSE before it is passed into
761 * xMessageBufferSendCompletedFromISR(). If calling
762 * xMessageBufferSendCompletedFromISR() removes a task from the Blocked state,
763 * and the task has a priority above the priority of the currently running task,
764 * then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a
765 * context switch should be performed before exiting the ISR.
767 * @return If a task was removed from the Blocked state then pdTRUE is returned.
768 * Otherwise pdFALSE is returned.
770 * \defgroup xMessageBufferSendCompletedFromISR xMessageBufferSendCompletedFromISR
771 * \ingroup StreamBufferManagement
773 #define xMessageBufferSendCompletedFromISR( xMessageBuffer, pxHigherPriorityTaskWoken ) \
774 xStreamBufferSendCompletedFromISR( ( StreamBufferHandle_t ) xMessageBuffer, pxHigherPriorityTaskWoken )
780 * BaseType_t xMessageBufferReceiveCompletedFromISR( MessageBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken );
783 * For advanced users only.
785 * The sbRECEIVE_COMPLETED() macro is called from within the FreeRTOS APIs when
786 * data is read out of a message buffer or stream buffer. If there was a task
787 * that was blocked on the message or stream buffer waiting for data to arrive
788 * then the sbRECEIVE_COMPLETED() macro sends a notification to the task to
789 * remove it from the Blocked state. xMessageBufferReceiveCompletedFromISR()
790 * does the same thing. It is provided to enable application writers to
791 * implement their own version of sbRECEIVE_COMPLETED(), and MUST NOT BE USED AT
794 * See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for
795 * additional information.
797 * @param xStreamBuffer The handle of the stream buffer from which data was
800 * @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be
801 * initialised to pdFALSE before it is passed into
802 * xMessageBufferReceiveCompletedFromISR(). If calling
803 * xMessageBufferReceiveCompletedFromISR() removes a task from the Blocked state,
804 * and the task has a priority above the priority of the currently running task,
805 * then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a
806 * context switch should be performed before exiting the ISR.
808 * @return If a task was removed from the Blocked state then pdTRUE is returned.
809 * Otherwise pdFALSE is returned.
811 * \defgroup xMessageBufferReceiveCompletedFromISR xMessageBufferReceiveCompletedFromISR
812 * \ingroup StreamBufferManagement
814 #define xMessageBufferReceiveCompletedFromISR( xMessageBuffer, pxHigherPriorityTaskWoken ) \
815 xStreamBufferReceiveCompletedFromISR( ( StreamBufferHandle_t ) xMessageBuffer, pxHigherPriorityTaskWoken )
818 #if defined( __cplusplus )
823 #endif /* !defined( FREERTOS_MESSAGE_BUFFER_H ) */