]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/stream_buffer.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Source / stream_buffer.c
index 392d04d37007ad44ff9e3b3d9e88eb889cb0db75..ec7b3e36559e9f81eaa9cfd9022f554f8264e20d 100644 (file)
@@ -1,6 +1,6 @@
 /*\r
- * FreeRTOS Kernel V10.0.1\r
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
+ * FreeRTOS Kernel V10.3.0\r
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
  *\r
  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
  * this software and associated documentation files (the "Software"), to deal in\r
@@ -210,7 +210,7 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
                                                                                  uint8_t * const pucBuffer,\r
                                                                                  size_t xBufferSizeBytes,\r
                                                                                  size_t xTriggerLevelBytes,\r
-                                                                                 BaseType_t xIsMessageBuffer ) PRIVILEGED_FUNCTION;\r
+                                                                                 uint8_t ucFlags ) PRIVILEGED_FUNCTION;\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
@@ -219,12 +219,24 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
        StreamBufferHandle_t xStreamBufferGenericCreate( size_t xBufferSizeBytes, size_t xTriggerLevelBytes, BaseType_t xIsMessageBuffer )\r
        {\r
        uint8_t *pucAllocatedMemory;\r
+       uint8_t ucFlags;\r
 \r
                /* In case the stream buffer is going to be used as a message buffer\r
                (that is, it will hold discrete messages with a little meta data that\r
                says how big the next message is) check the buffer will be large enough\r
                to hold at least one message. */\r
-               configASSERT( xBufferSizeBytes > sbBYTES_TO_STORE_MESSAGE_LENGTH );\r
+               if( xIsMessageBuffer == pdTRUE )\r
+               {\r
+                       /* Is a message buffer but not statically allocated. */\r
+                       ucFlags = sbFLAGS_IS_MESSAGE_BUFFER;\r
+                       configASSERT( xBufferSizeBytes > sbBYTES_TO_STORE_MESSAGE_LENGTH );\r
+               }\r
+               else\r
+               {\r
+                       /* Not a message buffer and not statically allocated. */\r
+                       ucFlags = 0;\r
+                       configASSERT( xBufferSizeBytes > 0 );\r
+               }\r
                configASSERT( xTriggerLevelBytes <= xBufferSizeBytes );\r
 \r
                /* A trigger level of 0 would cause a waiting task to unblock even when\r
@@ -251,7 +263,7 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
                                                                                   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
                                                                                   xBufferSizeBytes,\r
                                                                                   xTriggerLevelBytes,\r
-                                                                                  xIsMessageBuffer );\r
+                                                                                  ucFlags );\r
 \r
                        traceSTREAM_BUFFER_CREATE( ( ( StreamBuffer_t * ) pucAllocatedMemory ), xIsMessageBuffer );\r
                }\r
@@ -276,6 +288,7 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
        {\r
        StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) pxStaticStreamBuffer; /*lint !e740 !e9087 Safe cast as StaticStreamBuffer_t is opaque Streambuffer_t. */\r
        StreamBufferHandle_t xReturn;\r
+       uint8_t ucFlags;\r
 \r
                configASSERT( pucStreamBufferStorageArea );\r
                configASSERT( pxStaticStreamBuffer );\r
@@ -288,6 +301,17 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
                        xTriggerLevelBytes = ( size_t ) 1;\r
                }\r
 \r
+               if( xIsMessageBuffer != pdFALSE )\r
+               {\r
+                       /* Statically allocated message buffer. */\r
+                       ucFlags = sbFLAGS_IS_MESSAGE_BUFFER | sbFLAGS_IS_STATICALLY_ALLOCATED;\r
+               }\r
+               else\r
+               {\r
+                       /* Statically allocated stream buffer. */\r
+                       ucFlags = sbFLAGS_IS_STATICALLY_ALLOCATED;\r
+               }\r
+\r
                /* In case the stream buffer is going to be used as a message buffer\r
                (that is, it will hold discrete messages with a little meta data that\r
                says how big the next message is) check the buffer will be large enough\r
@@ -310,7 +334,7 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
                                                                                  pucStreamBufferStorageArea,\r
                                                                                  xBufferSizeBytes,\r
                                                                                  xTriggerLevelBytes,\r
-                                                                                 xIsMessageBuffer );\r
+                                                                                 ucFlags );\r
 \r
                        /* Remember this was statically allocated in case it is ever deleted\r
                        again. */\r
