CC2640R2 (BLE5)
Note: The following instructions have been written for SDK 3_40_00_10 but can be adapted to quite any SDK version (that is why I provided the sources but also the diff files)
At the end of this instruction, you will get a project which is not anymore able to send requests to update the connection parameters. The project will still be able to answer a connection request.
The goal is to save flash space and CPU time.
How to do this?
- Import the project you want (the OOB ble5_simple_peripheral or the project where you have already removed the display function, the secondary advertisement and the auto PHY functionalities [see here])
- Do the following in simple_peripheral.c
-
- Remove SimplePeripheral_processParamUpdate() function. Remove the call to the function (you can basically remove all the treatment of the events SP_SEND_PARAM_UPDATE_EVT and GAP_LINK_PARAM_UPDATE_EVENT)
- Modify the spConnRec_t structure to remove the elements pParamUpdateEventData and pUpdateClock. Remove the code using those elements too.
- Remove the list paramUpdateList (and the code referring to). As a result you can remove the functions SimplePeripheral_clearPendingParamUpdate()
- Remove the definition of the struct spConnHandleEntry_t
- Remove the inclusion of the list library: #include <ti/drivers/utils/List.h>
>> Here are the diff file and the file you are supposed to get if you also removed the display, the secondary advertisement and the auto PHY functionalities:
--- C:\ti\simplelink_cc2640r2_sdk_3_40_00_10\examples\rtos\CC2640R2_LAUNCHXL\ble5stack\simple_peripheral\src\app\simple_peripheral_without_autoPHY.c Wed Feb 12 13:02:31 2020
+++ C:\ti\simplelink_cc2640r2_sdk_3_40_00_10\examples\rtos\CC2640R2_LAUNCHXL\ble5stack\simple_peripheral\src\app\simple_peripheral_SIMPLE.c Wed Feb 12 15:55:05 2020
@@ -59,8 +59,6 @@
#include <intrinsics.h>
#endif
-#include <ti/drivers/utils/List.h>
-
#include <icall.h>
#include "util.h"
#include <bcomdef.h>
@@ -208,19 +206,10 @@
uint8_t data[];
} spClockEventData_t;
-// List element for parameter update and PHY command status lists
-typedef struct
-{
- List_Elem elem;
- uint16_t connHandle;
-} spConnHandleEntry_t;
-
// Connected device information
typedef struct
{
uint16_t connHandle; // Connection Handle
- spClockEventData_t* pParamUpdateEventData;
- Clock_Struct* pUpdateClock; // pointer to clock struct
} spConnRec_t;
/*********************************************************************
@@ -267,9 +256,6 @@
// Per-handle connection info
static spConnRec_t connList[MAX_NUM_BLE_CONNS];
-
-// List to store connection handles for queued param updates
-static List_List paramUpdateList;
// GAP GATT Attributes
static uint8_t attDeviceName[GAP_DEVICE_NAME_LEN] = "Simple Peripheral";
@@ -370,7 +356,6 @@
static uint8_t SimplePeripheral_addConn(uint16_t connHandle);
static uint8_t SimplePeripheral_getConnIndex(uint16_t connHandle);
static uint8_t SimplePeripheral_removeConn(uint16_t connHandle);
-static void SimplePeripheral_processParamUpdate(uint16_t connHandle);
static uint8_t SimplePeripheral_clearConnListEntry(uint16_t connHandle);
#ifdef PTM_MODE
void simple_peripheral_handleNPIRxInterceptEvent(uint8_t *pMsg); // Declaration
@@ -843,18 +828,6 @@
SimplePeripheral_updateRPA();
break;
#endif // PRIVACY_1_2_CFG
-
- case SP_SEND_PARAM_UPDATE_EVT:
- {
- // Extract connection handle from data
- uint16_t connHandle = *(uint16_t *)(((spClockEventData_t *)pMsg->pData)->data);
-
- SimplePeripheral_processParamUpdate(connHandle);
-
- // This data is not dynamically allocated
- dealloc = FALSE;
- break;
- }
default:
// Do nothing.
@@ -1031,28 +1004,6 @@
break;
}
- case GAP_LINK_PARAM_UPDATE_EVENT:
- {
- gapLinkUpdateEvent_t *pPkt = (gapLinkUpdateEvent_t *)pMsg;
-
- // Get the address from the connection handle
- linkDBInfo_t linkInfo;
- linkDB_GetInfo(pPkt->connectionHandle, &linkInfo);
-
- // Check if there are any queued parameter updates
- spConnHandleEntry_t *connHandleEntry = (spConnHandleEntry_t *)List_get(¶mUpdateList);
- if (connHandleEntry != NULL)
- {
- // Attempt to send queued update now
- SimplePeripheral_processParamUpdate(connHandleEntry->connHandle);
-
- // Free list element
- ICall_free(connHandleEntry);
- }
-
- break;
- }
-
default:
break;
}
@@ -1438,35 +1389,6 @@
// Found available entry to put a new connection info in
connList[i].connHandle = connHandle;
- // Allocate data to send through clock handler
- connList[i].pParamUpdateEventData = ICall_malloc(sizeof(spClockEventData_t) +
- sizeof (uint16_t));
- if(connList[i].pParamUpdateEventData)
- {
- connList[i].pParamUpdateEventData->event = SP_SEND_PARAM_UPDATE_EVT;
- *((uint16_t *)connList[i].pParamUpdateEventData->data) = connHandle;
-
- // Create a clock object and start
- connList[i].pUpdateClock
- = (Clock_Struct*) ICall_malloc(sizeof(Clock_Struct));
-
- if (connList[i].pUpdateClock)
- {
- Util_constructClock(connList[i].pUpdateClock,
- SimplePeripheral_clockHandler,
- SP_SEND_PARAM_UPDATE_DELAY, 0, true,
- (UArg) (connList[i].pParamUpdateEventData));
- }
- else
- {
- ICall_free(connList[i].pParamUpdateEventData);
- }
- }
- else
- {
- status = bleMemAllocError;
- }
-
break;
}
}
@@ -1534,28 +1456,6 @@
}
/*********************************************************************
- * @fn SimplePeripheral_clearPendingParamUpdate
- *
- * @brief clean pending param update request in the paramUpdateList list
- *
- * @param connHandle - connection handle to clean
- *
- * @return none
- */
-void SimplePeripheral_clearPendingParamUpdate(uint16_t connHandle)
-{
- List_Elem *curr;
-
- for (curr = List_head(¶mUpdateList); curr != NULL; curr = List_next(curr))
- {
- if (((spConnHandleEntry_t *)curr)->connHandle == connHandle)
- {
- List_remove(¶mUpdateList, curr);
- }
- }
-}
-
-/*********************************************************************
* @fn SimplePeripheral_removeConn
*
* @brief Remove a device from the connected device list
@@ -1570,83 +1470,11 @@
if(connIndex != MAX_NUM_BLE_CONNS)
{
- Clock_Struct* pUpdateClock = connList[connIndex].pUpdateClock;
-
- if (pUpdateClock != NULL)
- {
- // Stop and destruct the RTOS clock if it's still alive
- if (Util_isActive(pUpdateClock))
- {
- Util_stopClock(pUpdateClock);
- }
-
- // Destruct the clock object
- Clock_destruct(pUpdateClock);
- // Free clock struct
- ICall_free(pUpdateClock);
- // Free ParamUpdateEventData
- ICall_free(connList[connIndex].pParamUpdateEventData);
- }
- // Clear pending update requests from paramUpdateList
- SimplePeripheral_clearPendingParamUpdate(connHandle);
// Clear Connection List Entry
SimplePeripheral_clearConnListEntry(connHandle);
}
return connIndex;
-}
-
-/*********************************************************************
- * @fn SimplePeripheral_processParamUpdate
- *
- * @brief Process a parameters update request
- *
- * @return None
- */
-static void SimplePeripheral_processParamUpdate(uint16_t connHandle)
-{
- gapUpdateLinkParamReq_t req;
- uint8_t connIndex;
-
- req.connectionHandle = connHandle;
- req.connLatency = DEFAULT_DESIRED_SLAVE_LATENCY;
- req.connTimeout = DEFAULT_DESIRED_CONN_TIMEOUT;
- req.intervalMin = DEFAULT_DESIRED_MIN_CONN_INTERVAL;
- req.intervalMax = DEFAULT_DESIRED_MAX_CONN_INTERVAL;
-
- connIndex = SimplePeripheral_getConnIndex(connHandle);
- if (connIndex >= MAX_NUM_BLE_CONNS)
- {
- return;
- }
-
-
- // Deconstruct the clock object
- Clock_destruct(connList[connIndex].pUpdateClock);
- // Free clock struct, only in case it is not NULL
- if (connList[connIndex].pUpdateClock != NULL)
- {
- ICall_free(connList[connIndex].pUpdateClock);
- connList[connIndex].pUpdateClock = NULL;
- }
- // Free ParamUpdateEventData, only in case it is not NULL
- if (connList[connIndex].pParamUpdateEventData != NULL)
- ICall_free(connList[connIndex].pParamUpdateEventData);
-
- // Send parameter update
- bStatus_t status = GAP_UpdateLinkParamReq(&req);
-
- // If there is an ongoing update, queue this for when the udpate completes
- if (status == bleAlreadyInRequestedMode)
- {
- spConnHandleEntry_t *connHandleEntry = ICall_malloc(sizeof(spConnHandleEntry_t));
- if (connHandleEntry)
- {
- connHandleEntry->connHandle = connHandle;
-
- List_put(¶mUpdateList, (List_Elem *)connHandleEntry);
- }
- }
}
#ifdef PTM_MODE
Build and test your program. Everything should build and work smoothly.