From 1860c9ad09b98102a621a546a259ab69169f6579 Mon Sep 17 00:00:00 2001 From: Forty-Bot Date: Mon, 29 Jan 2024 00:37:43 -0500 Subject: [PATCH 1/4] GCC: MSP430F449: Fix pxPortInitialiseStack on EABI (#947) According to the MSP430 EABI [1] section 3.3, Arguments are assigned, in declared order, to the first available register single, pair, or quad from the following list into which it fits (with the following special exceptions). For MSP430 and MSP430X, the argument registers are: R12, R13, R14, R15 Therefore, pvParameters should be passed in R12, as it is the first argument, not R15. Keep passing the parameter in R15 for the MSP430 EABI, if anyone is still using it. [1] https://www.ti.com/lit/an/slaa534a/slaa534a.pdf --- portable/GCC/MSP430F449/port.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/portable/GCC/MSP430F449/port.c b/portable/GCC/MSP430F449/port.c index ca72b410b..488ad2d6f 100644 --- a/portable/GCC/MSP430F449/port.c +++ b/portable/GCC/MSP430F449/port.c @@ -183,16 +183,23 @@ StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack, pxTopOfStack--; *pxTopOfStack = ( StackType_t ) 0xbbbb; pxTopOfStack--; +#ifdef __MSPGCC__ *pxTopOfStack = ( StackType_t ) 0xcccc; +#else + /* The MSP430 EABI expects the function parameter in R12. */ + *pxTopOfStack = ( StackType_t ) pvParameters; +#endif pxTopOfStack--; *pxTopOfStack = ( StackType_t ) 0xdddd; pxTopOfStack--; *pxTopOfStack = ( StackType_t ) 0xeeee; pxTopOfStack--; - - /* When the task starts is will expect to find the function parameter in - * R15. */ +#ifdef __MSPGCC__ + /* The mspgcc ABI expects the function parameter in R15. */ *pxTopOfStack = ( StackType_t ) pvParameters; +#else + *pxTopOfStack = ( StackType_t ) 0xffff; +#endif pxTopOfStack--; /* The code generated by the mspgcc compiler does not maintain separate From 722596eaae46a54b48b194d21541a9ef24d84388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Mon, 29 Jan 2024 06:35:10 +0000 Subject: [PATCH 2/4] Add code to allow building for x64 in MSVC (#924) * Add code to allow building for x64 in MSVC - Add code for x64 arch. - Add initial value for local otherwise it won't get proper value in x64. * Moving init local to portGET_HIGHEST_PRIORITY - From code review. * More changes following review * Another style fix from review * Update formatting Signed-off-by: Gaurav Aggarwal --------- Signed-off-by: Gaurav Aggarwal Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> Co-authored-by: Nikhil Kamath <110539926+amazonKamath@users.noreply.github.com> Co-authored-by: Soren Ptak Co-authored-by: Gaurav Aggarwal --- portable/MSVC-MingW/portmacro.h | 48 ++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/portable/MSVC-MingW/portmacro.h b/portable/MSVC-MingW/portmacro.h index 48a8bf4b0..9e64b7343 100644 --- a/portable/MSVC-MingW/portmacro.h +++ b/portable/MSVC-MingW/portmacro.h @@ -121,32 +121,50 @@ void vPortExitCritical( void ); #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 #endif +/*-----------------------------------------------------------*/ + #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 -/* Check the configuration. */ + /* Check the configuration. */ #if ( configMAX_PRIORITIES > 32 ) #error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32. It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice. #endif -/* Store/clear the ready priorities in a bit map. */ - #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) ) - #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) ) - - -/*-----------------------------------------------------------*/ + /* Store/clear the ready priorities in a bit map. */ + #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( ( ( UBaseType_t ) 1 ) << ( uxPriority ) ) + #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( ( ( UBaseType_t ) 1 ) << ( uxPriority ) ) #ifdef __GNUC__ - #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) \ - __asm volatile ( "bsr %1, %0\n\t" \ - : "=r" ( uxTopPriority ) : "rm" ( uxReadyPriorities ) : "cc" ) - #else -/* BitScanReverse returns the bit position of the most significant '1' - * in the word. */ - #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) _BitScanReverse( ( DWORD * ) &( uxTopPriority ), ( uxReadyPriorities ) ) + #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) \ + __asm volatile ( "bsr %1, %0\n\t" \ + : "=r" ( uxTopPriority ) \ + : "rm" ( uxReadyPriorities ) \ + : "cc" ) + + #else /* __GNUC__ */ + + /* BitScanReverse returns the bit position of the most significant '1' + * in the word. */ + #if defined( __x86_64__ ) || defined( _M_X64 ) + + #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) \ + do \ + { \ + DWORD ulTopPriority; \ + _BitScanReverse64( &ulTopPriority, ( uxReadyPriorities ) ); \ + uxTopPriority = ulTopPriority; \ + } while( 0 ) + + #else /* #if defined( __x86_64__ ) || defined( _M_X64 ) */ + + #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) _BitScanReverse( ( DWORD * ) &( uxTopPriority ), ( uxReadyPriorities ) ) + + #endif /* #if defined( __x86_64__ ) || defined( _M_X64 ) */ + #endif /* __GNUC__ */ -#endif /* taskRECORD_READY_PRIORITY */ +#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */ #ifndef __GNUC__ __pragma( warning( disable:4211 ) ) /* Nonstandard extension used, as extern is only nonstandard to MSVC. */ From d63434493acd5f0943e34be763429ecb057432a0 Mon Sep 17 00:00:00 2001 From: Soren Ptak Date: Mon, 29 Jan 2024 12:19:09 -0500 Subject: [PATCH 3/4] Add missing Task Notification IFDEF (#967) Wrap the task notification check in vTaskGetInfo() in in a #if ( configUSE_TASK_NOTIFICATIONS == 1 ) --- tasks.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/tasks.c b/tasks.c index 9f6c5f879..b00d218bb 100644 --- a/tasks.c +++ b/tasks.c @@ -6212,21 +6212,25 @@ static void prvCheckTasksWaitingTermination( void ) } else { - BaseType_t x; - - /* The task does not appear on the event list item of - * and of the RTOS objects, but could still be in the - * blocked state if it is waiting on its notification - * rather than waiting on an object. If not, is - * suspended. */ - for( x = ( BaseType_t ) 0; x < ( BaseType_t ) configTASK_NOTIFICATION_ARRAY_ENTRIES; x++ ) + #if ( configUSE_TASK_NOTIFICATIONS == 1 ) { - if( pxTCB->ucNotifyState[ x ] == taskWAITING_NOTIFICATION ) + BaseType_t x; + + /* The task does not appear on the event list item of + * and of the RTOS objects, but could still be in the + * blocked state if it is waiting on its notification + * rather than waiting on an object. If not, is + * suspended. */ + for( x = ( BaseType_t ) 0; x < ( BaseType_t ) configTASK_NOTIFICATION_ARRAY_ENTRIES; x++ ) { - pxTaskStatus->eCurrentState = eBlocked; - break; + if( pxTCB->ucNotifyState[ x ] == taskWAITING_NOTIFICATION ) + { + pxTaskStatus->eCurrentState = eBlocked; + break; + } } } + #endif /* if ( configUSE_TASK_NOTIFICATIONS == 1 ) */ } } ( void ) xTaskResumeAll(); From 5a2237a1e26c23b40f45e0ad4f924b428fb6c094 Mon Sep 17 00:00:00 2001 From: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> Date: Mon, 29 Jan 2024 23:59:18 +0530 Subject: [PATCH 4/4] Remove configTOTAL_MPU_REGIONS from M3 MPU port (#966) The number of MPU regions is not configurable for Cortex-M3 port and therefore, it is misleading to have configTOTAL_MPU_REGIONS in portmacro.h. It was added in PR #952. Signed-off-by: Gaurav Aggarwal --- portable/GCC/ARM_CM3_MPU/portmacro.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/portable/GCC/ARM_CM3_MPU/portmacro.h b/portable/GCC/ARM_CM3_MPU/portmacro.h index a6e2ae261..5983c7912 100644 --- a/portable/GCC/ARM_CM3_MPU/portmacro.h +++ b/portable/GCC/ARM_CM3_MPU/portmacro.h @@ -86,15 +86,6 @@ typedef unsigned long UBaseType_t; #define portMPU_REGION_CACHEABLE_BUFFERABLE ( 0x07UL << 16UL ) #define portMPU_REGION_EXECUTE_NEVER ( 0x01UL << 28UL ) -/* MPU settings that can be overriden in FreeRTOSConfig.h. */ -#ifndef configTOTAL_MPU_REGIONS - /* Define to 8 for backward compatibility. */ - #define configTOTAL_MPU_REGIONS ( 8UL ) -#elif( configTOTAL_MPU_REGIONS != 8UL ) - /* The Cortex M3 only supports 8 MPU regions. For more information refer to: - * https://developer.arm.com/documentation/dui0552/a/cortex-m3-peripherals/optional-memory-protection-unit */ - #error configTOTAL_MPU_REGIONS must be 8 for this port. -#endif /* configTOTAL_MPU_REGIONS Check */ #define portSTACK_REGION ( 3UL ) #define portGENERAL_PERIPHERALS_REGION ( 4UL ) #define portUNPRIVILEGED_FLASH_REGION ( 5UL )