English
Language : 

AN91267 Datasheet, PDF (27/62 Pages) Ramtron International Corporation – Getting Started with PSoC
Getting Started with PSoC® 4 BLE
#include <project.h>
Code 1. System Initialization Firmware
#define LED_ON
#define LED_OFF
(0u)
(1u)
#define NO_ALERT
#define MILD_ALERT
#define HIGH_ALERT
(0u)
(1u)
(2u)
#define LED_TOGGLE_TIMEOUT
(100u)
void StackEventHandler(uint32 event, void *eventParam);
void IasEventHandler(uint32 event, void *eventParam);
uint8 alertLevel;
int main()
{
CYBLE_API_RESULT_T apiResult;
CyGlobalIntEnable;
apiResult = CyBle_Start(StackEventHandler);
if(apiResult != CYBLE_ERROR_OK)
{
/* BLE stack initialization failed, check your configuration */
CYASSERT(0);
}
CyBle_IasRegisterAttrCallback(IasEventHandler);
}
BLE Stack Event Handler
The BLE stack within the BLE Component generates events to provide the BLE interface status and data to the application
firmware through the BLE stack event handler registered by you. The event handler must handle a few basic events from the
stack, such as device connection and stack on, and configure the stack accordingly to establish and maintain the BLE link. For
the Find Me Target application that you are creating, the BLE stack event handler must process all the events described in
Table 1. The flow chart and the firmware for handling BLE stack events are shown in Figure 39 and Code 2.
Table 1. BLE Stack Events
BLE Stack Event Name
Event Description
CYBLE_EVT_STACK_ON
BLE stack initialization completed
successfully.
CYBLE_EVT_GAP_DEVICE_DISCONNECTED
BLE link with the peer device is
disconnected.
CYBLE_EVT_GAP_DEVICE_CONNECTED
BLE link with the peer device is
established.
CYBLE_EVT_GAPP_ADVERTISEMENT_START_STOP BLE stack advertisement start/stop
event.
Event Handler Action
Start advertisement and reflect the
advertisement state on the LED.
Restart advertisement and reflect the
advertisement state on the LED.
Update the BLE link state on the LED.
Configure the device in Stop mode if the
advertisement has timed out.
www.cypress.com
Document No. 001-91267 Rev. *D
27