@@ -360,7 +384,7 @@ StreamBuffer_t * pxStreamBuffer = xStreamBuffer;
        {\r
                /* The structure and buffer were not allocated dynamically and cannot be\r
                freed - just scrub the structure so future use will assert. */\r
-               memset( pxStreamBuffer, 0x00, sizeof( StreamBuffer_t ) );\r
+               ( void ) memset( pxStreamBuffer, 0x00, sizeof( StreamBuffer_t ) );\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -368,7 +392,7 @@ StreamBuffer_t * pxStreamBuffer = xStreamBuffer;
 BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer )\r
 {\r
 StreamBuffer_t * const pxStreamBuffer = xStreamBuffer;\r
-BaseType_t xReturn = pdFAIL, xIsMessageBuffer;\r
+BaseType_t xReturn = pdFAIL;\r
 \r
 #if( configUSE_TRACE_FACILITY == 1 )\r
        UBaseType_t uxStreamBufferNumber;\r
@@ -391,20 +415,11 @@ BaseType_t xReturn = pdFAIL, xIsMessageBuffer;
                {\r
                        if( pxStreamBuffer->xTaskWaitingToSend == NULL )\r
                        {\r
-                               if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 )\r
-                               {\r
-                                       xIsMessageBuffer = pdTRUE;\r
-                               }\r
-                               else\r
-                               {\r
-                                       xIsMessageBuffer = pdFALSE;\r
-                               }\r
-\r
                                prvInitialiseNewStreamBuffer( pxStreamBuffer,\r
                                                                                          pxStreamBuffer->pucBuffer,\r
                                                                                          pxStreamBuffer->xLength,\r
                                                                                          pxStreamBuffer->xTriggerLevelBytes,\r
-                                                                                         xIsMessageBuffer );\r
+                                                                                         pxStreamBuffer->ucFlags );\r
                                xReturn = pdPASS;\r
 \r
                                #if( configUSE_TRACE_FACILITY == 1 )\r
@@ -1085,7 +1100,7 @@ size_t xNextHead, xFirstLength;
 \r
        /* Write as many bytes as can be written in the first write. */\r
        configASSERT( ( xNextHead + xFirstLength ) <= pxStreamBuffer->xLength );\r
-       memcpy( ( void* ) ( &( pxStreamBuffer->pucBuffer[ xNextHead ] ) ), ( const void * ) pucData, xFirstLength ); /*lint !e9087 memcpy() requires void *. */\r
+       ( void ) memcpy( ( void* ) ( &( pxStreamBuffer->pucBuffer[ xNextHead ] ) ), ( const void * ) pucData, xFirstLength ); /*lint !e9087 memcpy() requires void *. */\r
 \r
        /* If the number of bytes written was less than the number that could be\r
        written in the first write... */\r
@@ -1093,7 +1108,7 @@ size_t xNextHead, xFirstLength;
        {\r
                /* ...then write the remaining bytes to the start of the buffer. */\r
                configASSERT( ( xCount - xFirstLength ) <= pxStreamBuffer->xLength );\r
-               memcpy( ( void * ) pxStreamBuffer->pucBuffer, ( const void * ) &( pucData[ xFirstLength ] ), xCount - xFirstLength ); /*lint !e9087 memcpy() requires void *. */\r
+               ( void ) memcpy( ( void * ) pxStreamBuffer->pucBuffer, ( const void * ) &( pucData[ xFirstLength ] ), xCount - xFirstLength ); /*lint !e9087 memcpy() requires void *. */\r
        }\r
        else\r
        {\r
@@ -1136,7 +1151,7 @@ size_t xCount, xFirstLength, xNextTail;
                read.  Asserts check bounds of read and write. */\r
                configASSERT( xFirstLength <= xMaxCount );\r
                configASSERT( ( xNextTail + xFirstLength ) <= pxStreamBuffer->xLength );\r
-               memcpy( ( void * ) pucData, ( const void * ) &( pxStreamBuffer->pucBuffer[ xNextTail ] ), xFirstLength ); /*lint !e9087 memcpy() requires void *. */\r
+               ( void ) memcpy( ( void * ) pucData, ( const void * ) &( pxStreamBuffer->pucBuffer[ xNextTail ] ), xFirstLength ); /*lint !e9087 memcpy() requires void *. */\r
 \r
                /* If the total number of wanted bytes is greater than the number\r
                that could be read in the first read... */\r
@@ -1144,7 +1159,7 @@ size_t xCount, xFirstLength, xNextTail;
                {\r
                        /*...then read the remaining bytes from the start of the buffer. */\r
                        configASSERT( xCount <= xMaxCount );\r
-                       memcpy( ( void * ) &( pucData[ xFirstLength ] ), ( void * ) ( pxStreamBuffer->pucBuffer ), xCount - xFirstLength ); /*lint !e9087 memcpy() requires void *. */\r
+                       ( void ) memcpy( ( void * ) &( pucData[ xFirstLength ] ), ( void * ) ( pxStreamBuffer->pucBuffer ), xCount - xFirstLength ); /*lint !e9087 memcpy() requires void *. */\r
                }\r
                else\r
                {\r
@@ -1195,7 +1210,7 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
                                                                                  uint8_t * const pucBuffer,\r
                                                                                  size_t xBufferSizeBytes,\r
                                                                                  size_t xTriggerLevelBytes,\r
-                                                                                 BaseType_t xIsMessageBuffer )\r
+                                                                                 uint8_t ucFlags )\r
 {\r
        /* Assert here is deliberately writing to the entire buffer to ensure it can\r
        be written to without generating exceptions, and is setting the buffer to a\r
@@ -1210,15 +1225,11 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
        } /*lint !e529 !e438 xWriteValue is only used if configASSERT() is defined. */\r
        #endif\r
 \r
-       memset( ( void * ) pxStreamBuffer, 0x00, sizeof( StreamBuffer_t ) ); /*lint !e9087 memset() requires void *. */\r
+       ( void ) memset( ( void * ) pxStreamBuffer, 0x00, sizeof( StreamBuffer_t ) ); /*lint !e9087 memset() requires void *. */\r
        pxStreamBuffer->pucBuffer = pucBuffer;\r
        pxStreamBuffer->xLength = xBufferSizeBytes;\r
        pxStreamBuffer->xTriggerLevelBytes = xTriggerLevelBytes;\r
-\r
-       if( xIsMessageBuffer != pdFALSE )\r
-       {\r
-               pxStreamBuffer->ucFlags |= sbFLAGS_IS_MESSAGE_BUFFER;\r
-       }\r
+       pxStreamBuffer->ucFlags = ucFlags;\r
 }\r
 \r
 #if ( configUSE_TRACE_FACILITY == 1 )\r