ESP32S2判断当前代码是否在中断

MilesWang
Posts: 5
Joined: Tue May 18, 2021 4:02 am

ESP32S2判断当前代码是否在中断

Postby MilesWang » Thu Jul 01, 2021 10:22 am

想要移植使用rt-thread的软件包,做了接口适配。
但是比如事件组,在rt-thread里是一个统一接口无需判断是否在中断,FreeRTOS里是区分普通代码和中断代码调用不同的API。
所以问题是,我怎么判断当前代码是否在中断中执行?

  1. rt_err_t IRAM_ATTR rt_event_send(rt_event_t event, rt_uint32_t set)
  2. {
  3.     if (vPortGetIPSR())
  4.     {
  5.         BaseType_t xHigherPriorityTaskWoken;
  6.         BaseType_t xResult;
  7.         xHigherPriorityTaskWoken = pdFALSE;
  8.         xResult = xEventGroupSetBitsFromISR(event->xHandler, set, &xHigherPriorityTaskWoken);
  9.         if (xResult != pdFAIL)
  10.         {
  11.             /* If xHigherPriorityTaskWoken is now set to pdTRUE then a context
  12.             switch should be requested.  The macro used is port specific and will
  13.             be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() - refer to
  14.             the documentation page for the port being used. */
  15.             portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
  16.         }
  17.     }
  18.     else
  19.     {
  20.         xEventGroupSetBits(event->xHandler, set);
  21.     }
  22.     return  RT_EOK;
  23. }

ESP_Gargamel
Posts: 786
Joined: Wed Nov 14, 2018 8:45 am

Re: ESP32S2判断当前代码是否在中断

Postby ESP_Gargamel » Fri Jul 02, 2021 8:57 am

可以用接口 xPortInIsrContext

Who is online

Users browsing this forum: No registered users and 171 guests