Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
461 views
in Technique[技术] by (71.8m points)

timer - Re-issue SysTick interrupt

I have a SysTick interrupt to trigger task switch 4 times per second, as shown below.

void SysTick_Handler(void) {
  SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk; // Set PendSV 
}

The tasks in the main are occasionally outputting some messages via one of the UART, and to ensure that they have exclusive I/O access, the output routines are protected with a mutex that is set with LDREX and STREX. Code works perfectly well over 90% of the time.

However, one side effect of that protection appears to be that when SysTick happens during the period when the mutex is set, the task switch will not happen, and the task that was running at that time will continue to run until the next task switch.

Is there a way to trigger SysTick again, say, 10 ms later, and do that until the mutex is cleared by the currently running task? For example:

void SysTick_Handler(void) {
  if (mutex) {
    // set SysTick to trigger again in 10 ms 
  } else {
    SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk; // Set PendSV 
  } 
}

If yes, how.

TIA

question from:https://stackoverflow.com/questions/65927739/re-issue-systick-interrupt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Set the SysTick, PendSV, SVCall or some other interrupt pending in your mutex release function.

If you want to avoid the cost of an unnecessary interrupt you can set an atomic flag in the systick handler and check it in the mutex release function so that you only trigger the interrupt if you missed your scheduled run.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...