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

How to calculate NRF_SDH_BLE_GAP_EVENT_LENGTH in SDK15 for determinded NRF_SDH_BLE_GATT_MAX_MTU_SIZE ?

Hello,

I would like to know how can I configure the parameter  NRF_SDH_BLE_GAP_EVENT_LENGTH for a determined NRF_SDH_BLE_GATT_MAX_MTU_SIZE  when enabling data extension.

I have defined my NRF_SDH_BLE_GATT_MAX_MTU_SIZE   as 158 bytes  set my softdevice to use 7 characteristics and to use the connection event lenght extension as shown below

void gatt_mtu_set(uint16_t att_mtu)
{
    ret_code_t err_code;

    err_code = nrf_ble_gatt_att_mtu_periph_set(&m_gatt, att_mtu);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_ble_gatt_att_mtu_central_set(&m_gatt, att_mtu);
    APP_ERROR_CHECK(err_code);
}


void conn_evt_len_ext_set(bool status)
{
    ret_code_t err_code;
    ble_opt_t  opt;

    memset(&opt, 0x00, sizeof(opt));
    opt.common_opt.conn_evt_ext.enable = status ? 1 : 0;

    err_code = sd_ble_opt_set(BLE_COMMON_OPT_CONN_EVT_EXT, &opt);
    APP_ERROR_CHECK(err_code);
}

void data_len_set(uint8_t value)
{
    ret_code_t err_code;
    err_code = nrf_ble_gatt_data_length_set(&m_gatt, BLE_CONN_HANDLE_INVALID, value);
    APP_ERROR_CHECK(err_code);

    m_test_params.data_len = value;
}

static void ble_stack_init(void)
{
    uint32_t err_code;


    err_code = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err_code);

    
    // Configure the BLE stack using the default settings.
    // Fetch the start address of the application RAM.
    uint32_t ram_start = 0;
    err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
    APP_ERROR_CHECK(err_code);


    // BLE Configuration
    ble_cfg_t ble_cfg;

    // Max Packets Per Connection Event
    memset(&ble_cfg, 0, sizeof ble_cfg);
    ble_cfg.conn_cfg.conn_cfg_tag                            = APP_BLE_CONN_CFG_TAG;
    ble_cfg.conn_cfg.params.gatts_conn_cfg.hvn_tx_queue_size = 7;
    err_code = sd_ble_cfg_set(BLE_CONN_CFG_GATTS, &ble_cfg, ram_start);
    APP_ERROR_CHECK(err_code);


    // Enable BLE stack.
    err_code = nrf_sdh_ble_enable(&ram_start);
    APP_ERROR_CHECK(err_code);

    // Register a handler for BLE events.
    NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
}

However,  I do not know what are the righet values for NRF_SDH_BLE_GAP_EVENT_LENGTH  and how shoud I suppose to calculte it. Could you provide me some hints about it?

Thanks in advance,

Kind regards

  • Hi Javier

    The NRF_SDH_BLE_GATT_MAX_MTU_SIZE  is irrelevant to the GAP event length, since the size of the on air packets is set by the NRF_SDH_BLE_GAP_DATA_LENGTH parameter. A large GATT MTU just means that the SoftDevice will have to split the transmission up into several link layer packets. 

    Even with the maximum NRF_SDH_BLE_GAP_DATA_LENGTH of 251 bytes, the default data length of 3 should be sufficient for at least one packet exchange. 

    As you can see here the maximum size of a BLE packet is 1 (preamble) + 4 (access address) + 2 (LL header) + 4 (L2CAP header) + 251 (ATT data) + 3 (CRC) bytes long, so a total of 265 bytes.
    At the default 1 Mbps on-air bitrate this packet will take a total of 2.12ms to transmit. Adding 150us for the TX/RX switch and 80us for an empty ACK packet you are still well within the 3.75ms that an event length of 3 gives you. 

    If you want to send multiple long packets within one interval, or send long packet in both directions, then you might need a larger event length to support it. 

    Best regards
    Torbjørn

     

     

Related