This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF52 running RTOS vs. SDK Scheduler

I'm trying to decide whether to use FreeRTOS or simply build on the Scheduler. What are the risks and benefits of using freeRTOS or another RTOS on a wearable sensor device vs using the scheduler?

  • I wont compare FreeRTOS with any other RTOS as that is completely different and long discussion. I will compare RTOS vs Scheduler

    priority vs scheduling

    RTOS will have scheduling of different threads based on many priorities. You can choose the scheduling scheme (on many RTOS). The scheduler in the SDK is simple, it will just queue a call from one context/priority and the call is dequeued in a different context/priority. The only scheduling happening is postponing execution from higher priority to lower priority context.

    features

    RTOS is rich with features like timers, FIFOs, messages, semaphores, mutexes etc. It is a design choice to see if you need all those as they will consume resources in terms of memory and CPU time.

    complexity

    It depends on how complex your application is. If it can handle most of the processing in the interrupts and main context, and if it is enough with the features SDK provides then it is best to keep it simple and not use any RTOS. But if the application is growing to be complex and you do not want to handle the complexity of context switches and their glitches then use RTOS which will handle threads for you. Scheduler in SDK cannot provide threads handling.

    These are few from top of my head.There could be more. We can only compare scheduling features of RTOS with SDK scheduler, other features that RTOS are not provided by SDK scheduler. It finally is your design choice, using RTOS will keep your design gives more control to the RTOS leaving most of the overhead to RTOS scheduling+ it features. Not using RTOS will have you in full control of every single context switch which you have to take into your design considerations. Some like RTOS and some like to just use SDK features, hard to say which one is best as it totally depends on the application and the use case.

  • Followup question, as this may be related, I'm trying to develop a low power ble sensor that generates an always on 20Hz sine wave from a 50 point pwm sine table. It will also capture raw ADC samples at 80Hz and processed samples at 10 Hz. The sine wave and samples have to be in-phase. Whats the optimal way to design such a scheme for lowest power consumption? Any help would save me a lot of time and is much appreciated!

  • since you are using nrf52, and we have dedicated PWM hardware, generating the sine wave is simple enough. ADC samples at 80 HZ can be interrupt based as processing them with 10HZ should not be a problem even with BLE (assuming low BLE traffic). If I were you, I would not use RTOS for this simple use case because processing tick interrupts and complex scheduling is unnecessary here in my opinion. Managing your application intterupt based seems to be enough making it power aware using just SDK features. This way we will save a lot of CPU processing time for RTOS scheduler and tick handler and hence will save power. But this is my opinion, so please use it as a suggestion, not recommendation.

Related