From a58579681c908d1e7896de488f2dc5003d9214a7 Mon Sep 17 00:00:00 2001 From: John Boiles Date: Tue, 21 Jan 2025 00:50:16 -0800 Subject: [PATCH 01/11] POSIX Simulator: Remove unused __APPLE__ mach_vm.h include (#1225) Remove unused __APPLE__ mach_vm.h include --- .github/workflows/kernel-demos.yml | 17 +++++++++++++---- portable/ThirdParty/GCC/Posix/port.c | 4 ---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/kernel-demos.yml b/.github/workflows/kernel-demos.yml index 94d5c73e2..f81ae33f3 100644 --- a/.github/workflows/kernel-demos.yml +++ b/.github/workflows/kernel-demos.yml @@ -150,16 +150,25 @@ jobs: with: path: ./FreeRTOS/Source - - name: Install MSP430 Toolchain + - env: + stepName: Install MSP430 Toolchain shell: bash run: | - sudo apt-get -y update - sudo apt-get -y install gcc-msp430 build-essential + # ${{ env.stepName }} + echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" + curl -L -O https://dr-download.ti.com/software-development/ide-configuration-compiler-or-debugger/MD-LlCjWuAbzH/9.3.1.2/msp430-gcc-full-linux-x64-installer-9.3.1.2.7z + sudo apt update -y + sudo apt install -y p7zip-full + 7z x ./msp430-gcc-full-linux-x64-installer-9.3.1.2.7z + chmod +x ./msp430-gcc-full-linux-x64-installer-9.3.1.2.run + sudo ./msp430-gcc-full-linux-x64-installer-9.3.1.2.run --prefix /usr/bin/msp430-gcc --mode unattended + echo "::endgroup::" + echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}" - name: Build msp430_GCC Demo shell: bash working-directory: FreeRTOS/Demo/msp430_GCC - run: make -j + run: make -j CC=/usr/bin/msp430-gcc/bin/msp430-elf-gcc OPT="-Os -I/usr/bin/msp430-gcc/include -L/usr/bin/msp430-gcc/include" MicroBlaze-GCC: name: GCC MicroBlaze Toolchain diff --git a/portable/ThirdParty/GCC/Posix/port.c b/portable/ThirdParty/GCC/Posix/port.c index 1bec7afd8..7cc32128f 100644 --- a/portable/ThirdParty/GCC/Posix/port.c +++ b/portable/ThirdParty/GCC/Posix/port.c @@ -65,10 +65,6 @@ #include #include -#ifdef __APPLE__ - #include -#endif - /* Scheduler includes. */ #include "FreeRTOS.h" #include "task.h" From b5d1b972cc2483d4397bbc4f0046b07fc4c3b698 Mon Sep 17 00:00:00 2001 From: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> Date: Tue, 21 Jan 2025 15:17:10 +0530 Subject: [PATCH 02/11] Update stream and message buffer documentation (#1226) Signed-off-by: Gaurav Aggarwal --- include/message_buffer.h | 60 ++++++++++++++++++++-------------------- include/stream_buffer.h | 48 ++++++++++++++++---------------- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/include/message_buffer.h b/include/message_buffer.h index 975a7e343..9fb97ffd0 100644 --- a/include/message_buffer.h +++ b/include/message_buffer.h @@ -43,12 +43,12 @@ * writer and reader to be different tasks or interrupts, but, unlike other * FreeRTOS objects, it is not safe to have multiple different writers or * multiple different readers. If there are to be multiple different writers - * then the application writer must place each call to a writing API function - * (such as xMessageBufferSend()) inside a critical section and set the send - * block time to 0. Likewise, if there are to be multiple different readers - * then the application writer must place each call to a reading API function - * (such as xMessageBufferRead()) inside a critical section and set the receive - * timeout to 0. + * then the application writer must serialize calls to writing API functions + * (such as xStreamBufferSend()). Likewise, if there are to be multiple + * different readers then the application writer must serialize calls to reading + * API functions (such as xStreamBufferReceive()). One way to achieve such + * serialization in single core or SMP kernel is to place each API call inside a + * critical section and use a block time of 0. * * Message buffers hold variable length messages. To enable that, when a * message is written to the message buffer an additional sizeof( size_t ) bytes @@ -306,12 +306,12 @@ typedef StreamBufferHandle_t MessageBufferHandle_t; * writer and reader to be different tasks or interrupts, but, unlike other * FreeRTOS objects, it is not safe to have multiple different writers or * multiple different readers. If there are to be multiple different writers - * then the application writer must place each call to a writing API function - * (such as xMessageBufferSend()) inside a critical section and set the send - * block time to 0. Likewise, if there are to be multiple different readers - * then the application writer must place each call to a reading API function - * (such as xMessageBufferRead()) inside a critical section and set the receive - * block time to 0. + * then the application writer must serialize calls to writing API functions + * (such as xStreamBufferSend()). Likewise, if there are to be multiple + * different readers then the application writer must serialize calls to reading + * API functions (such as xStreamBufferReceive()). One way to achieve such + * serialization in single core or SMP kernel is to place each API call inside a + * critical section and use a block time of 0. * * Use xMessageBufferSend() to write to a message buffer from a task. Use * xMessageBufferSendFromISR() to write to a message buffer from an interrupt @@ -409,12 +409,12 @@ typedef StreamBufferHandle_t MessageBufferHandle_t; * writer and reader to be different tasks or interrupts, but, unlike other * FreeRTOS objects, it is not safe to have multiple different writers or * multiple different readers. If there are to be multiple different writers - * then the application writer must place each call to a writing API function - * (such as xMessageBufferSend()) inside a critical section and set the send - * block time to 0. Likewise, if there are to be multiple different readers - * then the application writer must place each call to a reading API function - * (such as xMessageBufferRead()) inside a critical section and set the receive - * block time to 0. + * then the application writer must serialize calls to writing API functions + * (such as xStreamBufferSend()). Likewise, if there are to be multiple + * different readers then the application writer must serialize calls to reading + * API functions (such as xStreamBufferReceive()). One way to achieve such + * serialization in single core or SMP kernel is to place each API call inside a + * critical section and use a block time of 0. * * Use xMessageBufferSend() to write to a message buffer from a task. Use * xMessageBufferSendFromISR() to write to a message buffer from an interrupt @@ -516,12 +516,12 @@ typedef StreamBufferHandle_t MessageBufferHandle_t; * writer and reader to be different tasks or interrupts, but, unlike other * FreeRTOS objects, it is not safe to have multiple different writers or * multiple different readers. If there are to be multiple different writers - * then the application writer must place each call to a writing API function - * (such as xMessageBufferSend()) inside a critical section and set the send - * block time to 0. Likewise, if there are to be multiple different readers - * then the application writer must place each call to a reading API function - * (such as xMessageBufferRead()) inside a critical section and set the receive - * block time to 0. + * then the application writer must serialize calls to writing API functions + * (such as xStreamBufferSend()). Likewise, if there are to be multiple + * different readers then the application writer must serialize calls to reading + * API functions (such as xStreamBufferReceive()). One way to achieve such + * serialization in single core or SMP kernel is to place each API call inside a + * critical section and use a block time of 0. * * Use xMessageBufferReceive() to read from a message buffer from a task. Use * xMessageBufferReceiveFromISR() to read from a message buffer from an @@ -610,12 +610,12 @@ typedef StreamBufferHandle_t MessageBufferHandle_t; * writer and reader to be different tasks or interrupts, but, unlike other * FreeRTOS objects, it is not safe to have multiple different writers or * multiple different readers. If there are to be multiple different writers - * then the application writer must place each call to a writing API function - * (such as xMessageBufferSend()) inside a critical section and set the send - * block time to 0. Likewise, if there are to be multiple different readers - * then the application writer must place each call to a reading API function - * (such as xMessageBufferRead()) inside a critical section and set the receive - * block time to 0. + * then the application writer must serialize calls to writing API functions + * (such as xStreamBufferSend()). Likewise, if there are to be multiple + * different readers then the application writer must serialize calls to reading + * API functions (such as xStreamBufferReceive()). One way to achieve such + * serialization in single core or SMP kernel is to place each API call inside a + * critical section and use a block time of 0. * * Use xMessageBufferReceive() to read from a message buffer from a task. Use * xMessageBufferReceiveFromISR() to read from a message buffer from an diff --git a/include/stream_buffer.h b/include/stream_buffer.h index 9b15c8aff..b0093fc80 100644 --- a/include/stream_buffer.h +++ b/include/stream_buffer.h @@ -40,12 +40,12 @@ * writer and reader to be different tasks or interrupts, but, unlike other * FreeRTOS objects, it is not safe to have multiple different writers or * multiple different readers. If there are to be multiple different writers - * then the application writer must place each call to a writing API function - * (such as xStreamBufferSend()) inside a critical section and set the send - * block time to 0. Likewise, if there are to be multiple different readers - * then the application writer must place each call to a reading API function - * (such as xStreamBufferReceive()) inside a critical section section and set the - * receive block time to 0. + * then the application writer must serialize calls to writing API functions + * (such as xStreamBufferSend()). Likewise, if there are to be multiple + * different readers then the application writer must serialize calls to reading + * API functions (such as xStreamBufferReceive()). One way to achieve such + * serialization in single core or SMP kernel is to place each API call inside a + * critical section and use a block time of 0. * */ @@ -514,12 +514,12 @@ typedef void (* StreamBufferCallbackFunction_t)( StreamBufferHandle_t xStreamBuf * writer and reader to be different tasks or interrupts, but, unlike other * FreeRTOS objects, it is not safe to have multiple different writers or * multiple different readers. If there are to be multiple different writers - * then the application writer must place each call to a writing API function - * (such as xStreamBufferSend()) inside a critical section and set the send - * block time to 0. Likewise, if there are to be multiple different readers - * then the application writer must place each call to a reading API function - * (such as xStreamBufferReceive()) inside a critical section and set the receive - * block time to 0. + * then the application writer must serialize calls to writing API functions + * (such as xStreamBufferSend()). Likewise, if there are to be multiple + * different readers then the application writer must serialize calls to reading + * API functions (such as xStreamBufferReceive()). One way to achieve such + * serialization in single core or SMP kernel is to place each API call inside a + * critical section and use a block time of 0. * * Use xStreamBufferSend() to write to a stream buffer from a task. Use * xStreamBufferSendFromISR() to write to a stream buffer from an interrupt @@ -615,12 +615,12 @@ size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer, * writer and reader to be different tasks or interrupts, but, unlike other * FreeRTOS objects, it is not safe to have multiple different writers or * multiple different readers. If there are to be multiple different writers - * then the application writer must place each call to a writing API function - * (such as xStreamBufferSend()) inside a critical section and set the send - * block time to 0. Likewise, if there are to be multiple different readers - * then the application writer must place each call to a reading API function - * (such as xStreamBufferReceive()) inside a critical section and set the receive - * block time to 0. + * then the application writer must serialize calls to writing API functions + * (such as xStreamBufferSend()). Likewise, if there are to be multiple + * different readers then the application writer must serialize calls to reading + * API functions (such as xStreamBufferReceive()). One way to achieve such + * serialization in single core or SMP kernel is to place each API call inside a + * critical section and use a block time of 0. * * Use xStreamBufferSend() to write to a stream buffer from a task. Use * xStreamBufferSendFromISR() to write to a stream buffer from an interrupt @@ -718,12 +718,12 @@ size_t xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer, * writer and reader to be different tasks or interrupts, but, unlike other * FreeRTOS objects, it is not safe to have multiple different writers or * multiple different readers. If there are to be multiple different writers - * then the application writer must place each call to a writing API function - * (such as xStreamBufferSend()) inside a critical section and set the send - * block time to 0. Likewise, if there are to be multiple different readers - * then the application writer must place each call to a reading API function - * (such as xStreamBufferReceive()) inside a critical section and set the receive - * block time to 0. + * then the application writer must serialize calls to writing API functions + * (such as xStreamBufferSend()). Likewise, if there are to be multiple + * different readers then the application writer must serialize calls to reading + * API functions (such as xStreamBufferReceive()). One way to achieve such + * serialization in single core or SMP kernel is to place each API call inside a + * critical section and use a block time of 0. * * Use xStreamBufferReceive() to read from a stream buffer from a task. Use * xStreamBufferReceiveFromISR() to read from a stream buffer from an From 1b8f5965d360953ebf5559c97418f5f5264bdbee Mon Sep 17 00:00:00 2001 From: kzorer <98871026+kzorer@users.noreply.github.com> Date: Wed, 22 Jan 2025 12:23:35 +0300 Subject: [PATCH 03/11] Add xQueueCreateSetStatic method for static allocation of Queue Sets (#1228) Add xQueueCreateSetStatic method for static allocation of Queue Sets This commit introduces the xQueueCreateSetStatic function, which allows for the static allocation of Queue Sets in FreeRTOS when both configUSE_QUEUE_SETS and configSUPPORT_STATIC_ALLOCATION are enabled. --- include/FreeRTOS.h | 8 ++++ include/mpu_prototypes.h | 6 +++ include/mpu_wrappers.h | 1 + include/queue.h | 74 ++++++++++++++++++++++++++++--- portable/Common/mpu_wrappers.c | 28 ++++++++++++ portable/Common/mpu_wrappers_v2.c | 33 ++++++++++++++ queue.c | 22 ++++++++- 7 files changed, 164 insertions(+), 8 deletions(-) diff --git a/include/FreeRTOS.h b/include/FreeRTOS.h index dfccccb40..ce8530e7d 100644 --- a/include/FreeRTOS.h +++ b/include/FreeRTOS.h @@ -1484,6 +1484,14 @@ #define traceRETURN_xQueueCreateSet( pxQueue ) #endif +#ifndef traceENTER_xQueueCreateSetStatic + #define traceENTER_xQueueCreateSetStatic( uxEventQueueLength ) +#endif + +#ifndef traceRETURN_xQueueCreateSetStatic + #define traceRETURN_xQueueCreateSetStatic( pxQueue ) +#endif + #ifndef traceENTER_xQueueAddToSet #define traceENTER_xQueueAddToSet( xQueueOrSemaphore, xQueueSet ) #endif diff --git a/include/mpu_prototypes.h b/include/mpu_prototypes.h index 1efd13440..9df2a5762 100644 --- a/include/mpu_prototypes.h +++ b/include/mpu_prototypes.h @@ -269,6 +269,9 @@ uint8_t MPU_ucQueueGetQueueType( QueueHandle_t xQueue ) FREERTOS_SYSTEM_CALL; StaticQueue_t * pxStaticQueue, const uint8_t ucQueueType ) FREERTOS_SYSTEM_CALL; QueueSetHandle_t MPU_xQueueCreateSet( const UBaseType_t uxEventQueueLength ) FREERTOS_SYSTEM_CALL; + QueueSetHandle_t MPU_xQueueCreateSetStatic( const UBaseType_t uxEventQueueLength, + uint8_t * pucQueueStorage, + StaticQueue_t * pxStaticQueue ) FREERTOS_SYSTEM_CALL; BaseType_t MPU_xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) FREERTOS_SYSTEM_CALL; BaseType_t MPU_xQueueGenericReset( QueueHandle_t xQueue, @@ -294,6 +297,9 @@ uint8_t MPU_ucQueueGetQueueType( QueueHandle_t xQueue ) FREERTOS_SYSTEM_CALL; StaticQueue_t * pxStaticQueue, const uint8_t ucQueueType ) PRIVILEGED_FUNCTION; QueueSetHandle_t MPU_xQueueCreateSet( const UBaseType_t uxEventQueueLength ) PRIVILEGED_FUNCTION; + QueueSetHandle_t MPU_xQueueCreateSetStatic( const UBaseType_t uxEventQueueLength, + uint8_t * pucQueueStorage, + StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION; BaseType_t MPU_xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION; BaseType_t MPU_xQueueGenericReset( QueueHandle_t xQueue, diff --git a/include/mpu_wrappers.h b/include/mpu_wrappers.h index 4513ca996..3b4738e96 100644 --- a/include/mpu_wrappers.h +++ b/include/mpu_wrappers.h @@ -150,6 +150,7 @@ #define xQueueGenericCreateStatic MPU_xQueueGenericCreateStatic #define xQueueGenericReset MPU_xQueueGenericReset #define xQueueCreateSet MPU_xQueueCreateSet + #define xQueueCreateSetStatic MPU_xQueueCreateSetStatic #define xQueueRemoveFromSet MPU_xQueueRemoveFromSet #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) diff --git a/include/queue.h b/include/queue.h index 963904bb3..56753d300 100644 --- a/include/queue.h +++ b/include/queue.h @@ -1638,12 +1638,12 @@ BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex ) PRIVILEGED_FUNCTION; * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this * function. * - * A queue set must be explicitly created using a call to xQueueCreateSet() - * before it can be used. Once created, standard FreeRTOS queues and semaphores - * can be added to the set using calls to xQueueAddToSet(). - * xQueueSelectFromSet() is then used to determine which, if any, of the queues - * or semaphores contained in the set is in a state where a queue read or - * semaphore take operation would be successful. + * A queue set must be explicitly created using a call to xQueueCreateSet() or + * xQueueCreateSetStatic() before it can be used. Once created, standard + * FreeRTOS queues and semaphores can be added to the set using calls to + * xQueueAddToSet(). xQueueSelectFromSet() is then used to determine which, if + * any, of the queues or semaphores contained in the set is in a state where a + * queue read or semaphore take operation would be successful. * * Note 1: See the documentation on https://www.freertos.org/Documentation/02-Kernel/04-API-references/07-Queue-sets/00-RTOS-queue-sets * for reasons why queue sets are very rarely needed in practice as there are @@ -1683,9 +1683,69 @@ BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex ) PRIVILEGED_FUNCTION; QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength ) PRIVILEGED_FUNCTION; #endif +/* + * Queue sets provide a mechanism to allow a task to block (pend) on a read + * operation from multiple queues or semaphores simultaneously. + * + * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this + * function. + * + * A queue set must be explicitly created using a call to xQueueCreateSet() + * or xQueueCreateSetStatic() before it can be used. Once created, standard + * FreeRTOS queues and semaphores can be added to the set using calls to + * xQueueAddToSet(). xQueueSelectFromSet() is then used to determine which, if + * any, of the queues or semaphores contained in the set is in a state where a + * queue read or semaphore take operation would be successful. + * + * Note 1: See the documentation on https://www.freertos.org/Documentation/02-Kernel/04-API-references/07-Queue-sets/00-RTOS-queue-sets + * for reasons why queue sets are very rarely needed in practice as there are + * simpler methods of blocking on multiple objects. + * + * Note 2: Blocking on a queue set that contains a mutex will not cause the + * mutex holder to inherit the priority of the blocked task. + * + * Note 3: An additional 4 bytes of RAM is required for each space in a every + * queue added to a queue set. Therefore counting semaphores that have a high + * maximum count value should not be added to a queue set. + * + * Note 4: A receive (in the case of a queue) or take (in the case of a + * semaphore) operation must not be performed on a member of a queue set unless + * a call to xQueueSelectFromSet() has first returned a handle to that set member. + * + * @param uxEventQueueLength Queue sets store events that occur on + * the queues and semaphores contained in the set. uxEventQueueLength specifies + * the maximum number of events that can be queued at once. To be absolutely + * certain that events are not lost uxEventQueueLength should be set to the + * total sum of the length of the queues added to the set, where binary + * semaphores and mutexes have a length of 1, and counting semaphores have a + * length set by their maximum count value. Examples: + * + If a queue set is to hold a queue of length 5, another queue of length 12, + * and a binary semaphore, then uxEventQueueLength should be set to + * (5 + 12 + 1), or 18. + * + If a queue set is to hold three binary semaphores then uxEventQueueLength + * should be set to (1 + 1 + 1 ), or 3. + * + If a queue set is to hold a counting semaphore that has a maximum count of + * 5, and a counting semaphore that has a maximum count of 3, then + * uxEventQueueLength should be set to (5 + 3), or 8. + * + * @param pucQueueStorage pucQueueStorage must point to a uint8_t array that is + * at least large enough to hold uxEventQueueLength events. + * + * @param pxQueueBuffer Must point to a variable of type StaticQueue_t, which + * will be used to hold the queue's data structure. + * + * @return If the queue set is created successfully then a handle to the created + * queue set is returned. If pxQueueBuffer is NULL then NULL is returned. + */ +#if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + QueueSetHandle_t xQueueCreateSetStatic( const UBaseType_t uxEventQueueLength, + uint8_t * pucQueueStorage, + StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION; +#endif + /* * Adds a queue or semaphore to a queue set that was previously created by a - * call to xQueueCreateSet(). + * call to xQueueCreateSet() or xQueueCreateSetStatic(). * * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this * function. diff --git a/portable/Common/mpu_wrappers.c b/portable/Common/mpu_wrappers.c index 4c5731665..5bc4181e2 100644 --- a/portable/Common/mpu_wrappers.c +++ b/portable/Common/mpu_wrappers.c @@ -1524,6 +1524,34 @@ #endif /* if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */ /*-----------------------------------------------------------*/ + #if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + QueueSetHandle_t MPU_xQueueCreateSetStatic( const UBaseType_t uxEventQueueLength, + uint8_t * pucQueueStorage, + StaticQueue_t * pxStaticQueue ) /* FREERTOS_SYSTEM_CALL */ + { + QueueSetHandle_t xReturn; + + if( portIS_PRIVILEGED() == pdFALSE ) + { + portRAISE_PRIVILEGE(); + portMEMORY_BARRIER(); + + xReturn = xQueueCreateSetStatic( uxEventQueueLength, pucQueueStorage, pxStaticQueue ); + portMEMORY_BARRIER(); + + portRESET_PRIVILEGE(); + portMEMORY_BARRIER(); + } + else + { + xReturn = xQueueCreateSetStatic( uxEventQueueLength, pucQueueStorage, pxStaticQueue ); + } + + return xReturn; + } + #endif /* if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) */ +/*-----------------------------------------------------------*/ + #if ( configUSE_QUEUE_SETS == 1 ) QueueSetMemberHandle_t MPU_xQueueSelectFromSet( QueueSetHandle_t xQueueSet, TickType_t xBlockTimeTicks ) /* FREERTOS_SYSTEM_CALL */ diff --git a/portable/Common/mpu_wrappers_v2.c b/portable/Common/mpu_wrappers_v2.c index eb9e6f056..e92aca0f5 100644 --- a/portable/Common/mpu_wrappers_v2.c +++ b/portable/Common/mpu_wrappers_v2.c @@ -3016,6 +3016,39 @@ #endif /* if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */ /*-----------------------------------------------------------*/ + #if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + + QueueSetHandle_t MPU_xQueueCreateSetStatic( const UBaseType_t uxEventQueueLength, + uint8_t * pucQueueStorage, + StaticQueue_t * pxStaticQueue ) /* PRIVILEGED_FUNCTION */ + { + QueueSetHandle_t xInternalQueueSetHandle = NULL; + QueueSetHandle_t xExternalQueueSetHandle = NULL; + int32_t lIndex; + + lIndex = MPU_GetFreeIndexInKernelObjectPool(); + + if( lIndex != -1 ) + { + xInternalQueueSetHandle = xQueueCreateSetStatic( uxEventQueueLength, pucQueueStorage, pxStaticQueue ); + + if( xInternalQueueSetHandle != NULL ) + { + MPU_StoreQueueSetHandleAtIndex( lIndex, xInternalQueueSetHandle ); + xExternalQueueSetHandle = ( QueueSetHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex ); + } + else + { + MPU_SetIndexFreeInKernelObjectPool( lIndex ); + } + } + + return xExternalQueueSetHandle; + } + + #endif /* if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) */ +/*-----------------------------------------------------------*/ + #if ( configUSE_QUEUE_SETS == 1 ) BaseType_t MPU_xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, diff --git a/queue.c b/queue.c index 4759b439b..688fb3113 100644 --- a/queue.c +++ b/queue.c @@ -3186,7 +3186,27 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) return pxQueue; } -#endif /* configUSE_QUEUE_SETS */ +#endif /* #if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */ +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + + QueueSetHandle_t xQueueCreateSetStatic( const UBaseType_t uxEventQueueLength, + uint8_t * pucQueueStorage, + StaticQueue_t * pxStaticQueue ) + { + QueueSetHandle_t pxQueue; + + traceENTER_xQueueCreateSetStatic( uxEventQueueLength ); + + pxQueue = xQueueGenericCreateStatic( uxEventQueueLength, ( UBaseType_t ) sizeof( Queue_t * ), pucQueueStorage, pxStaticQueue, queueQUEUE_TYPE_SET ); + + traceRETURN_xQueueCreateSetStatic( pxQueue ); + + return pxQueue; + } + +#endif /* #if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) */ /*-----------------------------------------------------------*/ #if ( configUSE_QUEUE_SETS == 1 ) From ff0989e46b15dca255b57cecaff22795bff9df85 Mon Sep 17 00:00:00 2001 From: Marouen Ghodhbane Date: Wed, 9 Oct 2024 17:31:45 +0200 Subject: [PATCH 04/11] portable: aarch64_sre: add configUSE_TASK_FPU_SUPPORT support This is a direct backport of upstream commit [1] for aarch64 (legacy operation port) done under [2] The same code can be applied on the aarch SRE port to be able to enable FPU context saving on all tasks context switch to mitigate GCC optimization to use SIMD registers for copy. [1] "55eceb22: Add configUSE_TASK_FPU_SUPPORT to AARCH64 port (#1048)" [2] https://github.com/FreeRTOS/FreeRTOS-Kernel/pull/1048 Signed-off-by: Marouen Ghodhbane --- portable/GCC/ARM_AARCH64_SRE/port.c | 54 +++++++++++++++++++----- portable/GCC/ARM_AARCH64_SRE/portmacro.h | 15 +++++-- 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/portable/GCC/ARM_AARCH64_SRE/port.c b/portable/GCC/ARM_AARCH64_SRE/port.c index 1c96c0efd..8cebcaf54 100644 --- a/portable/GCC/ARM_AARCH64_SRE/port.c +++ b/portable/GCC/ARM_AARCH64_SRE/port.c @@ -121,6 +121,10 @@ ::"r" ( portUNMASK_VALUE ) ); \ } +/* The space on the stack required to hold the FPU registers. + * There are 32 128-bit registers.*/ +#define portFPU_REGISTER_WORDS ( 32 * 2 ) + /*-----------------------------------------------------------*/ /* @@ -229,23 +233,47 @@ StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack, *pxTopOfStack = ( StackType_t ) 0x00; /* XZR - has no effect, used so there are an even number of registers. */ pxTopOfStack--; *pxTopOfStack = ( StackType_t ) 0x00; /* R30 - procedure call link register. */ - pxTopOfStack--; + pxTopOfStack--; *pxTopOfStack = portINITIAL_PSTATE; - pxTopOfStack--; + pxTopOfStack--; *pxTopOfStack = ( StackType_t ) pxCode; /* Exception return address. */ - pxTopOfStack--; - /* The task will start with a critical nesting count of 0 as interrupts are - * enabled. */ - *pxTopOfStack = portNO_CRITICAL_NESTING; - pxTopOfStack--; + #if ( configUSE_TASK_FPU_SUPPORT == 1 ) + { + /* The task will start with a critical nesting count of 0 as interrupts are + * enabled. */ + pxTopOfStack--; + *pxTopOfStack = portNO_CRITICAL_NESTING; - /* The task will start without a floating point context. A task that uses - * the floating point hardware must call vPortTaskUsesFPU() before executing - * any floating point instructions. */ - *pxTopOfStack = portNO_FLOATING_POINT_CONTEXT; + /* The task will start without a floating point context. A task that + * uses the floating point hardware must call vPortTaskUsesFPU() before + * executing any floating point instructions. */ + pxTopOfStack--; + *pxTopOfStack = portNO_FLOATING_POINT_CONTEXT; + } + #elif ( configUSE_TASK_FPU_SUPPORT == 2 ) + { + /* The task will start with a floating point context. Leave enough + * space for the registers - and ensure they are initialised to 0. */ + pxTopOfStack -= portFPU_REGISTER_WORDS; + memset( pxTopOfStack, 0x00, portFPU_REGISTER_WORDS * sizeof( StackType_t ) ); + + /* The task will start with a critical nesting count of 0 as interrupts are + * enabled. */ + pxTopOfStack--; + *pxTopOfStack = portNO_CRITICAL_NESTING; + + pxTopOfStack--; + *pxTopOfStack = pdTRUE; + ullPortTaskHasFPUContext = pdTRUE; + } + #else /* if ( configUSE_TASK_FPU_SUPPORT == 1 ) */ + { + #error "Invalid configUSE_TASK_FPU_SUPPORT setting - configUSE_TASK_FPU_SUPPORT must be set to 1, 2, or left undefined." + } + #endif /* if ( configUSE_TASK_FPU_SUPPORT == 1 ) */ return pxTopOfStack; } @@ -384,6 +412,8 @@ void FreeRTOS_Tick_Handler( void ) } /*-----------------------------------------------------------*/ +#if ( configUSE_TASK_FPU_SUPPORT != 2 ) + void vPortTaskUsesFPU( void ) { /* A task is registering the fact that it needs an FPU context. Set the @@ -393,6 +423,8 @@ void vPortTaskUsesFPU( void ) /* Consider initialising the FPSR here - but probably not necessary in * AArch64. */ } + +#endif /* configUSE_TASK_FPU_SUPPORT */ /*-----------------------------------------------------------*/ void vPortClearInterruptMask( UBaseType_t uxNewMaskValue ) diff --git a/portable/GCC/ARM_AARCH64_SRE/portmacro.h b/portable/GCC/ARM_AARCH64_SRE/portmacro.h index 296984d5b..5810741d2 100644 --- a/portable/GCC/ARM_AARCH64_SRE/portmacro.h +++ b/portable/GCC/ARM_AARCH64_SRE/portmacro.h @@ -135,9 +135,18 @@ extern void vPortInstallFreeRTOSVectorTable( void ); * handler for whichever peripheral is used to generate the RTOS tick. */ void FreeRTOS_Tick_Handler( void ); -/* Any task that uses the floating point unit MUST call vPortTaskUsesFPU() - * before any floating point instructions are executed. */ -void vPortTaskUsesFPU( void ); +/* If configUSE_TASK_FPU_SUPPORT is set to 1 (or left undefined) then tasks are + * created without an FPU context and must call vPortTaskUsesFPU() to give + * themselves an FPU context before using any FPU instructions. If + * configUSE_TASK_FPU_SUPPORT is set to 2 then all tasks will have an FPU context + * by default. */ +#if ( configUSE_TASK_FPU_SUPPORT != 2 ) + void vPortTaskUsesFPU( void ); +#else + /* Each task has an FPU context already, so define this function away to + * nothing to prevent it from being called accidentally. */ + #define vPortTaskUsesFPU() +#endif #define portTASK_USES_FLOATING_POINT() vPortTaskUsesFPU() #define portLOWEST_INTERRUPT_PRIORITY ( ( ( uint32_t ) configUNIQUE_INTERRUPT_PRIORITIES ) - 1UL ) From 630cfb5b79dee06faaeedf2b69893b68a97c4c70 Mon Sep 17 00:00:00 2001 From: Marouen Ghodhbane Date: Wed, 9 Oct 2024 18:34:55 +0200 Subject: [PATCH 05/11] portable: aarch64_sre: add the configuration and status registers to the fpu saved context FPSR and FPCR are two 64-bits registers where only the lower 32 bits are defined. Save them when doing context switch with FPU context saving enabled. Signed-off-by: Marouen Ghodhbane --- portable/GCC/ARM_AARCH64_SRE/port.c | 4 ++-- portable/GCC/ARM_AARCH64_SRE/portASM.S | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/portable/GCC/ARM_AARCH64_SRE/port.c b/portable/GCC/ARM_AARCH64_SRE/port.c index 8cebcaf54..ffc34d746 100644 --- a/portable/GCC/ARM_AARCH64_SRE/port.c +++ b/portable/GCC/ARM_AARCH64_SRE/port.c @@ -122,8 +122,8 @@ } /* The space on the stack required to hold the FPU registers. - * There are 32 128-bit registers.*/ -#define portFPU_REGISTER_WORDS ( 32 * 2 ) + * There are 32 128-bit plus 2 64-bit status registers.*/ +#define portFPU_REGISTER_WORDS ( (32 * 2) + 2 ) /*-----------------------------------------------------------*/ diff --git a/portable/GCC/ARM_AARCH64_SRE/portASM.S b/portable/GCC/ARM_AARCH64_SRE/portASM.S index ed3c031d0..8d69b2aa1 100644 --- a/portable/GCC/ARM_AARCH64_SRE/portASM.S +++ b/portable/GCC/ARM_AARCH64_SRE/portASM.S @@ -87,7 +87,7 @@ LDR X0, ullPortTaskHasFPUContextConst LDR X2, [X0] - /* Save the FPU context, if any (32 128-bit registers). */ + /* Save the FPU context, if any (32 128-bit plus two 64-bit status registers). */ CMP X2, #0 B.EQ 1f STP Q0, Q1, [SP,#-0x20]! @@ -107,6 +107,11 @@ STP Q28, Q29, [SP,#-0x20]! STP Q30, Q31, [SP,#-0x20]! + /* Even though upper 32 bits of FPSR and FPCR are reserved, save and restore the whole 64 bits to keep 16-byte SP alignement. */ + MRS X9, FPSR + MRS X10, FPCR + STP X9, X10, [SP, #-0x10]! + 1: /* Store the critical nesting count and FPU context indicator. */ STP X2, X3, [SP, #-0x10]! @@ -157,6 +162,7 @@ /* Restore the FPU context, if any. */ CMP X2, #0 B.EQ 1f + LDP X9, X10, [SP], #0x10 LDP Q30, Q31, [SP], #0x20 LDP Q28, Q29, [SP], #0x20 LDP Q26, Q27, [SP], #0x20 @@ -173,6 +179,8 @@ LDP Q4, Q5, [SP], #0x20 LDP Q2, Q3, [SP], #0x20 LDP Q0, Q1, [SP], #0x20 + MSR FPSR, X9 + MSR FPCR, X10 1: LDP X2, X3, [SP], #0x10 /* SPSR and ELR. */ From 72bb476bf3d20c65d054557884f624fde9eec704 Mon Sep 17 00:00:00 2001 From: Marouen Ghodhbane Date: Fri, 11 Oct 2024 15:36:42 +0200 Subject: [PATCH 06/11] portable: aarch64_sre: Add support for vApplicationFPUSafeIRQHandler The application writer needs to name their IRQ handler as: 1. vApplicationIRQHandler if the IRQ handler does not use FPU registers. 2. vApplicationFPUSafeIRQHandler is the IRQ handler uses FPU registers. When the application uses vApplicationFPUSafeIRQHandler, a default implementation of vApplicationIRQHandler is used which stores FPU registers and then calls vApplicationFPUSafeIRQHandler. Note that recent versions of GCC may use FP/SIMD registers to optimize 16-bytes copy and especially when using va_start()/va_arg() functions (e.g printing some thing in IRQ handlers may trigger usage of FPU registers) This implementation is heavily inspired by both the ARM_CA9 port and the ARM_CRx_No_GIC port done in [1] [1] https://github.com/FreeRTOS/FreeRTOS-Kernel/pull/1113 Signed-off-by: Marouen Ghodhbane --- portable/GCC/ARM_AARCH64_SRE/port.c | 27 ++++++++++ portable/GCC/ARM_AARCH64_SRE/portASM.S | 74 ++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/portable/GCC/ARM_AARCH64_SRE/port.c b/portable/GCC/ARM_AARCH64_SRE/port.c index ffc34d746..ab9290d43 100644 --- a/portable/GCC/ARM_AARCH64_SRE/port.c +++ b/portable/GCC/ARM_AARCH64_SRE/port.c @@ -133,6 +133,27 @@ */ extern void vPortRestoreTaskContext( void ); +/* + * If the application provides an implementation of vApplicationIRQHandler(), + * then it will get called directly without saving the FPU registers on + * interrupt entry, and this weak implementation of + * vApplicationFPUSafeIRQHandler() is just provided to remove linkage errors - + * it should never actually get called so its implementation contains a + * call to configASSERT() that will always fail. + * + * If the application provides its own implementation of + * vApplicationFPUSafeIRQHandler() then the implementation of + * vApplicationIRQHandler() provided in portASM.S will save the FPU registers + * before calling it. + * + * Therefore, if the application writer wants FPU registers to be saved on + * interrupt entry their IRQ handler must be called + * vApplicationFPUSafeIRQHandler(), and if the application writer does not want + * FPU registers to be saved on interrupt entry their IRQ handler must be + * called vApplicationIRQHandler(). + */ +void vApplicationFPUSafeIRQHandler( uint32_t ulICCIAR ) __attribute__((weak) ); + /*-----------------------------------------------------------*/ /* A variable is used to keep track of the critical section nesting. This @@ -495,3 +516,9 @@ UBaseType_t uxPortSetInterruptMask( void ) #endif /* configASSERT_DEFINED */ /*-----------------------------------------------------------*/ + +void vApplicationFPUSafeIRQHandler( uint32_t ulICCIAR ) +{ + ( void ) ulICCIAR; + configASSERT( ( volatile void * ) NULL ); +} diff --git a/portable/GCC/ARM_AARCH64_SRE/portASM.S b/portable/GCC/ARM_AARCH64_SRE/portASM.S index 8d69b2aa1..f1f59cd33 100644 --- a/portable/GCC/ARM_AARCH64_SRE/portASM.S +++ b/portable/GCC/ARM_AARCH64_SRE/portASM.S @@ -414,8 +414,82 @@ Exit_IRQ_No_Context_Switch: ERET +/****************************************************************************** + * If the application provides an implementation of vApplicationIRQHandler(), + * then it will get called directly without saving the FPU registers on + * interrupt entry, and this weak implementation of + * vApplicationIRQHandler() will not get called. + * + * If the application provides its own implementation of + * vApplicationFPUSafeIRQHandler() then this implementation of + * vApplicationIRQHandler() will be called, save the FPU registers, and then + * call vApplicationFPUSafeIRQHandler(). + * + * Therefore, if the application writer wants FPU registers to be saved on + * interrupt entry their IRQ handler must be called + * vApplicationFPUSafeIRQHandler(), and if the application writer does not want + * FPU registers to be saved on interrupt entry their IRQ handler must be + * called vApplicationIRQHandler(). + *****************************************************************************/ +.align 8 +.weak vApplicationIRQHandler +.type vApplicationIRQHandler, %function +vApplicationIRQHandler: + /* Save LR and FP on the stack */ + STP X29, X30, [SP, #-0x10]! + /* Save FPU registers (32 128-bits + 2 64-bits configuration and status registers) */ + STP Q0, Q1, [SP,#-0x20]! + STP Q2, Q3, [SP,#-0x20]! + STP Q4, Q5, [SP,#-0x20]! + STP Q6, Q7, [SP,#-0x20]! + STP Q8, Q9, [SP,#-0x20]! + STP Q10, Q11, [SP,#-0x20]! + STP Q12, Q13, [SP,#-0x20]! + STP Q14, Q15, [SP,#-0x20]! + STP Q16, Q17, [SP,#-0x20]! + STP Q18, Q19, [SP,#-0x20]! + STP Q20, Q21, [SP,#-0x20]! + STP Q22, Q23, [SP,#-0x20]! + STP Q24, Q25, [SP,#-0x20]! + STP Q26, Q27, [SP,#-0x20]! + STP Q28, Q29, [SP,#-0x20]! + STP Q30, Q31, [SP,#-0x20]! + + /* Even though upper 32 bits of FPSR and FPCR are reserved, save and restore the whole 64 bits to keep 16-byte SP alignement. */ + MRS X9, FPSR + MRS X10, FPCR + STP X9, X10, [SP, #-0x10]! + + /* Call the C handler. */ + BL vApplicationFPUSafeIRQHandler + + /* Restore FPU registers */ + + LDP X9, X10, [SP], #0x10 + LDP Q30, Q31, [SP], #0x20 + LDP Q28, Q29, [SP], #0x20 + LDP Q26, Q27, [SP], #0x20 + LDP Q24, Q25, [SP], #0x20 + LDP Q22, Q23, [SP], #0x20 + LDP Q20, Q21, [SP], #0x20 + LDP Q18, Q19, [SP], #0x20 + LDP Q16, Q17, [SP], #0x20 + LDP Q14, Q15, [SP], #0x20 + LDP Q12, Q13, [SP], #0x20 + LDP Q10, Q11, [SP], #0x20 + LDP Q8, Q9, [SP], #0x20 + LDP Q6, Q7, [SP], #0x20 + LDP Q4, Q5, [SP], #0x20 + LDP Q2, Q3, [SP], #0x20 + LDP Q0, Q1, [SP], #0x20 + MSR FPSR, X9 + MSR FPCR, X10 + + /* Restore FP and LR */ + LDP X29, X30, [SP], #0x10 + RET .align 8 pxCurrentTCBConst: .dword pxCurrentTCB From 2b35979a1a3225750089d64dc964e5f19b00ce6d Mon Sep 17 00:00:00 2001 From: John Boiles Date: Fri, 24 Jan 2025 16:56:59 -0800 Subject: [PATCH 07/11] POSIX Simulator: Handle `pthread`s not created by FreeRTOS differently (#1223) --- portable/ThirdParty/GCC/Posix/port.c | 102 +++++++++++++++++++++------ 1 file changed, 82 insertions(+), 20 deletions(-) diff --git a/portable/ThirdParty/GCC/Posix/port.c b/portable/ThirdParty/GCC/Posix/port.c index 7cc32128f..c4eacb2ba 100644 --- a/portable/ThirdParty/GCC/Posix/port.c +++ b/portable/ThirdParty/GCC/Posix/port.c @@ -105,6 +105,8 @@ static BaseType_t xSchedulerEnd = pdFALSE; static pthread_t hTimerTickThread; static bool xTimerTickThreadShouldRun; static uint64_t prvStartTimeNs; +static pthread_mutex_t xThreadMutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_key_t xThreadKey = 0; /*-----------------------------------------------------------*/ static void prvSetupSignalsAndSchedulerPolicy( void ); @@ -119,6 +121,45 @@ static void vPortStartFirstTask( void ); static void prvPortYieldFromISR( void ); /*-----------------------------------------------------------*/ +void prvThreadKeyDestructor( void * data ) +{ + free( data ); +} + +static void prvInitThreadKey() +{ + pthread_mutex_lock( &xThreadMutex ); + + if( xThreadKey == 0 ) + { + pthread_key_create( &xThreadKey, prvThreadKeyDestructor ); + } + + pthread_mutex_unlock( &xThreadMutex ); +} + +static void prvMarkAsFreeRTOSThread( pthread_t thread ) +{ + prvInitThreadKey(); + uint8_t * thread_data = malloc( 1 ); + configASSERT( thread_data != NULL ); + *thread_data = 1; + pthread_setspecific( xThreadKey, thread_data ); +} + +static BaseType_t prvIsFreeRTOSThread( pthread_t thread ) +{ + uint8_t * thread_data = ( uint8_t * ) pthread_getspecific( xThreadKey ); + + return thread_data != NULL && *thread_data == 1; +} + +static void prvDestroyThreadKey() +{ + pthread_key_delete( xThreadKey ); +} +/*-----------------------------------------------------------*/ + static void prvFatalError( const char * pcCall, int iErrno ) __attribute__( ( __noreturn__ ) ); @@ -249,6 +290,8 @@ BaseType_t xPortStartScheduler( void ) /* Restore original signal mask. */ ( void ) pthread_sigmask( SIG_SETMASK, &xSchedulerOriginalSignalMask, NULL ); + prvDestroyThreadKey(); + return 0; } /*-----------------------------------------------------------*/ @@ -266,8 +309,12 @@ void vPortEndScheduler( void ) ( void ) pthread_kill( hMainThread, SIG_RESUME ); /* Waiting to be deleted here. */ - pxCurrentThread = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); - event_wait( pxCurrentThread->ev ); + if( prvIsFreeRTOSThread( pthread_self() ) == pdTRUE ) + { + pxCurrentThread = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); + event_wait( pxCurrentThread->ev ); + } + pthread_testcancel(); } /*-----------------------------------------------------------*/ @@ -322,13 +369,19 @@ void vPortYield( void ) void vPortDisableInterrupts( void ) { - pthread_sigmask( SIG_BLOCK, &xAllSignals, NULL ); + if( prvIsFreeRTOSThread( pthread_self() ) == pdTRUE ) + { + pthread_sigmask(SIG_BLOCK, &xAllSignals, NULL); + } } /*-----------------------------------------------------------*/ void vPortEnableInterrupts( void ) { - pthread_sigmask( SIG_UNBLOCK, &xAllSignals, NULL ); + if( prvIsFreeRTOSThread( pthread_self() ) == pdTRUE ) + { + pthread_sigmask(SIG_UNBLOCK, &xAllSignals, NULL); + } } /*-----------------------------------------------------------*/ @@ -364,6 +417,8 @@ static void * prvTimerTickHandler( void * arg ) { ( void ) arg; + prvMarkAsFreeRTOSThread( pthread_self() ); + prvPortSetCurrentThreadName("Scheduler timer"); while( xTimerTickThreadShouldRun ) @@ -396,26 +451,31 @@ void prvSetupTimerInterrupt( void ) static void vPortSystemTickHandler( int sig ) { - Thread_t * pxThreadToSuspend; - Thread_t * pxThreadToResume; - - ( void ) sig; - - uxCriticalNesting++; /* Signals are blocked in this signal handler. */ - - pxThreadToSuspend = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); - - if( xTaskIncrementTick() != pdFALSE ) + if( prvIsFreeRTOSThread( pthread_self() ) == pdTRUE ) { - /* Select Next Task. */ - vTaskSwitchContext(); + Thread_t * pxThreadToSuspend; + Thread_t * pxThreadToResume; - pxThreadToResume = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); + ( void ) sig; - prvSwitchThread( pxThreadToResume, pxThreadToSuspend ); + uxCriticalNesting++; /* Signals are blocked in this signal handler. */ + + pxThreadToSuspend = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); + + if( xTaskIncrementTick() != pdFALSE ) + { + /* Select Next Task. */ + vTaskSwitchContext(); + + pxThreadToResume = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); + + prvSwitchThread( pxThreadToResume, pxThreadToSuspend ); + } + + uxCriticalNesting--; + } else { + fprintf( stderr, "vPortSystemTickHandler called from non-FreeRTOS thread\n" ); } - - uxCriticalNesting--; } /*-----------------------------------------------------------*/ @@ -448,6 +508,8 @@ static void * prvWaitForStart( void * pvParams ) { Thread_t * pxThread = pvParams; + prvMarkAsFreeRTOSThread( pthread_self() ); + prvSuspendSelf( pxThread ); /* Resumed for the first time, unblocks all signals. */ From 11d0caa61487eacff89044efed4e19579b9e0a5e Mon Sep 17 00:00:00 2001 From: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> Date: Sat, 25 Jan 2025 13:34:03 +0530 Subject: [PATCH 08/11] Fix the context array size for MPU ports (#1230) Fix the context array size for MPU ports Ensure the saved context location falls within the reserved context area rather than overlapping with the next MPU_SETTINGS structure member. This never caused a problem because actual read/write operations start from one word before the saved context location. Signed-off-by: Gaurav Aggarwal --- .github/workflows/kernel-demos.yml | 4 ++-- portable/ARMv8M/non_secure/portmacrocommon.h | 16 ++++++++-------- .../GCC/ARM_CM23/non_secure/portmacrocommon.h | 16 ++++++++-------- .../ARM_CM23_NTZ/non_secure/portmacrocommon.h | 16 ++++++++-------- .../GCC/ARM_CM33/non_secure/portmacrocommon.h | 16 ++++++++-------- .../ARM_CM33_NTZ/non_secure/portmacrocommon.h | 16 ++++++++-------- .../GCC/ARM_CM35P/non_secure/portmacrocommon.h | 16 ++++++++-------- .../ARM_CM35P_NTZ/non_secure/portmacrocommon.h | 16 ++++++++-------- portable/GCC/ARM_CM3_MPU/portmacro.h | 8 ++++++++ portable/GCC/ARM_CM4_MPU/portmacro.h | 11 ++++++++++- .../GCC/ARM_CM55/non_secure/portmacrocommon.h | 16 ++++++++-------- .../ARM_CM55_NTZ/non_secure/portmacrocommon.h | 16 ++++++++-------- .../GCC/ARM_CM85/non_secure/portmacrocommon.h | 16 ++++++++-------- .../ARM_CM85_NTZ/non_secure/portmacrocommon.h | 16 ++++++++-------- .../IAR/ARM_CM23/non_secure/portmacrocommon.h | 16 ++++++++-------- .../ARM_CM23_NTZ/non_secure/portmacrocommon.h | 16 ++++++++-------- .../IAR/ARM_CM33/non_secure/portmacrocommon.h | 16 ++++++++-------- .../ARM_CM33_NTZ/non_secure/portmacrocommon.h | 16 ++++++++-------- .../IAR/ARM_CM35P/non_secure/portmacrocommon.h | 16 ++++++++-------- .../ARM_CM35P_NTZ/non_secure/portmacrocommon.h | 16 ++++++++-------- portable/IAR/ARM_CM4F_MPU/portmacro.h | 11 ++++++++++- .../IAR/ARM_CM55/non_secure/portmacrocommon.h | 16 ++++++++-------- .../ARM_CM55_NTZ/non_secure/portmacrocommon.h | 16 ++++++++-------- .../IAR/ARM_CM85/non_secure/portmacrocommon.h | 16 ++++++++-------- .../ARM_CM85_NTZ/non_secure/portmacrocommon.h | 16 ++++++++-------- portable/RVDS/ARM_CM4_MPU/portmacro.h | 11 ++++++++++- 26 files changed, 208 insertions(+), 173 deletions(-) diff --git a/.github/workflows/kernel-demos.yml b/.github/workflows/kernel-demos.yml index f81ae33f3..404c602b5 100644 --- a/.github/workflows/kernel-demos.yml +++ b/.github/workflows/kernel-demos.yml @@ -268,12 +268,12 @@ jobs: fetch-depth: 1 - env: - stepName: Fetch Community-Supported-Demos Submodule + stepName: Fetch Dependencies shell: bash run: | # ${{ env.stepName }} echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" - git submodule update --checkout --init --depth 1 FreeRTOS/Demo/ThirdParty/Community-Supported-Demos + git submodule update --checkout --init --depth 1 FreeRTOS/Demo/ThirdParty/Community-Supported-Demos FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}" # Checkout user pull request changes diff --git a/portable/ARMv8M/non_secure/portmacrocommon.h b/portable/ARMv8M/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/ARMv8M/non_secure/portmacrocommon.h +++ b/portable/ARMv8M/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/GCC/ARM_CM23/non_secure/portmacrocommon.h b/portable/GCC/ARM_CM23/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/GCC/ARM_CM23/non_secure/portmacrocommon.h +++ b/portable/GCC/ARM_CM23/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/GCC/ARM_CM23_NTZ/non_secure/portmacrocommon.h b/portable/GCC/ARM_CM23_NTZ/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/GCC/ARM_CM23_NTZ/non_secure/portmacrocommon.h +++ b/portable/GCC/ARM_CM23_NTZ/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/GCC/ARM_CM33/non_secure/portmacrocommon.h b/portable/GCC/ARM_CM33/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/GCC/ARM_CM33/non_secure/portmacrocommon.h +++ b/portable/GCC/ARM_CM33/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/GCC/ARM_CM33_NTZ/non_secure/portmacrocommon.h b/portable/GCC/ARM_CM33_NTZ/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/GCC/ARM_CM33_NTZ/non_secure/portmacrocommon.h +++ b/portable/GCC/ARM_CM33_NTZ/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/GCC/ARM_CM35P/non_secure/portmacrocommon.h b/portable/GCC/ARM_CM35P/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/GCC/ARM_CM35P/non_secure/portmacrocommon.h +++ b/portable/GCC/ARM_CM35P/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/GCC/ARM_CM35P_NTZ/non_secure/portmacrocommon.h b/portable/GCC/ARM_CM35P_NTZ/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/GCC/ARM_CM35P_NTZ/non_secure/portmacrocommon.h +++ b/portable/GCC/ARM_CM35P_NTZ/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/GCC/ARM_CM3_MPU/portmacro.h b/portable/GCC/ARM_CM3_MPU/portmacro.h index fb2c53832..a2e6883c0 100644 --- a/portable/GCC/ARM_CM3_MPU/portmacro.h +++ b/portable/GCC/ARM_CM3_MPU/portmacro.h @@ -125,6 +125,14 @@ typedef struct MPU_REGION_SETTINGS #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */ +/* + * +------------------------------+-------------------------------+-----+ + * | CONTROL, r4-r11, EXC_RETURN | PSP, r0-r3, r12, LR, PC, xPSR | | + * +------------------------------+-------------------------------+-----+ + * + * <-----------------------------><-------------------------------><----> + * 10 9 1 + */ #define MAX_CONTEXT_SIZE ( 20 ) /* Size of an Access Control List (ACL) entry in bits. */ diff --git a/portable/GCC/ARM_CM4_MPU/portmacro.h b/portable/GCC/ARM_CM4_MPU/portmacro.h index 0c40ac624..581b09d5c 100644 --- a/portable/GCC/ARM_CM4_MPU/portmacro.h +++ b/portable/GCC/ARM_CM4_MPU/portmacro.h @@ -219,7 +219,16 @@ typedef struct MPU_REGION_SETTINGS #endif /* configUSE_MPU_WRAPPERS_V1 == 0 */ -#define MAX_CONTEXT_SIZE ( 52 ) +/* + * +---------+---------------+-----------------+-----------------+-----+ + * | s16-s31 | s0-s15, FPSCR | CONTROL, r4-r11 | PSP, r0-r3, r12 | | + * | | | EXC_RETURN | LR, PC, xPSR | | + * +---------+---------------+-----------------+-----------------+-----+ + * + * <--------><---------------><----------------><----------------><----> + * 16 17 10 9 1 + */ +#define MAX_CONTEXT_SIZE ( 53 ) /* Size of an Access Control List (ACL) entry in bits. */ #define portACL_ENTRY_SIZE_BITS ( 32U ) diff --git a/portable/GCC/ARM_CM55/non_secure/portmacrocommon.h b/portable/GCC/ARM_CM55/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/GCC/ARM_CM55/non_secure/portmacrocommon.h +++ b/portable/GCC/ARM_CM55/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/GCC/ARM_CM55_NTZ/non_secure/portmacrocommon.h b/portable/GCC/ARM_CM55_NTZ/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/GCC/ARM_CM55_NTZ/non_secure/portmacrocommon.h +++ b/portable/GCC/ARM_CM55_NTZ/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/GCC/ARM_CM85/non_secure/portmacrocommon.h b/portable/GCC/ARM_CM85/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/GCC/ARM_CM85/non_secure/portmacrocommon.h +++ b/portable/GCC/ARM_CM85/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/GCC/ARM_CM85_NTZ/non_secure/portmacrocommon.h b/portable/GCC/ARM_CM85_NTZ/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/GCC/ARM_CM85_NTZ/non_secure/portmacrocommon.h +++ b/portable/GCC/ARM_CM85_NTZ/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/IAR/ARM_CM23/non_secure/portmacrocommon.h b/portable/IAR/ARM_CM23/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/IAR/ARM_CM23/non_secure/portmacrocommon.h +++ b/portable/IAR/ARM_CM23/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/IAR/ARM_CM23_NTZ/non_secure/portmacrocommon.h b/portable/IAR/ARM_CM23_NTZ/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/IAR/ARM_CM23_NTZ/non_secure/portmacrocommon.h +++ b/portable/IAR/ARM_CM23_NTZ/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/IAR/ARM_CM33/non_secure/portmacrocommon.h b/portable/IAR/ARM_CM33/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/IAR/ARM_CM33/non_secure/portmacrocommon.h +++ b/portable/IAR/ARM_CM33/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/IAR/ARM_CM33_NTZ/non_secure/portmacrocommon.h b/portable/IAR/ARM_CM33_NTZ/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/IAR/ARM_CM33_NTZ/non_secure/portmacrocommon.h +++ b/portable/IAR/ARM_CM33_NTZ/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/IAR/ARM_CM35P/non_secure/portmacrocommon.h b/portable/IAR/ARM_CM35P/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/IAR/ARM_CM35P/non_secure/portmacrocommon.h +++ b/portable/IAR/ARM_CM35P/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/IAR/ARM_CM35P_NTZ/non_secure/portmacrocommon.h b/portable/IAR/ARM_CM35P_NTZ/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/IAR/ARM_CM35P_NTZ/non_secure/portmacrocommon.h +++ b/portable/IAR/ARM_CM35P_NTZ/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/IAR/ARM_CM4F_MPU/portmacro.h b/portable/IAR/ARM_CM4F_MPU/portmacro.h index 08f849992..6b7600c15 100644 --- a/portable/IAR/ARM_CM4F_MPU/portmacro.h +++ b/portable/IAR/ARM_CM4F_MPU/portmacro.h @@ -221,7 +221,16 @@ typedef struct MPU_REGION_SETTINGS #endif /* configUSE_MPU_WRAPPERS_V1 == 0 */ -#define MAX_CONTEXT_SIZE ( 52 ) +/* + * +---------+---------------+-----------------+-----------------+-----+ + * | s16-s31 | s0-s15, FPSCR | CONTROL, r4-r11 | PSP, r0-r3, r12 | | + * | | | EXC_RETURN | LR, PC, xPSR | | + * +---------+---------------+-----------------+-----------------+-----+ + * + * <--------><---------------><----------------><----------------><----> + * 16 17 10 9 1 + */ +#define MAX_CONTEXT_SIZE ( 53 ) /* Size of an Access Control List (ACL) entry in bits. */ #define portACL_ENTRY_SIZE_BITS ( 32U ) diff --git a/portable/IAR/ARM_CM55/non_secure/portmacrocommon.h b/portable/IAR/ARM_CM55/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/IAR/ARM_CM55/non_secure/portmacrocommon.h +++ b/portable/IAR/ARM_CM55/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/IAR/ARM_CM55_NTZ/non_secure/portmacrocommon.h b/portable/IAR/ARM_CM55_NTZ/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/IAR/ARM_CM55_NTZ/non_secure/portmacrocommon.h +++ b/portable/IAR/ARM_CM55_NTZ/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/IAR/ARM_CM85/non_secure/portmacrocommon.h b/portable/IAR/ARM_CM85/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/IAR/ARM_CM85/non_secure/portmacrocommon.h +++ b/portable/IAR/ARM_CM85/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/IAR/ARM_CM85_NTZ/non_secure/portmacrocommon.h b/portable/IAR/ARM_CM85_NTZ/non_secure/portmacrocommon.h index e74fa8257..ec14d467d 100644 --- a/portable/IAR/ARM_CM85_NTZ/non_secure/portmacrocommon.h +++ b/portable/IAR/ARM_CM85_NTZ/non_secure/portmacrocommon.h @@ -251,9 +251,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><-----------><----> - * 16 16 8 8 5 16 1 + * 16 17 8 8 5 16 1 */ - #define MAX_CONTEXT_SIZE 70 + #define MAX_CONTEXT_SIZE 71 #elif ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 0 ) ) @@ -264,9 +264,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+------------------------------+-----+ * * <-----------><--------------><---------><----------------><-----------------------------><----> - * 16 16 8 8 5 1 + * 16 17 8 8 5 1 */ - #define MAX_CONTEXT_SIZE 54 + #define MAX_CONTEXT_SIZE 55 #elif ( ( configENABLE_TRUSTZONE == 0 ) && ( configENABLE_PAC == 1 ) ) @@ -277,9 +277,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><-----------><----> - * 16 16 8 8 4 16 1 + * 16 17 8 8 4 16 1 */ - #define MAX_CONTEXT_SIZE 69 + #define MAX_CONTEXT_SIZE 70 #else /* if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ @@ -290,9 +290,9 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P * +-----------+---------------+----------+-----------------+----------------------+-----+ * * <-----------><--------------><---------><----------------><---------------------><----> - * 16 16 8 8 4 1 + * 16 17 8 8 4 1 */ - #define MAX_CONTEXT_SIZE 53 + #define MAX_CONTEXT_SIZE 54 #endif /* #if ( ( configENABLE_TRUSTZONE == 1 ) && ( configENABLE_PAC == 1 ) ) */ diff --git a/portable/RVDS/ARM_CM4_MPU/portmacro.h b/portable/RVDS/ARM_CM4_MPU/portmacro.h index 5977f3f88..8e682ba74 100644 --- a/portable/RVDS/ARM_CM4_MPU/portmacro.h +++ b/portable/RVDS/ARM_CM4_MPU/portmacro.h @@ -218,7 +218,16 @@ typedef struct MPU_REGION_SETTINGS #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */ -#define MAX_CONTEXT_SIZE ( 52 ) +/* + * +---------+---------------+-----------------+-----------------+-----+ + * | s16-s31 | s0-s15, FPSCR | CONTROL, r4-r11 | PSP, r0-r3, r12 | | + * | | | EXC_RETURN | LR, PC, xPSR | | + * +---------+---------------+-----------------+-----------------+-----+ + * + * <--------><---------------><----------------><----------------><----> + * 16 17 10 9 1 + */ +#define MAX_CONTEXT_SIZE ( 53 ) /* Size of an Access Control List (ACL) entry in bits. */ #define portACL_ENTRY_SIZE_BITS ( 32U ) From b421abc7c389fbd02f25ec96fac9e4aed74f83ad Mon Sep 17 00:00:00 2001 From: Cavin McKinley <30472644+mcknly@users.noreply.github.com> Date: Sat, 25 Jan 2025 03:38:49 -0600 Subject: [PATCH 09/11] Update Community-Supported-Ports submod to fix RP2350 port - FreeRTOS-Kernel#1220 (#1232) Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> --- portable/ThirdParty/Community-Supported-Ports | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portable/ThirdParty/Community-Supported-Ports b/portable/ThirdParty/Community-Supported-Ports index 3c5bfb8f2..bae4c7aa1 160000 --- a/portable/ThirdParty/Community-Supported-Ports +++ b/portable/ThirdParty/Community-Supported-Ports @@ -1 +1 @@ -Subproject commit 3c5bfb8f2e557735b5200176b4a8b25a40c68d1b +Subproject commit bae4c7aa19009825ba48071a8fe25dcb8be84880 From f94bc89108ffca538cf91d5856149960a5d4be81 Mon Sep 17 00:00:00 2001 From: Kody Stribrny <89810515+kstribrnAmzn@users.noreply.github.com> Date: Tue, 28 Jan 2025 09:13:17 -0800 Subject: [PATCH 10/11] fix: SA violation fixes and simplification for idle task length restrictions (#1227) fix: SA violation fixes and simplification for idle task length restrictions This change: * Removes the dependency on strings.h for the prvCreateIdleTask function * Resolves several static analysis violations reported by tools like Parasoft Builds off of - https://github.com/FreeRTOS/FreeRTOS-Kernel/pull/1203 --- MISRA.md | 19 +++++++++++++++++++ tasks.c | 46 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/MISRA.md b/MISRA.md index 4355ec678..b5941037f 100644 --- a/MISRA.md +++ b/MISRA.md @@ -115,6 +115,25 @@ _Ref 11.5.5_ because data storage buffers are implemented as uint8_t arrays for the ease of sizing, alignment and access. +#### Rule 14.3 + +MISRA C-2012 Rule 14.3: Controlling expressions shall not be invariant. + +_Ref 14.3_ + - The `configMAX_TASK_NAME_LEN` and `taskRESERVED_TASK_NAME_LENGTH` are + evaluated to constants at compile time and may vary based on the build + configuration. + +#### Rule 18.1 + +MISRA C-2012 Rule 18.1: A pointer resulting from arithmetic on a pointer operand +shall address an element of the same array as that pointer operand. + +_Ref 18.1_ + - Array access remains within bounds since either the null terminator in + the IDLE task name will break the loop, or the loop will break normally + if the array size is smaller than the IDLE task name length. + #### Rule 21.6 MISRA C-2012 Rule 21.6: The Standard Library input/output functions shall not diff --git a/tasks.c b/tasks.c index d7153f680..518c9e87f 100644 --- a/tasks.c +++ b/tasks.c @@ -156,6 +156,23 @@ #define configIDLE_TASK_NAME "IDLE" #endif +#if ( configNUMBER_OF_CORES > 1 ) + /* Reserve space for Core ID and null termination. */ + #if ( configMAX_TASK_NAME_LEN < 2U ) + #error Minimum required task name length is 2. Please increase configMAX_TASK_NAME_LEN. + #endif + #define taskRESERVED_TASK_NAME_LENGTH 2U + +#elif ( configNUMBER_OF_CORES > 9 ) + #warning Please increase taskRESERVED_TASK_NAME_LENGTH. 1 character is insufficient to store the core ID. +#else + /* Reserve space for null termination. */ + #if ( configMAX_TASK_NAME_LEN < 1U ) + #error Minimum required task name length is 1. Please increase configMAX_TASK_NAME_LEN. + #endif + #define taskRESERVED_TASK_NAME_LENGTH 1U +#endif /* if ( ( configNUMBER_OF_CORES > 1 ) */ + #if ( configUSE_PORT_OPTIMISED_TASK_SELECTION == 0 ) /* If configUSE_PORT_OPTIMISED_TASK_SELECTION is 0 then task selection is @@ -3527,21 +3544,26 @@ static BaseType_t prvCreateIdleTasks( void ) BaseType_t xCoreID; char cIdleName[ configMAX_TASK_NAME_LEN ] = { 0 }; TaskFunction_t pxIdleTaskFunction = NULL; - BaseType_t xIdleTaskNameIndex; - BaseType_t xIdleNameLen; - BaseType_t xCopyLen; + UBaseType_t xIdleTaskNameIndex; - configASSERT( ( configIDLE_TASK_NAME != NULL ) && ( configMAX_TASK_NAME_LEN > 3 ) ); - - /* The length of the idle task name is limited to the minimum of the length - * of configIDLE_TASK_NAME and configMAX_TASK_NAME_LEN - 2, keeping space - * for the core ID suffix and the null-terminator. */ - xIdleNameLen = strlen( configIDLE_TASK_NAME ); - xCopyLen = xIdleNameLen < ( configMAX_TASK_NAME_LEN - 2 ) ? xIdleNameLen : ( configMAX_TASK_NAME_LEN - 2 ); - - for( xIdleTaskNameIndex = ( BaseType_t ) 0; xIdleTaskNameIndex < xCopyLen; xIdleTaskNameIndex++ ) + /* MISRA Ref 14.3.1 [Configuration dependent invariant] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-143. */ + /* coverity[misra_c_2012_rule_14_3_violation] */ + for( xIdleTaskNameIndex = 0U; xIdleTaskNameIndex < ( configMAX_TASK_NAME_LEN - taskRESERVED_TASK_NAME_LENGTH ); xIdleTaskNameIndex++ ) { + /* MISRA Ref 18.1.1 [Configuration dependent bounds checking] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-181. */ + /* coverity[misra_c_2012_rule_18_1_violation] */ cIdleName[ xIdleTaskNameIndex ] = configIDLE_TASK_NAME[ xIdleTaskNameIndex ]; + + if( cIdleName[ xIdleTaskNameIndex ] == ( char ) 0x00 ) + { + break; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } } /* Ensure null termination. */ From ad4e7238293cbe994e7450e1bc415136875da322 Mon Sep 17 00:00:00 2001 From: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> Date: Wed, 29 Jan 2025 07:27:30 +0530 Subject: [PATCH 11/11] Mark mutex as robust to prevent deadlocks (#1233) Mark mutex as robust to prevent deadlocks Prevent application hangs that occur when a thread dies while holding a mutex, particularly during vTaskEndScheduler or exit calls. This is achieved by setting the PTHREAD_MUTEX_ROBUST attribute on the mutex. Fixes: - GitHub issue: FreeRTOS/FreeRTOS-Kernel#1217 - Forum thread: freertos.org/t/22287 Signed-off-by: Gaurav Aggarwal --- portable/ThirdParty/GCC/Posix/port.c | 67 +++++++++++++------ .../GCC/Posix/utils/wait_for_event.c | 39 +++++++++-- 2 files changed, 80 insertions(+), 26 deletions(-) diff --git a/portable/ThirdParty/GCC/Posix/port.c b/portable/ThirdParty/GCC/Posix/port.c index c4eacb2ba..4f7d8b609 100644 --- a/portable/ThirdParty/GCC/Posix/port.c +++ b/portable/ThirdParty/GCC/Posix/port.c @@ -119,14 +119,20 @@ static void prvResumeThread( Thread_t * xThreadId ); static void vPortSystemTickHandler( int sig ); static void vPortStartFirstTask( void ); static void prvPortYieldFromISR( void ); +static void prvThreadKeyDestructor( void * pvData ); +static void prvInitThreadKey( void ); +static void prvMarkAsFreeRTOSThread( void ); +static BaseType_t prvIsFreeRTOSThread( void ); +static void prvDestroyThreadKey( void ); /*-----------------------------------------------------------*/ -void prvThreadKeyDestructor( void * data ) +static void prvThreadKeyDestructor( void * pvData ) { - free( data ); + free( pvData ); } +/*-----------------------------------------------------------*/ -static void prvInitThreadKey() +static void prvInitThreadKey( void ) { pthread_mutex_lock( &xThreadMutex ); @@ -137,24 +143,39 @@ static void prvInitThreadKey() pthread_mutex_unlock( &xThreadMutex ); } +/*-----------------------------------------------------------*/ -static void prvMarkAsFreeRTOSThread( pthread_t thread ) +static void prvMarkAsFreeRTOSThread( void ) { + uint8_t * pucThreadData = NULL; + prvInitThreadKey(); - uint8_t * thread_data = malloc( 1 ); - configASSERT( thread_data != NULL ); - *thread_data = 1; - pthread_setspecific( xThreadKey, thread_data ); -} -static BaseType_t prvIsFreeRTOSThread( pthread_t thread ) + pucThreadData = malloc( 1 ); + configASSERT( pucThreadData != NULL ); + + *pucThreadData = 1; + + pthread_setspecific( xThreadKey, pucThreadData ); +} +/*-----------------------------------------------------------*/ + +static BaseType_t prvIsFreeRTOSThread( void ) { - uint8_t * thread_data = ( uint8_t * ) pthread_getspecific( xThreadKey ); + uint8_t * pucThreadData = NULL; + BaseType_t xRet = pdFALSE; - return thread_data != NULL && *thread_data == 1; + pucThreadData = ( uint8_t * ) pthread_getspecific( xThreadKey ); + if( ( pucThreadData != NULL ) && ( *pucThreadData == 1 ) ) + { + xRet = pdTRUE; + } + + return xRet; } +/*-----------------------------------------------------------*/ -static void prvDestroyThreadKey() +static void prvDestroyThreadKey( void ) { pthread_key_delete( xThreadKey ); } @@ -309,7 +330,7 @@ void vPortEndScheduler( void ) ( void ) pthread_kill( hMainThread, SIG_RESUME ); /* Waiting to be deleted here. */ - if( prvIsFreeRTOSThread( pthread_self() ) == pdTRUE ) + if( prvIsFreeRTOSThread() == pdTRUE ) { pxCurrentThread = prvGetThreadFromTask( xTaskGetCurrentTaskHandle() ); event_wait( pxCurrentThread->ev ); @@ -369,7 +390,7 @@ void vPortYield( void ) void vPortDisableInterrupts( void ) { - if( prvIsFreeRTOSThread( pthread_self() ) == pdTRUE ) + if( prvIsFreeRTOSThread() == pdTRUE ) { pthread_sigmask(SIG_BLOCK, &xAllSignals, NULL); } @@ -378,9 +399,9 @@ void vPortDisableInterrupts( void ) void vPortEnableInterrupts( void ) { - if( prvIsFreeRTOSThread( pthread_self() ) == pdTRUE ) + if( prvIsFreeRTOSThread() == pdTRUE ) { - pthread_sigmask(SIG_UNBLOCK, &xAllSignals, NULL); + pthread_sigmask( SIG_UNBLOCK, &xAllSignals, NULL ); } } /*-----------------------------------------------------------*/ @@ -417,9 +438,9 @@ static void * prvTimerTickHandler( void * arg ) { ( void ) arg; - prvMarkAsFreeRTOSThread( pthread_self() ); + prvMarkAsFreeRTOSThread(); - prvPortSetCurrentThreadName("Scheduler timer"); + prvPortSetCurrentThreadName( "Scheduler timer" ); while( xTimerTickThreadShouldRun ) { @@ -451,7 +472,7 @@ void prvSetupTimerInterrupt( void ) static void vPortSystemTickHandler( int sig ) { - if( prvIsFreeRTOSThread( pthread_self() ) == pdTRUE ) + if( prvIsFreeRTOSThread() == pdTRUE ) { Thread_t * pxThreadToSuspend; Thread_t * pxThreadToResume; @@ -473,7 +494,9 @@ static void vPortSystemTickHandler( int sig ) } uxCriticalNesting--; - } else { + } + else + { fprintf( stderr, "vPortSystemTickHandler called from non-FreeRTOS thread\n" ); } } @@ -508,7 +531,7 @@ static void * prvWaitForStart( void * pvParams ) { Thread_t * pxThread = pvParams; - prvMarkAsFreeRTOSThread( pthread_self() ); + prvMarkAsFreeRTOSThread(); prvSuspendSelf( pxThread ); diff --git a/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c b/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c index bf744e27f..55fd7bbfc 100644 --- a/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c +++ b/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c @@ -35,9 +35,11 @@ struct event { pthread_mutex_t mutex; + pthread_mutexattr_t mutexattr; pthread_cond_t cond; bool event_triggered; }; +/*-----------------------------------------------------------*/ struct event * event_create( void ) { @@ -46,23 +48,36 @@ struct event * event_create( void ) if( ev != NULL ) { ev->event_triggered = false; - pthread_mutex_init( &ev->mutex, NULL ); + pthread_mutexattr_init( &ev->mutexattr ); + #ifndef __APPLE__ + pthread_mutexattr_setrobust( &ev->mutexattr, PTHREAD_MUTEX_ROBUST ); + #endif + pthread_mutex_init( &ev->mutex, &ev->mutexattr ); pthread_cond_init( &ev->cond, NULL ); } return ev; } +/*-----------------------------------------------------------*/ void event_delete( struct event * ev ) { pthread_mutex_destroy( &ev->mutex ); + pthread_mutexattr_destroy( &ev->mutexattr ); pthread_cond_destroy( &ev->cond ); free( ev ); } +/*-----------------------------------------------------------*/ bool event_wait( struct event * ev ) { - pthread_mutex_lock( &ev->mutex ); + if( pthread_mutex_lock( &ev->mutex ) == EOWNERDEAD ) + { + #ifndef __APPLE__ + /* If the thread owning the mutex died, make the mutex consistent. */ + pthread_mutex_consistent( &ev->mutex ); + #endif + } while( ev->event_triggered == false ) { @@ -73,6 +88,8 @@ bool event_wait( struct event * ev ) pthread_mutex_unlock( &ev->mutex ); return true; } +/*-----------------------------------------------------------*/ + bool event_wait_timed( struct event * ev, time_t ms ) { @@ -82,7 +99,13 @@ bool event_wait_timed( struct event * ev, clock_gettime( CLOCK_REALTIME, &ts ); ts.tv_sec += ms / 1000; ts.tv_nsec += ( ( ms % 1000 ) * 1000000 ); - pthread_mutex_lock( &ev->mutex ); + if( pthread_mutex_lock( &ev->mutex ) == EOWNERDEAD ) + { + #ifndef __APPLE__ + /* If the thread owning the mutex died, make the mutex consistent. */ + pthread_mutex_consistent( &ev->mutex ); + #endif + } while( ( ev->event_triggered == false ) && ( ret == 0 ) ) { @@ -98,11 +121,19 @@ bool event_wait_timed( struct event * ev, pthread_mutex_unlock( &ev->mutex ); return true; } +/*-----------------------------------------------------------*/ void event_signal( struct event * ev ) { - pthread_mutex_lock( &ev->mutex ); + if( pthread_mutex_lock( &ev->mutex ) == EOWNERDEAD ) + { + #ifndef __APPLE__ + /* If the thread owning the mutex died, make the mutex consistent. */ + pthread_mutex_consistent( &ev->mutex ); + #endif + } ev->event_triggered = true; pthread_cond_signal( &ev->cond ); pthread_mutex_unlock( &ev->mutex ); } +/*-----------------------------------------------------------*/