2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
29 /* Standard includes. */
\r
33 /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
\r
34 all the API functions to use the MPU wrappers. That should only be done when
\r
35 task.h is included from an application file. */
\r
36 #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
\r
38 /* FreeRTOS includes. */
\r
39 #include "FreeRTOS.h"
\r
41 #include "stream_buffer.h"
\r
43 /* Lint e961 and e750 are suppressed as a MISRA exception justified because the
\r
44 MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the
\r
45 header files above, but not in this file, in order to generate the correct
\r
46 privileged Vs unprivileged linkage and placement. */
\r
47 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */
\r
49 /* If the user has not provided application specific Rx notification macros,
\r
50 or #defined the notification macros away, them provide default implementations
\r
51 that uses task notifications. */
\r
52 /*lint -save -e9026 Function like macros allowed and needed here so they can be overidden. */
\r
53 #ifndef sbRECEIVE_COMPLETED
\r
54 #define sbRECEIVE_COMPLETED( pxStreamBuffer ) \
\r
55 vTaskSuspendAll(); \
\r
57 if( ( pxStreamBuffer )->xTaskWaitingToSend != NULL ) \
\r
59 ( void ) xTaskNotify( ( pxStreamBuffer )->xTaskWaitingToSend, \
\r
62 ( pxStreamBuffer )->xTaskWaitingToSend = NULL; \
\r
65 ( void ) xTaskResumeAll();
\r
66 #endif /* sbRECEIVE_COMPLETED */
\r
68 #ifndef sbRECEIVE_COMPLETED_FROM_ISR
\r
69 #define sbRECEIVE_COMPLETED_FROM_ISR( pxStreamBuffer, \
\r
70 pxHigherPriorityTaskWoken ) \
\r
72 UBaseType_t uxSavedInterruptStatus; \
\r
74 uxSavedInterruptStatus = ( UBaseType_t ) portSET_INTERRUPT_MASK_FROM_ISR(); \
\r
76 if( ( pxStreamBuffer )->xTaskWaitingToSend != NULL ) \
\r
78 ( void ) xTaskNotifyFromISR( ( pxStreamBuffer )->xTaskWaitingToSend, \
\r
81 pxHigherPriorityTaskWoken ); \
\r
82 ( pxStreamBuffer )->xTaskWaitingToSend = NULL; \
\r
85 portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); \
\r
87 #endif /* sbRECEIVE_COMPLETED_FROM_ISR */
\r
89 /* If the user has not provided an application specific Tx notification macro,
\r
90 or #defined the notification macro away, them provide a default implementation
\r
91 that uses task notifications. */
\r
92 #ifndef sbSEND_COMPLETED
\r
93 #define sbSEND_COMPLETED( pxStreamBuffer ) \
\r
94 vTaskSuspendAll(); \
\r
96 if( ( pxStreamBuffer )->xTaskWaitingToReceive != NULL ) \
\r
98 ( void ) xTaskNotify( ( pxStreamBuffer )->xTaskWaitingToReceive, \
\r
101 ( pxStreamBuffer )->xTaskWaitingToReceive = NULL; \
\r
104 ( void ) xTaskResumeAll();
\r
105 #endif /* sbSEND_COMPLETED */
\r
107 #ifndef sbSEND_COMPLETE_FROM_ISR
\r
108 #define sbSEND_COMPLETE_FROM_ISR( pxStreamBuffer, pxHigherPriorityTaskWoken ) \
\r
110 UBaseType_t uxSavedInterruptStatus; \
\r
112 uxSavedInterruptStatus = ( UBaseType_t ) portSET_INTERRUPT_MASK_FROM_ISR(); \
\r
114 if( ( pxStreamBuffer )->xTaskWaitingToReceive != NULL ) \
\r
116 ( void ) xTaskNotifyFromISR( ( pxStreamBuffer )->xTaskWaitingToReceive, \
\r
119 pxHigherPriorityTaskWoken ); \
\r
120 ( pxStreamBuffer )->xTaskWaitingToReceive = NULL; \
\r
123 portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); \
\r
125 #endif /* sbSEND_COMPLETE_FROM_ISR */
\r
126 /*lint -restore (9026) */
\r
128 /* The number of bytes used to hold the length of a message in the buffer. */
\r
129 #define sbBYTES_TO_STORE_MESSAGE_LENGTH ( sizeof( size_t ) )
\r
131 /* Bits stored in the ucFlags field of the stream buffer. */
\r
132 #define sbFLAGS_IS_MESSAGE_BUFFER ( ( uint8_t ) 1 ) /* Set if the stream buffer was created as a message buffer, in which case it holds discrete messages rather than a stream. */
\r
133 #define sbFLAGS_IS_STATICALLY_ALLOCATED ( ( uint8_t ) 2 ) /* Set if the stream buffer was created using statically allocated memory. */
\r
135 /*-----------------------------------------------------------*/
\r
137 /* Structure that hold state information on the buffer. */
\r
138 typedef struct xSTREAM_BUFFER /*lint !e9058 Style convention uses tag. */
\r
140 volatile size_t xTail; /* Index to the next item to read within the buffer. */
\r
141 volatile size_t xHead; /* Index to the next item to write within the buffer. */
\r
142 size_t xLength; /* The length of the buffer pointed to by pucBuffer. */
\r
143 size_t xTriggerLevelBytes; /* The number of bytes that must be in the stream buffer before a task that is waiting for data is unblocked. */
\r
144 volatile TaskHandle_t xTaskWaitingToReceive; /* Holds the handle of a task waiting for data, or NULL if no tasks are waiting. */
\r
145 volatile TaskHandle_t xTaskWaitingToSend; /* Holds the handle of a task waiting to send data to a message buffer that is full. */
\r
146 uint8_t *pucBuffer; /* Points to the buffer itself - that is - the RAM that stores the data passed through the buffer. */
\r
149 #if ( configUSE_TRACE_FACILITY == 1 )
\r
150 UBaseType_t uxStreamBufferNumber; /* Used for tracing purposes. */
\r
155 * The number of bytes available to be read from the buffer.
\r
157 static size_t prvBytesInBuffer( const StreamBuffer_t * const pxStreamBuffer ) PRIVILEGED_FUNCTION;
\r
160 * Add xCount bytes from pucData into the pxStreamBuffer message buffer.
\r
161 * Returns the number of bytes written, which will either equal xCount in the
\r
162 * success case, or 0 if there was not enough space in the buffer (in which case
\r
163 * no data is written into the buffer).
\r
165 static size_t prvWriteBytesToBuffer( StreamBuffer_t * const pxStreamBuffer, const uint8_t *pucData, size_t xCount ) PRIVILEGED_FUNCTION;
\r
168 * If the stream buffer is being used as a message buffer, then reads an entire
\r
169 * message out of the buffer. If the stream buffer is being used as a stream
\r
170 * buffer then read as many bytes as possible from the buffer.
\r
171 * prvReadBytesFromBuffer() is called to actually extract the bytes from the
\r
172 * buffer's data storage area.
\r
174 static size_t prvReadMessageFromBuffer( StreamBuffer_t *pxStreamBuffer,
\r
176 size_t xBufferLengthBytes,
\r
177 size_t xBytesAvailable,
\r
178 size_t xBytesToStoreMessageLength ) PRIVILEGED_FUNCTION;
\r
181 * If the stream buffer is being used as a message buffer, then writes an entire
\r
182 * message to the buffer. If the stream buffer is being used as a stream
\r
183 * buffer then write as many bytes as possible to the buffer.
\r
184 * prvWriteBytestoBuffer() is called to actually send the bytes to the buffer's
\r
185 * data storage area.
\r
187 static size_t prvWriteMessageToBuffer( StreamBuffer_t * const pxStreamBuffer,
\r
188 const void * pvTxData,
\r
189 size_t xDataLengthBytes,
\r
191 size_t xRequiredSpace ) PRIVILEGED_FUNCTION;
\r
194 * Read xMaxCount bytes from the pxStreamBuffer message buffer and write them
\r
197 static size_t prvReadBytesFromBuffer( StreamBuffer_t *pxStreamBuffer,
\r
200 size_t xBytesAvailable ); PRIVILEGED_FUNCTION
\r
203 * Called by both pxStreamBufferCreate() and pxStreamBufferCreateStatic() to
\r
204 * initialise the members of the newly created stream buffer structure.
\r
206 static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
\r
207 uint8_t * const pucBuffer,
\r
208 size_t xBufferSizeBytes,
\r
209 size_t xTriggerLevelBytes,
\r
210 BaseType_t xIsMessageBuffer ) PRIVILEGED_FUNCTION;
\r
212 /*-----------------------------------------------------------*/
\r
214 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
\r
216 StreamBufferHandle_t xStreamBufferGenericCreate( size_t xBufferSizeBytes, size_t xTriggerLevelBytes, BaseType_t xIsMessageBuffer )
\r
218 uint8_t *pucAllocatedMemory;
\r
220 /* In case the stream buffer is going to be used as a message buffer
\r
221 (that is, it will hold discrete messages with a little meta data that
\r
222 says how big the next message is) check the buffer will be large enough
\r
223 to hold at least one message. */
\r
224 configASSERT( xBufferSizeBytes > sbBYTES_TO_STORE_MESSAGE_LENGTH );
\r
225 configASSERT( xTriggerLevelBytes <= xBufferSizeBytes );
\r
227 /* A trigger level of 0 would cause a waiting task to unblock even when
\r
228 the buffer was empty. */
\r
229 if( xTriggerLevelBytes == ( size_t ) 0 )
\r
231 xTriggerLevelBytes = ( size_t ) 1; /*lint !e9044 Parameter modified to ensure it doesn't have a dangerous value. */
\r
234 /* A stream buffer requires a StreamBuffer_t structure and a buffer.
\r
235 Both are allocated in a single call to pvPortMalloc(). The
\r
236 StreamBuffer_t structure is placed at the start of the allocated memory
\r
237 and the buffer follows immediately after. The requested size is
\r
238 incremented so the free space is returned as the user would expect -
\r
239 this is a quirk of the implementation that means otherwise the free
\r
240 space would be reported as one byte smaller than would be logically
\r
242 xBufferSizeBytes++;
\r
243 pucAllocatedMemory = ( uint8_t * ) pvPortMalloc( xBufferSizeBytes + sizeof( StreamBuffer_t ) ); /*lint !e9079 malloc() only returns void*. */
\r
245 if( pucAllocatedMemory != NULL )
\r
247 prvInitialiseNewStreamBuffer( ( StreamBuffer_t * ) pucAllocatedMemory, /* Structure at the start of the allocated memory. */ /*lint !e9087 Safe cast as allocated memory is aligned. */ /*lint !e826 Area is not too small and alignment is guaranteed provided malloc() behaves as expected and returns aligned buffer. */
\r
248 pucAllocatedMemory + sizeof( StreamBuffer_t ), /* Storage area follows. */ /*lint !e9016 Indexing past structure valid for uint8_t pointer, also storage area has no alignment requirement. */
\r
250 xTriggerLevelBytes,
\r
251 xIsMessageBuffer );
\r
253 traceSTREAM_BUFFER_CREATE( ( ( StreamBuffer_t * ) pucAllocatedMemory ), xIsMessageBuffer );
\r
257 traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer );
\r
260 return ( StreamBufferHandle_t * ) pucAllocatedMemory; /*lint !e9087 !e826 Safe cast as allocated memory is aligned. */
\r
263 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
\r
264 /*-----------------------------------------------------------*/
\r
266 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
\r
268 StreamBufferHandle_t xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes,
\r
269 size_t xTriggerLevelBytes,
\r
270 BaseType_t xIsMessageBuffer,
\r
271 uint8_t * const pucStreamBufferStorageArea,
\r
272 StaticStreamBuffer_t * const pxStaticStreamBuffer )
\r
274 StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) pxStaticStreamBuffer; /*lint !e740 !e9087 Safe cast as StaticStreamBuffer_t is opaque Streambuffer_t. */
\r
275 StreamBufferHandle_t xReturn;
\r
277 configASSERT( pucStreamBufferStorageArea );
\r
278 configASSERT( pxStaticStreamBuffer );
\r
279 configASSERT( xTriggerLevelBytes <= xBufferSizeBytes );
\r
281 /* A trigger level of 0 would cause a waiting task to unblock even when
\r
282 the buffer was empty. */
\r
283 if( xTriggerLevelBytes == ( size_t ) 0 )
\r
285 xTriggerLevelBytes = ( size_t ) 1; /*lint !e9044 Function parameter deliberately modified to ensure it is in range. */
\r
288 /* In case the stream buffer is going to be used as a message buffer
\r
289 (that is, it will hold discrete messages with a little meta data that
\r
290 says how big the next message is) check the buffer will be large enough
\r
291 to hold at least one message. */
\r
292 configASSERT( xBufferSizeBytes > sbBYTES_TO_STORE_MESSAGE_LENGTH );
\r
294 #if( configASSERT_DEFINED == 1 )
\r
296 /* Sanity check that the size of the structure used to declare a
\r
297 variable of type StaticStreamBuffer_t equals the size of the real
\r
298 message buffer structure. */
\r
299 volatile size_t xSize = sizeof( StaticStreamBuffer_t );
\r
300 configASSERT( xSize == sizeof( StreamBuffer_t ) );
\r
302 #endif /* configASSERT_DEFINED */
\r
304 if( ( pucStreamBufferStorageArea != NULL ) && ( pxStaticStreamBuffer != NULL ) )
\r
306 prvInitialiseNewStreamBuffer( pxStreamBuffer,
\r
307 pucStreamBufferStorageArea,
\r
309 xTriggerLevelBytes,
\r
310 xIsMessageBuffer );
\r
312 /* Remember this was statically allocated in case it is ever deleted
\r
314 pxStreamBuffer->ucFlags |= sbFLAGS_IS_STATICALLY_ALLOCATED;
\r
316 traceSTREAM_BUFFER_CREATE( pxStreamBuffer, xIsMessageBuffer );
\r
318 xReturn = ( StreamBufferHandle_t ) pxStaticStreamBuffer; /*lint !e9087 Data hiding requires cast to opaque type. */
\r
323 traceSTREAM_BUFFER_CREATE_STATIC_FAILED( xReturn, xIsMessageBuffer );
\r
329 #endif /* ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
\r
330 /*-----------------------------------------------------------*/
\r
332 void vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer )
\r
334 StreamBuffer_t * pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */
\r
336 configASSERT( pxStreamBuffer );
\r
338 traceSTREAM_BUFFER_DELETE( xStreamBuffer );
\r
340 if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_STATICALLY_ALLOCATED ) == ( uint8_t ) pdFALSE )
\r
342 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
\r
344 /* Both the structure and the buffer were allocated using a single call
\r
345 to pvPortMalloc(), hence only one call to vPortFree() is required. */
\r
346 vPortFree( ( void * ) pxStreamBuffer ); /*lint !e9087 Standard free() semantics require void *, plus pxStreamBuffer was allocated by pvPortMalloc(). */
\r
350 /* Should not be possible to get here, ucFlags must be corrupt.
\r
351 Force an assert. */
\r
352 configASSERT( xStreamBuffer == ( StreamBufferHandle_t ) ~0 );
\r
358 /* The structure and buffer were not allocated dynamically and cannot be
\r
359 freed - just scrub the structure so future use will assert. */
\r
360 memset( pxStreamBuffer, 0x00, sizeof( StreamBuffer_t ) );
\r
363 /*-----------------------------------------------------------*/
\r
365 BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer )
\r
367 StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */
\r
368 BaseType_t xReturn = pdFAIL, xIsMessageBuffer;
\r
370 #if( configUSE_TRACE_FACILITY == 1 )
\r
371 UBaseType_t uxStreamBufferNumber;
\r
374 configASSERT( pxStreamBuffer );
\r
376 #if( configUSE_TRACE_FACILITY == 1 )
\r
378 /* Store the stream buffer number so it can be restored after the
\r
380 uxStreamBufferNumber = pxStreamBuffer->uxStreamBufferNumber;
\r
384 /* Can only reset a message buffer if there are no tasks blocked on it. */
\r
385 if( pxStreamBuffer->xTaskWaitingToReceive == NULL )
\r
387 if( pxStreamBuffer->xTaskWaitingToSend == NULL )
\r
389 if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 )
\r
391 xIsMessageBuffer = pdTRUE;
\r
395 xIsMessageBuffer = pdFALSE;
\r
398 prvInitialiseNewStreamBuffer( pxStreamBuffer,
\r
399 pxStreamBuffer->pucBuffer,
\r
400 pxStreamBuffer->xLength,
\r
401 pxStreamBuffer->xTriggerLevelBytes,
\r
402 xIsMessageBuffer );
\r
405 #if( configUSE_TRACE_FACILITY == 1 )
\r
407 pxStreamBuffer->uxStreamBufferNumber = uxStreamBufferNumber;
\r
411 traceSTREAM_BUFFER_RESET( xStreamBuffer );
\r
417 /*-----------------------------------------------------------*/
\r
419 BaseType_t xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer, size_t xTriggerLevel )
\r
421 StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */
\r
422 BaseType_t xReturn;
\r
424 configASSERT( pxStreamBuffer );
\r
426 /* It is not valid for the trigger level to be 0. */
\r
427 if( xTriggerLevel == ( size_t ) 0 )
\r
429 xTriggerLevel = ( size_t ) 1; /*lint !e9044 Parameter modified to ensure it doesn't have a dangerous value. */
\r
432 /* The trigger level is the number of bytes that must be in the stream
\r
433 buffer before a task that is waiting for data is unblocked. */
\r
434 if( xTriggerLevel <= pxStreamBuffer->xLength )
\r
436 pxStreamBuffer->xTriggerLevelBytes = xTriggerLevel;
\r
446 /*-----------------------------------------------------------*/
\r
448 size_t xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer )
\r
450 const StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */
\r
453 configASSERT( pxStreamBuffer );
\r
455 xSpace = pxStreamBuffer->xLength + pxStreamBuffer->xTail;
\r
456 xSpace -= pxStreamBuffer->xHead;
\r
457 xSpace -= ( size_t ) 1;
\r
459 if( xSpace >= pxStreamBuffer->xLength )
\r
461 xSpace -= pxStreamBuffer->xLength;
\r
465 mtCOVERAGE_TEST_MARKER();
\r
470 /*-----------------------------------------------------------*/
\r
472 size_t xStreamBufferBytesAvailable( StreamBufferHandle_t xStreamBuffer )
\r
474 const StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */
\r
477 configASSERT( pxStreamBuffer );
\r
479 xReturn = prvBytesInBuffer( pxStreamBuffer );
\r
482 /*-----------------------------------------------------------*/
\r
484 size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer,
\r
485 const void *pvTxData,
\r
486 size_t xDataLengthBytes,
\r
487 TickType_t xTicksToWait )
\r
489 StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */
\r
490 size_t xReturn, xSpace = 0;
\r
491 size_t xRequiredSpace = xDataLengthBytes;
\r
492 TimeOut_t xTimeOut;
\r
494 configASSERT( pvTxData );
\r
495 configASSERT( pxStreamBuffer );
\r
497 /* This send function is used to write to both message buffers and stream
\r
498 buffers. If this is a message buffer then the space needed must be
\r
499 increased by the amount of bytes needed to store the length of the
\r
501 if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 )
\r
503 xRequiredSpace += sbBYTES_TO_STORE_MESSAGE_LENGTH;
\r
507 mtCOVERAGE_TEST_MARKER();
\r
510 if( xTicksToWait != ( TickType_t ) 0 )
\r
512 vTaskSetTimeOutState( &xTimeOut );
\r
516 /* Wait until the required number of bytes are free in the message
\r
518 taskENTER_CRITICAL();
\r
520 xSpace = xStreamBufferSpacesAvailable( pxStreamBuffer );
\r
522 if( xSpace < xRequiredSpace )
\r
524 /* Clear notification state as going to wait for space. */
\r
525 ( void ) xTaskNotifyStateClear( NULL );
\r
527 /* Should only be one writer. */
\r
528 configASSERT( pxStreamBuffer->xTaskWaitingToSend == NULL );
\r
529 pxStreamBuffer->xTaskWaitingToSend = xTaskGetCurrentTaskHandle();
\r
533 taskEXIT_CRITICAL();
\r
537 taskEXIT_CRITICAL();
\r
539 traceBLOCKING_ON_STREAM_BUFFER_SEND( xStreamBuffer );
\r
540 ( void ) xTaskNotifyWait( ( uint32_t ) 0, UINT32_MAX, NULL, xTicksToWait );
\r
541 pxStreamBuffer->xTaskWaitingToSend = NULL;
\r
543 } while( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE );
\r
547 mtCOVERAGE_TEST_MARKER();
\r
550 if( xSpace == ( size_t ) 0 )
\r
552 xSpace = xStreamBufferSpacesAvailable( pxStreamBuffer );
\r
556 mtCOVERAGE_TEST_MARKER();
\r
559 xReturn = prvWriteMessageToBuffer( pxStreamBuffer, pvTxData, xDataLengthBytes, xSpace, xRequiredSpace );
\r
561 if( xReturn > ( size_t ) 0 )
\r
563 traceSTREAM_BUFFER_SEND( xStreamBuffer, xReturn );
\r
565 /* Was a task waiting for the data? */
\r
566 if( prvBytesInBuffer( pxStreamBuffer ) >= pxStreamBuffer->xTriggerLevelBytes )
\r
568 sbSEND_COMPLETED( pxStreamBuffer );
\r
572 mtCOVERAGE_TEST_MARKER();
\r
577 mtCOVERAGE_TEST_MARKER();
\r
578 traceSTREAM_BUFFER_SEND_FAILED( xStreamBuffer );
\r
583 /*-----------------------------------------------------------*/
\r
585 size_t xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer,
\r
586 const void *pvTxData,
\r
587 size_t xDataLengthBytes,
\r
588 BaseType_t * const pxHigherPriorityTaskWoken )
\r
590 StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */
\r
591 size_t xReturn, xSpace;
\r
592 size_t xRequiredSpace = xDataLengthBytes;
\r
594 configASSERT( pvTxData );
\r
595 configASSERT( pxStreamBuffer );
\r
597 /* This send function is used to write to both message buffers and stream
\r
598 buffers. If this is a message buffer then the space needed must be
\r
599 increased by the amount of bytes needed to store the length of the
\r
601 if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 )
\r
603 xRequiredSpace += sbBYTES_TO_STORE_MESSAGE_LENGTH;
\r
607 mtCOVERAGE_TEST_MARKER();
\r
610 xSpace = xStreamBufferSpacesAvailable( pxStreamBuffer );
\r
611 xReturn = prvWriteMessageToBuffer( pxStreamBuffer, pvTxData, xDataLengthBytes, xSpace, xRequiredSpace );
\r
613 if( xReturn > ( size_t ) 0 )
\r
615 /* Was a task waiting for the data? */
\r
616 if( prvBytesInBuffer( pxStreamBuffer ) >= pxStreamBuffer->xTriggerLevelBytes )
\r
618 sbSEND_COMPLETE_FROM_ISR( pxStreamBuffer, pxHigherPriorityTaskWoken );
\r
622 mtCOVERAGE_TEST_MARKER();
\r
627 mtCOVERAGE_TEST_MARKER();
\r
630 traceSTREAM_BUFFER_SEND_FROM_ISR( xStreamBuffer, xReturn );
\r
634 /*-----------------------------------------------------------*/
\r
636 static size_t prvWriteMessageToBuffer( StreamBuffer_t * const pxStreamBuffer,
\r
637 const void * pvTxData,
\r
638 size_t xDataLengthBytes,
\r
640 size_t xRequiredSpace )
\r
642 BaseType_t xShouldWrite;
\r
645 if( xSpace == ( size_t ) 0 )
\r
647 /* Doesn't matter if this is a stream buffer or a message buffer, there
\r
648 is no space to write. */
\r
649 xShouldWrite = pdFALSE;
\r
651 else if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) == ( uint8_t ) 0 )
\r
653 /* This is a stream buffer, as opposed to a message buffer, so writing a
\r
654 stream of bytes rather than discrete messages. Write as many bytes as
\r
656 xShouldWrite = pdTRUE;
\r
657 xDataLengthBytes = configMIN( xDataLengthBytes, xSpace ); /*lint !e9044 Function parameter modified to ensure it is capped to available space. */
\r
659 else if( xSpace >= xRequiredSpace )
\r
661 /* This is a message buffer, as opposed to a stream buffer, and there
\r
662 is enough space to write both the message length and the message itself
\r
663 into the buffer. Start by writing the length of the data, the data
\r
664 itself will be written later in this function. */
\r
665 xShouldWrite = pdTRUE;
\r
666 ( void ) prvWriteBytesToBuffer( pxStreamBuffer, ( const uint8_t * ) &( xDataLengthBytes ), sbBYTES_TO_STORE_MESSAGE_LENGTH );
\r
670 /* There is space available, but not enough space. */
\r
671 xShouldWrite = pdFALSE;
\r
674 if( xShouldWrite != pdFALSE )
\r
676 /* Writes the data itself. */
\r
677 xReturn = prvWriteBytesToBuffer( pxStreamBuffer, ( const uint8_t * ) pvTxData, xDataLengthBytes ); /*lint !e9079 Storage buffer is implemented as uint8_t for ease of sizing, alighment and access. */
\r
686 /*-----------------------------------------------------------*/
\r
688 size_t xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer,
\r
690 size_t xBufferLengthBytes,
\r
691 TickType_t xTicksToWait )
\r
693 StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */
\r
694 size_t xReceivedLength = 0, xBytesAvailable, xBytesToStoreMessageLength;
\r
696 configASSERT( pvRxData );
\r
697 configASSERT( pxStreamBuffer );
\r
699 /* This receive function is used by both message buffers, which store
\r
700 discrete messages, and stream buffers, which store a continuous stream of
\r
701 bytes. Discrete messages include an additional
\r
702 sbBYTES_TO_STORE_MESSAGE_LENGTH bytes that hold the length of the
\r
704 if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 )
\r
706 xBytesToStoreMessageLength = sbBYTES_TO_STORE_MESSAGE_LENGTH;
\r
710 xBytesToStoreMessageLength = 0;
\r
713 if( xTicksToWait != ( TickType_t ) 0 )
\r
715 /* Checking if there is data and clearing the notification state must be
\r
716 performed atomically. */
\r
717 taskENTER_CRITICAL();
\r
719 xBytesAvailable = prvBytesInBuffer( pxStreamBuffer );
\r
721 /* If this function was invoked by a message buffer read then
\r
722 xBytesToStoreMessageLength holds the number of bytes used to hold
\r
723 the length of the next discrete message. If this function was
\r
724 invoked by a stream buffer read then xBytesToStoreMessageLength will
\r
726 if( xBytesAvailable <= xBytesToStoreMessageLength )
\r
728 /* Clear notification state as going to wait for data. */
\r
729 ( void ) xTaskNotifyStateClear( NULL );
\r
731 /* Should only be one reader. */
\r
732 configASSERT( pxStreamBuffer->xTaskWaitingToReceive == NULL );
\r
733 pxStreamBuffer->xTaskWaitingToReceive = xTaskGetCurrentTaskHandle();
\r
737 mtCOVERAGE_TEST_MARKER();
\r
740 taskEXIT_CRITICAL();
\r
742 if( xBytesAvailable <= xBytesToStoreMessageLength )
\r
744 /* Wait for data to be available. */
\r
745 traceBLOCKING_ON_STREAM_BUFFER_RECEIVE( xStreamBuffer );
\r
746 ( void ) xTaskNotifyWait( ( uint32_t ) 0, UINT32_MAX, NULL, xTicksToWait );
\r
747 pxStreamBuffer->xTaskWaitingToReceive = NULL;
\r
749 /* Recheck the data available after blocking. */
\r
750 xBytesAvailable = prvBytesInBuffer( pxStreamBuffer );
\r
754 mtCOVERAGE_TEST_MARKER();
\r
759 xBytesAvailable = prvBytesInBuffer( pxStreamBuffer );
\r
762 /* Whether receiving a discrete message (where xBytesToStoreMessageLength
\r
763 holds the number of bytes used to store the message length) or a stream of
\r
764 bytes (where xBytesToStoreMessageLength is zero), the number of bytes
\r
765 available must be greater than xBytesToStoreMessageLength to be able to
\r
766 read bytes from the buffer. */
\r
767 if( xBytesAvailable > xBytesToStoreMessageLength )
\r
769 xReceivedLength = prvReadMessageFromBuffer( pxStreamBuffer, pvRxData, xBufferLengthBytes, xBytesAvailable, xBytesToStoreMessageLength );
\r
771 /* Was a task waiting for space in the buffer? */
\r
772 if( xReceivedLength != ( size_t ) 0 )
\r
774 traceSTREAM_BUFFER_RECEIVE( xStreamBuffer, xReceivedLength );
\r
775 sbRECEIVE_COMPLETED( pxStreamBuffer );
\r
779 mtCOVERAGE_TEST_MARKER();
\r
784 traceSTREAM_BUFFER_RECEIVE_FAILED( xStreamBuffer );
\r
785 mtCOVERAGE_TEST_MARKER();
\r
788 return xReceivedLength;
\r
790 /*-----------------------------------------------------------*/
\r
792 size_t xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer,
\r
794 size_t xBufferLengthBytes,
\r
795 BaseType_t * const pxHigherPriorityTaskWoken )
\r
797 StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */
\r
798 size_t xReceivedLength = 0, xBytesAvailable, xBytesToStoreMessageLength;
\r
800 configASSERT( pvRxData );
\r
801 configASSERT( pxStreamBuffer );
\r
803 /* This receive function is used by both message buffers, which store
\r
804 discrete messages, and stream buffers, which store a continuous stream of
\r
805 bytes. Discrete messages include an additional
\r
806 sbBYTES_TO_STORE_MESSAGE_LENGTH bytes that hold the length of the
\r
808 if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 )
\r
810 xBytesToStoreMessageLength = sbBYTES_TO_STORE_MESSAGE_LENGTH;
\r
814 xBytesToStoreMessageLength = 0;
\r
817 xBytesAvailable = prvBytesInBuffer( pxStreamBuffer );
\r
819 /* Whether receiving a discrete message (where xBytesToStoreMessageLength
\r
820 holds the number of bytes used to store the message length) or a stream of
\r
821 bytes (where xBytesToStoreMessageLength is zero), the number of bytes
\r
822 available must be greater than xBytesToStoreMessageLength to be able to
\r
823 read bytes from the buffer. */
\r
824 if( xBytesAvailable > xBytesToStoreMessageLength )
\r
826 xReceivedLength = prvReadMessageFromBuffer( pxStreamBuffer, pvRxData, xBufferLengthBytes, xBytesAvailable, xBytesToStoreMessageLength );
\r
828 /* Was a task waiting for space in the buffer? */
\r
829 if( xReceivedLength != ( size_t ) 0 )
\r
831 sbRECEIVE_COMPLETED_FROM_ISR( pxStreamBuffer, pxHigherPriorityTaskWoken );
\r
835 mtCOVERAGE_TEST_MARKER();
\r
840 mtCOVERAGE_TEST_MARKER();
\r
843 traceSTREAM_BUFFER_RECEIVE_FROM_ISR( xStreamBuffer, xReceivedLength );
\r
845 return xReceivedLength;
\r
847 /*-----------------------------------------------------------*/
\r
849 static size_t prvReadMessageFromBuffer( StreamBuffer_t *pxStreamBuffer,
\r
851 size_t xBufferLengthBytes,
\r
852 size_t xBytesAvailable,
\r
853 size_t xBytesToStoreMessageLength )
\r
855 size_t xOriginalTail, xReceivedLength, xNextMessageLength;
\r
857 if( xBytesToStoreMessageLength != ( size_t ) 0 )
\r
859 /* A discrete message is being received. First receive the length
\r
860 of the message. A copy of the tail is stored so the buffer can be
\r
861 returned to its prior state if the length of the message is too
\r
862 large for the provided buffer. */
\r
863 xOriginalTail = pxStreamBuffer->xTail;
\r
864 ( void ) prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) &xNextMessageLength, xBytesToStoreMessageLength, xBytesAvailable );
\r
866 /* Reduce the number of bytes available by the number of bytes just
\r
868 xBytesAvailable -= xBytesToStoreMessageLength;
\r
870 /* Check there is enough space in the buffer provided by the
\r
872 if( xNextMessageLength > xBufferLengthBytes )
\r
874 /* The user has provided insufficient space to read the message
\r
875 so return the buffer to its previous state (so the length of
\r
876 the message is in the buffer again). */
\r
877 pxStreamBuffer->xTail = xOriginalTail;
\r
878 xNextMessageLength = 0;
\r
882 mtCOVERAGE_TEST_MARKER();
\r
887 /* A stream of bytes is being received (as opposed to a discrete
\r
888 message), so read as many bytes as possible. */
\r
889 xNextMessageLength = xBufferLengthBytes;
\r
892 /* Read the actual data. */
\r
893 xReceivedLength = prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) pvRxData, xNextMessageLength, xBytesAvailable ); /*lint !e9079 Data storage area is implemented as uint8_t array for ease of sizing, indexing and alignment. */
\r
895 return xReceivedLength;
\r
897 /*-----------------------------------------------------------*/
\r
899 BaseType_t xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer )
\r
901 const StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */
\r
902 BaseType_t xReturn;
\r
905 configASSERT( pxStreamBuffer );
\r
907 /* True if no bytes are available. */
\r
908 xTail = pxStreamBuffer->xTail;
\r
909 if( pxStreamBuffer->xHead == xTail )
\r
920 /*-----------------------------------------------------------*/
\r
922 BaseType_t xStreamBufferIsFull( StreamBufferHandle_t xStreamBuffer )
\r
924 BaseType_t xReturn;
\r
925 size_t xBytesToStoreMessageLength;
\r
926 const StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */
\r
928 configASSERT( pxStreamBuffer );
\r
930 /* This generic version of the receive function is used by both message
\r
931 buffers, which store discrete messages, and stream buffers, which store a
\r
932 continuous stream of bytes. Discrete messages include an additional
\r
933 sbBYTES_TO_STORE_MESSAGE_LENGTH bytes that hold the length of the message. */
\r
934 if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 )
\r
936 xBytesToStoreMessageLength = sbBYTES_TO_STORE_MESSAGE_LENGTH;
\r
940 xBytesToStoreMessageLength = 0;
\r
943 /* True if the available space equals zero. */
\r
944 if( xStreamBufferSpacesAvailable( xStreamBuffer ) <= xBytesToStoreMessageLength )
\r
955 /*-----------------------------------------------------------*/
\r
957 BaseType_t xStreamBufferSendCompletedFromISR( StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken )
\r
959 StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */
\r
960 BaseType_t xReturn;
\r
961 UBaseType_t uxSavedInterruptStatus;
\r
963 configASSERT( pxStreamBuffer );
\r
965 uxSavedInterruptStatus = ( UBaseType_t ) portSET_INTERRUPT_MASK_FROM_ISR();
\r
967 if( ( pxStreamBuffer )->xTaskWaitingToReceive != NULL )
\r
969 ( void ) xTaskNotifyFromISR( ( pxStreamBuffer )->xTaskWaitingToReceive,
\r
972 pxHigherPriorityTaskWoken );
\r
973 ( pxStreamBuffer )->xTaskWaitingToReceive = NULL;
\r
981 portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
\r
985 /*-----------------------------------------------------------*/
\r
987 BaseType_t xStreamBufferReceiveCompletedFromISR( StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken )
\r
989 StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */
\r
990 BaseType_t xReturn;
\r
991 UBaseType_t uxSavedInterruptStatus;
\r
993 configASSERT( pxStreamBuffer );
\r
995 uxSavedInterruptStatus = ( UBaseType_t ) portSET_INTERRUPT_MASK_FROM_ISR();
\r
997 if( ( pxStreamBuffer )->xTaskWaitingToSend != NULL )
\r
999 ( void ) xTaskNotifyFromISR( ( pxStreamBuffer )->xTaskWaitingToSend,
\r
1002 pxHigherPriorityTaskWoken );
\r
1003 ( pxStreamBuffer )->xTaskWaitingToSend = NULL;
\r
1008 xReturn = pdFALSE;
\r
1011 portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
\r
1015 /*-----------------------------------------------------------*/
\r
1017 static size_t prvWriteBytesToBuffer( StreamBuffer_t * const pxStreamBuffer, const uint8_t *pucData, size_t xCount )
\r
1019 size_t xNextHead, xFirstLength;
\r
1021 configASSERT( xCount > ( size_t ) 0 );
\r
1023 xNextHead = pxStreamBuffer->xHead;
\r
1025 /* Calculate the number of bytes that can be added in the first write -
\r
1026 which may be less than the total number of bytes that need to be added if
\r
1027 the buffer will wrap back to the beginning. */
\r
1028 xFirstLength = configMIN( pxStreamBuffer->xLength - xNextHead, xCount );
\r
1030 /* Write as many bytes as can be written in the first write. */
\r
1031 configASSERT( ( xNextHead + xFirstLength ) <= pxStreamBuffer->xLength );
\r
1032 memcpy( ( void* ) ( &( pxStreamBuffer->pucBuffer[ xNextHead ] ) ), ( const void * ) pucData, xFirstLength ); /*lint !e9087 memcpy() requires void *. */
\r
1034 /* If the number of bytes written was less than the number that could be
\r
1035 written in the first write... */
\r
1036 if( xCount > xFirstLength )
\r
1038 /* ...then write the remaining bytes to the start of the buffer. */
\r
1039 configASSERT( ( xCount - xFirstLength ) <= pxStreamBuffer->xLength );
\r
1040 memcpy( ( void * ) pxStreamBuffer->pucBuffer, ( const void * ) &( pucData[ xFirstLength ] ), xCount - xFirstLength ); /*lint !e9087 memcpy() requires void *. */
\r
1044 mtCOVERAGE_TEST_MARKER();
\r
1047 xNextHead += xCount;
\r
1048 if( xNextHead >= pxStreamBuffer->xLength )
\r
1050 xNextHead -= pxStreamBuffer->xLength;
\r
1054 mtCOVERAGE_TEST_MARKER();
\r
1057 pxStreamBuffer->xHead = xNextHead;
\r
1061 /*-----------------------------------------------------------*/
\r
1063 static size_t prvReadBytesFromBuffer( StreamBuffer_t *pxStreamBuffer, uint8_t *pucData, size_t xMaxCount, size_t xBytesAvailable )
\r
1065 size_t xCount, xFirstLength, xNextTail;
\r
1067 /* Use the minimum of the wanted bytes and the available bytes. */
\r
1068 xCount = configMIN( xBytesAvailable, xMaxCount );
\r
1070 if( xCount > ( size_t ) 0 )
\r
1072 xNextTail = pxStreamBuffer->xTail;
\r
1074 /* Calculate the number of bytes that can be read - which may be
\r
1075 less than the number wanted if the data wraps around to the start of
\r
1077 xFirstLength = configMIN( pxStreamBuffer->xLength - xNextTail, xCount );
\r
1079 /* Obtain the number of bytes it is possible to obtain in the first
\r
1080 read. Asserts check bounds of read and write. */
\r
1081 configASSERT( xFirstLength <= xMaxCount );
\r
1082 configASSERT( ( xNextTail + xFirstLength ) <= pxStreamBuffer->xLength );
\r
1083 memcpy( ( void * ) pucData, ( const void * ) &( pxStreamBuffer->pucBuffer[ xNextTail ] ), xFirstLength ); /*lint !e9087 memcpy() requires void *. */
\r
1085 /* If the total number of wanted bytes is greater than the number
\r
1086 that could be read in the first read... */
\r
1087 if( xCount > xFirstLength )
\r
1089 /*...then read the remaining bytes from the start of the buffer. */
\r
1090 configASSERT( xCount <= xMaxCount );
\r
1091 memcpy( ( void * ) &( pucData[ xFirstLength ] ), ( void * ) ( pxStreamBuffer->pucBuffer ), xCount - xFirstLength ); /*lint !e9087 memcpy() requires void *. */
\r
1095 mtCOVERAGE_TEST_MARKER();
\r
1098 /* Move the tail pointer to effectively remove the data read from
\r
1100 xNextTail += xCount;
\r
1102 if( xNextTail >= pxStreamBuffer->xLength )
\r
1104 xNextTail -= pxStreamBuffer->xLength;
\r
1107 pxStreamBuffer->xTail = xNextTail;
\r
1111 mtCOVERAGE_TEST_MARKER();
\r
1116 /*-----------------------------------------------------------*/
\r
1118 static size_t prvBytesInBuffer( const StreamBuffer_t * const pxStreamBuffer )
\r
1120 /* Returns the distance between xTail and xHead. */
\r
1123 xCount = pxStreamBuffer->xLength + pxStreamBuffer->xHead;
\r
1124 xCount -= pxStreamBuffer->xTail;
\r
1125 if ( xCount >= pxStreamBuffer->xLength )
\r
1127 xCount -= pxStreamBuffer->xLength;
\r
1131 mtCOVERAGE_TEST_MARKER();
\r
1136 /*-----------------------------------------------------------*/
\r
1138 static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
\r
1139 uint8_t * const pucBuffer,
\r
1140 size_t xBufferSizeBytes,
\r
1141 size_t xTriggerLevelBytes,
\r
1142 BaseType_t xIsMessageBuffer )
\r
1144 /* Assert here is deliberately writing to the entire buffer to ensure it can
\r
1145 be written to without generating exceptions, and is setting the buffer to a
\r
1146 known value to assist in development/debugging. */
\r
1147 #if( configASSERT_DEFINED == 1 )
\r
1149 /* The value written just has to be identifiable when looking at the
\r
1150 memory. Don't use 0xA5 as that is the stack fill value and could
\r
1151 result in confusion as to what is actually being observed. */
\r
1152 const BaseType_t xWriteValue = 0x55;
\r
1153 configASSERT( memset( pucBuffer, ( int ) xWriteValue, xBufferSizeBytes ) == pucBuffer );
\r
1157 memset( ( void * ) pxStreamBuffer, 0x00, sizeof( StreamBuffer_t ) ); /*lint !e9087 memset() requires void *. */
\r
1158 pxStreamBuffer->pucBuffer = pucBuffer;
\r
1159 pxStreamBuffer->xLength = xBufferSizeBytes;
\r
1160 pxStreamBuffer->xTriggerLevelBytes = xTriggerLevelBytes;
\r
1162 if( xIsMessageBuffer != pdFALSE )
\r
1164 pxStreamBuffer->ucFlags |= sbFLAGS_IS_MESSAGE_BUFFER;
\r
1168 #if ( configUSE_TRACE_FACILITY == 1 )
\r
1170 UBaseType_t uxStreamBufferGetStreamBufferNumber( StreamBufferHandle_t xStreamBuffer )
\r
1172 return ( ( StreamBuffer_t * ) xStreamBuffer )->uxStreamBufferNumber;
\r
1175 #endif /* configUSE_TRACE_FACILITY */
\r
1176 /*-----------------------------------------------------------*/
\r
1178 #if ( configUSE_TRACE_FACILITY == 1 )
\r
1180 void vStreamBufferSetStreamBufferNumber( StreamBufferHandle_t xStreamBuffer, UBaseType_t uxStreamBufferNumber )
\r
1182 ( ( StreamBuffer_t * ) xStreamBuffer )->uxStreamBufferNumber = uxStreamBufferNumber;
\r
1185 #endif /* configUSE_TRACE_FACILITY */
\r
1186 /*-----------------------------------------------------------*/
\r
1188 #if ( configUSE_TRACE_FACILITY == 1 )
\r
1190 uint8_t ucStreamBufferGetStreamBufferType( StreamBufferHandle_t xStreamBuffer )
\r
1192 return ( ( StreamBuffer_t * )xStreamBuffer )->ucFlags | sbFLAGS_IS_MESSAGE_BUFFER;
\r
1195 #endif /* configUSE_TRACE_FACILITY */
\r
1196 /*-----------------------------------------------------------*/
\r