This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2640R2F: How to remove RSSI monitoring and auto PHY update from simple_peripheral project

Part Number: CC2640R2F

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)

This modification should free up some FLASH and some CPU time. The amount of stack required by the example should be decreased too.
We are going to basically stop reading the RSSI of our BLE connection. As a result, we will remove all the code allowing to change PHY according to the RSSI value.

How to do this?

  1. Import the project you want (the OOB ble5_simple_peripheral or the project where you have already removed the display function and/or the long range advertisement [see here])

  2. In simple_peripheral.c:

    • Remove the code executed when a HCI_READ_RSSI command is completed. As a result, you can remove the function SimplePeripheral_processCmdCompleteEvt(). Don’t forget to remove all the calls to it.
    • Remove the function SimplePeripheral_initPHYRSSIArray() and its calls
    • Remove the function SimplePeripheral_startAutoPhyChange() and its calls. This will allow you to delete the SimplePeripheral_connEvtCB() function.
    • Remove the function SimplePeripheral_stopAutoPhyChange() and its calls
    • Remove the RSSI thresholds defined (this does not save any FLASH or RAM but it these defines are useless now). Same remark for SP_MAX_RSSI_STORE_DEPTH, SP_RSSI_TRACK_CHNLS . You can also remove all the define related to auto-phy update: SP_PHY_NONE, SP_INVALID_HANDLE, AUTO_PHY_UPDATE (used for auto phy update)
    • Modify the spConnRec_t structure. We don’t need any more the RSSI related elements (rssiArr, rssiCntr, rssiAvg) and the PHY change related (currPhy, rqPhy, phyCngRq, phyRqFailCnt, isAutoPHYEnable). Remove all the code referring to these elements.
    • Remove the call to HCI_ReadRssiCmd(). As a result you can remove the whole SimplePeripheral_processConnEvt() function (and its call too)
    • Remove the functions SimplePeripheral_doSetConnPhy()and SimplePeripheral_setPhy(). You can also remove the global variable menuConnHandle
    • Remove the list setPhyCommStatList and the code related to it (as a result you can remove SimplePeripheral_updatePHYStat() function)
    • Remove the function SimplePeripheral_processCmdCompleteEvt() (this function is now empty, maybe you already removed it before). Don’t forget to remove all the calls to it.

       >> Here are the diff file and the file you are supposed to get if you also removed the display and the secondary advertisement:

                   

simple_peripheral_remove_RSSI_autoPHY.diff
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
--- C:\ti\simplelink_cc2640r2_sdk_3_40_00_10\examples\rtos\CC2640R2_LAUNCHXL\ble5stack\simple_peripheral\src\app\simple_peripheral_without_long_range.c Tue Feb 11 16:12:11 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 13:02:31 2020
@@ -154,17 +154,6 @@
// Size of string-converted device address ("0xXXXXXXXXXXXX")
#define SP_ADDR_STR_SIZE 15
-// For storing the active connections
-#define SP_RSSI_TRACK_CHNLS 1 // Max possible channels can be GAP_BONDINGS_MAX
-#define SP_MAX_RSSI_STORE_DEPTH 5
-#define SP_INVALID_HANDLE 0xFFFF
-#define RSSI_2M_THRSHLD -30
-#define RSSI_1M_THRSHLD -40
-#define RSSI_S2_THRSHLD -50
-#define RSSI_S8_THRSHLD -60
-#define SP_PHY_NONE LL_PHY_NONE // No PHY set
-#define AUTO_PHY_UPDATE 0xFF
-
// Spin if the expression is not true
#define SIMPLEPERIPHERAL_ASSERT(expr) if (!(expr)) simple_peripheral_spin();
@@ -232,14 +221,6 @@
uint16_t connHandle; // Connection Handle
spClockEventData_t* pParamUpdateEventData;
Clock_Struct* pUpdateClock; // pointer to clock struct
- int8_t rssiArr[SP_MAX_RSSI_STORE_DEPTH];
- uint8_t rssiCntr;
- int8_t rssiAvg;
- bool phyCngRq; // Set to true if PHY change request is in progress
- uint8_t currPhy;
- uint8_t rqPhy;
- uint8_t phyRqFailCnt; // PHY change request count
- bool isAutoPHYEnable; // Flag to indicate auto phy change
} spConnRec_t;
/*********************************************************************
@@ -286,12 +267,6 @@
// Per-handle connection info
static spConnRec_t connList[MAX_NUM_BLE_CONNS];
-
-// Current connection handle as chosen by menu
-static uint16_t menuConnHandle = CONNHANDLE_INVALID;
-
-// List to store connection handles for set phy command status's
-static List_List setPhyCommStatList;
// List to store connection handles for queued param updates
static List_List paramUpdateList;
@@ -392,21 +367,11 @@
static void SimplePeripheral_processPasscode(spPasscodeData_t *pPasscodeData);
static void SimplePeripheral_charValueChangeCB(uint8_t paramId);
static status_t SimplePeripheral_enqueueMsg(uint8_t event, void *pData);
-static void SimplePeripheral_processCmdCompleteEvt(hciEvt_CmdComplete_t *pMsg);
-static void SimplePeripheral_initPHYRSSIArray(void);
-static void SimplePeripheral_updatePHYStat(uint16_t eventCode, uint8_t *pMsg);
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 status_t SimplePeripheral_startAutoPhyChange(uint16_t connHandle);
-static status_t SimplePeripheral_stopAutoPhyChange(uint16_t connHandle);
-static status_t SimplePeripheral_setPhy(uint16_t connHandle, uint8_t allPhys,
- uint8_t txPhy, uint8_t rxPhy,
- uint16_t phyOpts);
static uint8_t SimplePeripheral_clearConnListEntry(uint16_t connHandle);
-static void SimplePeripheral_connEvtCB(Gap_ConnEventRpt_t *pReport);
-static void SimplePeripheral_processConnEvt(Gap_ConnEventRpt_t *pReport);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  
6786.simple_peripheral_SIMPLE.c
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/******************************************************************************
@file simple_peripheral.c
@brief This file contains the Simple Peripheral sample application for use
with the CC2650 Bluetooth Low Energy Protocol Stack.
Group: WCS, BTS
Target Device: cc2640r2
******************************************************************************
Copyright (c) 2013-2020, Texas Instruments Incorporated
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Texas Instruments Incorporated nor the names of
its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************
*****************************************************************************/
/*********************************************************************
* INCLUDES
*/
#include <string.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Event.h>
#include <ti/sysbios/knl/Queue.h>
#if !(defined __TI_COMPILER_VERSION__)
#include <intrinsics.h>
#endif
#include <ti/drivers/utils/List.h>
#include <icall.h>
#include "util.h"
#include <bcomdef.h>
/* This Header file contains all BLE API and icall structure definition */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Build and test your program. Everything should build and work smoothly.