What is the best method to update flag from interrupt?

Hi, I have to implement one comparator intrrupt in Stm32F3 for protection of my circuit. When Ever interrupt comes i need to set one flag and need to check into task which i can not out into wait state/ bloack state for waiting the flag is set. I am using FreeRTOS 7.6 in my project. I am right now using One global flag variable of volatile type and updating it. 1. Can you please let me know is there any issue i can face in updating the flag this way? 2. Any other safe alternative of this? So that my task should not enter into wait/block state . – Mukesh

What is the best method to update flag from interrupt?

Sorry – I don’t understand your requirements, can you try re-phrasing “When Ever interrupt comes i need to set one flag and need to check into task which i can not out into wait state/ bloack state for waiting the flag is set.”

What is the best method to update flag from interrupt?

sorry for typo. I mean one flag should be set into by Comparator interrupt. And based on this flag want to take decission in one task. This task i can not put into block/wait state.

What is the best method to update flag from interrupt?

Hello Muku,
1 Can you please let me know is there any issue i can face in updating the flag this way?
You are accessing a memory location from both an interrupt as well as from a task. That is perfectly legal. You already made the shared variable volatile, which forces the compiler not to use caching but in stead to access the physical memory each time you read or write it: ~~~~~ volatile BaseType_t xCounter = 0; void ISR() { /* No critical section is needed because nobody will access xCounter while this ISR is active. */ xCounter++; } void vMyTask( void pvParameter ) { for( ;; ) { / When reading the variable no critical section is needed. / if( xCounter > 0 ) { / * Need a critical section because: * ld.w r9,r8[0x0] // load * sub r9,1 // decrement * st.w r8[0x0],r9 // store */ taskENTER_CRITICAL(); xCounter–; taskEXIT_CRITICAL(); } } } ~~~~~
2 Any other safe alternative of this? So that my task should not enter into wait/block state
As stated here above, you can read the common variable without a problem. When changing the variable (increment/decrement), make sure this is done in a critical section. If not you might miss changes that are made in the ISR. Just curious, wouldn’t it be profitable to use some blocking mechanism? Why can’t you do that? Regards.