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

write_cmd_tx_queue count wraps around when counting amount of queued writes and decreasing the count on tx complete event

Hi,

I´m using nrf52840 with softdevice S132 and set ble_gattc_conn_cfg_t::write_cmd_tx_queue_size to larger than 1. I´m count number of queued writes by increasing a counter each time I receive NRF_SUCCESS back from sd_ble_gattc_write and decerasing the counter on BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE event with p_ble_evt->evt.gattc_evt.params.write_cmd_tx_complete.count.

But it happens sometimes that the counter wraps around on the negative side so that it becomes 255 or 254. How is this possible?

This must mean that BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE event was fired before actually increasing the counter at some point.

The counter is not used any where else, and is set to 0 when connection is established.

I have measured that the amount of times I manage to queue write with NRF_SUCCESS is equal to number of BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE events.

Parents
  • Hi,

    Which SDK and SoftDevice version are you using?

    But it happens sometimes that the counter wraps around on the negative side so that it becomes 255 or 254. How is this possible?

    This seems odd. Do you by any chance use multiple connections, and if so could it be that you count for BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE for another connection as well? (just a shot in the dark).

    I have measured that the amount of times I manage to queue write with NRF_SUCCESS is equal to number of BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE events.

    So this means that you get a BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE for every successful call to sd_ble_gattc_write(), so if p_ble_evt->evt.gattc_evt.params.write_cmd_tx_complete.count always was 1, this would be correct? But sometimes it is more than 1?

  • SDK version is 15.2 and softdevice is S132.

    This seems odd. Do you by any chance use multiple connections, and if so could it be that you count for BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE for another connection as well? (just a shot in the dark).

    I have only 1 connection.

    So this means that you get a BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE for every successful call to sd_ble_gattc_write(), so if p_ble_evt->evt.gattc_evt.params.write_cmd_tx_complete.count always was 1, this would be correct? But sometimes it is more than 1?

    The write_cmd_tx_complete.count is always 1. I was no precise in my description, I measured the counts of BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE by accumulating the counter with p_ble_evt->evt.gattc_evt.params.write_cmd_tx_complete.count. And the total amount of completed tx writes are exactly same as total amount of queued writes.

    The only explanation I can come up with is that the BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE event was issued before incrementing counter after receiving NRF_SUCCESS at some point which is very weird.

Reply
  • SDK version is 15.2 and softdevice is S132.

    This seems odd. Do you by any chance use multiple connections, and if so could it be that you count for BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE for another connection as well? (just a shot in the dark).

    I have only 1 connection.

    So this means that you get a BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE for every successful call to sd_ble_gattc_write(), so if p_ble_evt->evt.gattc_evt.params.write_cmd_tx_complete.count always was 1, this would be correct? But sometimes it is more than 1?

    The write_cmd_tx_complete.count is always 1. I was no precise in my description, I measured the counts of BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE by accumulating the counter with p_ble_evt->evt.gattc_evt.params.write_cmd_tx_complete.count. And the total amount of completed tx writes are exactly same as total amount of queued writes.

    The only explanation I can come up with is that the BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE event was issued before incrementing counter after receiving NRF_SUCCESS at some point which is very weird.

Children
Related