Skip to content

Commit b375458

Browse files
authored
Add port-optimised task selection for ARMv8-M (#703)
Add port-optimised task selection for ARMv8-M
1 parent 0d03a93 commit b375458

File tree

76 files changed

+1940
-890
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1940
-890
lines changed

portable/ARMv8M/non_secure/port.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,13 +495,13 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
495495
* FreeRTOS API functions are not called from interrupts that have been assigned
496496
* a priority above configMAX_SYSCALL_INTERRUPT_PRIORITY.
497497
*/
498-
#if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_BASEPRI == 1 ) )
498+
#if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_ARMV8M_MAIN_EXTENSION == 1 ) )
499499

500500
static uint8_t ucMaxSysCallPriority = 0;
501501
static uint32_t ulMaxPRIGROUPValue = 0;
502502
static const volatile uint8_t * const pcInterruptPriorityRegisters = ( const volatile uint8_t * ) portNVIC_IP_REGISTERS_OFFSET_16;
503503

504-
#endif /* #if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_BASEPRI == 1 ) ) */
504+
#endif /* #if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_ARMV8M_MAIN_EXTENSION == 1 ) ) */
505505

506506
#if ( configUSE_TICKLESS_IDLE == 1 )
507507

@@ -1614,7 +1614,7 @@ StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
16141614

16151615
BaseType_t xPortStartScheduler( void ) /* PRIVILEGED_FUNCTION */
16161616
{
1617-
#if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_BASEPRI == 1 ) )
1617+
#if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_ARMV8M_MAIN_EXTENSION == 1 ) )
16181618
{
16191619
volatile uint32_t ulOriginalPriority;
16201620
volatile uint32_t ulImplementedPrioBits = 0;
@@ -1695,7 +1695,7 @@ BaseType_t xPortStartScheduler( void ) /* PRIVILEGED_FUNCTION */
16951695
* value. */
16961696
portNVIC_SHPR2_REG = ulOriginalPriority;
16971697
}
1698-
#endif /* #if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_BASEPRI == 1 ) ) */
1698+
#endif /* #if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_ARMV8M_MAIN_EXTENSION == 1 ) ) */
16991699

17001700
/* Make PendSV, CallSV and SysTick the same priority as the kernel. */
17011701
portNVIC_SHPR3_REG |= portNVIC_PENDSV_PRI;
@@ -1936,7 +1936,7 @@ BaseType_t xPortIsInsideInterrupt( void )
19361936
}
19371937
/*-----------------------------------------------------------*/
19381938

1939-
#if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_BASEPRI == 1 ) )
1939+
#if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_ARMV8M_MAIN_EXTENSION == 1 ) )
19401940

19411941
void vPortValidateInterruptPriority( void )
19421942
{
@@ -1994,5 +1994,5 @@ BaseType_t xPortIsInsideInterrupt( void )
19941994
configASSERT( ( portAIRCR_REG & portPRIORITY_GROUP_MASK ) <= ulMaxPRIGROUPValue );
19951995
}
19961996

1997-
#endif /* #if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_BASEPRI == 1 ) ) */
1997+
#endif /* #if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_ARMV8M_MAIN_EXTENSION == 1 ) ) */
19981998
/*-----------------------------------------------------------*/

portable/ARMv8M/non_secure/portable/GCC/ARM_CM23/portmacro.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
/**
4949
* Architecture specifics.
5050
*/
51-
#define portARCH_NAME "Cortex-M23"
52-
#define portHAS_BASEPRI 0
53-
#define portDONT_DISCARD __attribute__( ( used ) )
51+
#define portARCH_NAME "Cortex-M23"
52+
#define portHAS_ARMV8M_MAIN_EXTENSION 0
53+
#define portDONT_DISCARD __attribute__( ( used ) )
5454
/*-----------------------------------------------------------*/
5555

5656
/* ARMv8-M common port configurations. */

portable/ARMv8M/non_secure/portable/GCC/ARM_CM23_NTZ/portmacro.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
/**
4949
* Architecture specifics.
5050
*/
51-
#define portARCH_NAME "Cortex-M23"
52-
#define portHAS_BASEPRI 0
53-
#define portDONT_DISCARD __attribute__( ( used ) )
51+
#define portARCH_NAME "Cortex-M23"
52+
#define portHAS_ARMV8M_MAIN_EXTENSION 0
53+
#define portDONT_DISCARD __attribute__( ( used ) )
5454
/*-----------------------------------------------------------*/
5555

5656
/* ARMv8-M common port configurations. */

portable/ARMv8M/non_secure/portable/GCC/ARM_CM33/portmacro.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
* Architecture specifics.
5050
*/
5151
#define portARCH_NAME "Cortex-M33"
52-
#define portHAS_BASEPRI 1
52+
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5353
#define portDONT_DISCARD __attribute__( ( used ) )
5454
/*-----------------------------------------------------------*/
5555

portable/ARMv8M/non_secure/portable/GCC/ARM_CM33_NTZ/portmacro.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
* Architecture specifics.
5050
*/
5151
#define portARCH_NAME "Cortex-M33"
52-
#define portHAS_BASEPRI 1
52+
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5353
#define portDONT_DISCARD __attribute__( ( used ) )
5454
/*-----------------------------------------------------------*/
5555

portable/ARMv8M/non_secure/portable/GCC/ARM_CM35P/portmacro.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
* Architecture specifics.
5050
*/
5151
#define portARCH_NAME "Cortex-M35P"
52-
#define portHAS_BASEPRI 1
52+
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5353
#define portDONT_DISCARD __attribute__( ( used ) )
5454
/*-----------------------------------------------------------*/
5555

portable/ARMv8M/non_secure/portable/GCC/ARM_CM55/portmacro.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
* Architecture specifics.
5555
*/
5656
#define portARCH_NAME "Cortex-M55"
57-
#define portHAS_BASEPRI 1
57+
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5858
#define portDONT_DISCARD __attribute__( ( used ) )
5959
/*-----------------------------------------------------------*/
6060

portable/ARMv8M/non_secure/portable/GCC/ARM_CM85/portmacro.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
* Architecture specifics.
5555
*/
5656
#define portARCH_NAME "Cortex-M85"
57-
#define portHAS_BASEPRI 1
57+
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5858
#define portDONT_DISCARD __attribute__( ( used ) )
5959
/*-----------------------------------------------------------*/
6060

portable/ARMv8M/non_secure/portable/IAR/ARM_CM23/portmacro.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
/**
4949
* Architecture specifics.
5050
*/
51-
#define portARCH_NAME "Cortex-M23"
52-
#define portHAS_BASEPRI 0
53-
#define portDONT_DISCARD __root
51+
#define portARCH_NAME "Cortex-M23"
52+
#define portHAS_ARMV8M_MAIN_EXTENSION 0
53+
#define portDONT_DISCARD __root
5454
/*-----------------------------------------------------------*/
5555

5656
/* ARMv8-M common port configurations. */

portable/ARMv8M/non_secure/portable/IAR/ARM_CM23_NTZ/portmacro.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
/**
4949
* Architecture specifics.
5050
*/
51-
#define portARCH_NAME "Cortex-M23"
52-
#define portHAS_BASEPRI 0
53-
#define portDONT_DISCARD __root
51+
#define portARCH_NAME "Cortex-M23"
52+
#define portHAS_ARMV8M_MAIN_EXTENSION 0
53+
#define portDONT_DISCARD __root
5454
/*-----------------------------------------------------------*/
5555

5656
/* ARMv8-M common port configurations. */

portable/ARMv8M/non_secure/portable/IAR/ARM_CM33/portmacro.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
* Architecture specifics.
5050
*/
5151
#define portARCH_NAME "Cortex-M33"
52-
#define portHAS_BASEPRI 1
52+
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5353
#define portDONT_DISCARD __root
5454
/*-----------------------------------------------------------*/
5555

portable/ARMv8M/non_secure/portable/IAR/ARM_CM33_NTZ/portmacro.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
* Architecture specifics.
5050
*/
5151
#define portARCH_NAME "Cortex-M33"
52-
#define portHAS_BASEPRI 1
52+
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5353
#define portDONT_DISCARD __root
5454
/*-----------------------------------------------------------*/
5555

portable/ARMv8M/non_secure/portable/IAR/ARM_CM35P/portmacro.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
* Architecture specifics.
5050
*/
5151
#define portARCH_NAME "Cortex-M35P"
52-
#define portHAS_BASEPRI 1
52+
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5353
#define portDONT_DISCARD __root
5454
/*-----------------------------------------------------------*/
5555

portable/ARMv8M/non_secure/portable/IAR/ARM_CM55/portmacro.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
* Architecture specifics.
5555
*/
5656
#define portARCH_NAME "Cortex-M55"
57-
#define portHAS_BASEPRI 1
57+
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5858
#define portDONT_DISCARD __root
5959
/*-----------------------------------------------------------*/
6060

portable/ARMv8M/non_secure/portable/IAR/ARM_CM85/portmacro.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
* Architecture specifics.
5555
*/
5656
#define portARCH_NAME "Cortex-M85"
57-
#define portHAS_BASEPRI 1
57+
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5858
#define portDONT_DISCARD __root
5959
/*-----------------------------------------------------------*/
6060

portable/ARMv8M/non_secure/portmacrocommon.h

Lines changed: 84 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ typedef unsigned long UBaseType_t;
8181
typedef uint32_t TickType_t;
8282
#define portMAX_DELAY ( TickType_t ) 0xffffffffUL
8383

84-
/* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
85-
* not need to be guarded with a critical section. */
84+
/* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
85+
* not need to be guarded with a critical section. */
8686
#define portTICK_TYPE_IS_ATOMIC 1
8787
#else
8888
#error configTICK_TYPE_WIDTH_IN_BITS set to unsupported tick type width.
@@ -307,7 +307,7 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P
307307
* system calls.
308308
*/
309309
#ifdef configASSERT
310-
#if ( portHAS_BASEPRI == 1 )
310+
#if ( portHAS_ARMV8M_MAIN_EXTENSION == 1 )
311311
void vPortValidateInterruptPriority( void );
312312
#define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() vPortValidateInterruptPriority()
313313
#endif
@@ -364,49 +364,49 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P
364364

365365
#if ( configENABLE_TRUSTZONE == 1 )
366366

367-
/**
368-
* @brief Allocate a secure context for the task.
369-
*
370-
* Tasks are not created with a secure context. Any task that is going to call
371-
* secure functions must call portALLOCATE_SECURE_CONTEXT() to allocate itself a
372-
* secure context before it calls any secure function.
373-
*
374-
* @param[in] ulSecureStackSize The size of the secure stack to be allocated.
375-
*/
367+
/**
368+
* @brief Allocate a secure context for the task.
369+
*
370+
* Tasks are not created with a secure context. Any task that is going to call
371+
* secure functions must call portALLOCATE_SECURE_CONTEXT() to allocate itself a
372+
* secure context before it calls any secure function.
373+
*
374+
* @param[in] ulSecureStackSize The size of the secure stack to be allocated.
375+
*/
376376
#define portALLOCATE_SECURE_CONTEXT( ulSecureStackSize ) vPortAllocateSecureContext( ulSecureStackSize )
377377

378-
/**
379-
* @brief Called when a task is deleted to delete the task's secure context,
380-
* if it has one.
381-
*
382-
* @param[in] pxTCB The TCB of the task being deleted.
383-
*/
378+
/**
379+
* @brief Called when a task is deleted to delete the task's secure context,
380+
* if it has one.
381+
*
382+
* @param[in] pxTCB The TCB of the task being deleted.
383+
*/
384384
#define portCLEAN_UP_TCB( pxTCB ) vPortFreeSecureContext( ( uint32_t * ) pxTCB )
385385
#endif /* configENABLE_TRUSTZONE */
386386
/*-----------------------------------------------------------*/
387387

388388
#if ( configENABLE_MPU == 1 )
389389

390-
/**
391-
* @brief Checks whether or not the processor is privileged.
392-
*
393-
* @return 1 if the processor is already privileged, 0 otherwise.
394-
*/
390+
/**
391+
* @brief Checks whether or not the processor is privileged.
392+
*
393+
* @return 1 if the processor is already privileged, 0 otherwise.
394+
*/
395395
#define portIS_PRIVILEGED() xIsPrivileged()
396396

397-
/**
398-
* @brief Raise an SVC request to raise privilege.
399-
*
400-
* The SVC handler checks that the SVC was raised from a system call and only
401-
* then it raises the privilege. If this is called from any other place,
402-
* the privilege is not raised.
403-
*/
397+
/**
398+
* @brief Raise an SVC request to raise privilege.
399+
*
400+
* The SVC handler checks that the SVC was raised from a system call and only
401+
* then it raises the privilege. If this is called from any other place,
402+
* the privilege is not raised.
403+
*/
404404
#define portRAISE_PRIVILEGE() __asm volatile ( "svc %0 \n" ::"i" ( portSVC_RAISE_PRIVILEGE ) : "memory" );
405405

406-
/**
407-
* @brief Lowers the privilege level by setting the bit 0 of the CONTROL
408-
* register.
409-
*/
406+
/**
407+
* @brief Lowers the privilege level by setting the bit 0 of the CONTROL
408+
* register.
409+
*/
410410
#define portRESET_PRIVILEGE() vResetPrivilege()
411411
#else
412412
#define portIS_PRIVILEGED()
@@ -435,6 +435,56 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P
435435
#define portMEMORY_BARRIER() __asm volatile ( "" ::: "memory" )
436436
/*-----------------------------------------------------------*/
437437

438+
/* Select correct value of configUSE_PORT_OPTIMISED_TASK_SELECTION
439+
* based on whether or not Mainline extension is implemented. */
440+
#ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
441+
#if ( portHAS_ARMV8M_MAIN_EXTENSION == 1 )
442+
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
443+
#else
444+
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
445+
#endif
446+
#endif /* #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION */
447+
448+
/**
449+
* @brief Port-optimised task selection.
450+
*/
451+
#if ( configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 )
452+
453+
/**
454+
* @brief Count the number of leading zeros in a 32-bit value.
455+
*/
456+
static portFORCE_INLINE uint32_t ulPortCountLeadingZeros( uint32_t ulBitmap )
457+
{
458+
uint32_t ulReturn;
459+
460+
__asm volatile ( "clz %0, %1" : "=r" ( ulReturn ) : "r" ( ulBitmap ) : "memory" );
461+
462+
return ulReturn;
463+
}
464+
465+
/* Check the configuration. */
466+
#if ( configMAX_PRIORITIES > 32 )
467+
#error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32. It is very rare that a system requires more than 10 to 15 different priorities as tasks that share a priority will time slice.
468+
#endif
469+
470+
#if ( portHAS_ARMV8M_MAIN_EXTENSION == 0 )
471+
#error ARMv8-M baseline implementations (such as Cortex-M23) do not support port-optimised task selection. Please set configUSE_PORT_OPTIMISED_TASK_SELECTION to 0 or leave it undefined.
472+
#endif
473+
474+
/**
475+
* @brief Store/clear the ready priorities in a bit map.
476+
*/
477+
#define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
478+
#define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
479+
480+
/**
481+
* @brief Get the priority of the highest-priority task that is ready to execute.
482+
*/
483+
#define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ulPortCountLeadingZeros( ( uxReadyPriorities ) ) )
484+
485+
#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
486+
/*-----------------------------------------------------------*/
487+
438488
/* *INDENT-OFF* */
439489
#ifdef __cplusplus
440490
}

