Part Number: CC2640R2F
I wanted to register and quickly unregister a connection event callback in a BLE5 peripheral application using simplelink_cc2640r2_sdk_2_30_00_28, but I ran into a problem (BTW I have not tried it in 2.40 yet). I could not unregister the callback with Gap_RegisterConnEventCb(NULL, GAP_CB_UNREGISTER, connHandle). It returns status = 2, which is a) not supposed to be one of the valid return values, and b) using the normal status values indicates INVALIDPARAMETER. The callback keeps being called after that failed attempt.
I thought maybe I was doing something wrong, so I tried it in the simple_peripheral project, and it failed there, too! It is easy to try with some simple modifications to add debug printing to the terminal. Then just connect to it, select "Auto PHY change", then switch it to something else. The display will show the start (register callback status) and stop (unregister callback status), but also shows that the callback itself is still running. It keeps running until the connection is terminated.
Is this a known problem (I did not see anything in the forum)? Is there a workaround? Seems like a lot of overhead to let it keep running, especially with short connection intervals.
Thanks!
dave
#define SP_ROW_DEBUG (TBM_ROW_APP + 8)
static status_t SimplePeripheral_startAutoPhyChange(uint16_t connHandle)
{
status_t status = FAILURE;
// Get connection index from handle
uint8_t connIndex = SimplePeripheral_getConnIndex(connHandle);
SIMPLEPERIPHERAL_ASSERT(connIndex < MAX_NUM_BLE_CONNS);
// Start Connection Event notice for RSSI calculation
status = Gap_RegisterConnEventCb(SimplePeripheral_connEvtCB, GAP_CB_REGISTER, connHandle);
Display_printf(dispHandle, SP_ROW_DEBUG+1, 0, "start/%d",status);
// Flag in connection info if successful
if (status == SUCCESS)
{
connList[connIndex].isAutoPHYEnable = TRUE;
}
return status;
}
static status_t SimplePeripheral_stopAutoPhyChange(uint16_t connHandle)
{
// Get connection index from handle
uint8_t connIndex = SimplePeripheral_getConnIndex(connHandle);
SIMPLEPERIPHERAL_ASSERT(connIndex < MAX_NUM_BLE_CONNS);
// Stop connection event notice
status_t status= Gap_RegisterConnEventCb(NULL, GAP_CB_UNREGISTER, connHandle);
Display_printf(dispHandle, SP_ROW_DEBUG+1, 0, "stop/%d",status);
// Also update the phychange request status for active RSSI tracking connection
connList[connIndex].phyCngRq = FALSE;
connList[connIndex].isAutoPHYEnable = FALSE;
return SUCCESS;
}
static void SimplePeripheral_processConnEvt(Gap_ConnEventRpt_t *pReport)
{
static uint8_t c=0;
Display_printf(dispHandle, SP_ROW_DEBUG, c, "%x", c);
c = 0xf&(++c);
// Get index from handle
uint8_t connIndex = SimplePeripheral_getConnIndex(pReport->handle);
SIMPLEPERIPHERAL_ASSERT(connIndex < MAX_NUM_BLE_CONNS);
// If auto phy change is enabled
if (connList[connIndex].isAutoPHYEnable == TRUE)
{
// Read the RSSI
HCI_ReadRssiCmd(pReport->handle);
}
}