Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Does the context switch routine have consider "Pendsv" handler? #120

Closed
Nigelwz opened this issue Apr 14, 2023 · 4 comments
Closed

Comments

@Nigelwz
Copy link

Nigelwz commented Apr 14, 2023

  • In some os, like freertos, it can run PendSV() in context switch.. Does the osek or autosar have consider PendSv check?
@jlbirccyn
Copy link
Member

Hello,

You mean that the context switching is done by the PendSV handler I guess?

Best regards

@Nigelwz
Copy link
Author

Nigelwz commented Apr 14, 2023

Yes, because I saw a lot of sample, the context switch all run on systick or timer.

@jlbirccyn
Copy link
Member

I still don't understand what you are saying. If the context switch occurs in the Systick or timer handler then it does not occur in the PendSV handler.

If you mean that the context switch occurs in the PendSV handler and the PendSV was triggered by the Systick or Timer handler then I don't see the point of invoking a PendSV rather than doing the context switch directly at the end of the Systick or Timer handler.

Also, I doubt that context switching is only done asynchronously in the handler of a hardware IT. When a synchronous system call leads to a context switch, it should be done immediately, not 1ms later (at worst).

@Nigelwz
Copy link
Author

Nigelwz commented Apr 14, 2023

Thanks for your information!!
That's my first time to investigate the automotive indudtry.
Because sometime the "systick interrupt" and "hardware interrupt" can occur simultaneously , (e.g: uart, spi, button, hardware fault...), so some os can set the systick's priority be lower than other hardware interrupt, then if the systick triggered, it can enable the pendsv interrupt, then do context switch in pendsv.
Below is sample code..

void xPortSysTickHandler( void )
{
	/* The SysTick runs at the lowest interrupt priority, so when this interrupt
	executes all interrupts must be unmasked.  There is therefore no need to
	save and then restore the interrupt mask value as its value is already
	known.
	 */
	portDISABLE_INTERRUPTS();
	{
		/* 
		Increment the RTOS tick. 
		*/
		if( xTaskIncrementTick() != pdFALSE )
		{
			/* 
			A context switch is required.  Context switching is performed in
			the PendSV interrupt.  Pend the PendSV interrupt. 
			*/
			portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;
		}
	}
	/*
	Enable interrupt, increntment pensv ISR.
	*/
	portENABLE_INTERRUPTS();
}
BaseType_t xTaskIncrementTick( void )
{
/// do context switch....
}

Or we just need to set ISR1 or ISR2 on trampline, is it correct?

@jlbirccyn jlbirccyn closed this as not planned Won't fix, can't repro, duplicate, stale Oct 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants