Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Reason for external variables for all the services though *_DEF()

This question is related to https://devzone.nordicsemi.com/f/nordic-q-a/24860/sdk14-static-service-structures

Typically in your SDK examples you put global variables for all the services in your main.c, e.g. the battery service which is defined through BLE_BAS_DEF(m_bas); 

The only time you use this variable is when calling functions within ble_bas.c . In fact almost all the functions within ble_bas.c take ble_bas_t * p_bas as a parameter. This creates the issue referred to in the other question in having to abstract the functions in order to call them from other files. Instead, if the variable was declared within ble_bas.c, you could remove the ble_bas_t* p_bas parameter from all the functions.

Why isn't the variable defined inside of ble_bas.c instead? The only reason I can think of is if you want to have multiple instances of battery services, but then you would need a UUID for each instance. However, the UUID is hardcoded in the ble_bas.c (and in the BLE specification). So I don't see when you would have multiple instances.

Related