77 #ifndef configKERNEL_INTERRUPT_PRIORITY
78 #define configKERNEL_INTERRUPT_PRIORITY 255
81 #ifndef configSYSTICK_CLOCK_HZ
82 #define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ
86 #define portNVIC_SYSTICK_CTRL_REG ( * ( ( volatile unsigned long * ) 0xe000e010 ) )
87 #define portNVIC_SYSTICK_LOAD_REG ( * ( ( volatile unsigned long * ) 0xe000e014 ) )
88 #define portNVIC_SYSTICK_CURRENT_VALUE_REG ( * ( ( volatile unsigned long * ) 0xe000e018 ) )
89 #define portNVIC_SYSPRI2_REG ( * ( ( volatile unsigned long * ) 0xe000ed20 ) )
91 #define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
92 #define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
93 #define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
94 #define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL )
95 #define portNVIC_PENDSVCLEAR_BIT ( 1UL << 27UL )
96 #define portNVIC_PEND_SYSTICK_CLEAR_BIT ( 1UL << 25UL )
98 #define portNVIC_PENDSV_PRI ( ( ( unsigned long ) configKERNEL_INTERRUPT_PRIORITY ) << 16UL )
99 #define portNVIC_SYSTICK_PRI ( ( ( unsigned long ) configKERNEL_INTERRUPT_PRIORITY ) << 24UL )
102 #define portFIRST_USER_INTERRUPT_NUMBER ( 16 )
103 #define portNVIC_IP_REGISTERS_OFFSET_16 ( 0xE000E3F0 )
104 #define portAIRCR_REG ( * ( ( volatile unsigned long * ) 0xE000ED0C ) )
105 #define portMAX_8_BIT_VALUE ( ( unsigned char ) 0xff )
106 #define portTOP_BIT_OF_BYTE ( ( unsigned char ) 0x80 )
107 #define portMAX_PRIGROUP_BITS ( ( unsigned char ) 7 )
108 #define portPRIORITY_GROUP_MASK ( 0x07UL << 8UL )
109 #define portPRIGROUP_SHIFT ( 8UL )
112 #define portINITIAL_XPSR ( 0x01000000UL )
115 #define portMAX_24_BIT_NUMBER ( 0xffffffUL )
120 #define portMISSED_COUNTS_FACTOR ( 45UL )
125 #ifdef configTASK_RETURN_ADDRESS
126 #define portTASK_RETURN_ADDRESS configTASK_RETURN_ADDRESS
128 #define portTASK_RETURN_ADDRESS prvTaskExitError
133 static unsigned portBASE_TYPE uxCriticalNesting = 0xaaaaaaaa;
152 static
void prvPortStartFirstTask(
void )
__attribute__ (( naked ));
157 static
void prvTaskExitError(
void );
164 #if configUSE_TICKLESS_IDLE == 1
165 static unsigned long ulTimerCountsForOneTick = 0;
172 #if configUSE_TICKLESS_IDLE == 1
173 static unsigned long xMaximumPossibleSuppressedTicks = 0;
180 #if configUSE_TICKLESS_IDLE == 1
181 static unsigned long ulStoppedTimerCompensation = 0;
189 #if ( configASSERT_DEFINED == 1 )
190 static unsigned char ucMaxSysCallPriority = 0;
191 static unsigned long ulMaxPRIGROUPValue = 0;
218 static void prvTaskExitError(
void )
235 " ldr r3, pxCurrentTCBConst2 \n"
238 " ldmia r0!, {r4-r11} \n"
241 " msr basepri, r0 \n"
246 "pxCurrentTCBConst2: .word pxCurrentTCB \n"
251 static void prvPortStartFirstTask(
void )
254 " ldr r0, =0xE000ED08 \n"
274 #if( configASSERT_DEFINED == 1 )
276 volatile unsigned long ulOriginalPriority;
278 volatile unsigned char ucMaxPriorityValue;
286 ulOriginalPriority = *pcFirstUserPriorityRegister;
293 ucMaxPriorityValue = *pcFirstUserPriorityRegister;
303 ulMaxPRIGROUPValue--;
304 ucMaxPriorityValue <<= (
unsigned char ) 0x01;
314 *pcFirstUserPriorityRegister = ulOriginalPriority;
327 uxCriticalNesting = 0;
330 prvPortStartFirstTask();
351 __asm
volatile(
"dsb" );
352 __asm
volatile(
"isb" );
360 __asm
volatile(
"dsb" );
361 __asm
volatile(
"isb" );
368 if( uxCriticalNesting == 0 )
379 " mrs r0, basepri \n" \
381 " msr basepri, r1 \n" \
396 " msr basepri, r0 \n" \
402 ( void ) ulNewMaskValue;
414 " ldr r3, pxCurrentTCBConst \n"
417 " stmdb r0!, {r4-r11} \n"
420 " stmdb sp!, {r3, r14} \n"
422 " msr basepri, r0 \n"
423 " bl vTaskSwitchContext \n"
425 " msr basepri, r0 \n"
426 " ldmia sp!, {r3, r14} \n"
430 " ldmia r0!, {r4-r11} \n"
435 "pxCurrentTCBConst: .word pxCurrentTCB \n"
461 #if configUSE_TICKLESS_IDLE == 1
465 unsigned long ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements;
469 if( xExpectedIdleTime > xMaximumPossibleSuppressedTicks )
471 xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
484 if( ulReloadValue > ulStoppedTimerCompensation )
486 ulReloadValue -= ulStoppedTimerCompensation;
491 __asm
volatile(
"cpsid i" );
510 __asm
volatile(
"cpsie i" );
529 xModifiableIdleTime = xExpectedIdleTime;
531 if( xModifiableIdleTime > 0 )
533 __asm
volatile(
"dsb" );
534 __asm
volatile(
"wfi" );
535 __asm
volatile(
"isb" );
547 __asm
volatile(
"cpsie i" );
551 unsigned long ulCalculatedLoadValue;
562 if( ( ulCalculatedLoadValue < ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) )
564 ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL );
574 ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
586 ulCompleteTickPeriods = ulCompletedSysTickDecrements / ulTimerCountsForOneTick;
619 #if configUSE_TICKLESS_IDLE == 1
633 #if( configASSERT_DEFINED == 1 )
635 void vPortValidateInterruptPriority(
void )
637 unsigned long ulCurrentInterrupt;
638 unsigned char ucCurrentPriority;
641 __asm
volatile(
"mrs %0, ipsr" :
"=r"( ulCurrentInterrupt ) );
647 ucCurrentPriority = pcInterruptPriorityRegisters[ ulCurrentInterrupt ];
672 configASSERT( ucCurrentPriority >= ucMaxSysCallPriority );