mirror of
				https://github.com/FreeRTOS/FreeRTOS-Kernel.git
				synced 2025-11-04 02:32:42 -05:00 
			
		
		
		
	Ensure interrupts are enabled at first task start (#214)
Critical sections in FreeRTOS are implemented using the following two
functions:
void vPortEnterCritical( void )
{
    portDISABLE_INTERRUPTS();
    uxCriticalNesting++;
}
void vPortExitCritical( void )
{
    uxCriticalNesting--;
    if( uxCriticalNesting == 0 )
    {
        portENABLE_INTERRUPTS();
    }
}
uxCriticalNesting is initialized to a large value at the start and set
to zero when the scheduler is started (xPortStartScheduler). As a
result, before the scheduler is started, a pair of enter/exit critical
section will leave the interrupts disabled because uxCriticalNesting
will not reach zero in the vPortExitCritical function. This is done to
ensure that the interrupts remain disabled from the time first FreeRTOS
API is called to the time when the scheduler is started. The scheduler
starting code is expected to enure that interrupts are enabled before
the first task starts executing.
Cortex-M33 ports were not enabling interrupts before starting the first
task and as a result, the first task was started with interrupts
disabled. This PR fixes the issue by ensuring that interrupts are
enabled before the first task is started.
Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
			
			
This commit is contained in:
		
							parent
							
								
									1431b65110
								
							
						
					
					
						commit
						ebbe2cf854
					
				
					 16 changed files with 59 additions and 33 deletions
				
			
		| 
						 | 
				
			
			@ -128,6 +128,8 @@ vRestoreContextOfFirstTask:
 | 
			
		|||
	adds r0, #32							/* Discard everything up to r0. */
 | 
			
		||||
	msr  psp, r0							/* This is now the new top of stack to use in the task. */
 | 
			
		||||
	isb
 | 
			
		||||
	mov  r0, #0
 | 
			
		||||
	msr  basepri, r0						/* Ensure that interrupts are enabled when the first task starts. */
 | 
			
		||||
	bx   r4									/* Finally, branch to EXC_RETURN. */
 | 
			
		||||
#else /* configENABLE_MPU */
 | 
			
		||||
	ldm  r0!, {r1-r3}						/* Read from stack - r1 = xSecureContext, r2 = PSPLIM and r3 = EXC_RETURN. */
 | 
			
		||||
| 
						 | 
				
			
			@ -139,6 +141,8 @@ vRestoreContextOfFirstTask:
 | 
			
		|||
	adds r0, #32							/* Discard everything up to r0. */
 | 
			
		||||
	msr  psp, r0							/* This is now the new top of stack to use in the task. */
 | 
			
		||||
	isb
 | 
			
		||||
	mov  r0, #0
 | 
			
		||||
	msr  basepri, r0						/* Ensure that interrupts are enabled when the first task starts. */
 | 
			
		||||
	bx   r3									/* Finally, branch to EXC_RETURN. */
 | 
			
		||||
#endif /* configENABLE_MPU */
 | 
			
		||||
/*-----------------------------------------------------------*/
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue