In my below FreeRTOS code, the global variable command_buffer is protected from altering by using critical API ( taskENTER_CRITICAL() and taskEXIT_CRITICAL() API). Is it possible that any interrupts with a priority, say 4 can still access this global variable?
void command_handling_task(void *params) {
while(1) {
xTaskNotifyWait(0,0,NULL,portMAX_DELAY);
taskENTER_CRITICAL();
new_cmd = parseCMD(command_buffer);
taskEXIT_CRITICAL();
xQueueSendToFront(command_queue_handle, &new_cmd, portMAX_DELAY);
}
}
taskENTER_CRITICAL
implementation varies depending on the port. In ARM_CM4 port, it raises BASEPRI (does not disable all interrupts). Interrupts below (interrupt priority is numerically opposite in ARM devices) configMAX_SYSCALL_INTERRUPT_PRIORITY
(BASEPRI value) will be in a pending state until you come out of the critical section and all high priority interrupts have been executed.
1 Like
Lets assume configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY = 5, and still any interrupt with higest priority (NVIC_SetPriority(USART2_IRQn, 0)) can access any global variable in between taskENTER_CRITICAL() and taskEXIT_CRITICAL(). Am I correct??
1 Like
Yes, you are correct. FreeRTOS does not disable all interrupts to avoid increasing interrupt latency.
You can keep a breakpoint at the critical section, and another inside an interrupt to analyse this yourself.
2 Likes