Least restrictive critical section?
Posted: Fri Dec 06, 2019 11:17 pm
I have set up an external interrupt on a pin successfully, I use a FreeRTOS queue to queue some data which is fetched in the main loop(). This works well but I also have to access a variable from both the loop() and the ISR.
It is my understanding that my only option is a critical section using portENTER_CRITICAL and portEXIT_CRITICAL. When inside the critical section interrupts are disabled. This is what I want since I don't want the code in the loop() that modifies the shared variable to be interrupted by the ISR which also want to modify the share resources.
Two questions:
It is my understanding that my only option is a critical section using portENTER_CRITICAL and portEXIT_CRITICAL. When inside the critical section interrupts are disabled. This is what I want since I don't want the code in the loop() that modifies the shared variable to be interrupted by the ISR which also want to modify the share resources.
Two questions:
- It seems disabling ALL interrupts during the critical section is somewhat overkill? I just don't want the scheduler to be able to interrupt and the ISR for the external interrupt. All other interrupts should be fine since they don't touch the data? Is there a way to be more specific or is this an all or nothing thing?
- I read in another post on this forum that portENTER_CRITICAL_ISR is not required inside the ISR. Why is it safe to not call portENTER_CRITICAL_ISR? Could'nt the FreeRTOS scheduler ISR interrupt my ISR and start scheduling the loop task again somehow? Or will the scheduler never pre-empt an interrupt?