I've implemented a fault task in the FreeRTOS which is taking a binary semaphore used as a fault flag. That fault flag is triggered by the STM32 HAL error callback functions, such as HAL_I2C_ErrorCallback
or HAL_UART_ErrorCallback
. If an error occurs, error callbacks functions will call signalFault()
function, which will raise the fault flag by giving the binary semaphore.
My question is: is my signalFault()
function treated as an interrupt service routine (ISR) or not, because it is being called in the HAL ISR error callbacks? Do I need to call xSemaphoreGiveFromISR()
or xSemaphoreGive()
function in signalFault()
function to raise the fault flag?
Sure, you should use xSemaphoreGiveFromISR
if the calling context is an ISR. A function called from an ISR is still part of the ISR.
If you do not trust us then simple check if you are in the interrupt. It will be 100% safe.
int isInISR( void )
{
return ( portNVIC_INT_CTRL_REG & portVECTACTIVE_MASK );
}
and in your code:
if(isInISR()) xSemaphoreGiveFromISR(...);
else xSemaphoreGive(...);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.