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

Functions running outside the main loop?

Hi there,

quite a beginner here and tring to figure some stuff out about the nordic programming style.

when sniffing around the given examples in the newest SDK(SES IDE) I was suprised to see that the functions(For example in the "blinky_freertos" example)

Manage to somehow regularly run even when the program is in the loop section of the main() function while it is completely empty.

How does it do that? How do we take advantage of it?

Also saw something weird with that example which is that function"UNUSED_VARIABLE()"

Which I don't get the point of and couldn't find anything about it in the infocenter but from selecting it and going to "Go to defenition" it looks like it takes what ever is in it and adds "void" before it....

  • Hi,

    The freeRTOS (and our BLE) examples uses timers and interrupts to call functions on certain events. So even if there is nothing going on in the main() while loop the timers are running in the background and wakes up the system now and then. In the case of the blinky_freertos example, led_toggle_timer_callback() is fed to the freeRTOS "engine" in the function called xTimerCreate(). The freeRTOS then handles the calling of the function for you. Callbacks like this is used a lot in our SDKs.

    Regarding the UNUSED_VARIABLE() function, you can find an explanation here: https://devzone.nordicsemi.com/question/89089/what-is-the-purpose-of-unused_variable-when-the-effect-is-the-same-without-it/

  • Thansk the UNUSED_VARIABLE() function now makes sense but I don't understand why would you make the examples use timers and interrupts for the beginners? It just makes it harder to understand and makes you dive way dipper into the code and hides things you want to understand and another exmpale is the SAADC there I couldn't find where and how an ADC sample function it related to any timer or interrupt.

    If we are on it do you maybe have a source of tutorials for the basic use of SES IDE with the NRF52 that includes things like importing external libraries and libraries from the sdk?

  • There is also the "pure" blinky example (without the rtos). That one doesn't use timers etc. There is an eternal struggle between tech support, product management, and the SDK team regarding the level of complexity of the SDK examples. We get a constant stream of suggestions for the SDK from large and small customers, and we also want to provide drivers and examples for all new SoC features and specifications. Hence we have to prioritise. From a tech support view though, I tend to agree with you and would rather see many simple examples, than just a few complex ones showcasing everything at once.

    Regarding SES tutorials my only suggestion is to take a look at some of these blog posts.

Related