日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

FreeRTOS軟件定時器apollo中斷狀態判斷_操作系統

作者:jiang_2018 ? 更新時間: 2022-06-09 編程語言

問題場景

開發中發現FreeRTOS軟件定時器不走了,具體表現在軟件定時器中斷進不去。

分析問題

觀察發現只有在某個任務執行期間,FreeRTOS的軟件定時器才會不走,其他任務執行時正常,排查后是此任務的優先級比定時器任務高,且占用時間比較長,導致任務切不出去。

解決問題

在FreeRTOSConfig.h中修改定時器任務優先級為最高解決問題

apollo中斷狀態判斷

在看apollo3 代碼時發現下面這個函數

void WsfSetOsSpecificEvent(void)
{
  if(xRadioTaskEventObject != NULL) 
  {
      BaseType_t xHigherPriorityTaskWoken, xResult;
      if(xPortIsInsideInterrupt() == pdTRUE) {
          // Send an event to the main radio task
          xHigherPriorityTaskWoken = pdFALSE;
          xResult = xEventGroupSetBitsFromISR(xRadioTaskEventObject, 1,
                                              &xHigherPriorityTaskWoken);
          // If the radio task is higher-priority than the context we're currently
          // running from, we should yield now and run the radio task.
          //
          if ( xResult != pdFAIL )
          {
              portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
          }    
      }
      else {
          xResult = xEventGroupSetBits(xRadioTaskEventObject, 1);
          //
          // If the radio task is higher priority than the context we're currently
          // running from, we should yield now and run the radio task.
          //
          if ( xResult != pdFAIL )
          {
              portYIELD();
          }
      }

  }    
}

這是FreeRTOS發送一個事件標志組,xPortIsInsideInterrupt這個函數判斷是否在中斷中,進而調用判斷是否調用FromISR結尾的api,下面看下原理

static portFORCE_INLINE BaseType_t xPortIsInsideInterrupt( void )
{
uint32_t ulCurrentInterrupt;
BaseType_t xReturn;
	/* Obtain the number of the currently executing interrupt. */
	__asm
	{
		mrs ulCurrentInterrupt, ipsr
	}
	if( ulCurrentInterrupt == 0 )
	{
		xReturn = pdFALSE;
	}
	else
	{
		xReturn = pdTRUE;
	}
	return xReturn;
}

讀IPSR寄存器,0表示當前沒有中斷在運行,非0表示正在運行的中斷號,即處于中斷中,所以要用FromISR結尾的api

原文鏈接:https://blog.csdn.net/weixin_41572450/article/details/109637997

欄目分類
最近更新