diff --git a/.github/workflows/kernel-demos.yml b/.github/workflows/kernel-demos.yml index 96a4c59759..865f4eefb5 100644 --- a/.github/workflows/kernel-demos.yml +++ b/.github/workflows/kernel-demos.yml @@ -123,9 +123,22 @@ jobs: with: ref: main repository: FreeRTOS/FreeRTOS - submodules: 'recursive' fetch-depth: 1 + - name: Fetch Community-Supported-Demos Submodule + shell: bash + run: | + # Fetch Community-Supported-Demos Submodule + echo "::group::Fetch Community-Supported-Demos Submodule" + git submodule update --checkout --init --depth 1 FreeRTOS/Demo/ThirdParty/Community-Supported-Demos + echo "::engdroup::" + if [ "$?" = "0" ]; then + echo -e "\033[32;3mCloned the Community-Supported-Demos\033[0m" + else + echo -e "\033[32;31mCommunity-Supported-Demos Clone Failed...\033[0m" + exit 1 + fi + # Checkout user pull request changes - name: Checkout Pull Request uses: actions/checkout@v2 @@ -169,7 +182,7 @@ jobs: - name: Build CORTEX_M0+_RP2040 Demos shell: bash - working-directory: FreeRTOS/Demo/ThirdParty/Community-Supported/CORTEX_M0+_RP2040 + working-directory: FreeRTOS/Demo/ThirdParty/Community-Supported-Demos/CORTEX_M0+_RP2040 run: | git clone https://github.com/raspberrypi/pico-sdk.git cmake -B build -DPICO_SDK_PATH=pico-sdk -GNinja diff --git a/History.txt b/History.txt index 98f9822d45..d1dba25468 100644 --- a/History.txt +++ b/History.txt @@ -61,8 +61,8 @@ Changes between FreeRTOS V10.5.1 and FreeRTOS 10.6.0 released July 13, 2023 China. - Xinwen Fu of Department of Computer Science, University of Massachusetts Lowell, USA. - - Yueqi Chen, Zicheng Wang, Minghao Lin of University of Colorado - Boulder, USA. + - Yueqi Chen, Zicheng Wang, Minghao Lin, Jiahe Wang of University of + Colorado Boulder, USA. + Add Cortex-M35P port. Contributed by @urutva. + Add embedded extension (RV32E) support to the IAR RISC-V port. + Add ulTaskGetRunTimeCounter and ulTaskGetRunTimePercent APIs. Contributed by diff --git a/README.md b/README.md index dd79eee6ce..38cb586222 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,13 @@ FetchContent_Declare( freertos_kernel ) ``` +In case you prefer to add it as a git submodule, do: + +```bash +$ git submodule add https://github.com/FreeRTOS/FreeRTOS-Kernel.git +$ git submodule update --init +``` + - Add a freertos_config library (typically an INTERFACE library) The following assumes the directory structure: - `include/FreeRTOSConfig.h` ```cmake @@ -41,6 +48,12 @@ target_compile_definitions(freertos_config ) ``` +In case you installed FreeRTOS-Kernel as a submodule, you will have to add it as a subdirectory: + +```cmake +add_subdirectory(${FREERTOS_PATH}) +``` + - Configure the FreeRTOS-Kernel and make it available - this particular example supports a native and cross-compiled build option. @@ -56,6 +69,13 @@ endif() FetchContent_MakeAvailable(freertos_kernel) ``` +- In case of cross compilation, you should also add the following to `freertos_config`: + +```cmake +target_compile_definitions(freertos_config INTERFACE ${definitions}) +target_compile_options(freertos_config INTERFACE ${options}) +``` + ### Consuming stand-alone - Cloning this repository To clone using HTTPS: diff --git a/include/mpu_prototypes.h b/include/mpu_prototypes.h index 633efd4a81..2b6b6cb82f 100644 --- a/include/mpu_prototypes.h +++ b/include/mpu_prototypes.h @@ -223,11 +223,11 @@ void MPU_vTimerSetTimerID( TimerHandle_t xTimer, void * pvNewID ) FREERTOS_SYSTEM_CALL; BaseType_t MPU_xTimerIsTimerActive( TimerHandle_t xTimer ) FREERTOS_SYSTEM_CALL; TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ) FREERTOS_SYSTEM_CALL; -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL; const char * MPU_pcTimerGetName( TimerHandle_t xTimer ) FREERTOS_SYSTEM_CALL; void MPU_vTimerSetReloadMode( TimerHandle_t xTimer, const UBaseType_t uxAutoReload ) FREERTOS_SYSTEM_CALL; @@ -252,6 +252,11 @@ TimerHandle_t MPU_xTimerCreateStatic( const char * const pcTimerName, StaticTimer_t * pxTimerBuffer ) PRIVILEGED_FUNCTION; BaseType_t MPU_xTimerGetStaticBuffer( TimerHandle_t xTimer, StaticTimer_t ** ppxTimerBuffer ) PRIVILEGED_FUNCTION; +BaseType_t MPU_xTimerGenericCommandFromISR( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; /* MPU versions of event_group.h API functions. */ EventBits_t MPU_xEventGroupWaitBits( EventGroupHandle_t xEventGroup, diff --git a/include/mpu_wrappers.h b/include/mpu_wrappers.h index 020efc3ef6..a0ebf6030a 100644 --- a/include/mpu_wrappers.h +++ b/include/mpu_wrappers.h @@ -156,7 +156,7 @@ #define vTimerSetTimerID MPU_vTimerSetTimerID #define xTimerIsTimerActive MPU_xTimerIsTimerActive #define xTimerGetTimerDaemonTaskHandle MPU_xTimerGetTimerDaemonTaskHandle - #define xTimerGenericCommand MPU_xTimerGenericCommand + #define xTimerGenericCommandFromTask MPU_xTimerGenericCommandFromTask #define pcTimerGetName MPU_pcTimerGetName #define vTimerSetReloadMode MPU_vTimerSetReloadMode #define uxTimerGetReloadMode MPU_uxTimerGetReloadMode @@ -167,10 +167,11 @@ * the application can use opaque handles maintained in mpu_wrappers.c * with all the APIs. */ #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) - #define xTimerGetReloadMode MPU_xTimerGetReloadMode - #define xTimerCreate MPU_xTimerCreate - #define xTimerCreateStatic MPU_xTimerCreateStatic - #define xTimerGetStaticBuffer MPU_xTimerGetStaticBuffer + #define xTimerGetReloadMode MPU_xTimerGetReloadMode + #define xTimerCreate MPU_xTimerCreate + #define xTimerCreateStatic MPU_xTimerCreateStatic + #define xTimerGetStaticBuffer MPU_xTimerGetStaticBuffer + #define xTimerGenericCommandFromISR MPU_xTimerGenericCommandFromISR #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */ /* Map standard event_group.h API functions to the MPU equivalents. */ diff --git a/include/task.h b/include/task.h index d0441f4395..97809fc33c 100644 --- a/include/task.h +++ b/include/task.h @@ -167,7 +167,7 @@ typedef struct xTASK_STATUS UBaseType_t uxBasePriority; /* The priority to which the task will return if the task's current priority has been inherited to avoid unbounded priority inversion when obtaining a mutex. Only valid if configUSE_MUTEXES is defined as 1 in FreeRTOSConfig.h. */ configRUN_TIME_COUNTER_TYPE ulRunTimeCounter; /* The total run time allocated to the task so far, as defined by the run time stats clock. See https://www.FreeRTOS.org/rtos-run-time-stats.html. Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */ StackType_t * pxStackBase; /* Points to the lowest address of the task's stack area. */ - #if ( ( portSTACK_GROWTH > 0 ) && ( configRECORD_STACK_HIGH_ADDRESS == 1 ) ) + #if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) ) StackType_t * pxTopOfStack; /* Points to the top address of the task's stack area. */ StackType_t * pxEndOfStack; /* Points to the end address of the task's stack area. */ #endif diff --git a/portable/ARMv8M/non_secure/port.c b/portable/ARMv8M/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/ARMv8M/non_secure/port.c +++ b/portable/ARMv8M/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/ARMv8M/non_secure/portable/GCC/ARM_CM23/mpu_wrappers_v2_asm.c b/portable/ARMv8M/non_secure/portable/GCC/ARM_CM23/mpu_wrappers_v2_asm.c index a1e5ce0828..795f2195c2 100644 --- a/portable/ARMv8M/non_secure/portable/GCC/ARM_CM23/mpu_wrappers_v2_asm.c +++ b/portable/ARMv8M/non_secure/portable/GCC/ARM_CM23/mpu_wrappers_v2_asm.c @@ -1726,41 +1726,38 @@ TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ) /* __attribute__ (( nake #if ( configUSE_TIMERS == 1 ) -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; - -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ -{ - __asm volatile - ( - " .syntax unified \n" - " .extern MPU_xTimerGenericCommandImpl \n" - " \n" - " push {r0, r1} \n" - " mrs r0, ipsr \n" - " cmp r0, #0 \n" - " bne MPU_xTimerGenericCommand_Priv \n" - " mrs r0, control \n" - " movs r1, #1 \n" - " tst r0, r1 \n" - " beq MPU_xTimerGenericCommand_Priv \n" - " MPU_xTimerGenericCommand_Unpriv: \n" - " pop {r0, r1} \n" - " svc %0 \n" - " bl MPU_xTimerGenericCommandImpl \n" - " svc %1 \n" - " bx lr \n" - " MPU_xTimerGenericCommand_Priv: \n" - " pop {r0, r1} \n" - " b MPU_xTimerGenericCommandImpl \n" - " \n" +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; + +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ +{ + __asm volatile + ( + " .syntax unified \n" + " .extern MPU_xTimerGenericCommandFromTaskImpl \n" + " \n" + " push {r0, r1} \n" + " mrs r0, control \n" + " movs r1, #1 \n" + " tst r0, r1 \n" + " bne MPU_xTimerGenericCommandFromTask_Unpriv \n" + " MPU_xTimerGenericCommandFromTask_Priv: \n" + " pop {r0, r1} \n" + " b MPU_xTimerGenericCommandFromTaskImpl \n" + " MPU_xTimerGenericCommandFromTask_Unpriv: \n" + " pop {r0, r1} \n" + " svc %0 \n" + " bl MPU_xTimerGenericCommandFromTaskImpl \n" + " svc %1 \n" + " bx lr \n" + " \n" : : "i" ( portSVC_SYSTEM_CALL_ENTER_1 ), "i" ( portSVC_SYSTEM_CALL_EXIT ) : "memory" ); } diff --git a/portable/ARMv8M/non_secure/portable/GCC/ARM_CM23_NTZ/mpu_wrappers_v2_asm.c b/portable/ARMv8M/non_secure/portable/GCC/ARM_CM23_NTZ/mpu_wrappers_v2_asm.c index a1e5ce0828..795f2195c2 100644 --- a/portable/ARMv8M/non_secure/portable/GCC/ARM_CM23_NTZ/mpu_wrappers_v2_asm.c +++ b/portable/ARMv8M/non_secure/portable/GCC/ARM_CM23_NTZ/mpu_wrappers_v2_asm.c @@ -1726,41 +1726,38 @@ TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ) /* __attribute__ (( nake #if ( configUSE_TIMERS == 1 ) -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; - -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ -{ - __asm volatile - ( - " .syntax unified \n" - " .extern MPU_xTimerGenericCommandImpl \n" - " \n" - " push {r0, r1} \n" - " mrs r0, ipsr \n" - " cmp r0, #0 \n" - " bne MPU_xTimerGenericCommand_Priv \n" - " mrs r0, control \n" - " movs r1, #1 \n" - " tst r0, r1 \n" - " beq MPU_xTimerGenericCommand_Priv \n" - " MPU_xTimerGenericCommand_Unpriv: \n" - " pop {r0, r1} \n" - " svc %0 \n" - " bl MPU_xTimerGenericCommandImpl \n" - " svc %1 \n" - " bx lr \n" - " MPU_xTimerGenericCommand_Priv: \n" - " pop {r0, r1} \n" - " b MPU_xTimerGenericCommandImpl \n" - " \n" +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; + +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ +{ + __asm volatile + ( + " .syntax unified \n" + " .extern MPU_xTimerGenericCommandFromTaskImpl \n" + " \n" + " push {r0, r1} \n" + " mrs r0, control \n" + " movs r1, #1 \n" + " tst r0, r1 \n" + " bne MPU_xTimerGenericCommandFromTask_Unpriv \n" + " MPU_xTimerGenericCommandFromTask_Priv: \n" + " pop {r0, r1} \n" + " b MPU_xTimerGenericCommandFromTaskImpl \n" + " MPU_xTimerGenericCommandFromTask_Unpriv: \n" + " pop {r0, r1} \n" + " svc %0 \n" + " bl MPU_xTimerGenericCommandFromTaskImpl \n" + " svc %1 \n" + " bx lr \n" + " \n" : : "i" ( portSVC_SYSTEM_CALL_ENTER_1 ), "i" ( portSVC_SYSTEM_CALL_EXIT ) : "memory" ); } diff --git a/portable/ARMv8M/non_secure/portable/GCC/ARM_CM33/mpu_wrappers_v2_asm.c b/portable/ARMv8M/non_secure/portable/GCC/ARM_CM33/mpu_wrappers_v2_asm.c index 6e2043427f..9e1b9ed858 100644 --- a/portable/ARMv8M/non_secure/portable/GCC/ARM_CM33/mpu_wrappers_v2_asm.c +++ b/portable/ARMv8M/non_secure/portable/GCC/ARM_CM33/mpu_wrappers_v2_asm.c @@ -1676,41 +1676,37 @@ TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ) /* __attribute__ (( nake #if ( configUSE_TIMERS == 1 ) -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; - -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ -{ - __asm volatile - ( - " .syntax unified \n" - " .extern MPU_xTimerGenericCommandImpl \n" - " \n" - " push {r0} \n" - " mrs r0, ipsr \n" - " cmp r0, #0 \n" - " bne MPU_xTimerGenericCommand_Priv \n" - " mrs r0, control \n" - " tst r0, #1 \n" - " beq MPU_xTimerGenericCommand_Priv \n" - " MPU_xTimerGenericCommand_Unpriv: \n" - " pop {r0} \n" - " svc %0 \n" - " bl MPU_xTimerGenericCommandImpl \n" - " svc %1 \n" - " bx lr \n" - " MPU_xTimerGenericCommand_Priv: \n" - " pop {r0} \n" - " b MPU_xTimerGenericCommandImpl \n" - " \n" - " \n" +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; + +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ +{ + __asm volatile + ( + " .syntax unified \n" + " .extern MPU_xTimerGenericCommandFromTaskImpl \n" + " \n" + " push {r0} \n" + " mrs r0, control \n" + " tst r0, #1 \n" + " bne MPU_xTimerGenericCommandFromTask_Unpriv \n" + " MPU_xTimerGenericCommandFromTask_Priv: \n" + " pop {r0} \n" + " b MPU_xTimerGenericCommandFromTaskImpl \n" + " MPU_xTimerGenericCommandFromTask_Unpriv: \n" + " pop {r0} \n" + " svc %0 \n" + " bl MPU_xTimerGenericCommandFromTaskImpl \n" + " svc %1 \n" + " bx lr \n" + " \n" : : "i" ( portSVC_SYSTEM_CALL_ENTER_1 ), "i" ( portSVC_SYSTEM_CALL_EXIT ) : "memory" ); } diff --git a/portable/ARMv8M/non_secure/portable/GCC/ARM_CM33_NTZ/mpu_wrappers_v2_asm.c b/portable/ARMv8M/non_secure/portable/GCC/ARM_CM33_NTZ/mpu_wrappers_v2_asm.c index 6e2043427f..9e1b9ed858 100644 --- a/portable/ARMv8M/non_secure/portable/GCC/ARM_CM33_NTZ/mpu_wrappers_v2_asm.c +++ b/portable/ARMv8M/non_secure/portable/GCC/ARM_CM33_NTZ/mpu_wrappers_v2_asm.c @@ -1676,41 +1676,37 @@ TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ) /* __attribute__ (( nake #if ( configUSE_TIMERS == 1 ) -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; - -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ -{ - __asm volatile - ( - " .syntax unified \n" - " .extern MPU_xTimerGenericCommandImpl \n" - " \n" - " push {r0} \n" - " mrs r0, ipsr \n" - " cmp r0, #0 \n" - " bne MPU_xTimerGenericCommand_Priv \n" - " mrs r0, control \n" - " tst r0, #1 \n" - " beq MPU_xTimerGenericCommand_Priv \n" - " MPU_xTimerGenericCommand_Unpriv: \n" - " pop {r0} \n" - " svc %0 \n" - " bl MPU_xTimerGenericCommandImpl \n" - " svc %1 \n" - " bx lr \n" - " MPU_xTimerGenericCommand_Priv: \n" - " pop {r0} \n" - " b MPU_xTimerGenericCommandImpl \n" - " \n" - " \n" +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; + +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ +{ + __asm volatile + ( + " .syntax unified \n" + " .extern MPU_xTimerGenericCommandFromTaskImpl \n" + " \n" + " push {r0} \n" + " mrs r0, control \n" + " tst r0, #1 \n" + " bne MPU_xTimerGenericCommandFromTask_Unpriv \n" + " MPU_xTimerGenericCommandFromTask_Priv: \n" + " pop {r0} \n" + " b MPU_xTimerGenericCommandFromTaskImpl \n" + " MPU_xTimerGenericCommandFromTask_Unpriv: \n" + " pop {r0} \n" + " svc %0 \n" + " bl MPU_xTimerGenericCommandFromTaskImpl \n" + " svc %1 \n" + " bx lr \n" + " \n" : : "i" ( portSVC_SYSTEM_CALL_ENTER_1 ), "i" ( portSVC_SYSTEM_CALL_EXIT ) : "memory" ); } diff --git a/portable/ARMv8M/non_secure/portable/IAR/ARM_CM23/mpu_wrappers_v2_asm.S b/portable/ARMv8M/non_secure/portable/IAR/ARM_CM23/mpu_wrappers_v2_asm.S index 867642b5e9..f2098b57da 100644 --- a/portable/ARMv8M/non_secure/portable/IAR/ARM_CM23/mpu_wrappers_v2_asm.S +++ b/portable/ARMv8M/non_secure/portable/IAR/ARM_CM23/mpu_wrappers_v2_asm.S @@ -945,28 +945,22 @@ MPU_xTimerGetTimerDaemonTaskHandle: bx lr /*-----------------------------------------------------------*/ - PUBLIC MPU_xTimerGenericCommand -MPU_xTimerGenericCommand: + PUBLIC MPU_xTimerGenericCommandFromTask +MPU_xTimerGenericCommandFromTask: push {r0, r1} - /* This function can be called from ISR also and therefore, we need a check - * to take privileged path, if called from ISR. */ - mrs r0, ipsr - cmp r0, #0 - bne MPU_xTimerGenericCommand_Priv mrs r0, control movs r1, #1 tst r0, r1 - beq MPU_xTimerGenericCommand_Priv - MPU_xTimerGenericCommand_Unpriv: + bne MPU_xTimerGenericCommandFromTask_Unpriv + MPU_xTimerGenericCommandFromTask_Priv: + pop {r0, r1} + b MPU_xTimerGenericCommandFromTaskImpl + MPU_xTimerGenericCommandFromTask_Unpriv: pop {r0, r1} svc #portSVC_SYSTEM_CALL_ENTER_1 - bl MPU_xTimerGenericCommandImpl + bl MPU_xTimerGenericCommandFromTaskImpl svc #portSVC_SYSTEM_CALL_EXIT bx lr - MPU_xTimerGenericCommand_Priv: - pop {r0, r1} - b MPU_xTimerGenericCommandImpl - /*-----------------------------------------------------------*/ PUBLIC MPU_pcTimerGetName @@ -1532,9 +1526,9 @@ MPU_xTimerIsTimerActiveImpl: MPU_xTimerGetTimerDaemonTaskHandleImpl: b MPU_xTimerGetTimerDaemonTaskHandleImpl - PUBWEAK MPU_xTimerGenericCommandImpl -MPU_xTimerGenericCommandImpl: - b MPU_xTimerGenericCommandImpl + PUBWEAK MPU_xTimerGenericCommandFromTaskImpl +MPU_xTimerGenericCommandFromTaskImpl: + b MPU_xTimerGenericCommandFromTaskImpl PUBWEAK MPU_pcTimerGetNameImpl MPU_pcTimerGetNameImpl: diff --git a/portable/ARMv8M/non_secure/portable/IAR/ARM_CM23_NTZ/mpu_wrappers_v2_asm.S b/portable/ARMv8M/non_secure/portable/IAR/ARM_CM23_NTZ/mpu_wrappers_v2_asm.S index 867642b5e9..f2098b57da 100644 --- a/portable/ARMv8M/non_secure/portable/IAR/ARM_CM23_NTZ/mpu_wrappers_v2_asm.S +++ b/portable/ARMv8M/non_secure/portable/IAR/ARM_CM23_NTZ/mpu_wrappers_v2_asm.S @@ -945,28 +945,22 @@ MPU_xTimerGetTimerDaemonTaskHandle: bx lr /*-----------------------------------------------------------*/ - PUBLIC MPU_xTimerGenericCommand -MPU_xTimerGenericCommand: + PUBLIC MPU_xTimerGenericCommandFromTask +MPU_xTimerGenericCommandFromTask: push {r0, r1} - /* This function can be called from ISR also and therefore, we need a check - * to take privileged path, if called from ISR. */ - mrs r0, ipsr - cmp r0, #0 - bne MPU_xTimerGenericCommand_Priv mrs r0, control movs r1, #1 tst r0, r1 - beq MPU_xTimerGenericCommand_Priv - MPU_xTimerGenericCommand_Unpriv: + bne MPU_xTimerGenericCommandFromTask_Unpriv + MPU_xTimerGenericCommandFromTask_Priv: + pop {r0, r1} + b MPU_xTimerGenericCommandFromTaskImpl + MPU_xTimerGenericCommandFromTask_Unpriv: pop {r0, r1} svc #portSVC_SYSTEM_CALL_ENTER_1 - bl MPU_xTimerGenericCommandImpl + bl MPU_xTimerGenericCommandFromTaskImpl svc #portSVC_SYSTEM_CALL_EXIT bx lr - MPU_xTimerGenericCommand_Priv: - pop {r0, r1} - b MPU_xTimerGenericCommandImpl - /*-----------------------------------------------------------*/ PUBLIC MPU_pcTimerGetName @@ -1532,9 +1526,9 @@ MPU_xTimerIsTimerActiveImpl: MPU_xTimerGetTimerDaemonTaskHandleImpl: b MPU_xTimerGetTimerDaemonTaskHandleImpl - PUBWEAK MPU_xTimerGenericCommandImpl -MPU_xTimerGenericCommandImpl: - b MPU_xTimerGenericCommandImpl + PUBWEAK MPU_xTimerGenericCommandFromTaskImpl +MPU_xTimerGenericCommandFromTaskImpl: + b MPU_xTimerGenericCommandFromTaskImpl PUBWEAK MPU_pcTimerGetNameImpl MPU_pcTimerGetNameImpl: diff --git a/portable/ARMv8M/non_secure/portable/IAR/ARM_CM33/mpu_wrappers_v2_asm.S b/portable/ARMv8M/non_secure/portable/IAR/ARM_CM33/mpu_wrappers_v2_asm.S index f051a6073d..9cb9a9d725 100644 --- a/portable/ARMv8M/non_secure/portable/IAR/ARM_CM33/mpu_wrappers_v2_asm.S +++ b/portable/ARMv8M/non_secure/portable/IAR/ARM_CM33/mpu_wrappers_v2_asm.S @@ -895,27 +895,21 @@ MPU_xTimerGetTimerDaemonTaskHandle: bx lr /*-----------------------------------------------------------*/ - PUBLIC MPU_xTimerGenericCommand -MPU_xTimerGenericCommand: + PUBLIC MPU_xTimerGenericCommandFromTask +MPU_xTimerGenericCommandFromTask: push {r0} - /* This function can be called from ISR also and therefore, we need a check - * to take privileged path, if called from ISR. */ - mrs r0, ipsr - cmp r0, #0 - bne MPU_xTimerGenericCommand_Priv mrs r0, control tst r0, #1 - beq MPU_xTimerGenericCommand_Priv - MPU_xTimerGenericCommand_Unpriv: + bne MPU_xTimerGenericCommandFromTask_Unpriv + MPU_xTimerGenericCommandFromTask_Priv: + pop {r0} + b MPU_xTimerGenericCommandFromTaskImpl + MPU_xTimerGenericCommandFromTask_Unpriv: pop {r0} svc #portSVC_SYSTEM_CALL_ENTER_1 - bl MPU_xTimerGenericCommandImpl + bl MPU_xTimerGenericCommandFromTaskImpl svc #portSVC_SYSTEM_CALL_EXIT bx lr - MPU_xTimerGenericCommand_Priv: - pop {r0} - b MPU_xTimerGenericCommandImpl - /*-----------------------------------------------------------*/ PUBLIC MPU_pcTimerGetName @@ -1461,9 +1455,9 @@ MPU_xTimerIsTimerActiveImpl: MPU_xTimerGetTimerDaemonTaskHandleImpl: b MPU_xTimerGetTimerDaemonTaskHandleImpl - PUBWEAK MPU_xTimerGenericCommandImpl -MPU_xTimerGenericCommandImpl: - b MPU_xTimerGenericCommandImpl + PUBWEAK MPU_xTimerGenericCommandFromTaskImpl +MPU_xTimerGenericCommandFromTaskImpl: + b MPU_xTimerGenericCommandFromTaskImpl PUBWEAK MPU_pcTimerGetNameImpl MPU_pcTimerGetNameImpl: diff --git a/portable/ARMv8M/non_secure/portable/IAR/ARM_CM33_NTZ/mpu_wrappers_v2_asm.S b/portable/ARMv8M/non_secure/portable/IAR/ARM_CM33_NTZ/mpu_wrappers_v2_asm.S index f051a6073d..9cb9a9d725 100644 --- a/portable/ARMv8M/non_secure/portable/IAR/ARM_CM33_NTZ/mpu_wrappers_v2_asm.S +++ b/portable/ARMv8M/non_secure/portable/IAR/ARM_CM33_NTZ/mpu_wrappers_v2_asm.S @@ -895,27 +895,21 @@ MPU_xTimerGetTimerDaemonTaskHandle: bx lr /*-----------------------------------------------------------*/ - PUBLIC MPU_xTimerGenericCommand -MPU_xTimerGenericCommand: + PUBLIC MPU_xTimerGenericCommandFromTask +MPU_xTimerGenericCommandFromTask: push {r0} - /* This function can be called from ISR also and therefore, we need a check - * to take privileged path, if called from ISR. */ - mrs r0, ipsr - cmp r0, #0 - bne MPU_xTimerGenericCommand_Priv mrs r0, control tst r0, #1 - beq MPU_xTimerGenericCommand_Priv - MPU_xTimerGenericCommand_Unpriv: + bne MPU_xTimerGenericCommandFromTask_Unpriv + MPU_xTimerGenericCommandFromTask_Priv: + pop {r0} + b MPU_xTimerGenericCommandFromTaskImpl + MPU_xTimerGenericCommandFromTask_Unpriv: pop {r0} svc #portSVC_SYSTEM_CALL_ENTER_1 - bl MPU_xTimerGenericCommandImpl + bl MPU_xTimerGenericCommandFromTaskImpl svc #portSVC_SYSTEM_CALL_EXIT bx lr - MPU_xTimerGenericCommand_Priv: - pop {r0} - b MPU_xTimerGenericCommandImpl - /*-----------------------------------------------------------*/ PUBLIC MPU_pcTimerGetName @@ -1461,9 +1455,9 @@ MPU_xTimerIsTimerActiveImpl: MPU_xTimerGetTimerDaemonTaskHandleImpl: b MPU_xTimerGetTimerDaemonTaskHandleImpl - PUBWEAK MPU_xTimerGenericCommandImpl -MPU_xTimerGenericCommandImpl: - b MPU_xTimerGenericCommandImpl + PUBWEAK MPU_xTimerGenericCommandFromTaskImpl +MPU_xTimerGenericCommandFromTaskImpl: + b MPU_xTimerGenericCommandFromTaskImpl PUBWEAK MPU_pcTimerGetNameImpl MPU_pcTimerGetNameImpl: diff --git a/portable/Common/mpu_wrappers.c b/portable/Common/mpu_wrappers.c index c9951956fe..e877dcea9a 100644 --- a/portable/Common/mpu_wrappers.c +++ b/portable/Common/mpu_wrappers.c @@ -1943,11 +1943,11 @@ /*-----------------------------------------------------------*/ #if ( configUSE_TIMERS == 1 ) - BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) /* FREERTOS_SYSTEM_CALL */ + BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) /* FREERTOS_SYSTEM_CALL */ { BaseType_t xReturn; @@ -1956,7 +1956,7 @@ portRAISE_PRIVILEGE(); portMEMORY_BARRIER(); - xReturn = xTimerGenericCommand( xTimer, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait ); + xReturn = xTimerGenericCommandFromTask( xTimer, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait ); portMEMORY_BARRIER(); portRESET_PRIVILEGE(); @@ -1964,7 +1964,7 @@ } else { - xReturn = xTimerGenericCommand( xTimer, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait ); + xReturn = xTimerGenericCommandFromTask( xTimer, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait ); } return xReturn; diff --git a/portable/Common/mpu_wrappers_v2.c b/portable/Common/mpu_wrappers_v2.c index 1a976cb50d..91a2e7055f 100644 --- a/portable/Common/mpu_wrappers_v2.c +++ b/portable/Common/mpu_wrappers_v2.c @@ -2917,17 +2917,17 @@ #if ( configUSE_TIMERS == 1 ) - BaseType_t MPU_xTimerGenericCommandImpl( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; - - BaseType_t MPU_xTimerGenericCommandImpl( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */ + BaseType_t MPU_xTimerGenericCommandFromTaskImpl( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + + BaseType_t MPU_xTimerGenericCommandFromTaskImpl( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */ { BaseType_t xReturn = pdFALSE; TimerHandle_t xInternalTimerHandle = NULL; @@ -2951,7 +2951,7 @@ if( xInternalTimerHandle != NULL ) { - xReturn = xTimerGenericCommand( xInternalTimerHandle, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait ); + xReturn = xTimerGenericCommandFromTask( xInternalTimerHandle, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait ); } } } @@ -3232,6 +3232,47 @@ #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 ) */ /*-----------------------------------------------------------*/ + #if ( configUSE_TIMERS == 1 ) + + BaseType_t MPU_xTimerGenericCommandFromISR( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */ + { + BaseType_t xReturn = pdFALSE; + TimerHandle_t xInternalTimerHandle = NULL; + int32_t lIndex; + BaseType_t xIsHigherPriorityTaskWokenWriteable = pdFALSE; + + if( pxHigherPriorityTaskWoken != NULL ) + { + xIsHigherPriorityTaskWokenWriteable = xPortIsAuthorizedToAccessBuffer( pxHigherPriorityTaskWoken, + sizeof( BaseType_t ), + tskMPU_WRITE_PERMISSION ); + } + + if( ( pxHigherPriorityTaskWoken == NULL ) || ( xIsHigherPriorityTaskWokenWriteable == pdTRUE ) ) + { + lIndex = ( int32_t ) xTimer; + + if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE ) + { + xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) ); + + if( xInternalTimerHandle != NULL ) + { + xReturn = xTimerGenericCommandFromISR( xInternalTimerHandle, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait ); + } + } + } + + return xReturn; + } + + #endif /* if ( configUSE_TIMERS == 1 ) */ +/*-----------------------------------------------------------*/ + /*-----------------------------------------------------------*/ /* MPU wrappers for event group APIs. */ /*-----------------------------------------------------------*/ diff --git a/portable/GCC/ARM_CM23/non_secure/mpu_wrappers_v2_asm.c b/portable/GCC/ARM_CM23/non_secure/mpu_wrappers_v2_asm.c index a1e5ce0828..795f2195c2 100644 --- a/portable/GCC/ARM_CM23/non_secure/mpu_wrappers_v2_asm.c +++ b/portable/GCC/ARM_CM23/non_secure/mpu_wrappers_v2_asm.c @@ -1726,41 +1726,38 @@ TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ) /* __attribute__ (( nake #if ( configUSE_TIMERS == 1 ) -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; - -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ -{ - __asm volatile - ( - " .syntax unified \n" - " .extern MPU_xTimerGenericCommandImpl \n" - " \n" - " push {r0, r1} \n" - " mrs r0, ipsr \n" - " cmp r0, #0 \n" - " bne MPU_xTimerGenericCommand_Priv \n" - " mrs r0, control \n" - " movs r1, #1 \n" - " tst r0, r1 \n" - " beq MPU_xTimerGenericCommand_Priv \n" - " MPU_xTimerGenericCommand_Unpriv: \n" - " pop {r0, r1} \n" - " svc %0 \n" - " bl MPU_xTimerGenericCommandImpl \n" - " svc %1 \n" - " bx lr \n" - " MPU_xTimerGenericCommand_Priv: \n" - " pop {r0, r1} \n" - " b MPU_xTimerGenericCommandImpl \n" - " \n" +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; + +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ +{ + __asm volatile + ( + " .syntax unified \n" + " .extern MPU_xTimerGenericCommandFromTaskImpl \n" + " \n" + " push {r0, r1} \n" + " mrs r0, control \n" + " movs r1, #1 \n" + " tst r0, r1 \n" + " bne MPU_xTimerGenericCommandFromTask_Unpriv \n" + " MPU_xTimerGenericCommandFromTask_Priv: \n" + " pop {r0, r1} \n" + " b MPU_xTimerGenericCommandFromTaskImpl \n" + " MPU_xTimerGenericCommandFromTask_Unpriv: \n" + " pop {r0, r1} \n" + " svc %0 \n" + " bl MPU_xTimerGenericCommandFromTaskImpl \n" + " svc %1 \n" + " bx lr \n" + " \n" : : "i" ( portSVC_SYSTEM_CALL_ENTER_1 ), "i" ( portSVC_SYSTEM_CALL_EXIT ) : "memory" ); } diff --git a/portable/GCC/ARM_CM23/non_secure/port.c b/portable/GCC/ARM_CM23/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/GCC/ARM_CM23/non_secure/port.c +++ b/portable/GCC/ARM_CM23/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/GCC/ARM_CM23_NTZ/non_secure/mpu_wrappers_v2_asm.c b/portable/GCC/ARM_CM23_NTZ/non_secure/mpu_wrappers_v2_asm.c index a1e5ce0828..795f2195c2 100644 --- a/portable/GCC/ARM_CM23_NTZ/non_secure/mpu_wrappers_v2_asm.c +++ b/portable/GCC/ARM_CM23_NTZ/non_secure/mpu_wrappers_v2_asm.c @@ -1726,41 +1726,38 @@ TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ) /* __attribute__ (( nake #if ( configUSE_TIMERS == 1 ) -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; - -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ -{ - __asm volatile - ( - " .syntax unified \n" - " .extern MPU_xTimerGenericCommandImpl \n" - " \n" - " push {r0, r1} \n" - " mrs r0, ipsr \n" - " cmp r0, #0 \n" - " bne MPU_xTimerGenericCommand_Priv \n" - " mrs r0, control \n" - " movs r1, #1 \n" - " tst r0, r1 \n" - " beq MPU_xTimerGenericCommand_Priv \n" - " MPU_xTimerGenericCommand_Unpriv: \n" - " pop {r0, r1} \n" - " svc %0 \n" - " bl MPU_xTimerGenericCommandImpl \n" - " svc %1 \n" - " bx lr \n" - " MPU_xTimerGenericCommand_Priv: \n" - " pop {r0, r1} \n" - " b MPU_xTimerGenericCommandImpl \n" - " \n" +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; + +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ +{ + __asm volatile + ( + " .syntax unified \n" + " .extern MPU_xTimerGenericCommandFromTaskImpl \n" + " \n" + " push {r0, r1} \n" + " mrs r0, control \n" + " movs r1, #1 \n" + " tst r0, r1 \n" + " bne MPU_xTimerGenericCommandFromTask_Unpriv \n" + " MPU_xTimerGenericCommandFromTask_Priv: \n" + " pop {r0, r1} \n" + " b MPU_xTimerGenericCommandFromTaskImpl \n" + " MPU_xTimerGenericCommandFromTask_Unpriv: \n" + " pop {r0, r1} \n" + " svc %0 \n" + " bl MPU_xTimerGenericCommandFromTaskImpl \n" + " svc %1 \n" + " bx lr \n" + " \n" : : "i" ( portSVC_SYSTEM_CALL_ENTER_1 ), "i" ( portSVC_SYSTEM_CALL_EXIT ) : "memory" ); } diff --git a/portable/GCC/ARM_CM23_NTZ/non_secure/port.c b/portable/GCC/ARM_CM23_NTZ/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/GCC/ARM_CM23_NTZ/non_secure/port.c +++ b/portable/GCC/ARM_CM23_NTZ/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/GCC/ARM_CM33/non_secure/mpu_wrappers_v2_asm.c b/portable/GCC/ARM_CM33/non_secure/mpu_wrappers_v2_asm.c index 6e2043427f..9e1b9ed858 100644 --- a/portable/GCC/ARM_CM33/non_secure/mpu_wrappers_v2_asm.c +++ b/portable/GCC/ARM_CM33/non_secure/mpu_wrappers_v2_asm.c @@ -1676,41 +1676,37 @@ TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ) /* __attribute__ (( nake #if ( configUSE_TIMERS == 1 ) -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; - -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ -{ - __asm volatile - ( - " .syntax unified \n" - " .extern MPU_xTimerGenericCommandImpl \n" - " \n" - " push {r0} \n" - " mrs r0, ipsr \n" - " cmp r0, #0 \n" - " bne MPU_xTimerGenericCommand_Priv \n" - " mrs r0, control \n" - " tst r0, #1 \n" - " beq MPU_xTimerGenericCommand_Priv \n" - " MPU_xTimerGenericCommand_Unpriv: \n" - " pop {r0} \n" - " svc %0 \n" - " bl MPU_xTimerGenericCommandImpl \n" - " svc %1 \n" - " bx lr \n" - " MPU_xTimerGenericCommand_Priv: \n" - " pop {r0} \n" - " b MPU_xTimerGenericCommandImpl \n" - " \n" - " \n" +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; + +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ +{ + __asm volatile + ( + " .syntax unified \n" + " .extern MPU_xTimerGenericCommandFromTaskImpl \n" + " \n" + " push {r0} \n" + " mrs r0, control \n" + " tst r0, #1 \n" + " bne MPU_xTimerGenericCommandFromTask_Unpriv \n" + " MPU_xTimerGenericCommandFromTask_Priv: \n" + " pop {r0} \n" + " b MPU_xTimerGenericCommandFromTaskImpl \n" + " MPU_xTimerGenericCommandFromTask_Unpriv: \n" + " pop {r0} \n" + " svc %0 \n" + " bl MPU_xTimerGenericCommandFromTaskImpl \n" + " svc %1 \n" + " bx lr \n" + " \n" : : "i" ( portSVC_SYSTEM_CALL_ENTER_1 ), "i" ( portSVC_SYSTEM_CALL_EXIT ) : "memory" ); } diff --git a/portable/GCC/ARM_CM33/non_secure/port.c b/portable/GCC/ARM_CM33/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/GCC/ARM_CM33/non_secure/port.c +++ b/portable/GCC/ARM_CM33/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/GCC/ARM_CM33_NTZ/non_secure/mpu_wrappers_v2_asm.c b/portable/GCC/ARM_CM33_NTZ/non_secure/mpu_wrappers_v2_asm.c index 6e2043427f..9e1b9ed858 100644 --- a/portable/GCC/ARM_CM33_NTZ/non_secure/mpu_wrappers_v2_asm.c +++ b/portable/GCC/ARM_CM33_NTZ/non_secure/mpu_wrappers_v2_asm.c @@ -1676,41 +1676,37 @@ TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ) /* __attribute__ (( nake #if ( configUSE_TIMERS == 1 ) -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; - -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ -{ - __asm volatile - ( - " .syntax unified \n" - " .extern MPU_xTimerGenericCommandImpl \n" - " \n" - " push {r0} \n" - " mrs r0, ipsr \n" - " cmp r0, #0 \n" - " bne MPU_xTimerGenericCommand_Priv \n" - " mrs r0, control \n" - " tst r0, #1 \n" - " beq MPU_xTimerGenericCommand_Priv \n" - " MPU_xTimerGenericCommand_Unpriv: \n" - " pop {r0} \n" - " svc %0 \n" - " bl MPU_xTimerGenericCommandImpl \n" - " svc %1 \n" - " bx lr \n" - " MPU_xTimerGenericCommand_Priv: \n" - " pop {r0} \n" - " b MPU_xTimerGenericCommandImpl \n" - " \n" - " \n" +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; + +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ +{ + __asm volatile + ( + " .syntax unified \n" + " .extern MPU_xTimerGenericCommandFromTaskImpl \n" + " \n" + " push {r0} \n" + " mrs r0, control \n" + " tst r0, #1 \n" + " bne MPU_xTimerGenericCommandFromTask_Unpriv \n" + " MPU_xTimerGenericCommandFromTask_Priv: \n" + " pop {r0} \n" + " b MPU_xTimerGenericCommandFromTaskImpl \n" + " MPU_xTimerGenericCommandFromTask_Unpriv: \n" + " pop {r0} \n" + " svc %0 \n" + " bl MPU_xTimerGenericCommandFromTaskImpl \n" + " svc %1 \n" + " bx lr \n" + " \n" : : "i" ( portSVC_SYSTEM_CALL_ENTER_1 ), "i" ( portSVC_SYSTEM_CALL_EXIT ) : "memory" ); } diff --git a/portable/GCC/ARM_CM33_NTZ/non_secure/port.c b/portable/GCC/ARM_CM33_NTZ/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/GCC/ARM_CM33_NTZ/non_secure/port.c +++ b/portable/GCC/ARM_CM33_NTZ/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/GCC/ARM_CM35P/non_secure/mpu_wrappers_v2_asm.c b/portable/GCC/ARM_CM35P/non_secure/mpu_wrappers_v2_asm.c index 6e2043427f..9e1b9ed858 100644 --- a/portable/GCC/ARM_CM35P/non_secure/mpu_wrappers_v2_asm.c +++ b/portable/GCC/ARM_CM35P/non_secure/mpu_wrappers_v2_asm.c @@ -1676,41 +1676,37 @@ TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ) /* __attribute__ (( nake #if ( configUSE_TIMERS == 1 ) -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; - -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ -{ - __asm volatile - ( - " .syntax unified \n" - " .extern MPU_xTimerGenericCommandImpl \n" - " \n" - " push {r0} \n" - " mrs r0, ipsr \n" - " cmp r0, #0 \n" - " bne MPU_xTimerGenericCommand_Priv \n" - " mrs r0, control \n" - " tst r0, #1 \n" - " beq MPU_xTimerGenericCommand_Priv \n" - " MPU_xTimerGenericCommand_Unpriv: \n" - " pop {r0} \n" - " svc %0 \n" - " bl MPU_xTimerGenericCommandImpl \n" - " svc %1 \n" - " bx lr \n" - " MPU_xTimerGenericCommand_Priv: \n" - " pop {r0} \n" - " b MPU_xTimerGenericCommandImpl \n" - " \n" - " \n" +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; + +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ +{ + __asm volatile + ( + " .syntax unified \n" + " .extern MPU_xTimerGenericCommandFromTaskImpl \n" + " \n" + " push {r0} \n" + " mrs r0, control \n" + " tst r0, #1 \n" + " bne MPU_xTimerGenericCommandFromTask_Unpriv \n" + " MPU_xTimerGenericCommandFromTask_Priv: \n" + " pop {r0} \n" + " b MPU_xTimerGenericCommandFromTaskImpl \n" + " MPU_xTimerGenericCommandFromTask_Unpriv: \n" + " pop {r0} \n" + " svc %0 \n" + " bl MPU_xTimerGenericCommandFromTaskImpl \n" + " svc %1 \n" + " bx lr \n" + " \n" : : "i" ( portSVC_SYSTEM_CALL_ENTER_1 ), "i" ( portSVC_SYSTEM_CALL_EXIT ) : "memory" ); } diff --git a/portable/GCC/ARM_CM35P/non_secure/port.c b/portable/GCC/ARM_CM35P/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/GCC/ARM_CM35P/non_secure/port.c +++ b/portable/GCC/ARM_CM35P/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/GCC/ARM_CM35P_NTZ/non_secure/mpu_wrappers_v2_asm.c b/portable/GCC/ARM_CM35P_NTZ/non_secure/mpu_wrappers_v2_asm.c index 6e2043427f..9e1b9ed858 100644 --- a/portable/GCC/ARM_CM35P_NTZ/non_secure/mpu_wrappers_v2_asm.c +++ b/portable/GCC/ARM_CM35P_NTZ/non_secure/mpu_wrappers_v2_asm.c @@ -1676,41 +1676,37 @@ TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ) /* __attribute__ (( nake #if ( configUSE_TIMERS == 1 ) -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; - -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ -{ - __asm volatile - ( - " .syntax unified \n" - " .extern MPU_xTimerGenericCommandImpl \n" - " \n" - " push {r0} \n" - " mrs r0, ipsr \n" - " cmp r0, #0 \n" - " bne MPU_xTimerGenericCommand_Priv \n" - " mrs r0, control \n" - " tst r0, #1 \n" - " beq MPU_xTimerGenericCommand_Priv \n" - " MPU_xTimerGenericCommand_Unpriv: \n" - " pop {r0} \n" - " svc %0 \n" - " bl MPU_xTimerGenericCommandImpl \n" - " svc %1 \n" - " bx lr \n" - " MPU_xTimerGenericCommand_Priv: \n" - " pop {r0} \n" - " b MPU_xTimerGenericCommandImpl \n" - " \n" - " \n" +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; + +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ +{ + __asm volatile + ( + " .syntax unified \n" + " .extern MPU_xTimerGenericCommandFromTaskImpl \n" + " \n" + " push {r0} \n" + " mrs r0, control \n" + " tst r0, #1 \n" + " bne MPU_xTimerGenericCommandFromTask_Unpriv \n" + " MPU_xTimerGenericCommandFromTask_Priv: \n" + " pop {r0} \n" + " b MPU_xTimerGenericCommandFromTaskImpl \n" + " MPU_xTimerGenericCommandFromTask_Unpriv: \n" + " pop {r0} \n" + " svc %0 \n" + " bl MPU_xTimerGenericCommandFromTaskImpl \n" + " svc %1 \n" + " bx lr \n" + " \n" : : "i" ( portSVC_SYSTEM_CALL_ENTER_1 ), "i" ( portSVC_SYSTEM_CALL_EXIT ) : "memory" ); } diff --git a/portable/GCC/ARM_CM35P_NTZ/non_secure/port.c b/portable/GCC/ARM_CM35P_NTZ/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/GCC/ARM_CM35P_NTZ/non_secure/port.c +++ b/portable/GCC/ARM_CM35P_NTZ/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/GCC/ARM_CM3_MPU/mpu_wrappers_v2_asm.c b/portable/GCC/ARM_CM3_MPU/mpu_wrappers_v2_asm.c index df9239a41d..d9aa1a3fd3 100644 --- a/portable/GCC/ARM_CM3_MPU/mpu_wrappers_v2_asm.c +++ b/portable/GCC/ARM_CM3_MPU/mpu_wrappers_v2_asm.c @@ -1676,41 +1676,37 @@ TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ) /* __attribute__ (( nake #if ( configUSE_TIMERS == 1 ) -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; - -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ -{ - __asm volatile - ( - " .syntax unified \n" - " .extern MPU_xTimerGenericCommandImpl \n" - " \n" - " push {r0} \n" - " mrs r0, ipsr \n" - " cmp r0, #0 \n" - " bne MPU_xTimerGenericCommand_Priv \n" - " mrs r0, control \n" - " tst r0, #1 \n" - " beq MPU_xTimerGenericCommand_Priv \n" - " MPU_xTimerGenericCommand_Unpriv: \n" - " pop {r0} \n" - " svc %0 \n" - " bl MPU_xTimerGenericCommandImpl \n" - " svc %1 \n" - " bx lr \n" - " MPU_xTimerGenericCommand_Priv: \n" - " pop {r0} \n" - " b MPU_xTimerGenericCommandImpl \n" - " \n" - " \n" +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; + +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ +{ + __asm volatile + ( + " .syntax unified \n" + " .extern MPU_xTimerGenericCommandFromTaskImpl \n" + " \n" + " push {r0} \n" + " mrs r0, control \n" + " tst r0, #1 \n" + " bne MPU_xTimerGenericCommandFromTask_Unpriv \n" + " MPU_xTimerGenericCommandFromTask_Priv: \n" + " pop {r0} \n" + " b MPU_xTimerGenericCommandFromTaskImpl \n" + " MPU_xTimerGenericCommandFromTask_Unpriv: \n" + " pop {r0} \n" + " svc %0 \n" + " bl MPU_xTimerGenericCommandFromTaskImpl \n" + " svc %1 \n" + " bx lr \n" + " \n" : : "i" ( portSVC_SYSTEM_CALL_ENTER_1 ), "i" ( portSVC_SYSTEM_CALL_EXIT ) : "memory" ); } diff --git a/portable/GCC/ARM_CM4_MPU/mpu_wrappers_v2_asm.c b/portable/GCC/ARM_CM4_MPU/mpu_wrappers_v2_asm.c index df9239a41d..d9aa1a3fd3 100644 --- a/portable/GCC/ARM_CM4_MPU/mpu_wrappers_v2_asm.c +++ b/portable/GCC/ARM_CM4_MPU/mpu_wrappers_v2_asm.c @@ -1676,41 +1676,37 @@ TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ) /* __attribute__ (( nake #if ( configUSE_TIMERS == 1 ) -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; - -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ -{ - __asm volatile - ( - " .syntax unified \n" - " .extern MPU_xTimerGenericCommandImpl \n" - " \n" - " push {r0} \n" - " mrs r0, ipsr \n" - " cmp r0, #0 \n" - " bne MPU_xTimerGenericCommand_Priv \n" - " mrs r0, control \n" - " tst r0, #1 \n" - " beq MPU_xTimerGenericCommand_Priv \n" - " MPU_xTimerGenericCommand_Unpriv: \n" - " pop {r0} \n" - " svc %0 \n" - " bl MPU_xTimerGenericCommandImpl \n" - " svc %1 \n" - " bx lr \n" - " MPU_xTimerGenericCommand_Priv: \n" - " pop {r0} \n" - " b MPU_xTimerGenericCommandImpl \n" - " \n" - " \n" +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; + +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ +{ + __asm volatile + ( + " .syntax unified \n" + " .extern MPU_xTimerGenericCommandFromTaskImpl \n" + " \n" + " push {r0} \n" + " mrs r0, control \n" + " tst r0, #1 \n" + " bne MPU_xTimerGenericCommandFromTask_Unpriv \n" + " MPU_xTimerGenericCommandFromTask_Priv: \n" + " pop {r0} \n" + " b MPU_xTimerGenericCommandFromTaskImpl \n" + " MPU_xTimerGenericCommandFromTask_Unpriv: \n" + " pop {r0} \n" + " svc %0 \n" + " bl MPU_xTimerGenericCommandFromTaskImpl \n" + " svc %1 \n" + " bx lr \n" + " \n" : : "i" ( portSVC_SYSTEM_CALL_ENTER_1 ), "i" ( portSVC_SYSTEM_CALL_EXIT ) : "memory" ); } diff --git a/portable/GCC/ARM_CM55/non_secure/mpu_wrappers_v2_asm.c b/portable/GCC/ARM_CM55/non_secure/mpu_wrappers_v2_asm.c index 6e2043427f..9e1b9ed858 100644 --- a/portable/GCC/ARM_CM55/non_secure/mpu_wrappers_v2_asm.c +++ b/portable/GCC/ARM_CM55/non_secure/mpu_wrappers_v2_asm.c @@ -1676,41 +1676,37 @@ TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ) /* __attribute__ (( nake #if ( configUSE_TIMERS == 1 ) -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; - -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ -{ - __asm volatile - ( - " .syntax unified \n" - " .extern MPU_xTimerGenericCommandImpl \n" - " \n" - " push {r0} \n" - " mrs r0, ipsr \n" - " cmp r0, #0 \n" - " bne MPU_xTimerGenericCommand_Priv \n" - " mrs r0, control \n" - " tst r0, #1 \n" - " beq MPU_xTimerGenericCommand_Priv \n" - " MPU_xTimerGenericCommand_Unpriv: \n" - " pop {r0} \n" - " svc %0 \n" - " bl MPU_xTimerGenericCommandImpl \n" - " svc %1 \n" - " bx lr \n" - " MPU_xTimerGenericCommand_Priv: \n" - " pop {r0} \n" - " b MPU_xTimerGenericCommandImpl \n" - " \n" - " \n" +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; + +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ +{ + __asm volatile + ( + " .syntax unified \n" + " .extern MPU_xTimerGenericCommandFromTaskImpl \n" + " \n" + " push {r0} \n" + " mrs r0, control \n" + " tst r0, #1 \n" + " bne MPU_xTimerGenericCommandFromTask_Unpriv \n" + " MPU_xTimerGenericCommandFromTask_Priv: \n" + " pop {r0} \n" + " b MPU_xTimerGenericCommandFromTaskImpl \n" + " MPU_xTimerGenericCommandFromTask_Unpriv: \n" + " pop {r0} \n" + " svc %0 \n" + " bl MPU_xTimerGenericCommandFromTaskImpl \n" + " svc %1 \n" + " bx lr \n" + " \n" : : "i" ( portSVC_SYSTEM_CALL_ENTER_1 ), "i" ( portSVC_SYSTEM_CALL_EXIT ) : "memory" ); } diff --git a/portable/GCC/ARM_CM55/non_secure/port.c b/portable/GCC/ARM_CM55/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/GCC/ARM_CM55/non_secure/port.c +++ b/portable/GCC/ARM_CM55/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/GCC/ARM_CM55_NTZ/non_secure/mpu_wrappers_v2_asm.c b/portable/GCC/ARM_CM55_NTZ/non_secure/mpu_wrappers_v2_asm.c index 6e2043427f..9e1b9ed858 100644 --- a/portable/GCC/ARM_CM55_NTZ/non_secure/mpu_wrappers_v2_asm.c +++ b/portable/GCC/ARM_CM55_NTZ/non_secure/mpu_wrappers_v2_asm.c @@ -1676,41 +1676,37 @@ TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ) /* __attribute__ (( nake #if ( configUSE_TIMERS == 1 ) -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; - -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ -{ - __asm volatile - ( - " .syntax unified \n" - " .extern MPU_xTimerGenericCommandImpl \n" - " \n" - " push {r0} \n" - " mrs r0, ipsr \n" - " cmp r0, #0 \n" - " bne MPU_xTimerGenericCommand_Priv \n" - " mrs r0, control \n" - " tst r0, #1 \n" - " beq MPU_xTimerGenericCommand_Priv \n" - " MPU_xTimerGenericCommand_Unpriv: \n" - " pop {r0} \n" - " svc %0 \n" - " bl MPU_xTimerGenericCommandImpl \n" - " svc %1 \n" - " bx lr \n" - " MPU_xTimerGenericCommand_Priv: \n" - " pop {r0} \n" - " b MPU_xTimerGenericCommandImpl \n" - " \n" - " \n" +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; + +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ +{ + __asm volatile + ( + " .syntax unified \n" + " .extern MPU_xTimerGenericCommandFromTaskImpl \n" + " \n" + " push {r0} \n" + " mrs r0, control \n" + " tst r0, #1 \n" + " bne MPU_xTimerGenericCommandFromTask_Unpriv \n" + " MPU_xTimerGenericCommandFromTask_Priv: \n" + " pop {r0} \n" + " b MPU_xTimerGenericCommandFromTaskImpl \n" + " MPU_xTimerGenericCommandFromTask_Unpriv: \n" + " pop {r0} \n" + " svc %0 \n" + " bl MPU_xTimerGenericCommandFromTaskImpl \n" + " svc %1 \n" + " bx lr \n" + " \n" : : "i" ( portSVC_SYSTEM_CALL_ENTER_1 ), "i" ( portSVC_SYSTEM_CALL_EXIT ) : "memory" ); } diff --git a/portable/GCC/ARM_CM55_NTZ/non_secure/port.c b/portable/GCC/ARM_CM55_NTZ/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/GCC/ARM_CM55_NTZ/non_secure/port.c +++ b/portable/GCC/ARM_CM55_NTZ/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/GCC/ARM_CM85/non_secure/mpu_wrappers_v2_asm.c b/portable/GCC/ARM_CM85/non_secure/mpu_wrappers_v2_asm.c index 6e2043427f..9e1b9ed858 100644 --- a/portable/GCC/ARM_CM85/non_secure/mpu_wrappers_v2_asm.c +++ b/portable/GCC/ARM_CM85/non_secure/mpu_wrappers_v2_asm.c @@ -1676,41 +1676,37 @@ TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ) /* __attribute__ (( nake #if ( configUSE_TIMERS == 1 ) -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; - -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ -{ - __asm volatile - ( - " .syntax unified \n" - " .extern MPU_xTimerGenericCommandImpl \n" - " \n" - " push {r0} \n" - " mrs r0, ipsr \n" - " cmp r0, #0 \n" - " bne MPU_xTimerGenericCommand_Priv \n" - " mrs r0, control \n" - " tst r0, #1 \n" - " beq MPU_xTimerGenericCommand_Priv \n" - " MPU_xTimerGenericCommand_Unpriv: \n" - " pop {r0} \n" - " svc %0 \n" - " bl MPU_xTimerGenericCommandImpl \n" - " svc %1 \n" - " bx lr \n" - " MPU_xTimerGenericCommand_Priv: \n" - " pop {r0} \n" - " b MPU_xTimerGenericCommandImpl \n" - " \n" - " \n" +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; + +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ +{ + __asm volatile + ( + " .syntax unified \n" + " .extern MPU_xTimerGenericCommandFromTaskImpl \n" + " \n" + " push {r0} \n" + " mrs r0, control \n" + " tst r0, #1 \n" + " bne MPU_xTimerGenericCommandFromTask_Unpriv \n" + " MPU_xTimerGenericCommandFromTask_Priv: \n" + " pop {r0} \n" + " b MPU_xTimerGenericCommandFromTaskImpl \n" + " MPU_xTimerGenericCommandFromTask_Unpriv: \n" + " pop {r0} \n" + " svc %0 \n" + " bl MPU_xTimerGenericCommandFromTaskImpl \n" + " svc %1 \n" + " bx lr \n" + " \n" : : "i" ( portSVC_SYSTEM_CALL_ENTER_1 ), "i" ( portSVC_SYSTEM_CALL_EXIT ) : "memory" ); } diff --git a/portable/GCC/ARM_CM85/non_secure/port.c b/portable/GCC/ARM_CM85/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/GCC/ARM_CM85/non_secure/port.c +++ b/portable/GCC/ARM_CM85/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/GCC/ARM_CM85_NTZ/non_secure/mpu_wrappers_v2_asm.c b/portable/GCC/ARM_CM85_NTZ/non_secure/mpu_wrappers_v2_asm.c index 6e2043427f..9e1b9ed858 100644 --- a/portable/GCC/ARM_CM85_NTZ/non_secure/mpu_wrappers_v2_asm.c +++ b/portable/GCC/ARM_CM85_NTZ/non_secure/mpu_wrappers_v2_asm.c @@ -1676,41 +1676,37 @@ TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ) /* __attribute__ (( nake #if ( configUSE_TIMERS == 1 ) -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; - -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ -{ - __asm volatile - ( - " .syntax unified \n" - " .extern MPU_xTimerGenericCommandImpl \n" - " \n" - " push {r0} \n" - " mrs r0, ipsr \n" - " cmp r0, #0 \n" - " bne MPU_xTimerGenericCommand_Priv \n" - " mrs r0, control \n" - " tst r0, #1 \n" - " beq MPU_xTimerGenericCommand_Priv \n" - " MPU_xTimerGenericCommand_Unpriv: \n" - " pop {r0} \n" - " svc %0 \n" - " bl MPU_xTimerGenericCommandImpl \n" - " svc %1 \n" - " bx lr \n" - " MPU_xTimerGenericCommand_Priv: \n" - " pop {r0} \n" - " b MPU_xTimerGenericCommandImpl \n" - " \n" - " \n" +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) __attribute__ (( naked )) FREERTOS_SYSTEM_CALL; + +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) /* __attribute__ (( naked )) FREERTOS_SYSTEM_CALL */ +{ + __asm volatile + ( + " .syntax unified \n" + " .extern MPU_xTimerGenericCommandFromTaskImpl \n" + " \n" + " push {r0} \n" + " mrs r0, control \n" + " tst r0, #1 \n" + " bne MPU_xTimerGenericCommandFromTask_Unpriv \n" + " MPU_xTimerGenericCommandFromTask_Priv: \n" + " pop {r0} \n" + " b MPU_xTimerGenericCommandFromTaskImpl \n" + " MPU_xTimerGenericCommandFromTask_Unpriv: \n" + " pop {r0} \n" + " svc %0 \n" + " bl MPU_xTimerGenericCommandFromTaskImpl \n" + " svc %1 \n" + " bx lr \n" + " \n" : : "i" ( portSVC_SYSTEM_CALL_ENTER_1 ), "i" ( portSVC_SYSTEM_CALL_EXIT ) : "memory" ); } diff --git a/portable/GCC/ARM_CM85_NTZ/non_secure/port.c b/portable/GCC/ARM_CM85_NTZ/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/GCC/ARM_CM85_NTZ/non_secure/port.c +++ b/portable/GCC/ARM_CM85_NTZ/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/GCC/RL78/port.c b/portable/GCC/RL78/port.c index 35ff7df538..5525b10140 100644 --- a/portable/GCC/RL78/port.c +++ b/portable/GCC/RL78/port.c @@ -136,7 +136,7 @@ uint32_t *pulLocal; } /*-----------------------------------------------------------*/ -portBASE_TYPE xPortStartScheduler( void ) +BaseType_t xPortStartScheduler( void ) { /* Setup the hardware to generate the tick. Interrupts are disabled when this function is called. */ diff --git a/portable/IAR/ARM_CM23/non_secure/mpu_wrappers_v2_asm.S b/portable/IAR/ARM_CM23/non_secure/mpu_wrappers_v2_asm.S index 867642b5e9..f2098b57da 100644 --- a/portable/IAR/ARM_CM23/non_secure/mpu_wrappers_v2_asm.S +++ b/portable/IAR/ARM_CM23/non_secure/mpu_wrappers_v2_asm.S @@ -945,28 +945,22 @@ MPU_xTimerGetTimerDaemonTaskHandle: bx lr /*-----------------------------------------------------------*/ - PUBLIC MPU_xTimerGenericCommand -MPU_xTimerGenericCommand: + PUBLIC MPU_xTimerGenericCommandFromTask +MPU_xTimerGenericCommandFromTask: push {r0, r1} - /* This function can be called from ISR also and therefore, we need a check - * to take privileged path, if called from ISR. */ - mrs r0, ipsr - cmp r0, #0 - bne MPU_xTimerGenericCommand_Priv mrs r0, control movs r1, #1 tst r0, r1 - beq MPU_xTimerGenericCommand_Priv - MPU_xTimerGenericCommand_Unpriv: + bne MPU_xTimerGenericCommandFromTask_Unpriv + MPU_xTimerGenericCommandFromTask_Priv: + pop {r0, r1} + b MPU_xTimerGenericCommandFromTaskImpl + MPU_xTimerGenericCommandFromTask_Unpriv: pop {r0, r1} svc #portSVC_SYSTEM_CALL_ENTER_1 - bl MPU_xTimerGenericCommandImpl + bl MPU_xTimerGenericCommandFromTaskImpl svc #portSVC_SYSTEM_CALL_EXIT bx lr - MPU_xTimerGenericCommand_Priv: - pop {r0, r1} - b MPU_xTimerGenericCommandImpl - /*-----------------------------------------------------------*/ PUBLIC MPU_pcTimerGetName @@ -1532,9 +1526,9 @@ MPU_xTimerIsTimerActiveImpl: MPU_xTimerGetTimerDaemonTaskHandleImpl: b MPU_xTimerGetTimerDaemonTaskHandleImpl - PUBWEAK MPU_xTimerGenericCommandImpl -MPU_xTimerGenericCommandImpl: - b MPU_xTimerGenericCommandImpl + PUBWEAK MPU_xTimerGenericCommandFromTaskImpl +MPU_xTimerGenericCommandFromTaskImpl: + b MPU_xTimerGenericCommandFromTaskImpl PUBWEAK MPU_pcTimerGetNameImpl MPU_pcTimerGetNameImpl: diff --git a/portable/IAR/ARM_CM23/non_secure/port.c b/portable/IAR/ARM_CM23/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/IAR/ARM_CM23/non_secure/port.c +++ b/portable/IAR/ARM_CM23/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/IAR/ARM_CM23_NTZ/non_secure/mpu_wrappers_v2_asm.S b/portable/IAR/ARM_CM23_NTZ/non_secure/mpu_wrappers_v2_asm.S index 867642b5e9..f2098b57da 100644 --- a/portable/IAR/ARM_CM23_NTZ/non_secure/mpu_wrappers_v2_asm.S +++ b/portable/IAR/ARM_CM23_NTZ/non_secure/mpu_wrappers_v2_asm.S @@ -945,28 +945,22 @@ MPU_xTimerGetTimerDaemonTaskHandle: bx lr /*-----------------------------------------------------------*/ - PUBLIC MPU_xTimerGenericCommand -MPU_xTimerGenericCommand: + PUBLIC MPU_xTimerGenericCommandFromTask +MPU_xTimerGenericCommandFromTask: push {r0, r1} - /* This function can be called from ISR also and therefore, we need a check - * to take privileged path, if called from ISR. */ - mrs r0, ipsr - cmp r0, #0 - bne MPU_xTimerGenericCommand_Priv mrs r0, control movs r1, #1 tst r0, r1 - beq MPU_xTimerGenericCommand_Priv - MPU_xTimerGenericCommand_Unpriv: + bne MPU_xTimerGenericCommandFromTask_Unpriv + MPU_xTimerGenericCommandFromTask_Priv: + pop {r0, r1} + b MPU_xTimerGenericCommandFromTaskImpl + MPU_xTimerGenericCommandFromTask_Unpriv: pop {r0, r1} svc #portSVC_SYSTEM_CALL_ENTER_1 - bl MPU_xTimerGenericCommandImpl + bl MPU_xTimerGenericCommandFromTaskImpl svc #portSVC_SYSTEM_CALL_EXIT bx lr - MPU_xTimerGenericCommand_Priv: - pop {r0, r1} - b MPU_xTimerGenericCommandImpl - /*-----------------------------------------------------------*/ PUBLIC MPU_pcTimerGetName @@ -1532,9 +1526,9 @@ MPU_xTimerIsTimerActiveImpl: MPU_xTimerGetTimerDaemonTaskHandleImpl: b MPU_xTimerGetTimerDaemonTaskHandleImpl - PUBWEAK MPU_xTimerGenericCommandImpl -MPU_xTimerGenericCommandImpl: - b MPU_xTimerGenericCommandImpl + PUBWEAK MPU_xTimerGenericCommandFromTaskImpl +MPU_xTimerGenericCommandFromTaskImpl: + b MPU_xTimerGenericCommandFromTaskImpl PUBWEAK MPU_pcTimerGetNameImpl MPU_pcTimerGetNameImpl: diff --git a/portable/IAR/ARM_CM23_NTZ/non_secure/port.c b/portable/IAR/ARM_CM23_NTZ/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/IAR/ARM_CM23_NTZ/non_secure/port.c +++ b/portable/IAR/ARM_CM23_NTZ/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/IAR/ARM_CM33/non_secure/mpu_wrappers_v2_asm.S b/portable/IAR/ARM_CM33/non_secure/mpu_wrappers_v2_asm.S index f051a6073d..9cb9a9d725 100644 --- a/portable/IAR/ARM_CM33/non_secure/mpu_wrappers_v2_asm.S +++ b/portable/IAR/ARM_CM33/non_secure/mpu_wrappers_v2_asm.S @@ -895,27 +895,21 @@ MPU_xTimerGetTimerDaemonTaskHandle: bx lr /*-----------------------------------------------------------*/ - PUBLIC MPU_xTimerGenericCommand -MPU_xTimerGenericCommand: + PUBLIC MPU_xTimerGenericCommandFromTask +MPU_xTimerGenericCommandFromTask: push {r0} - /* This function can be called from ISR also and therefore, we need a check - * to take privileged path, if called from ISR. */ - mrs r0, ipsr - cmp r0, #0 - bne MPU_xTimerGenericCommand_Priv mrs r0, control tst r0, #1 - beq MPU_xTimerGenericCommand_Priv - MPU_xTimerGenericCommand_Unpriv: + bne MPU_xTimerGenericCommandFromTask_Unpriv + MPU_xTimerGenericCommandFromTask_Priv: + pop {r0} + b MPU_xTimerGenericCommandFromTaskImpl + MPU_xTimerGenericCommandFromTask_Unpriv: pop {r0} svc #portSVC_SYSTEM_CALL_ENTER_1 - bl MPU_xTimerGenericCommandImpl + bl MPU_xTimerGenericCommandFromTaskImpl svc #portSVC_SYSTEM_CALL_EXIT bx lr - MPU_xTimerGenericCommand_Priv: - pop {r0} - b MPU_xTimerGenericCommandImpl - /*-----------------------------------------------------------*/ PUBLIC MPU_pcTimerGetName @@ -1461,9 +1455,9 @@ MPU_xTimerIsTimerActiveImpl: MPU_xTimerGetTimerDaemonTaskHandleImpl: b MPU_xTimerGetTimerDaemonTaskHandleImpl - PUBWEAK MPU_xTimerGenericCommandImpl -MPU_xTimerGenericCommandImpl: - b MPU_xTimerGenericCommandImpl + PUBWEAK MPU_xTimerGenericCommandFromTaskImpl +MPU_xTimerGenericCommandFromTaskImpl: + b MPU_xTimerGenericCommandFromTaskImpl PUBWEAK MPU_pcTimerGetNameImpl MPU_pcTimerGetNameImpl: diff --git a/portable/IAR/ARM_CM33/non_secure/port.c b/portable/IAR/ARM_CM33/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/IAR/ARM_CM33/non_secure/port.c +++ b/portable/IAR/ARM_CM33/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/IAR/ARM_CM33_NTZ/non_secure/mpu_wrappers_v2_asm.S b/portable/IAR/ARM_CM33_NTZ/non_secure/mpu_wrappers_v2_asm.S index f051a6073d..9cb9a9d725 100644 --- a/portable/IAR/ARM_CM33_NTZ/non_secure/mpu_wrappers_v2_asm.S +++ b/portable/IAR/ARM_CM33_NTZ/non_secure/mpu_wrappers_v2_asm.S @@ -895,27 +895,21 @@ MPU_xTimerGetTimerDaemonTaskHandle: bx lr /*-----------------------------------------------------------*/ - PUBLIC MPU_xTimerGenericCommand -MPU_xTimerGenericCommand: + PUBLIC MPU_xTimerGenericCommandFromTask +MPU_xTimerGenericCommandFromTask: push {r0} - /* This function can be called from ISR also and therefore, we need a check - * to take privileged path, if called from ISR. */ - mrs r0, ipsr - cmp r0, #0 - bne MPU_xTimerGenericCommand_Priv mrs r0, control tst r0, #1 - beq MPU_xTimerGenericCommand_Priv - MPU_xTimerGenericCommand_Unpriv: + bne MPU_xTimerGenericCommandFromTask_Unpriv + MPU_xTimerGenericCommandFromTask_Priv: + pop {r0} + b MPU_xTimerGenericCommandFromTaskImpl + MPU_xTimerGenericCommandFromTask_Unpriv: pop {r0} svc #portSVC_SYSTEM_CALL_ENTER_1 - bl MPU_xTimerGenericCommandImpl + bl MPU_xTimerGenericCommandFromTaskImpl svc #portSVC_SYSTEM_CALL_EXIT bx lr - MPU_xTimerGenericCommand_Priv: - pop {r0} - b MPU_xTimerGenericCommandImpl - /*-----------------------------------------------------------*/ PUBLIC MPU_pcTimerGetName @@ -1461,9 +1455,9 @@ MPU_xTimerIsTimerActiveImpl: MPU_xTimerGetTimerDaemonTaskHandleImpl: b MPU_xTimerGetTimerDaemonTaskHandleImpl - PUBWEAK MPU_xTimerGenericCommandImpl -MPU_xTimerGenericCommandImpl: - b MPU_xTimerGenericCommandImpl + PUBWEAK MPU_xTimerGenericCommandFromTaskImpl +MPU_xTimerGenericCommandFromTaskImpl: + b MPU_xTimerGenericCommandFromTaskImpl PUBWEAK MPU_pcTimerGetNameImpl MPU_pcTimerGetNameImpl: diff --git a/portable/IAR/ARM_CM33_NTZ/non_secure/port.c b/portable/IAR/ARM_CM33_NTZ/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/IAR/ARM_CM33_NTZ/non_secure/port.c +++ b/portable/IAR/ARM_CM33_NTZ/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/IAR/ARM_CM35P/non_secure/mpu_wrappers_v2_asm.S b/portable/IAR/ARM_CM35P/non_secure/mpu_wrappers_v2_asm.S index f051a6073d..9cb9a9d725 100644 --- a/portable/IAR/ARM_CM35P/non_secure/mpu_wrappers_v2_asm.S +++ b/portable/IAR/ARM_CM35P/non_secure/mpu_wrappers_v2_asm.S @@ -895,27 +895,21 @@ MPU_xTimerGetTimerDaemonTaskHandle: bx lr /*-----------------------------------------------------------*/ - PUBLIC MPU_xTimerGenericCommand -MPU_xTimerGenericCommand: + PUBLIC MPU_xTimerGenericCommandFromTask +MPU_xTimerGenericCommandFromTask: push {r0} - /* This function can be called from ISR also and therefore, we need a check - * to take privileged path, if called from ISR. */ - mrs r0, ipsr - cmp r0, #0 - bne MPU_xTimerGenericCommand_Priv mrs r0, control tst r0, #1 - beq MPU_xTimerGenericCommand_Priv - MPU_xTimerGenericCommand_Unpriv: + bne MPU_xTimerGenericCommandFromTask_Unpriv + MPU_xTimerGenericCommandFromTask_Priv: + pop {r0} + b MPU_xTimerGenericCommandFromTaskImpl + MPU_xTimerGenericCommandFromTask_Unpriv: pop {r0} svc #portSVC_SYSTEM_CALL_ENTER_1 - bl MPU_xTimerGenericCommandImpl + bl MPU_xTimerGenericCommandFromTaskImpl svc #portSVC_SYSTEM_CALL_EXIT bx lr - MPU_xTimerGenericCommand_Priv: - pop {r0} - b MPU_xTimerGenericCommandImpl - /*-----------------------------------------------------------*/ PUBLIC MPU_pcTimerGetName @@ -1461,9 +1455,9 @@ MPU_xTimerIsTimerActiveImpl: MPU_xTimerGetTimerDaemonTaskHandleImpl: b MPU_xTimerGetTimerDaemonTaskHandleImpl - PUBWEAK MPU_xTimerGenericCommandImpl -MPU_xTimerGenericCommandImpl: - b MPU_xTimerGenericCommandImpl + PUBWEAK MPU_xTimerGenericCommandFromTaskImpl +MPU_xTimerGenericCommandFromTaskImpl: + b MPU_xTimerGenericCommandFromTaskImpl PUBWEAK MPU_pcTimerGetNameImpl MPU_pcTimerGetNameImpl: diff --git a/portable/IAR/ARM_CM35P/non_secure/port.c b/portable/IAR/ARM_CM35P/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/IAR/ARM_CM35P/non_secure/port.c +++ b/portable/IAR/ARM_CM35P/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/IAR/ARM_CM35P_NTZ/non_secure/mpu_wrappers_v2_asm.S b/portable/IAR/ARM_CM35P_NTZ/non_secure/mpu_wrappers_v2_asm.S index f051a6073d..9cb9a9d725 100644 --- a/portable/IAR/ARM_CM35P_NTZ/non_secure/mpu_wrappers_v2_asm.S +++ b/portable/IAR/ARM_CM35P_NTZ/non_secure/mpu_wrappers_v2_asm.S @@ -895,27 +895,21 @@ MPU_xTimerGetTimerDaemonTaskHandle: bx lr /*-----------------------------------------------------------*/ - PUBLIC MPU_xTimerGenericCommand -MPU_xTimerGenericCommand: + PUBLIC MPU_xTimerGenericCommandFromTask +MPU_xTimerGenericCommandFromTask: push {r0} - /* This function can be called from ISR also and therefore, we need a check - * to take privileged path, if called from ISR. */ - mrs r0, ipsr - cmp r0, #0 - bne MPU_xTimerGenericCommand_Priv mrs r0, control tst r0, #1 - beq MPU_xTimerGenericCommand_Priv - MPU_xTimerGenericCommand_Unpriv: + bne MPU_xTimerGenericCommandFromTask_Unpriv + MPU_xTimerGenericCommandFromTask_Priv: + pop {r0} + b MPU_xTimerGenericCommandFromTaskImpl + MPU_xTimerGenericCommandFromTask_Unpriv: pop {r0} svc #portSVC_SYSTEM_CALL_ENTER_1 - bl MPU_xTimerGenericCommandImpl + bl MPU_xTimerGenericCommandFromTaskImpl svc #portSVC_SYSTEM_CALL_EXIT bx lr - MPU_xTimerGenericCommand_Priv: - pop {r0} - b MPU_xTimerGenericCommandImpl - /*-----------------------------------------------------------*/ PUBLIC MPU_pcTimerGetName @@ -1461,9 +1455,9 @@ MPU_xTimerIsTimerActiveImpl: MPU_xTimerGetTimerDaemonTaskHandleImpl: b MPU_xTimerGetTimerDaemonTaskHandleImpl - PUBWEAK MPU_xTimerGenericCommandImpl -MPU_xTimerGenericCommandImpl: - b MPU_xTimerGenericCommandImpl + PUBWEAK MPU_xTimerGenericCommandFromTaskImpl +MPU_xTimerGenericCommandFromTaskImpl: + b MPU_xTimerGenericCommandFromTaskImpl PUBWEAK MPU_pcTimerGetNameImpl MPU_pcTimerGetNameImpl: diff --git a/portable/IAR/ARM_CM35P_NTZ/non_secure/port.c b/portable/IAR/ARM_CM35P_NTZ/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/IAR/ARM_CM35P_NTZ/non_secure/port.c +++ b/portable/IAR/ARM_CM35P_NTZ/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/IAR/ARM_CM4F_MPU/mpu_wrappers_v2_asm.S b/portable/IAR/ARM_CM4F_MPU/mpu_wrappers_v2_asm.S index a0541f790b..f18d7410e7 100644 --- a/portable/IAR/ARM_CM4F_MPU/mpu_wrappers_v2_asm.S +++ b/portable/IAR/ARM_CM4F_MPU/mpu_wrappers_v2_asm.S @@ -899,27 +899,21 @@ MPU_xTimerGetTimerDaemonTaskHandle: bx lr /*-----------------------------------------------------------*/ - PUBLIC MPU_xTimerGenericCommand -MPU_xTimerGenericCommand: + PUBLIC MPU_xTimerGenericCommandFromTask +MPU_xTimerGenericCommandFromTask: push {r0} - /* This function can be called from ISR also and therefore, we need a check - * to take privileged path, if called from ISR. */ - mrs r0, ipsr - cmp r0, #0 - bne MPU_xTimerGenericCommand_Priv mrs r0, control tst r0, #1 - beq MPU_xTimerGenericCommand_Priv - MPU_xTimerGenericCommand_Unpriv: + bne MPU_xTimerGenericCommandFromTask_Unpriv + MPU_xTimerGenericCommandFromTask_Priv: + pop {r0} + b MPU_xTimerGenericCommandFromTaskImpl + MPU_xTimerGenericCommandFromTask_Unpriv: pop {r0} svc #portSVC_SYSTEM_CALL_ENTER_1 - bl MPU_xTimerGenericCommandImpl + bl MPU_xTimerGenericCommandFromTaskImpl svc #portSVC_SYSTEM_CALL_EXIT bx lr - MPU_xTimerGenericCommand_Priv: - pop {r0} - b MPU_xTimerGenericCommandImpl - /*-----------------------------------------------------------*/ PUBLIC MPU_pcTimerGetName @@ -1465,9 +1459,9 @@ MPU_xTimerIsTimerActiveImpl: MPU_xTimerGetTimerDaemonTaskHandleImpl: b MPU_xTimerGetTimerDaemonTaskHandleImpl - PUBWEAK MPU_xTimerGenericCommandImpl -MPU_xTimerGenericCommandImpl: - b MPU_xTimerGenericCommandImpl + PUBWEAK MPU_xTimerGenericCommandFromTaskImpl +MPU_xTimerGenericCommandFromTaskImpl: + b MPU_xTimerGenericCommandFromTaskImpl PUBWEAK MPU_pcTimerGetNameImpl MPU_pcTimerGetNameImpl: diff --git a/portable/IAR/ARM_CM55/non_secure/mpu_wrappers_v2_asm.S b/portable/IAR/ARM_CM55/non_secure/mpu_wrappers_v2_asm.S index f051a6073d..9cb9a9d725 100644 --- a/portable/IAR/ARM_CM55/non_secure/mpu_wrappers_v2_asm.S +++ b/portable/IAR/ARM_CM55/non_secure/mpu_wrappers_v2_asm.S @@ -895,27 +895,21 @@ MPU_xTimerGetTimerDaemonTaskHandle: bx lr /*-----------------------------------------------------------*/ - PUBLIC MPU_xTimerGenericCommand -MPU_xTimerGenericCommand: + PUBLIC MPU_xTimerGenericCommandFromTask +MPU_xTimerGenericCommandFromTask: push {r0} - /* This function can be called from ISR also and therefore, we need a check - * to take privileged path, if called from ISR. */ - mrs r0, ipsr - cmp r0, #0 - bne MPU_xTimerGenericCommand_Priv mrs r0, control tst r0, #1 - beq MPU_xTimerGenericCommand_Priv - MPU_xTimerGenericCommand_Unpriv: + bne MPU_xTimerGenericCommandFromTask_Unpriv + MPU_xTimerGenericCommandFromTask_Priv: + pop {r0} + b MPU_xTimerGenericCommandFromTaskImpl + MPU_xTimerGenericCommandFromTask_Unpriv: pop {r0} svc #portSVC_SYSTEM_CALL_ENTER_1 - bl MPU_xTimerGenericCommandImpl + bl MPU_xTimerGenericCommandFromTaskImpl svc #portSVC_SYSTEM_CALL_EXIT bx lr - MPU_xTimerGenericCommand_Priv: - pop {r0} - b MPU_xTimerGenericCommandImpl - /*-----------------------------------------------------------*/ PUBLIC MPU_pcTimerGetName @@ -1461,9 +1455,9 @@ MPU_xTimerIsTimerActiveImpl: MPU_xTimerGetTimerDaemonTaskHandleImpl: b MPU_xTimerGetTimerDaemonTaskHandleImpl - PUBWEAK MPU_xTimerGenericCommandImpl -MPU_xTimerGenericCommandImpl: - b MPU_xTimerGenericCommandImpl + PUBWEAK MPU_xTimerGenericCommandFromTaskImpl +MPU_xTimerGenericCommandFromTaskImpl: + b MPU_xTimerGenericCommandFromTaskImpl PUBWEAK MPU_pcTimerGetNameImpl MPU_pcTimerGetNameImpl: diff --git a/portable/IAR/ARM_CM55/non_secure/port.c b/portable/IAR/ARM_CM55/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/IAR/ARM_CM55/non_secure/port.c +++ b/portable/IAR/ARM_CM55/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/IAR/ARM_CM55_NTZ/non_secure/mpu_wrappers_v2_asm.S b/portable/IAR/ARM_CM55_NTZ/non_secure/mpu_wrappers_v2_asm.S index f051a6073d..9cb9a9d725 100644 --- a/portable/IAR/ARM_CM55_NTZ/non_secure/mpu_wrappers_v2_asm.S +++ b/portable/IAR/ARM_CM55_NTZ/non_secure/mpu_wrappers_v2_asm.S @@ -895,27 +895,21 @@ MPU_xTimerGetTimerDaemonTaskHandle: bx lr /*-----------------------------------------------------------*/ - PUBLIC MPU_xTimerGenericCommand -MPU_xTimerGenericCommand: + PUBLIC MPU_xTimerGenericCommandFromTask +MPU_xTimerGenericCommandFromTask: push {r0} - /* This function can be called from ISR also and therefore, we need a check - * to take privileged path, if called from ISR. */ - mrs r0, ipsr - cmp r0, #0 - bne MPU_xTimerGenericCommand_Priv mrs r0, control tst r0, #1 - beq MPU_xTimerGenericCommand_Priv - MPU_xTimerGenericCommand_Unpriv: + bne MPU_xTimerGenericCommandFromTask_Unpriv + MPU_xTimerGenericCommandFromTask_Priv: + pop {r0} + b MPU_xTimerGenericCommandFromTaskImpl + MPU_xTimerGenericCommandFromTask_Unpriv: pop {r0} svc #portSVC_SYSTEM_CALL_ENTER_1 - bl MPU_xTimerGenericCommandImpl + bl MPU_xTimerGenericCommandFromTaskImpl svc #portSVC_SYSTEM_CALL_EXIT bx lr - MPU_xTimerGenericCommand_Priv: - pop {r0} - b MPU_xTimerGenericCommandImpl - /*-----------------------------------------------------------*/ PUBLIC MPU_pcTimerGetName @@ -1461,9 +1455,9 @@ MPU_xTimerIsTimerActiveImpl: MPU_xTimerGetTimerDaemonTaskHandleImpl: b MPU_xTimerGetTimerDaemonTaskHandleImpl - PUBWEAK MPU_xTimerGenericCommandImpl -MPU_xTimerGenericCommandImpl: - b MPU_xTimerGenericCommandImpl + PUBWEAK MPU_xTimerGenericCommandFromTaskImpl +MPU_xTimerGenericCommandFromTaskImpl: + b MPU_xTimerGenericCommandFromTaskImpl PUBWEAK MPU_pcTimerGetNameImpl MPU_pcTimerGetNameImpl: diff --git a/portable/IAR/ARM_CM55_NTZ/non_secure/port.c b/portable/IAR/ARM_CM55_NTZ/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/IAR/ARM_CM55_NTZ/non_secure/port.c +++ b/portable/IAR/ARM_CM55_NTZ/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/IAR/ARM_CM85/non_secure/mpu_wrappers_v2_asm.S b/portable/IAR/ARM_CM85/non_secure/mpu_wrappers_v2_asm.S index f051a6073d..9cb9a9d725 100644 --- a/portable/IAR/ARM_CM85/non_secure/mpu_wrappers_v2_asm.S +++ b/portable/IAR/ARM_CM85/non_secure/mpu_wrappers_v2_asm.S @@ -895,27 +895,21 @@ MPU_xTimerGetTimerDaemonTaskHandle: bx lr /*-----------------------------------------------------------*/ - PUBLIC MPU_xTimerGenericCommand -MPU_xTimerGenericCommand: + PUBLIC MPU_xTimerGenericCommandFromTask +MPU_xTimerGenericCommandFromTask: push {r0} - /* This function can be called from ISR also and therefore, we need a check - * to take privileged path, if called from ISR. */ - mrs r0, ipsr - cmp r0, #0 - bne MPU_xTimerGenericCommand_Priv mrs r0, control tst r0, #1 - beq MPU_xTimerGenericCommand_Priv - MPU_xTimerGenericCommand_Unpriv: + bne MPU_xTimerGenericCommandFromTask_Unpriv + MPU_xTimerGenericCommandFromTask_Priv: + pop {r0} + b MPU_xTimerGenericCommandFromTaskImpl + MPU_xTimerGenericCommandFromTask_Unpriv: pop {r0} svc #portSVC_SYSTEM_CALL_ENTER_1 - bl MPU_xTimerGenericCommandImpl + bl MPU_xTimerGenericCommandFromTaskImpl svc #portSVC_SYSTEM_CALL_EXIT bx lr - MPU_xTimerGenericCommand_Priv: - pop {r0} - b MPU_xTimerGenericCommandImpl - /*-----------------------------------------------------------*/ PUBLIC MPU_pcTimerGetName @@ -1461,9 +1455,9 @@ MPU_xTimerIsTimerActiveImpl: MPU_xTimerGetTimerDaemonTaskHandleImpl: b MPU_xTimerGetTimerDaemonTaskHandleImpl - PUBWEAK MPU_xTimerGenericCommandImpl -MPU_xTimerGenericCommandImpl: - b MPU_xTimerGenericCommandImpl + PUBWEAK MPU_xTimerGenericCommandFromTaskImpl +MPU_xTimerGenericCommandFromTaskImpl: + b MPU_xTimerGenericCommandFromTaskImpl PUBWEAK MPU_pcTimerGetNameImpl MPU_pcTimerGetNameImpl: diff --git a/portable/IAR/ARM_CM85/non_secure/port.c b/portable/IAR/ARM_CM85/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/IAR/ARM_CM85/non_secure/port.c +++ b/portable/IAR/ARM_CM85/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/IAR/ARM_CM85_NTZ/non_secure/mpu_wrappers_v2_asm.S b/portable/IAR/ARM_CM85_NTZ/non_secure/mpu_wrappers_v2_asm.S index f051a6073d..9cb9a9d725 100644 --- a/portable/IAR/ARM_CM85_NTZ/non_secure/mpu_wrappers_v2_asm.S +++ b/portable/IAR/ARM_CM85_NTZ/non_secure/mpu_wrappers_v2_asm.S @@ -895,27 +895,21 @@ MPU_xTimerGetTimerDaemonTaskHandle: bx lr /*-----------------------------------------------------------*/ - PUBLIC MPU_xTimerGenericCommand -MPU_xTimerGenericCommand: + PUBLIC MPU_xTimerGenericCommandFromTask +MPU_xTimerGenericCommandFromTask: push {r0} - /* This function can be called from ISR also and therefore, we need a check - * to take privileged path, if called from ISR. */ - mrs r0, ipsr - cmp r0, #0 - bne MPU_xTimerGenericCommand_Priv mrs r0, control tst r0, #1 - beq MPU_xTimerGenericCommand_Priv - MPU_xTimerGenericCommand_Unpriv: + bne MPU_xTimerGenericCommandFromTask_Unpriv + MPU_xTimerGenericCommandFromTask_Priv: + pop {r0} + b MPU_xTimerGenericCommandFromTaskImpl + MPU_xTimerGenericCommandFromTask_Unpriv: pop {r0} svc #portSVC_SYSTEM_CALL_ENTER_1 - bl MPU_xTimerGenericCommandImpl + bl MPU_xTimerGenericCommandFromTaskImpl svc #portSVC_SYSTEM_CALL_EXIT bx lr - MPU_xTimerGenericCommand_Priv: - pop {r0} - b MPU_xTimerGenericCommandImpl - /*-----------------------------------------------------------*/ PUBLIC MPU_pcTimerGetName @@ -1461,9 +1455,9 @@ MPU_xTimerIsTimerActiveImpl: MPU_xTimerGetTimerDaemonTaskHandleImpl: b MPU_xTimerGetTimerDaemonTaskHandleImpl - PUBWEAK MPU_xTimerGenericCommandImpl -MPU_xTimerGenericCommandImpl: - b MPU_xTimerGenericCommandImpl + PUBWEAK MPU_xTimerGenericCommandFromTaskImpl +MPU_xTimerGenericCommandFromTaskImpl: + b MPU_xTimerGenericCommandFromTaskImpl PUBWEAK MPU_pcTimerGetNameImpl MPU_pcTimerGetNameImpl: diff --git a/portable/IAR/ARM_CM85_NTZ/non_secure/port.c b/portable/IAR/ARM_CM85_NTZ/non_secure/port.c index 04901015f5..e027b21e1b 100644 --- a/portable/IAR/ARM_CM85_NTZ/non_secure/port.c +++ b/portable/IAR/ARM_CM85_NTZ/non_secure/port.c @@ -754,8 +754,15 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void ) /* PRIVILEGED_FU } #endif /* configUSE_TICKLESS_IDLE */ - /* Stop and reset the SysTick. */ - portNVIC_SYSTICK_CTRL_REG = 0UL; + /* Stop and reset SysTick. + * + * QEMU versions older than 7.0.0 contain a bug which causes an error if we + * enable SysTick without first selecting a valid clock source. We trigger + * the bug if we change clock sources from a clock with a zero clock period + * to one with a nonzero clock period and enable Systick at the same time. + * So we configure the CLKSOURCE bit here, prior to setting the ENABLE bit. + * This workaround avoids the bug in QEMU versions older than 7.0.0. */ + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT_CONFIG; portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; /* Configure SysTick to interrupt at the requested rate. */ diff --git a/portable/MSVC-MingW/port.c b/portable/MSVC-MingW/port.c index f39f0ecbb8..c85cfc1931 100644 --- a/portable/MSVC-MingW/port.c +++ b/portable/MSVC-MingW/port.c @@ -340,6 +340,9 @@ SYSTEM_INFO xSystemInfo; /* Start the first task. */ ResumeThread( pxThreadState->pvThread ); + /* The scheduler is now running. */ + xPortRunning = pdTRUE; + /* Handle all simulated interrupts - including yield requests and simulated ticks. */ prvProcessSimulatedInterrupts(); @@ -376,6 +379,8 @@ uint32_t ulSwitchRequired, i; ThreadState_t *pxThreadState; void *pvObjectList[ 2 ]; CONTEXT xContext; +DWORD xWinApiResult; +const DWORD xTimeoutMilliseconds = 1000; /* Going to block on the mutex that ensured exclusive access to the simulated interrupt objects, and the event that signals that a simulated interrupt @@ -388,105 +393,109 @@ CONTEXT xContext; ulPendingInterrupts |= ( 1 << portINTERRUPT_TICK ); SetEvent( pvInterruptEvent ); - xPortRunning = pdTRUE; - - for(;;) + while( xPortRunning == pdTRUE ) { xInsideInterrupt = pdFALSE; - WaitForMultipleObjects( sizeof( pvObjectList ) / sizeof( void * ), pvObjectList, TRUE, INFINITE ); - - /* Cannot be in a critical section to get here. Tasks that exit a - critical section will block on a yield mutex to wait for an interrupt to - process if an interrupt was set pending while the task was inside the - critical section. xInsideInterrupt prevents interrupts that contain - critical sections from doing the same. */ - xInsideInterrupt = pdTRUE; - - /* Used to indicate whether the simulated interrupt processing has - necessitated a context switch to another task/thread. */ - ulSwitchRequired = pdFALSE; - - /* For each interrupt we are interested in processing, each of which is - represented by a bit in the 32bit ulPendingInterrupts variable. */ - for( i = 0; i < portMAX_INTERRUPTS; i++ ) + + /* Wait with timeout so that we can exit from this loop when + * the scheduler is stopped by calling vPortEndScheduler. */ + xWinApiResult = WaitForMultipleObjects( sizeof( pvObjectList ) / sizeof( void * ), pvObjectList, TRUE, xTimeoutMilliseconds ); + + if( xWinApiResult != WAIT_TIMEOUT ) { - /* Is the simulated interrupt pending? */ - if( ( ulPendingInterrupts & ( 1UL << i ) ) != 0 ) + /* Cannot be in a critical section to get here. Tasks that exit a + critical section will block on a yield mutex to wait for an interrupt to + process if an interrupt was set pending while the task was inside the + critical section. xInsideInterrupt prevents interrupts that contain + critical sections from doing the same. */ + xInsideInterrupt = pdTRUE; + + /* Used to indicate whether the simulated interrupt processing has + necessitated a context switch to another task/thread. */ + ulSwitchRequired = pdFALSE; + + /* For each interrupt we are interested in processing, each of which is + represented by a bit in the 32bit ulPendingInterrupts variable. */ + for( i = 0; i < portMAX_INTERRUPTS; i++ ) { - /* Is a handler installed? */ - if( ulIsrHandler[ i ] != NULL ) + /* Is the simulated interrupt pending? */ + if( ( ulPendingInterrupts & ( 1UL << i ) ) != 0 ) { - /* Run the actual handler. Handlers return pdTRUE if they - necessitate a context switch. */ - if( ulIsrHandler[ i ]() != pdFALSE ) + /* Is a handler installed? */ + if( ulIsrHandler[ i ] != NULL ) { - /* A bit mask is used purely to help debugging. */ - ulSwitchRequired |= ( 1 << i ); + /* Run the actual handler. Handlers return pdTRUE if they + necessitate a context switch. */ + if( ulIsrHandler[ i ]() != pdFALSE ) + { + /* A bit mask is used purely to help debugging. */ + ulSwitchRequired |= ( 1 << i ); + } } - } - /* Clear the interrupt pending bit. */ - ulPendingInterrupts &= ~( 1UL << i ); + /* Clear the interrupt pending bit. */ + ulPendingInterrupts &= ~( 1UL << i ); + } } - } - if( ulSwitchRequired != pdFALSE ) - { - void *pvOldCurrentTCB; + if( ulSwitchRequired != pdFALSE ) + { + void *pvOldCurrentTCB; - pvOldCurrentTCB = pxCurrentTCB; + pvOldCurrentTCB = pxCurrentTCB; - /* Select the next task to run. */ - vTaskSwitchContext(); + /* Select the next task to run. */ + vTaskSwitchContext(); - /* If the task selected to enter the running state is not the task - that is already in the running state. */ - if( pvOldCurrentTCB != pxCurrentTCB ) - { - /* Suspend the old thread. In the cases where the (simulated) - interrupt is asynchronous (tick event swapping a task out rather - than a task blocking or yielding) it doesn't matter if the - 'suspend' operation doesn't take effect immediately - if it - doesn't it would just be like the interrupt occurring slightly - later. In cases where the yield was caused by a task blocking - or yielding then the task will block on a yield event after the - yield operation in case the 'suspend' operation doesn't take - effect immediately. */ - pxThreadState = ( ThreadState_t *) *( ( size_t * ) pvOldCurrentTCB ); - SuspendThread( pxThreadState->pvThread ); - - /* Ensure the thread is actually suspended by performing a - synchronous operation that can only complete when the thread is - actually suspended. The below code asks for dummy register - data. Experimentation shows that these two lines don't appear - to do anything now, but according to - https://devblogs.microsoft.com/oldnewthing/20150205-00/?p=44743 - they do - so as they do not harm (slight run-time hit). */ - xContext.ContextFlags = CONTEXT_INTEGER; - ( void ) GetThreadContext( pxThreadState->pvThread, &xContext ); - - /* Obtain the state of the task now selected to enter the - Running state. */ - pxThreadState = ( ThreadState_t * ) ( *( size_t *) pxCurrentTCB ); - - /* pxThreadState->pvThread can be NULL if the task deleted - itself - but a deleted task should never be resumed here. */ - configASSERT( pxThreadState->pvThread != NULL ); - ResumeThread( pxThreadState->pvThread ); + /* If the task selected to enter the running state is not the task + that is already in the running state. */ + if( pvOldCurrentTCB != pxCurrentTCB ) + { + /* Suspend the old thread. In the cases where the (simulated) + interrupt is asynchronous (tick event swapping a task out rather + than a task blocking or yielding) it doesn't matter if the + 'suspend' operation doesn't take effect immediately - if it + doesn't it would just be like the interrupt occurring slightly + later. In cases where the yield was caused by a task blocking + or yielding then the task will block on a yield event after the + yield operation in case the 'suspend' operation doesn't take + effect immediately. */ + pxThreadState = ( ThreadState_t *) *( ( size_t * ) pvOldCurrentTCB ); + SuspendThread( pxThreadState->pvThread ); + + /* Ensure the thread is actually suspended by performing a + synchronous operation that can only complete when the thread is + actually suspended. The below code asks for dummy register + data. Experimentation shows that these two lines don't appear + to do anything now, but according to + https://devblogs.microsoft.com/oldnewthing/20150205-00/?p=44743 + they do - so as they do not harm (slight run-time hit). */ + xContext.ContextFlags = CONTEXT_INTEGER; + ( void ) GetThreadContext( pxThreadState->pvThread, &xContext ); + + /* Obtain the state of the task now selected to enter the + Running state. */ + pxThreadState = ( ThreadState_t * ) ( *( size_t *) pxCurrentTCB ); + + /* pxThreadState->pvThread can be NULL if the task deleted + itself - but a deleted task should never be resumed here. */ + configASSERT( pxThreadState->pvThread != NULL ); + ResumeThread( pxThreadState->pvThread ); + } } - } - /* If the thread that is about to be resumed stopped running - because it yielded then it will wait on an event when it resumed - (to ensure it does not continue running after the call to - SuspendThread() above as SuspendThread() is asynchronous). - Signal the event to ensure the thread can proceed now it is - valid for it to do so. Signaling the event is benign in the case that - the task was switched out asynchronously by an interrupt as the event - is reset before the task blocks on it. */ - pxThreadState = ( ThreadState_t * ) ( *( size_t *) pxCurrentTCB ); - SetEvent( pxThreadState->pvYieldEvent ); - ReleaseMutex( pvInterruptEventMutex ); + /* If the thread that is about to be resumed stopped running + because it yielded then it will wait on an event when it resumed + (to ensure it does not continue running after the call to + SuspendThread() above as SuspendThread() is asynchronous). + Signal the event to ensure the thread can proceed now it is + valid for it to do so. Signaling the event is benign in the case that + the task was switched out asynchronously by an interrupt as the event + is reset before the task blocks on it. */ + pxThreadState = ( ThreadState_t * ) ( *( size_t *) pxCurrentTCB ); + SetEvent( pxThreadState->pvYieldEvent ); + ReleaseMutex( pvInterruptEventMutex ); + } } } /*-----------------------------------------------------------*/ diff --git a/portable/RVDS/ARM_CM4_MPU/mpu_wrappers_v2_asm.c b/portable/RVDS/ARM_CM4_MPU/mpu_wrappers_v2_asm.c index aa1e825fc1..0de1b53bf4 100644 --- a/portable/RVDS/ARM_CM4_MPU/mpu_wrappers_v2_asm.c +++ b/portable/RVDS/ARM_CM4_MPU/mpu_wrappers_v2_asm.c @@ -1426,37 +1426,34 @@ MPU_xTimerGetTimerDaemonTaskHandle_Unpriv #if ( configUSE_TIMERS == 1 ) -BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL; -__asm BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, - const BaseType_t xCommandID, - const TickType_t xOptionalValue, - BaseType_t * const pxHigherPriorityTaskWoken, - const TickType_t xTicksToWait ) /* FREERTOS_SYSTEM_CALL */ +__asm BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) /* FREERTOS_SYSTEM_CALL */ { PRESERVE8 - extern MPU_xTimerGenericCommandImpl + extern MPU_xTimerGenericCommandFromTaskImpl push {r0} - mrs r0, ipsr - cmp r0, #0 - bne MPU_xTimerGenericCommand_Priv mrs r0, control tst r0, #1 - beq MPU_xTimerGenericCommand_Priv -MPU_xTimerGenericCommand_Unpriv + bne MPU_xTimerGenericCommandFromTask_Unpriv +MPU_xTimerGenericCommandFromTask_Priv + pop {r0} + b MPU_xTimerGenericCommandFromTaskImpl +MPU_xTimerGenericCommandFromTask_Unpriv pop {r0} svc #portSVC_SYSTEM_CALL_ENTER_1 - bl MPU_xTimerGenericCommandImpl + bl MPU_xTimerGenericCommandFromTaskImpl svc #portSVC_SYSTEM_CALL_EXIT bx lr -MPU_xTimerGenericCommand_Priv - pop {r0} - b MPU_xTimerGenericCommandImpl } #endif /* if ( configUSE_TIMERS == 1 ) */ diff --git a/portable/ThirdParty/Community-Supported-Ports b/portable/ThirdParty/Community-Supported-Ports index 4273ca3211..d4cccca297 160000 --- a/portable/ThirdParty/Community-Supported-Ports +++ b/portable/ThirdParty/Community-Supported-Ports @@ -1 +1 @@ -Subproject commit 4273ca3211b99914f31518378fb590fbff064953 +Subproject commit d4cccca2971d6ffca581564f8142069cb854bd15 diff --git a/portable/ThirdParty/GCC/Posix/port.c b/portable/ThirdParty/GCC/Posix/port.c index 54134873fb..a8cb257346 100644 --- a/portable/ThirdParty/GCC/Posix/port.c +++ b/portable/ThirdParty/GCC/Posix/port.c @@ -100,10 +100,10 @@ static pthread_once_t hSigSetupThread = PTHREAD_ONCE_INIT; static sigset_t xAllSignals; static sigset_t xSchedulerOriginalSignalMask; static pthread_t hMainThread = ( pthread_t ) NULL; -static volatile portBASE_TYPE uxCriticalNesting; +static volatile BaseType_t uxCriticalNesting; /*-----------------------------------------------------------*/ -static portBASE_TYPE xSchedulerEnd = pdFALSE; +static BaseType_t xSchedulerEnd = pdFALSE; /*-----------------------------------------------------------*/ static void prvSetupSignalsAndSchedulerPolicy( void ); @@ -131,10 +131,10 @@ void prvFatalError( const char * pcCall, /* * See header file for description. */ -portSTACK_TYPE * pxPortInitialiseStack( StackType_t * pxTopOfStack, - StackType_t * pxEndOfStack, - TaskFunction_t pxCode, - void * pvParameters ) +StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack, + StackType_t * pxEndOfStack, + TaskFunction_t pxCode, + void * pvParameters ) { Thread_t * thread; pthread_attr_t xThreadAttributes; @@ -147,7 +147,7 @@ portSTACK_TYPE * pxPortInitialiseStack( StackType_t * pxTopOfStack, * Store the additional thread data at the start of the stack. */ thread = ( Thread_t * ) ( pxTopOfStack + 1 ) - 1; - pxTopOfStack = ( portSTACK_TYPE * ) thread - 1; + pxTopOfStack = ( StackType_t * ) thread - 1; ulStackSize = ( size_t )( pxTopOfStack + 1 - pxEndOfStack ) * sizeof( *pxTopOfStack ); #ifdef __APPLE__ @@ -197,7 +197,7 @@ void vPortStartFirstTask( void ) /* * See header file for description. */ -portBASE_TYPE xPortStartScheduler( void ) +BaseType_t xPortStartScheduler( void ) { int iSignal; sigset_t xSignals; diff --git a/portable/ThirdParty/GCC/RP2040/include/portmacro.h b/portable/ThirdParty/GCC/RP2040/include/portmacro.h index 655b8ec744..7880a99034 100644 --- a/portable/ThirdParty/GCC/RP2040/include/portmacro.h +++ b/portable/ThirdParty/GCC/RP2040/include/portmacro.h @@ -194,7 +194,7 @@ static inline void vPortRecursiveLock(uint32_t ulLockNum, spin_lock_t *pxSpinLock, BaseType_t uxAcquire) { static uint8_t ucOwnedByCore[ portMAX_CORE_COUNT ]; static uint8_t ucRecursionCountByLock[ portRTOS_SPINLOCK_COUNT ]; - configASSERT(ulLockNum >= 0 && ulLockNum < portRTOS_SPINLOCK_COUNT ); + configASSERT( ulLockNum < portRTOS_SPINLOCK_COUNT ); uint32_t ulCoreNum = get_core_num(); uint32_t ulLockBit = 1u << ulLockNum; configASSERT(ulLockBit < 256u ); diff --git a/portable/ThirdParty/Partner-Supported-Ports b/portable/ThirdParty/Partner-Supported-Ports index 3f9c99a682..d38f59dbcd 160000 --- a/portable/ThirdParty/Partner-Supported-Ports +++ b/portable/ThirdParty/Partner-Supported-Ports @@ -1 +1 @@ -Subproject commit 3f9c99a682c5c796bb7eb89fd9c4385688fce27a +Subproject commit d38f59dbcdfabbe71361764e194e1ad6202f902c diff --git a/queue.c b/queue.c old mode 100644 new mode 100755 index e87db0f45e..76006d05d5 --- a/queue.c +++ b/queue.c @@ -490,7 +490,7 @@ BaseType_t xQueueGenericReset( QueueHandle_t xQueue, /* Check for multiplication overflow. */ ( ( SIZE_MAX / uxQueueLength ) >= uxItemSize ) && /* Check for addition overflow. */ - ( ( SIZE_MAX - sizeof( Queue_t ) ) >= ( uxQueueLength * uxItemSize ) ) ) + ( ( UBaseType_t ) ( SIZE_MAX - sizeof( Queue_t ) ) >= ( uxQueueLength * uxItemSize ) ) ) { /* Allocate enough space to hold the maximum number of items that * can be in the queue at any time. It is valid for uxItemSize to be @@ -1329,7 +1329,7 @@ BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue, * can be assumed there is no mutex holder and no need to determine if * priority disinheritance is needed. Simply increase the count of * messages (semaphores) available. */ - pxQueue->uxMessagesWaiting = uxMessagesWaiting + ( UBaseType_t ) 1; + pxQueue->uxMessagesWaiting = ( UBaseType_t ) ( uxMessagesWaiting + ( UBaseType_t ) 1 ); /* The event list is not altered if the queue is locked. This will * be done when the queue is unlocked later. */ @@ -1474,7 +1474,7 @@ BaseType_t xQueueReceive( QueueHandle_t xQueue, /* Data available, remove one item. */ prvCopyDataFromQueue( pxQueue, pvBuffer ); traceQUEUE_RECEIVE( pxQueue ); - pxQueue->uxMessagesWaiting = uxMessagesWaiting - ( UBaseType_t ) 1; + pxQueue->uxMessagesWaiting = ( UBaseType_t ) ( uxMessagesWaiting - ( UBaseType_t ) 1 ); /* There is now space in the queue, were any tasks waiting to * post to the queue? If so, unblock the highest priority waiting @@ -1631,7 +1631,7 @@ BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue, /* Semaphores are queues with a data size of zero and where the * messages waiting is the semaphore's count. Reduce the count. */ - pxQueue->uxMessagesWaiting = uxSemaphoreCount - ( UBaseType_t ) 1; + pxQueue->uxMessagesWaiting = ( UBaseType_t ) ( uxSemaphoreCount - ( UBaseType_t ) 1 ); #if ( configUSE_MUTEXES == 1 ) { @@ -2003,7 +2003,7 @@ BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, traceQUEUE_RECEIVE_FROM_ISR( pxQueue ); prvCopyDataFromQueue( pxQueue, pvBuffer ); - pxQueue->uxMessagesWaiting = uxMessagesWaiting - ( UBaseType_t ) 1; + pxQueue->uxMessagesWaiting = ( UBaseType_t ) ( uxMessagesWaiting - ( UBaseType_t ) 1 ); /* If the queue is locked the event list will not be modified. * Instead update the lock count so the task that unlocks the queue @@ -2137,7 +2137,7 @@ UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue ) taskENTER_CRITICAL(); { - uxReturn = pxQueue->uxLength - pxQueue->uxMessagesWaiting; + uxReturn = ( UBaseType_t ) ( pxQueue->uxLength - pxQueue->uxMessagesWaiting ); } taskEXIT_CRITICAL(); @@ -2250,7 +2250,7 @@ UBaseType_t uxQueueGetQueueItemSize( QueueHandle_t xQueue ) /* PRIVILEGED_FUNCTI * mutex. */ if( listCURRENT_LIST_LENGTH( &( pxQueue->xTasksWaitingToReceive ) ) > 0U ) { - uxHighestPriorityOfWaitingTasks = ( UBaseType_t ) configMAX_PRIORITIES - ( UBaseType_t ) listGET_ITEM_VALUE_OF_HEAD_ENTRY( &( pxQueue->xTasksWaitingToReceive ) ); + uxHighestPriorityOfWaitingTasks = ( UBaseType_t ) ( ( UBaseType_t ) configMAX_PRIORITIES - ( UBaseType_t ) listGET_ITEM_VALUE_OF_HEAD_ENTRY( &( pxQueue->xTasksWaitingToReceive ) ) ); } else { @@ -2340,7 +2340,7 @@ static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, } } - pxQueue->uxMessagesWaiting = uxMessagesWaiting + ( UBaseType_t ) 1; + pxQueue->uxMessagesWaiting = ( UBaseType_t ) ( uxMessagesWaiting + ( UBaseType_t ) 1 ); return xReturn; } diff --git a/stream_buffer.c b/stream_buffer.c index b7410fc066..3a82ba31c7 100644 --- a/stream_buffer.c +++ b/stream_buffer.c @@ -27,7 +27,6 @@ */ /* Standard includes. */ -#include #include /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining @@ -1448,7 +1447,7 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer, uint8_t ucStreamBufferGetStreamBufferType( StreamBufferHandle_t xStreamBuffer ) { - return( xStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ); + return( ( uint8_t ) ( xStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) ); } #endif /* configUSE_TRACE_FACILITY */ diff --git a/tasks.c b/tasks.c index b991b7da4b..f08215adfa 100644 --- a/tasks.c +++ b/tasks.c @@ -760,7 +760,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; static void prvYieldCore( BaseType_t xCoreID ) { /* This must be called from a critical section and xCoreID must be valid. */ - if( ( portCHECK_IF_IN_ISR() == pdTRUE ) && ( xCoreID == portGET_CORE_ID() ) ) + if( ( portCHECK_IF_IN_ISR() == pdTRUE ) && ( xCoreID == ( BaseType_t ) portGET_CORE_ID() ) ) { xYieldPendings[ xCoreID ] = pdTRUE; } @@ -768,7 +768,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; { if( pxCurrentTCBs[ xCoreID ]->xTaskRunState != taskTASK_YIELDING ) { - if( xCoreID == portGET_CORE_ID() ) + if( xCoreID == ( BaseType_t ) portGET_CORE_ID() ) { xYieldPendings[ xCoreID ] = pdTRUE; } @@ -2002,7 +2002,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, /* Force a reschedule if the task that has just been deleted was running. */ if( ( xSchedulerRunning != pdFALSE ) && ( taskTASK_IS_RUNNING( pxTCB ) == pdTRUE ) ) { - if( pxTCB->xTaskRunState == portGET_CORE_ID() ) + if( pxTCB->xTaskRunState == ( TaskRunning_t ) portGET_CORE_ID() ) { configASSERT( uxSchedulerSuspended == 0 ); vTaskYieldWithinAPI(); @@ -2829,7 +2829,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, { if( xSchedulerRunning != pdFALSE ) { - if( xTaskRunningOnCore == portGET_CORE_ID() ) + if( xTaskRunningOnCore == ( TaskRunning_t ) portGET_CORE_ID() ) { /* The current task has just been suspended. */ configASSERT( uxSchedulerSuspended == 0 ); @@ -3511,7 +3511,7 @@ BaseType_t xTaskResumeAll( void ) taskENTER_CRITICAL(); { BaseType_t xCoreID; - xCoreID = portGET_CORE_ID(); + xCoreID = ( BaseType_t ) portGET_CORE_ID(); /* If uxSchedulerSuspended is zero then this function does not match a * previous call to vTaskSuspendAll(). */ @@ -3969,19 +3969,19 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char do { uxQueue--; - uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &( pxReadyTasksLists[ uxQueue ] ), eReady ); + uxTask = ( UBaseType_t ) ( uxTask + prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &( pxReadyTasksLists[ uxQueue ] ), eReady ) ); } while( uxQueue > ( UBaseType_t ) tskIDLE_PRIORITY ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ /* Fill in an TaskStatus_t structure with information on each * task in the Blocked state. */ - uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( List_t * ) pxDelayedTaskList, eBlocked ); - uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( List_t * ) pxOverflowDelayedTaskList, eBlocked ); + uxTask = ( UBaseType_t ) ( uxTask + prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( List_t * ) pxDelayedTaskList, eBlocked ) ); + uxTask = ( UBaseType_t ) ( uxTask + prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( List_t * ) pxOverflowDelayedTaskList, eBlocked ) ); #if ( INCLUDE_vTaskDelete == 1 ) { /* Fill in an TaskStatus_t structure with information on * each task that has been deleted but not yet cleaned up. */ - uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xTasksWaitingTermination, eDeleted ); + uxTask = ( UBaseType_t ) ( uxTask + prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xTasksWaitingTermination, eDeleted ) ); } #endif @@ -3989,7 +3989,7 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char { /* Fill in an TaskStatus_t structure with information on * each task in the Suspended state. */ - uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xSuspendedTaskList, eSuspended ); + uxTask = ( UBaseType_t ) ( uxTask + prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xSuspendedTaskList, eSuspended ) ); } #endif @@ -4398,7 +4398,7 @@ BaseType_t xTaskIncrementTick( void ) #else /* #if ( configNUMBER_OF_CORES == 1 ) */ { BaseType_t xCoreID, xCurrentCoreID; - xCurrentCoreID = portGET_CORE_ID(); + xCurrentCoreID = ( BaseType_t ) portGET_CORE_ID(); for( xCoreID = 0; xCoreID < ( BaseType_t ) configNUMBER_OF_CORES; xCoreID++ ) { @@ -5545,7 +5545,7 @@ static void prvCheckTasksWaitingTermination( void ) pxTaskStatus->pcTaskName = ( const char * ) &( pxTCB->pcTaskName[ 0 ] ); pxTaskStatus->uxCurrentPriority = pxTCB->uxPriority; pxTaskStatus->pxStackBase = pxTCB->pxStack; - #if ( ( portSTACK_GROWTH > 0 ) && ( configRECORD_STACK_HIGH_ADDRESS == 1 ) ) + #if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) ) pxTaskStatus->pxTopOfStack = pxTCB->pxTopOfStack; pxTaskStatus->pxEndOfStack = pxTCB->pxEndOfStack; #endif