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

SDK14 static service structures

The *_DEF macros in SDK14 define service structures as static. This means that the application level functions for a service must all be called from the same c file where the structure was defined (since the structure must be passed as a parameter).

What is Nordic's recommended method for calling a service from multiple c files? In previous SDKs, I declared the service structures extern in a "BLE Manager" header file. Options:

  1. define wrappers in my BLE Manager which don't require the service structure as a parameter
  2. store pointers to the service structures in new variables which are extern
  3. don't use the *_DEF macros, omit static from the service structure declarations
  4. something I haven't thought of
  • Hi Daniel

    I don't think there are any official Nordic recommendations on this, but what I would recommend is to abstract away the service init and configuration into a separate module. This module could have a more application specific interface, abstracting away the BLE API's, and then you could easily share this module between multiple files.

    This is similar to how it is done in our reference design software, which are typically more complex than the SDK examples.

    Best regards
    Torbjørn

Related