English
Language : 

AN91267 Datasheet, PDF (31/62 Pages) Ramtron International Corporation – Getting Started with PSoC
Getting Started with PSoC® 4 BLE
Code 4. Main Loop Firmware
for(;;)
{
static uint8 toggleTimeout = 0;
CYBLE_BLESS_STATE_T blessState;
uint8 intrStatus;
/* Single API call to service all the BLE stack events. Must be
* called at least once in a BLE connection interval */
CyBle_ProcessEvents();
/* Update Alert Level value on the blue LED */
switch(alertLevel)
{
case NO_ALERT:
Alert_LED_Write(LED_OFF);
break;
case MILD_ALERT:
toggleTimeout++;
if(toggleTimeout == LED_TOGGLE_TIMEOUT)
{
/* Toggle alert LED after timeout */
Alert_LED_Write(Alert_LED_Read() ^ 0x01);
toggleTimeout = 0;
}
break;
case HIGH_ALERT:
Alert_LED_Write(LED_ON);
break;
}
/* Configure BLESS in Deep-Sleep mode */
CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP);
/* Prevent interrupts while entering system low power modes */
intrStatus = CyEnterCriticalSection();
/* Get the current state of BLESS block */
blessState = CyBle_GetBleSsState();
/* If BLESS is in Deep-Sleep mode or the XTAL oscillator is turning on,
* then PSoC 4 BLE can enter Deep-Sleep mode (1.3uA current consumption) */
if(blessState == CYBLE_BLESS_STATE_ECO_ON ||
blessState == CYBLE_BLESS_STATE_DEEPSLEEP)
{
CySysPmDeepSleep();
}
else if(blessState != CYBLE_BLESS_STATE_EVENT_CLOSE)
{
/* If BLESS is active, then configure PSoC 4 BLE system in
* Sleep mode (~1.6mA current consumption) */
CySysPmSleep();
www.cypress.com
Document No. 001-91267 Rev. *D
31