TI CC2540 Bluetooth low energy Sample Applications Guide v1.4.1 SWRU297 Version 1.4.1
Page 30 of 36
Copyright © 2011-2015 Texas Instruments, Inc
16.1.2 Basic Operation
When the application powers up it displays "Time App", the BD address of the device, and a
default time and date of "00:00 Jan01 2000". To connect, press Joystick Up to start advertising
then initiate a connection from a peer device. The connection status will be displayed. Once
connected, the application will attempt to discover the following services on the peer device:
Current Time Service
DST Change Service
Reference Time Service
Alert Notification Service
Phone Alert Status Service
Network Availability Service
Battery Service
The discovery procedure will cache handles of interest. When bonded to a peer device, the
handles are saved so that the discovery procedure is not performed on subsequent connections.
If a service is discovered certain service characteristics are read and displayed. The network
availability status and battery level will be displayed and the current time will be updated.
The application also enables notification or indication for characteristics that support these
operations. This allows the peer device to send notifications or indications updating the time,
network availability, or battery status. The peer device can also send alert notification messages
and unread message alerts. These updates and messages will be displayed on the LCD.
The peer device may initiate pairing. If a passcode is required the application will generate and
display a random passcode. Enter this passcode on the peer device to proceed with pairing.
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 followed by the slow interval. When a
connection is terminated for any other reason the application will start advertising at the slow
interval. The advertising intervals and durations are configurable in file timeapp.c.
16.2 Software Description
The TimeApp application is implemented in the following files:
timeapp.c: Main initialization, event handling and callback functions.
timeapp_clock.c: Clock timekeeping and display functions.
timeapp_config.c: Characteristic configuration functions.
timeapp_discovery.c: Service discovery functions.
timeapp_ind.c: Indication and notification handling functions.
16.2.1 Initialization
The initialization of the application occurs in two phases: first, the TimeApp_Init function is called
by the OSAL. This function configures parameters in the peripheral profile, GAP, and GAP bond
manager and also initializes GATT for client operation. It also sets up 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 TimeApp_ProcessEvent
function. During this phase, the GAPRole_StartDevice function is called to set up the GAP
functions of the application. Then GAPBondMgr_Register is called to register with the bond
manager.
16.2.2 Event Processing
The application has two main event processing functions, TimeApp_ProcessEvent and
timeApp_ProcessOSALMsg.
Function TimeApp_ProcessEvent handles events as follows:
SYS_EVENT_MSG: Service the OSAL queue and process OSAL messages.