Other Parts Discussed in Thread: SYSCONFIG
CC26x2
Note: The following instructions have been written for SDK 3_40_00_02 but can be adapted to quite any SDK version (that is why I provided the sources but also the diff files). In addition, the code was written for CC2642R but can be adapted to all the devices of the family (CC2652R, CC2652P, CC1352R, CC1352P)
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 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 is 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_cc13x2_26x2_sdk_3_40_00_02\examples\rtos\CC26X2R1_LAUNCHXL\ble5stack\simple_peripheral\Application\simple_peripheral_withoutAutoPHY.c Wed Feb 12 13:28:45 2020 +++ C:\ti\simplelink_cc13x2_26x2_sdk_3_40_00_02\examples\rtos\CC26X2R1_LAUNCHXL\ble5stack\simple_peripheral\Application\simple_peripheral_SIMPLE.c Wed Feb 12 15:35:38 2020 @@ -59,8 +59,6 @@ #include <intrinsics.h> #endif -#include <ti/drivers/utils/List.h> - #include <icall.h> #include "util.h" #include <bcomdef.h> @@ -180,19 +178,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; /********************************************************************* @@ -239,9 +228,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; // Advertising handles static uint8 advHandleLegacy; @@ -281,7 +267,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 @@ -749,18 +734,6 @@ case SP_READ_RPA_EVT: SimplePeripheral_updateRPA(); break; - - 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. @@ -934,28 +907,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; } @@ -1096,11 +1047,6 @@ // Post event to read the current RPA SimplePeripheral_enqueueMsg(SP_READ_RPA_EVT, NULL); } - else if (pData->event == SP_SEND_PARAM_UPDATE_EVT) - { - // Send message to app - SimplePeripheral_enqueueMsg(SP_SEND_PARAM_UPDATE_EVT, pData); - } } /********************************************************************* @@ -1323,34 +1269,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, - SEND_PARAM_UPDATE_DELAY, 0, true, - (UArg) (connList[i].pParamUpdateEventData)); - } - else - { - ICall_free(connList[i].pParamUpdateEventData); - } - } - else - { - status = bleMemAllocError; - } break; } } @@ -1418,28 +1336,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 @@ -1454,25 +1350,6 @@ 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); } @@ -1481,56 +1358,4 @@ } /********************************************************************* - * @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); - } - } -} - -/********************************************************************* *********************************************************************/
Build and test your program. Except the eventual warning raised by SysConfig due to modification we did earlier, everything should build and work smoothly.