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

Is the data passed to sd_ble_gatts_hvx() queued by value or by reference?

Using an approach similar to what's in the ble_app_att_mtu_throughput example, my goal is to transfer data as fast as possible.  (I.e. call sd_ble_gatts_hvx() on the same characteristic until I receive an NRF_ERROR_RESOURCES reply and then wait for the BLE_GATTS_EVT_HVN_TX_COMPLETE event before proceeding with notifications again.)

My questions are focused on the p_data member of the ble_gatts_hvx_params_t struct passed to sd_ble_gatts_hvx().

  • Within that call, what gets added to the value notification queue?
  • Does the value data being pointed to get copied into the queue, or does the pointer itself simply get saved in order to have the data obtained later when ready to be sent?
  • Ultimately, can the same underlying, changing data buffer be used repeatedly, or does each call to sd_ble_gatts_hvx() need to have a unique buffer to back p_data?

For what it's worth, it appears that the couple of examples doing this are set up with a single buffer, suggesting the data is copied into the notification queue.  But I would greatly appreciate the definitive answer on what's happening in the SoftDevice.

Parents Reply
  • Hi Torbjørn sorry to dig up an old post. 

    Can I just ask, at what point is it safe to overwrite the p_data memory - I assume when sd_ble_gatts_hvx() returns? But I wanted to check, I've been experiencing crashing when I call this aggressively fast during testing so I want to understand it as much as possible. Can I safely wait for sd_ble_gatts_hvx() to return and immediately overwrite p_data?

    Thanks very much.

Children
No Data
Related