Monday, December 15, 2014

Is there some RTOS?

Code example for capacitive level sensor seems short and simple (there is even haven't used interrupts!), but some parts may looks quite unusual.

First, seems like there is no RTOS. Yes, there no side RTOS, just hardware drivers. However, if look closer, we realize that main cycle plays the same role  like a main cycle in any RTOS, clocked by hardware timer.

event chart, hardware-driven RTOS

Difference in who clocks CPU - actually there TIM2 triggers ADC,  then ADC starts measurements, and only when it done, ADC triggers main cycle. All CPU needs to do is get fresh data, and work with it. We may say there is a very small hardware-driven RTOS. Or, as was mention before, there is not a emulation of hardware device by CPU, but chains of peripheral devices, configured and serviced by CPU.

This brings us to another difference - event chaining procedures. This procedures connect hardware in functional chains, it allow to work together without disturbing CPU. Actually, in this example peripherals drives CPU, and CPU just services peripherals. All other time CPU free to think or sleep. First may be used for filtering or statistic, second - to lowing current consumption.

Because of simplifying code example, there are simple pooling loop in ADC cycle, and it's means that current consumption close to maximum 14mA. But consumption can be significantly lowered close to zero by using sleep mode with interrupt routine. By the way - event chaining appear not to replace interrupts, but to complement it from hardware side, for unloading CPU from extrinsic tasks.

Code compiled in Keil µVision 4 .71 with standard libraries for STM32F0.

Final binary code not exceed 7kb in size, and leaves free 6kb even for cheapest chip in line like STM32F050F4P6.


No comments:

Post a Comment