Page 1 of 1

Keep system responsive with long control interrupt

Posted: Tue Apr 07, 2015 8:03 am
by tecnologic
Hi All,

i recently ran into a Problem. In my Application i have an control function with an execution time of approx 30µs on stm32f4. This function needs to run every 50µs.
My first architecture was to use a high prio task for this triggerd by the ADC via binary semaphore. This prevents low Prio serial communication from getting timeout with my PC programm controling the device. Because uart interrupts can be served when control is calculating.

Now i had the idea of saving the 2 task stwiches to and from the controltask every 50µs. From the interrupt to the start of task execution there are 1 - 2µs delay. This ist quite fast for an RTOS, this is why i choosed Chibi, but i want to port the application to STM32F3 with the control runnig from CCM i can get this running at 12kHz but i need to save the task switches.

My thought is to trigger an Softwareinterrupt from the high ADC interrupt. And calulate the control function in this interrupt. So i can set uart int to higher Prio than the Software interrupt and have normal serial communcation. The Os then handles all low Prio stuff.

So i think i have only the nested interrupt switching instead of an hole task switch.

Or am i totaly wrong with this approach?


@edit: an other idea i just had, is to set the ADC int to lowest Prio. and Run the Control function directly from this int. so all other ints can get served by the controller and i can use os funktions to inform low prio threads of important things from the int. but i have no task switching delay. only small interruptions by the higher prio interrupts. With big DMA buffers for Uart this impact could be very small.

Any other ideas?

Re: Keep system responsive with long control interrupt

Posted: Tue Apr 07, 2015 8:37 am
by Giovanni
If you need ultra low latencies the correct approach is to use "fast interrupts", by default priorities 0 and 1 are reserved for that, of course priority zero has the lowest latency and jitter.

Fast interrupts can preempt the kernel and thus cannot invoke any RTOS function. You can implement a state machine with them and then "delegate" the call to the OS to a lower priority interrupt, usually PENDSW, when you reach some state of your state machine.

From the low priority interrupt you can call any RTOS function as usual.

Note that HAL interrupts handler are not designed to operate as fast interrupts, you need custom code there.

Giovanni

Re: Keep system responsive with long control interrupt

Posted: Tue Apr 07, 2015 8:58 am
by tecnologic
Hi Giovanni,

i do not need lowest latencys. But taskswitching an 20kHz is about 10% CPU-Time and this i want to reduce. But when i use the Fast Interrupts no other interrupt gets served so my system ist not responding 30µs out of 50µs. So i may get data loss in the uart because the dma interrupt could not be served. This is my concern.

@edit: the code for the control function is all custom made with code from Matlab embedded coder.

Re: Keep system responsive with long control interrupt

Posted: Tue Apr 07, 2015 9:30 am
by Giovanni
You could try the simplified IRQ mode of the Cortex-M port, it makes everything a bit faster.

Giovanni

Re: Keep system responsive with long control interrupt

Posted: Tue Apr 07, 2015 9:52 am
by tecnologic
This simplified Mode is without nesting? or whats the difference? between the modes?

But normal Interrupt latency should be even short enough. it may sound as false design to run 60% of the runtime in interrupt but with nested interrupts i think its no Problem. i will eliminate variables on stack to prevent issues with interrupt stack. In my actual thinking this is the best solution.

Re: Keep system responsive with long control interrupt

Posted: Tue Apr 07, 2015 9:54 am
by Giovanni
The difference is in the implementation of critical zones, normally it is done by priority masking, the simplified mode just disables/enables interrupts globally, which is a bit faster. Interrupts nesting is still there.

The limitation is: no fast interrupts.

Giovanni

Re: Keep system responsive with long control interrupt

Posted: Tue Apr 07, 2015 9:59 am
by tecnologic
cause i dont need the fast interrupts and i can live with the jitter from the critical zones this is a good option. So the Tast switch is faster?
I'll give this a try. And i compare control Task to low Prio Control interrupt.

Interupt nesting is not affected bei die Simple mode? Ist only the handling of critical zones? Its the define "CORTEX_SIMPLIFIED_PRIO" or so it was called i think. I have seen this in the code.

Thanks Giovanni