2014-05-05 03:33 PM
Dear,
i have the following issue: i have seen that i cannot process too many instructions from inside interrupt. I guess there is a limit. (still didn't looked the datasheet), So i decided to do just some few operations in the interrupt routine, pushing the input in a fifo, and then process this input from the main loop. But now, how can avoid race conditions if interrupt is triggered just when the main loop is processing/modifing the stack ? Maybe someone can help me on the proper way to go. Thanks. Angelo2014-05-06 06:58 AM
There is no limit to the length of an interrupt service routine other than the limits imposed by the application. However it is good programming practice to minimize the size of the service routine, and defer processing to a completion task.
If you have a critical section in your main task then disable interrupts during the critical section to prevent a collision with the interrupt. Update your FIFO extract pointer inside a critical section in the main loop to avoid the case of buffer overrun where insert and extract pointers are updated out of sequence due to interrupts. Jack Peacock2014-05-06 07:37 AM
Hi
Jack is right on both points (size of ISR and critical sections). Instead of trying to do this in bare hand crafted code - try one of the open source RTOS. FreeRTOS is popular for developing commercial products. ChiliOS has a few people here on the forum asking questions. ecos - some one recently asked about this on this forum. FreeRTOS definitely has inter-task messaging, with a special function for sending from ISR to task. The inter-task messaging is a FIFO, the FIFO mutex/semaphore is implemented by the OS for you so you do not have to worry about it.2014-05-06 02:16 PM
Dear,
many thanks, for strategic reasons i don't use any OS. I looked the STM324xx library and didn't seen any lock/mutex/semaphore support. So i have to do it in a rude/raw way. Is it possible to disable from the main loop just the interrupt i don't want to engage for race conditions ? I found (IRQn_Type IRQn) (and Disable) Can be used ? Or i should disable/reenable all interrupts ?2014-05-07 01:12 AM
Hi
''Is it possible to disable from the main loop just the interrupt i don't want to engage '' Yes. ''I found (IRQn_Type IRQn) (and Disable) Can be used ? Or i should disable/reenable all interrupts ?'' Look at the implementation and cross reference with the reference manual. I think this may not disable some IRQs (such as the sysTick).2014-05-07 02:03 AM
To truely disable all IRQs - I looked up how FreeRTOS does it.
It masks ALL IRQs in the ARM basepri register. (I do not know I the copyright allows me to paste the code here)2014-05-09 12:25 AM
Hello,
thanks, yes i see FreeRTOS code, but can't understand it clearly. I surfed the forum, and couldn't find any help. I would like to be sure of a way to disable EXTI15_10_IRQn (Ext int line 0), possible without disabling all interrupts. Any help is appreciated.2014-05-09 12:59 AM
''I would like to be sure of a way to disable EXTI15_10_IRQn (Ext int line 0), possible without disabling all interrupts.''
This is pretty easy. Just disable it in the EXTI or via the NVIC : EXTI_InitStructure.EXTI_LineCmd = DISABLE; or NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;