5. Overview of the Initial Project
As mentioned in the introduction, we will be using the Advertiser Demo application, ble_adv
, from the SDK as our starting point.
Before we start modifying the project, we will take a quick look at some key aspects of the implementation.
In e2 studio, open main.c
and scroll down to the function main()
. In this function, the SysInit task, sys_init
, is created and the OS task scheduler is started.
All of this is standard FreeRTOS stuff.
The sys_init()
task is implemented just above main.c
. In this function, we do the following:
Configure the clock tree
Set the sleep mode
Initialize the BLE Manager
Start our main application task (“Advertiser Demo” or
ble_adv_demo_task
)Finally, we delete the SysInit task itself, as it has fulfilled its purpose
At this time we will take a look at the application task itself.
Still in main.c
, scroll down to the application task, OS_TASK_FUNCTION(ble_adv_demo_task, pvParameters)
.
This task does a few things:
It registers itself with the watchdog in order for the watchdog to monitor proper execution of the application task
It starts the BLE device as a peripheral
It configures the BLE peripheral parameters, and starts advertising
It starts an infinite loop where we wait for any incoming BLE events while also maintaining the watchdog
The Advertiser Demo application task will act on the following 3 Bluetooth events:
BLE_EVT_GAP_CONNECTED
which triggershandle_evt_gap_connected()
when a central BLE device connectsBLE_EVT_GAP_DISCONNECTED
which triggershandle_evt_gap_disconnected()
when a central BLE device disconnectsBLE_EVT_GAP_PAIR_REQ
which triggershandle_evt_gap_pair_req()
when a central BLE device requests pairing
Note
You can take a look at the ble_evt_gap
enumeration in sdk\ble\api\include\ble_gap.h
for an overview of the potential BLE GAP events an application task can monitor.
Having reviewed the existing code, we can start modifying the project.