TI CC2540 Bluetooth low energy Sample Applications Guide v1.4.1 SWRU297 Version 1.4.1
Page 16 of 36
Copyright © 2011-2015 Texas Instruments, Inc
6.1.2 Basic Operation
Power up the device and press the right button to enable advertising. From a RSC collector peer
device, initiate a device discovery and connection procedure to discover and connect to the
cycling sensor. The peer device should receive a slave security request and initiate a bond.
Once bonded, the collector should discover the RSC service and configure it to enable running
speed and cadence measurements.
Once RSC measurement notifications have been enabled the application will begin sending data
to the peer containing simulated measurement values. Pressing the left button cycles through
different data formats as follows:
At rest: neither instantaneous stride length nor total distance is included in measurement.
Stride: instantaneous stride length is included in measurement.
Distance: total distance is included in measurement.
All: both stride length and total distance are included in measurement.
The application advertises using either a fast interval or a slow interval. When advertising is
initiated by a button press or when a connection is terminated due to link loss, the application will
start advertising at the fast interval for 30 seconds. If the sensor has successfully bonded to a
peer device and stored the devices address in its white list, then for the for the first 10 seconds of
advertising the sensor will only attempt to connect to any device addresses stored in its white list.
After 10 seconds, the sensor will attempt to connect to any peer device that wishes to connect.
Independent of white list use, after 30 seconds of fast interval connection, a 30 second period of
slow interval advertising passes. After this, the device sleeps and waits for the right button to be
pressed before resuming advertising again.
If the device terminates connection for any other reason, the sensor will advertise for 60 seconds
at a slow interval and then sleep if no connection is made. It will begin advertising again only if
the right button is pressed.
6.2 Software Description
The application is implemented in the file runningSensor.c.
6.2.1 Initialization
Initialization of the application occurs in two phases: first, the RunningSensor_Init function is
called by the OSAL. This function configures parameters in the peripheral profile, GAP, and GAP
bond manager. It also sets up the RSC service along with standard GATT and GAP services in
the attribute server. Then it sets an OSAL START_DEVICE_EVT event. This triggers the second
phase of the initialization, which can be found within the RunningSensor_ProcessEvent
function. During this phase, the GAPRole_StartDevice function is called to set up the GAP
functions of the application. Then GAPBOND_Mgr_Register is called to register with the bond
manager.
6.2.2 Event Processing
The application has two main event processing functions, RunningSensor_ProcessEvent and
sensor_ProcessOSALMsg.
Function RunningSensor_ProcessEvent handles events as follows:
SYS_EVENT_MSG: Service the OSAL queue and process OSAL messages.
START_DEVICE_EVT: Start the device, as described in the previous section.
RSC_PERIODIC_EVT: Send periodic CSC measurements.
RSC_CONN_PARAM_UPDATE_EVT: send parameter update until successful
RSC_NEGLECT_TIMEOUT_EVT: see section 6.2.8
RSC_RESET_EVT: reset device as described above