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

alternatives: runtime initialization of the context pointer in NRF_SDH_BLE_OBSERVER()

NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, pContext );


evidently I register here a callback "ble_evt_handler" to the softdevice for ble events. additionally, i expect the callback "ble_evt_handler"
to provide me back the context provider that i set here.

However, "pContext", in my case, is a dynamic-location that of-course is available only during the run-time. As is already documented,
the above macro-call is initialized only at the link-time; with the consequence that the "ble_evt_handler" always returns a "null"
"pContext" pointer in my case.


It doesn't help that in my linker descriptor file, i locate the above section to the RAM region i.e.,
  .sdh_ble_observers :
  {
    PROVIDE(__start_sdh_ble_observers = .);
    KEEP(*(SORT(.sdh_ble_observers*)))
    PROVIDE(__stop_sdh_ble_observers = .);
  } > RAM

} INSERT AFTER .data;


Is there an official (or for that matter an non-official) workaround for this? (apart from using global/static variables) 
I would really appreciate some suggestions.

Parents Reply
  • Hi,

    thanks for your answer. actually this is how i am presently dealing with it. In my case, this is actually  the address of an (class) object that i had wanted to pass via the context pointer argument, but now i store this instead as a static pointer. but i don't find it so elegant.

    Since this is also your recommendation, so it looks like, the dynamic assignment of the context pointer argument can't be used.

Children
Related