portable/GCC/ARM_CM23/non_secure/port.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,13 +495,13 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
495495
* FreeRTOS API functions are not called from interrupts that have been assigned
496496
* a priority above configMAX_SYSCALL_INTERRUPT_PRIORITY.
497497
*/
498-
#if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_BASEPRI == 1 ) )
498+
#if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_ARMV8M_MAIN_EXTENSION == 1 ) )
499499

500500
static uint8_t ucMaxSysCallPriority = 0;
501501
static uint32_t ulMaxPRIGROUPValue = 0;
502502
static const volatile uint8_t * const pcInterruptPriorityRegisters = ( const volatile uint8_t * ) portNVIC_IP_REGISTERS_OFFSET_16;
503503

504-
#endif /* #if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_BASEPRI == 1 ) ) */
504+
#endif /* #if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_ARMV8M_MAIN_EXTENSION == 1 ) ) */
505505

506506
#if ( configUSE_TICKLESS_IDLE == 1 )
507507

@@ -1614,7 +1614,7 @@ StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
16141614

16151615
BaseType_t xPortStartScheduler( void ) /* PRIVILEGED_FUNCTION */
16161616
{
1617-
#if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_BASEPRI == 1 ) )
1617+
#if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_ARMV8M_MAIN_EXTENSION == 1 ) )
16181618
{
16191619
volatile uint32_t ulOriginalPriority;
16201620
volatile uint32_t ulImplementedPrioBits = 0;
@@ -1695,7 +1695,7 @@ BaseType_t xPortStartScheduler( void ) /* PRIVILEGED_FUNCTION */
16951695
* value. */
16961696
portNVIC_SHPR2_REG = ulOriginalPriority;
16971697
}
1698-
#endif /* #if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_BASEPRI == 1 ) ) */
1698+
#endif /* #if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_ARMV8M_MAIN_EXTENSION == 1 ) ) */
16991699

17001700
/* Make PendSV, CallSV and SysTick the same priority as the kernel. */
17011701
portNVIC_SHPR3_REG |= portNVIC_PENDSV_PRI;
@@ -1936,7 +1936,7 @@ BaseType_t xPortIsInsideInterrupt( void )
19361936
}
19371937
/*-----------------------------------------------------------*/
19381938

1939-
#if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_BASEPRI == 1 ) )
1939+
#if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_ARMV8M_MAIN_EXTENSION == 1 ) )
19401940

19411941
void vPortValidateInterruptPriority( void )
19421942
{
@@ -1994,5 +1994,5 @@ BaseType_t xPortIsInsideInterrupt( void )
19941994
configASSERT( ( portAIRCR_REG & portPRIORITY_GROUP_MASK ) <= ulMaxPRIGROUPValue );
19951995
}
19961996

1997-
#endif /* #if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_BASEPRI == 1 ) ) */
1997+
#endif /* #if ( ( configASSERT_DEFINED == 1 ) && ( portHAS_ARMV8M_MAIN_EXTENSION == 1 ) ) */
19981998
/*-----------------------------------------------------------*/

0 commit comments

Comments
 (0)