Beispiel #1
0
/*******************************************************************************
* Function Name: LowPowerImplementation()
********************************************************************************
* Summary:
* Implements low power in the project.
*
* Parameters:
* None
*
* Return:
* None
*
* Theory:
* The function tries to enter deep sleep as much as possible - whenever the 
* BLE is idle and the UART transmission/reception is not happening. At all other
* times, the function tries to enter CPU sleep.
*
*******************************************************************************/
static void LowPowerImplementation(void)
{
    CYBLE_LP_MODE_T bleMode;
    uint8 interruptStatus;
    
    /* For advertising and connected states, implement deep sleep 
     * functionality to achieve low power in the system. For more details
     * on the low power implementation, refer to the Low Power Application 
     * Note.
     */
    if((CyBle_GetState() == CYBLE_STATE_ADVERTISING) || 
       (CyBle_GetState() == CYBLE_STATE_CONNECTED))
    {
        /* Request BLE subsystem to enter into Deep-Sleep mode between connection and advertising intervals */
        bleMode = CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP);
        /* Disable global interrupts */
        interruptStatus = CyEnterCriticalSection();
        /* When BLE subsystem has been put into Deep-Sleep mode */
        if(bleMode == CYBLE_BLESS_DEEPSLEEP)
        {
            /* And it is still there or ECO is on */
            if((CyBle_GetBleSsState() == CYBLE_BLESS_STATE_ECO_ON) || 
               (CyBle_GetBleSsState() == CYBLE_BLESS_STATE_DEEPSLEEP))
            {
            #if (DEBUG_UART_ENABLED == ENABLED)
                /* Put the CPU into the Deep-Sleep mode when all debug information has been sent */
                if((UART_DEB_SpiUartGetTxBufferSize() + UART_DEB_GET_TX_FIFO_SR_VALID) == 0u)
                {
                    CySysPmDeepSleep();
                }
                else /* Put the CPU into Sleep mode and let SCB to continue sending debug data */
                {
                    CySysPmSleep();
                }
            #else
                CySysPmDeepSleep();
            #endif /* (DEBUG_UART_ENABLED == ENABLED) */
            }
        }
        else /* When BLE subsystem has been put into Sleep mode or is active */
        {
            /* And hardware doesn't finish Tx/Rx opeation - put the CPU into Sleep mode */
            if(CyBle_GetBleSsState() != CYBLE_BLESS_STATE_EVENT_CLOSE)
            {
                CySysPmSleep();
            }
        }
        /* Enable global interrupt */
        CyExitCriticalSection(interruptStatus);
    }
}
Beispiel #2
0
/*******************************************************************************
* Function Name: System_ManagePower
********************************************************************************
*
* Summary:
*  configures the peripherals used in the design and the device into possible
*  low power modes based on the state of the system.
*
* Parameters:  
*  None
*
* Return: 
*  None
*
*******************************************************************************/
void System_ManagePower (void)
{
    CYBLE_LP_MODE_T lpMode;
    CYBLE_BLESS_STATE_T blessState;
    uint32 intStatus;
    
    lpMode = CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP); /* try configuring BLESS in DeepSleep mode */
        
    intStatus = CyEnterCriticalSection();
    
    blessState = CyBle_GetBleSsState(); /* Check the current state of the BLESS */

    if(lpMode == CYBLE_BLESS_DEEPSLEEP) /* BLESS had entered low power mode */
    {   
        /* and it continues to be in a state where BLESS can enter DeepSleep mode */
        if(blessState == CYBLE_BLESS_STATE_ECO_ON || blessState == CYBLE_BLESS_STATE_DEEPSLEEP)
        {
            #if(CONSOLE_LOG_ENABLED)
                /* Put the device into the Dee Sleep mode only when all debug information has been sent */
            if((Debug_Console_SpiUartGetTxBufferSize() + Debug_Console_GET_TX_FIFO_SR_VALID) == 0u)
            {
                CySysPmDeepSleep();
            }
            else
            {
                /* Wait for UART interface to finish data transfer */
                CySysPmSleep();
            }
            #else
            CySysPmDeepSleep();    
            #endif    
        }
    }
    else
    {
        /* BLESS can't enter DeepSleep as next BLE connection interval is close by, go to Sleep for now */
        if(blessState != CYBLE_BLESS_STATE_EVENT_CLOSE)
        {
            CySysPmSleep();
        }
    }
    
    CyExitCriticalSection(intStatus);
}
Beispiel #3
0
/*******************************************************************************
* Function Name: LowPowerImplementation()
********************************************************************************
* Summary:
* Implements low power in the project.
*
* Parameters:
* None
*
* Return:
* None
*
* Theory:
* The function tries to enter deep sleep as much as possible - whenever the 
* BLE is idle and the UART transmission/reception is not happening. At all other
* times, the function tries to enter CPU sleep.
*
*******************************************************************************/
static void LowPowerImplementation(void)
{
    CYBLE_LP_MODE_T bleMode;
    uint8 interruptStatus;
    
    /* For advertising and connected states, implement deep sleep 
     * functionality to achieve low power in the system. For more details
     * on the low power implementation, refer to the Low Power Application 
     * Note.
     */
    if((CyBle_GetState() == CYBLE_STATE_ADVERTISING) || 
       (CyBle_GetState() == CYBLE_STATE_CONNECTED))
    {
        bleMode = CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP);
        interruptStatus = CyEnterCriticalSection();
        if(bleMode == CYBLE_BLESS_DEEPSLEEP)
        {
            if((CyBle_GetBleSsState() == CYBLE_BLESS_STATE_ECO_ON) || 
               (CyBle_GetBleSsState() == CYBLE_BLESS_STATE_DEEPSLEEP))
            {
                /* Deep sleep only if UART completes transfer and we
                 * are not waiting for the user to enter anything.
                 */
                if(((UART_SpiUartGetTxBufferSize() + UART_GET_TX_FIFO_SR_VALID) == 0u) && 
                   (ancsUsageState != ANCS_USAGE_INCOMING_CALL_WAITING_FOR_INPUT))
                {
                    CySysPmDeepSleep();
                }
                else
                {
                    CySysPmSleep();
                }
            }
        }
        else
        {
            if(CyBle_GetBleSsState() != CYBLE_BLESS_STATE_EVENT_CLOSE)
            {
                CySysPmSleep();
            }
        }
        CyExitCriticalSection(interruptStatus);
    }
}
Beispiel #4
0
int main()
{
    CyGlobalIntEnable;                  /* Enable global interrupts */
    UART_RX_ISR_StartEx(RX_interrupt);  /* Set interrupt address */
    UART_BLE_RX_ISR_StartEx(BLE_RX_interrupt);  /* Set interrupt address */
    UART_Start();                       /* Start UART */
    UART_BLE_Start();                       /* Start UART */
    CySysPmSleep();                     /* Enter Sleep mode */
    return 0;
}
Beispiel #5
0
/*******************************************************************************
* Function Name: main
********************************************************************************
*
* Summary:
*  Main function.
*
* Parameters:
*  None
*
* Return:
*  None
*
*******************************************************************************/
int main()
{
    CYBLE_API_RESULT_T apiResult;
    CYBLE_STATE_T bleState;

    CyGlobalIntEnable;
	
    PWM_Start();
	UART_Start();
	UART_UartPutString("Welcome to BLE OOB Pairing Demo\r\n");

    apiResult = CyBle_Start(StackEventHandler);

    if(apiResult != CYBLE_ERROR_OK)
    {
        /* BLE stack initialization failed, check your configuration */
        CYASSERT(0);
    }

    CyBle_IasRegisterAttrCallback(IasEventHandler);

    for(;;)
    {
        /* Single API call to service all the BLE stack events. Must be
         * called at least once in a BLE connection interval */
        CyBle_ProcessEvents();

        bleState = CyBle_GetState();

        if(bleState != CYBLE_STATE_STOPPED &&
            bleState != CYBLE_STATE_INITIALIZING)
        {
            /* Configure BLESS in DeepSleep mode  */
            CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP);

            /* Configure PSoC 4 BLE system in sleep mode */
            CySysPmSleep();

            /* BLE link layer timing interrupt will wake up the system */
        }
    }
}
Beispiel #6
0
int main()
{
    uint8 interruptState;

    CyGlobalIntEnable; /* Enable global interrupts */
    
    EZI2C_Start(); /* Start EZI2C component */
    
    /*
    * Set up communication and initialize data buffer to CapSense data structure
    * to use Tuner application
    */
    EZI2C_EzI2CSetBuffer1(sizeof(CapSense_dsRam), sizeof(CapSense_dsRam),
                            (uint8 *)&CapSense_dsRam);

    CapSense_Start(); /* Initialize component */

    BleHandler_Init();
    Tuner_Init(BleHandler_RefreshBuffer, BleHandler_SendBuffer);

    CapSense_ScanAllWidgets(); /* Scan all widgets */

    for(;;)
    {
        /* Do this only when a scan is done */
        interruptState = CyEnterCriticalSection();
        if(CapSense_NOT_BUSY == CapSense_IsBusy())
        {
            CyExitCriticalSection(interruptState);
            CapSense_ProcessAllWidgets(); /* Process all widgets */
            Tuner_RunTuner();

            if (CapSense_IsAnyWidgetActive()) /* Scan result verification */
            {
                /* add custom tasks to execute when touch detected */
            }
            CapSense_ScanAllWidgets(); /* Start next scan */
        }
        CySysPmSleep(); /* Sleep until scan is finished */
        CyExitCriticalSection(interruptState);
    }
}
Beispiel #7
0
/*******************************************************************************
* Function Name: EnterLowPowerMode
********************************************************************************
*
* Summary:
*  This configures the BLESS and system in low power mode whenever possible.
*
* Parameters:
*  None
*
* Return:
*  None
*
*******************************************************************************/
void EnterLowPowerMode(void)
{
    CYBLE_BLESS_STATE_T blessState;
    uint8 intrStatus;

    /* 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) */
        CySysClkWriteHfclkDirect(CY_SYS_CLK_HFCLK_ECO);
        CySysClkImoStop();
        CySysPmSleep();
        CySysClkImoStart();
        CySysClkWriteHfclkDirect(CY_SYS_CLK_HFCLK_IMO);
    }
    else
    {
        /* Keep trying to enter either Sleep or Deep-Sleep mode */
    }

    CyExitCriticalSection(intrStatus);
}
Beispiel #8
0
void LowPower(void)
{
    CYBLE_LP_MODE_T pwrState;
    CYBLE_BLESS_STATE_T blessState;
    uint8 intStatus = 0;

    pwrState  = CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP); /* Configure BLESS in Deep-Sleep mode */

    intStatus = CyEnterCriticalSection(); /* No interrupts allowed while entering system low power modes */
        blessState = CyBle_GetBleSsState();

        if(pwrState == CYBLE_BLESS_DEEPSLEEP) /* Make sure BLESS is in Deep-Sleep before configuring system in Deep-Sleep */
        {
            if(blessState == CYBLE_BLESS_STATE_ECO_ON || blessState == CYBLE_BLESS_STATE_DEEPSLEEP)
            {
                CySysPmDeepSleep(); /* System Deep-Sleep. 1.3uA mode */
            }
        }
        else if (blessState != CYBLE_BLESS_STATE_EVENT_CLOSE)
        {
             /* Change HF clock source from IMO to ECO, as IMO can be stopped to save power */
            CySysClkWriteHfclkDirect(CY_SYS_CLK_HFCLK_ECO); 
            
            /* Stop IMO for reducing power consumption */
            CySysClkImoStop(); 
            
            /* Put the CPU to Sleep. 1.1mA mode */
            CySysPmSleep();
            
            /* Starts execution after waking up, start IMO */
            CySysClkImoStart();
            
            /* Change HF clock source back to IMO */
            CySysClkWriteHfclkDirect(CY_SYS_CLK_HFCLK_IMO);
        }
    CyExitCriticalSection(intStatus);
}
Beispiel #9
0
int main()
{
    const char8 serialNumber[] = SERIAL_NUMBER;
    CYBLE_LP_MODE_T lpMode;
    CYBLE_BLESS_STATE_T blessState;

    packetRXFlag = 0u;

    DBG_PRINT_TEXT("\r\n");
    DBG_PRINT_TEXT("\r\n");
    DBG_PRINT_TEXT("===============================================================================\r\n");
    DBG_PRINT_TEXT("=              BLE_External_Memory_Bootloadable Application Started            \r\n");
    DBG_PRINT_TEXT("=              Version: 1.0                                                    \r\n");
#if (LED_ADV_COLOR == LED_GREEN)
    DBG_PRINT_TEXT("=              Code: LED_GREEN                                                 \r\n");
#else
    DBG_PRINT_TEXT("=              Code: LED_BLUE                                                 \r\n");
#endif /*LED_ADV_COLOR == LED_GREEN*/
    DBG_PRINTF    ("=              Compile Date and Time : %s %s                                   \r\n", __DATE__,__TIME__);
#if (ENCRYPTION_ENABLED == YES)
    DBG_PRINT_TEXT("=              ENCRYPTION OPTION : ENABLED                                                \r\n");
#else
    DBG_PRINT_TEXT("=              ENCRYPTION OPTION : DISABLED                                               \r\n");
#endif /*LED_ADV_COLOR == LED_GREEN*/
#if (CI_PACKET_CHECKSUM_CRC == YES)
    DBG_PRINT_TEXT("=              PACKET CHECKSUM TYPE: CRC-16-CCITT                                         \r\n");
#else
    DBG_PRINT_TEXT("=              PACKET CHECKSUM TYPE: BASIC SUMMATION                                      \r\n");
#endif /*LED_ADV_COLOR == LED_GREEN*/

    DBG_PRINT_TEXT("===============================================================================\r\n");
    DBG_PRINT_TEXT("\r\n");
    DBG_PRINT_TEXT("\r\n");

    CyGlobalIntEnable;

    Bootloading_LED_Write(LED_OFF);
    Advertising_LED_1_Write(LED_OFF);
    Advertising_LED_2_Write(LED_OFF);


    CyBle_Start(AppCallBack);

    /*Initialization of encryption in BLE stack*/
#if (ENCRYPTION_ENABLED == YES)
    CR_Initialization();
#endif /*(ENCRYPTION_ENABLED == YES)*/


    /* Set Serial Number string not initialised in GUI */
    CyBle_DissSetCharacteristicValue(CYBLE_DIS_SERIAL_NUMBER, sizeof(serialNumber), (uint8 *)serialNumber);

    /* Disable bootloader service */
    CyBle_GattsDisableAttribute(cyBle_customs[0].customServiceHandle);

    /* Force client to rediscover services in range of bootloader service */
    WriteAttrServChanged();

    WDT_Start();

    while(1u == 1u)
    {
        if(CyBle_GetState() != CYBLE_STATE_INITIALIZING)
        {
            /* Enter DeepSleep mode between connection intervals */
            lpMode = CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP);
            CyGlobalIntDisable;
            blessState = CyBle_GetBleSsState();

            if(lpMode == CYBLE_BLESS_DEEPSLEEP)
            {
                if(blessState == CYBLE_BLESS_STATE_ECO_ON || blessState == CYBLE_BLESS_STATE_DEEPSLEEP)
                {
                    CySysPmDeepSleep();
                }
            }
            else
            {
                if(blessState != CYBLE_BLESS_STATE_EVENT_CLOSE)
                {
                    CySysPmSleep();
                }
            }
            CyGlobalIntEnable;
        }

        CyBle_ProcessEvents();

        /* If key press event was detected - debounce it and switch to bootloader emulator mode */
        if (Bootloader_Service_Activation_Read() == 0u)
        {
            CyDelay(100u);

            if (Bootloader_Service_Activation_Read() == 0u)
            {
                DBG_PRINTF("Bootloader service activated!\r\n");
                CyBle_GattsEnableAttribute(cyBle_customs[0u].customServiceHandle);
                LED_WRITE_MACRO(LED_OFF);
                bootloadingMode = 1u;

                /* Force client to rediscover services in range of bootloader service */
                WriteAttrServChanged();

                BootloaderEmulator_Start();
            }
        }
    }
}
Beispiel #10
0
/*******************************************************************************
* Function Name: System_ManagePower()
********************************************************************************
*
* Summary:
*   This function puts the system in appropriate low power modes based on the 
*   state of BLESS and application power state.
*
* Parameters:
*  none
*
********************************************************************************/
inline void System_ManagePower()
{
    /* Variable declarations */
    CYBLE_BLESS_STATE_T blePower;
    uint8 interruptStatus ;
    
   /* Disable global interrupts to avoid any other tasks from interrupting this section of code*/
    interruptStatus  = CyEnterCriticalSection();
    
    /* Get current state of BLE sub system to check if it has successfully entered deep sleep state */
    blePower = CyBle_GetBleSsState();
    
    /* System can enter DeepSleep only when BLESS and rest of the application are in DeepSleep or equivalent
     * power modes */
    if((blePower == CYBLE_BLESS_STATE_DEEPSLEEP || blePower == CYBLE_BLESS_STATE_ECO_ON) && 
        Application_GetPowerState() == DEEPSLEEP)
    {
        Application_SetPowerState(WAKEUP_DEEPSLEEP);
        
#if DEBUG_ENABLE
        DeepSleep_Write(1);
#endif /* End of #if DEBUG_ENABLE */
        
        CySysPmDeepSleep();
        
#if DEBUG_ENABLE
        DeepSleep_Write(0);
#endif /* End of #if DEBUG_ENABLE */
    }
    else if((blePower != CYBLE_BLESS_STATE_EVENT_CLOSE))
    {
        if(Application_GetPowerState() == DEEPSLEEP)
        {
            Application_SetPowerState(WAKEUP_DEEPSLEEP);
            
            /* change HF clock source from IMO to ECO, as IMO can be stopped to save power */
            CySysClkWriteHfclkDirect(CY_SYS_CLK_HFCLK_ECO); 
            /* stop IMO for reducing power consumption */
            CySysClkImoStop(); 
            /* put the CPU to sleep */
#if DEBUG_ENABLE
            Sleep_Write(1);
#endif /* End of #if DEBUG_ENABLE */      

            CySysPmSleep();
            
#if DEBUG_ENABLE
            Sleep_Write(0);
#endif /* End of #if DEBUG_ENABLE */           
            /* starts execution after waking up, start IMO */
            CySysClkImoStart();
            /* change HF clock source back to IMO */
            CySysClkWriteHfclkDirect(CY_SYS_CLK_HFCLK_IMO);
        }
        else if(Application_GetPowerState() == SLEEP )
        {
            /* If the application is using IMO for its operation, we shouldn't switch over the HFCLK source */
            Application_SetPowerState(WAKEUP_SLEEP);
            
#if DEBUG_ENABLE
            Sleep_Write(1);
#endif /* End of #if DEBUG_ENABLE */     

            CySysPmSleep();
            
#if DEBUG_ENABLE
            Sleep_Write(0);
#endif /* End of #if DEBUG_ENABLE */
        }
    }
    
    /* Enable interrupts */
    CyExitCriticalSection(interruptStatus );
}
Beispiel #11
0
/*******************************************************************************
* Function Name: main
********************************************************************************
*
* Summary:
*  Main function.
*
* Parameters:  
*  None
*
* Return: 
*  None
*
*******************************************************************************/
int main()
{
    CYBLE_LP_MODE_T lpMode;
    CYBLE_BLESS_STATE_T blessState;
    CYBLE_API_RESULT_T apiResult = CYBLE_ERROR_OK;
  
    CyGlobalIntEnable; 

    /* ADD_CODE_TO - Start the BLE component and register StackEventHandler function */
    apiResult = CyBle_Start(StackEventHandler);

    if(apiResult != CYBLE_ERROR_OK)
    {
        /* BLE stack initialization failed, check your configuration */
        CYASSERT(0);
    }

    /* Register LLS event handler function */
    CyBle_LlsRegisterAttrCallback(LlsEventHandler);
        
    while(1)
    {
        /* Process all the pending BLE tasks. This single API call will service all 
         * the BLE stack events. This API MUST be called at least once per BLE connection interval */
        CyBle_ProcessEvents();

        if(CyBle_GetState() != CYBLE_STATE_INITIALIZING) /* Waiting for BLE component initialization */
        {
            static uint8 blinkTimeout = BLINK_TIMEOUT;

            /* Update link loss alert LED status based on IAS Alert level characteristic */
            if(CyBle_GetState() == CYBLE_STATE_DISCONNECTED || 
                (CyBle_GetState() == CYBLE_STATE_CONNECTED && CyBle_GetRssi() > RSSI_THRESHOLD))
            {
                switch(linkAlertLevel)
                {
                    case NO_ALERT:
                        Link_Alert_LED_Write(LED_OFF);
                    break;

                    case MILD_ALERT:
                    if(--blinkTimeout == 0)
                    {
                        Link_Alert_LED_Write(Link_Alert_LED_Read() ^ 0x01);
                        blinkTimeout = BLINK_TIMEOUT;
                    }
                    break;

                    case HIGH_ALERT:
                        Link_Alert_LED_Write(LED_ON);
                    break;
                }
            }
            else
            {
                Link_Alert_LED_Write(LED_OFF);
            }
        }
        
        lpMode = CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP);
        CyGlobalIntDisable;
        blessState = CyBle_GetBleSsState();

        if(lpMode == CYBLE_BLESS_DEEPSLEEP) 
        {   
            if(blessState == CYBLE_BLESS_STATE_ECO_ON || blessState == CYBLE_BLESS_STATE_DEEPSLEEP)
            {
                /* Put the device into the Deep Sleep mode only when all debug information has been sent */
                if((UART_SpiUartGetTxBufferSize() + UART_GET_TX_FIFO_SR_VALID) == 0u)
                {
                    CySysPmDeepSleep();
                }
                else
                {
                    CySysPmSleep();
                }
            }
        }
        else
        {
            if(blessState != CYBLE_BLESS_STATE_EVENT_CLOSE)
            {
                CySysPmSleep();
            }
        }
        CyGlobalIntEnable;
        
        if((cyBle_pendingFlashWrite != 0u) &&
                    ((UART_SpiUartGetTxBufferSize() + UART_GET_TX_FIFO_SR_VALID) == 0u))
        {
            apiResult = CyBle_StoreBondingData(0u);
            printf("Store bonding data, status: %x \r\n", apiResult);
        }
    }
}
Beispiel #12
0
int main()
{
    CYBLE_LP_MODE_T lpMode;
    CYBLE_BLESS_STATE_T blessState;
    CYBLE_STACK_LIB_VERSION_T stackVersion;

    CyGlobalIntEnable;

    UART_DEB_Start();               /* Start communication component */
    printf("BLE Heart Rate Collector Example Project \r\n");

    Disconnect_LED_Write(LED_OFF);
    Scanning_LED_Write(LED_OFF);
    Notification_LED_Write(LED_OFF);

    apiResult = CyBle_Start(AppCallBack);
    if(apiResult != CYBLE_ERROR_OK)
    {
        printf("CyBle_Start API Error: 0x%x \r\n", apiResult);
    }

    apiResult = CyBle_GetStackLibraryVersion(&stackVersion);
    if(apiResult != CYBLE_ERROR_OK)
    {
        printf("CyBle_GetStackLibraryVersion API Error: 0x%x \r\n", apiResult);
    }
    else
    {
        printf("Stack Version: %d.%d.%d.%d \r\n", stackVersion.majorVersion,
               stackVersion.minorVersion, stackVersion.patch, stackVersion.buildNumber);
    }

    CyBle_BasRegisterAttrCallback(BasCallBack);
    HrsInit();

    while(1)
    {
        if(CyBle_GetState() != CYBLE_STATE_INITIALIZING)
        {
            /* Enter DeepSleep mode between connection intervals */
            lpMode = CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP);
            CyGlobalIntDisable;
            blessState = CyBle_GetBleSsState();

            if(lpMode == CYBLE_BLESS_DEEPSLEEP)
            {
                if(blessState == CYBLE_BLESS_STATE_ECO_ON || blessState == CYBLE_BLESS_STATE_DEEPSLEEP)
                {
                    /* Put the device into the DeepSleep mode only when all debug information has been sent */
                    if((UART_DEB_SpiUartGetTxBufferSize() + UART_DEB_GET_TX_FIFO_SR_VALID) == 0u)
                    {
                        CySysPmDeepSleep();
                    }
                    else
                    {
                        CySysPmSleep();
                    }
                }
            }
            else
            {
                if(blessState != CYBLE_BLESS_STATE_EVENT_CLOSE)
                {
                    CySysPmSleep();
                }
            }
            CyGlobalIntEnable;

            /* Handle advertising led blinking */
            HandleLeds();
        }

        /* Store bonding data to flash only when all debug information has been sent */
        if((cyBle_pendingFlashWrite != 0u) &&
                ((UART_DEB_SpiUartGetTxBufferSize() + UART_DEB_GET_TX_FIFO_SR_VALID) == 0u))
        {
            apiResult = CyBle_StoreBondingData(0u);
            printf("Store bonding data, status: %x \r\n", apiResult);
        }


        /*******************************************************************
        *  Processes all pending BLE events in the stack
        *******************************************************************/
        CyBle_ProcessEvents();
    }
}
Beispiel #13
0
/*******************************************************************************
* Function Name: main
********************************************************************************
*
* Summary:
*   This is the main entry point for this application. This function initializes all the 
*	components used in the project. It computes the frequency whenever a capture event is 
*
* Parameters:  
*   None
*
* Return:
*   None
*
*******************************************************************************/
int main()
{
	#if(UART_DEBUG_ENABLE)
		/* Variable to store the loop number */
		uint8 loopNo = 0;
	#endif
	/* Enable global interrupt mask */
	CyGlobalIntEnable;	
	
	/* Disable ILO as it is not used */
	CySysClkIloStop();
	
	/* Initialize components related to BLE communication */
	InitializeBLESystem();
	
	/* Initialize components related to frequency counting */
	Initialize_Freq_Meas_System();
	
	/* Start UART component if UART debug is enabled */
	#if(UART_DEBUG_ENABLE)
		/* Start UART component and send welcome string to hyper terminal on PC */
		UART_Start();
		UART_UartPutString("Welcome to Frequency Measurement Using PSoC 4 BLE\n");
		UART_PutCRLF();
	#endif
	
    while(1)
    {
		/* Compute frequency once in every PWM interval(2s) */
		if(Calculate_Frequency == TRUE)
		{
			/* Check if valid capture event is detected */
			if((Input_Sig_Ctr_Capture == 1) && (Ref_Clk_Ctr_Capture == 1))
			{
				/* Compute frequency using the latched count value, computed frequency 
				will be stored in ASCII format in a global array */
				Compute_Frequency();
				
				#if(UART_DEBUG_ENABLE)
					/* Print input signal counter value in hexadecimal */
					UART_UartPutString("Input Signal Counter Value: ");
					UART_SendDebugData(Input_Signal_Count);
					UART_UartPutString("      ");
					
					/* Print input signal counter value in ASCII format */	
					/* Reset the array before storing the ASCII character */
					Reset_Array(InputCounter_ASCII, DATA_END);
					
					Convert_HextoDec(Input_Signal_Count, InputCounter_ASCII);
					for(loopNo = 0; loopNo < DATA_END; loopNo++)
					{
						UART_UartPutChar(InputCounter_ASCII[DATA_END - loopNo -1]);
					}
					UART_PutCRLF();	

					/* Print reference clock counter value */
					UART_UartPutString("Reference Clock Counter Value: ");
					UART_SendDebugData(Ref_Clock_Count);
					UART_UartPutString("      ");
					
					/* Print input signal counter value in ASCII format */	
					/* Reset the array before storing the ASCII character */				
					Reset_Array(RefCounter_ASCII, DATA_END);
					Convert_HextoDec(Ref_Clock_Count, RefCounter_ASCII);
					for(loopNo = 0; loopNo < DATA_END; loopNo++)
					{
						UART_UartPutChar(RefCounter_ASCII[DATA_END - loopNo -1]);
					}
					UART_PutCRLF();
					
					/* Print Input Signal Frequency in decimal format */
					UART_UartPutString("Input Frequency: ");
					for(loopNo = 0; loopNo < DATA_END; loopNo++)
					{
						UART_UartPutChar(Input_Frequency[DATA_END - loopNo -1]);
					}
					UART_PutCRLF();			
				#endif
				/* Reset the capture flag after computing the frequency */
				Input_Sig_Ctr_Capture = 0;
				Ref_Clk_Ctr_Capture = 0;
			} 
			/* If valid capture event is not registered, set the value of frequency to 
			   zero */
			else
			{
				/* Reset the input_frequency array before storing the frequency value */
				Reset_Array(Input_Frequency, DATA_END);

				/* If no capture event is detected in the 1s interval, set the frequency to zero */
				FormatFrequencyData(ZERO_HZ);
				
				#if(UART_DEBUG_ENABLE)
					/* Print Input Signal Frequency in decimal format */
					UART_UartPutString("Input Frequency: ");
					for(loopNo = 0; loopNo < DATA_END; loopNo++)
					{
						UART_UartPutChar(Input_Frequency[DATA_END - loopNo -1]);
					}
					UART_PutCRLF();	
				#endif
			}
			/* Reset the 2s interval flag for computing the frequency in the next interval */
			Calculate_Frequency = 0;
			/* Send frequency value only if BLE device is connected */
			if(TRUE == deviceConnected) 
			{
				/* Send frequency value when notifications are enabled */
				if((startNotification & CCCD_NTF_BIT_MASK))
				{

					/* Send the frequency value to BLE central device by notifications */
					SendDataOverFreqCounterNotification(Input_Frequency);
				}
			}
		}

		
		/* Function to handle LED status depending on BLE state */
		HandleStatusLED();
		
		/* Handle CCCD value update only if BLE device is connected */
		if(TRUE == deviceConnected) 
		{
	
			/* When the Client Characteristic Configuration descriptor (CCCD) is written
			* by Central device for enabling/disabling notifications, then the same
			* descriptor value has to be explicitly updated in application so that
			* it reflects the correct value when the descriptor is read */
			UpdateNotificationCCCD();	
		}		
		if(restartAdvertisement)
		{
			/* Reset 'restartAdvertisement' flag*/
			restartAdvertisement = FALSE;
			
			/* Start Advertisement and enter Discoverable mode*/
			CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);	
		}
		/*Process Event callback to handle BLE events. The events generated and 
		* used for this application are inside the 'CustomEventHandler' routine*/
		CyBle_ProcessEvents();
		
		/* Put CPU to sleep */
		CySysPmSleep();
    }
}
int main()
{
    CYBLE_API_RESULT_T apiResult;
  
    CYBLE_LP_MODE_T lpMode;

    CyGlobalIntEnable;
    
    CommInit();               /* Start communication component */
    printf("BLE Uart Transmission Collector Example Project \r\n");
    
    Scanning_LED_Write(LED_OFF);

    apiResult = CyBle_Start(AppCallBack);
    if(apiResult != CYBLE_ERROR_OK)
    {
        printf("CyBle_Start API Error: %xd \r\n", apiResult);
    }
		else
			{
				printf("CyBle_Start API ok \r\n");
			}
    
		/* Enable the Interrupt component connected to interrupt */
		TC_CC_ISR_StartEx(InterruptHandler);
		
		/* Start the components */
		Timer_Start();
    
    while(1)
    {
        if(CyBle_GetState() != CYBLE_STATE_INITIALIZING)
        {
            /* Enter DeepSleep mode between connection intervals */
            lpMode = CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP);
            if(lpMode == CYBLE_BLESS_DEEPSLEEP) 
            {
                /* Put the device into the Deep Sleep mode only when all debug information has been sent 
			                if(UART_DEB_SpiUartGetTxBufferSize() == 0u)
			                {
			                    CySysPmDeepSleep();
			                }
			                else
			                {
			                    CySysPmSleep();
			                }*/
                CySysPmSleep();
                /* Handle scanning led blinking */
                HandleLEDs(ble_state);
            }
            HandleLEDs(ble_state);
        }
		/***********************************************************************
        * Wait for connection established with Central device
        ***********************************************************************/
        if(CyBle_GetState() == CYBLE_STATE_CONNECTED)
        {
            /*******************************************************************
            *  Periodically measure a battery level and temperature and send 
            *  results to the Client
            *******************************************************************/    
            CommMonitorUart();
            CommMonitorBLE();
            
            #if 0
            if(mainTimer != 0u)
            {
                mainTimer = 0u;

                if(storeBondingData == ENABLED)
                {
                    cystatus retValue;
                    retValue = CyBle_StoreBondingData(0u);
                    printf("Store bonding data, status: %lx \r\n", retValue);
                    storeBondingData = DISABLED;
                }
    
            }
            #endif
            
            
        }
        
        
        /*******************************************************************
        *  Processes all pending BLE events in the stack
        *******************************************************************/        
        CyBle_ProcessEvents();
    }
}
Beispiel #15
0
int main()
{
   
    /* Variable declarations */
    CYBLE_LP_MODE_T lpMode;
    CYBLE_BLESS_STATE_T blessState;
    uint8 InterruptsStatus;
      
   
    /* Start communication component */
    UART_Start();
    
    /* Enable global interrupts */
    CyGlobalIntEnable;
       
    /* Internal low power oscillator is stopped as it is not used in this project */
    CySysClkIloStop();
    
    /* Set the divider for ECO, ECO will be used as source when IMO is switched off to save power,
    **  to drive the HFCLK */
    CySysClkWriteEcoDiv(CY_SYS_CLK_ECO_DIV8);
    
    CyBle_Start(StackEventHandler);
   
    /*Infinite Loop*/
    for(;;)
    {
       
        if((UART_SpiUartGetTxBufferSize() + UART_GET_TX_FIFO_SR_VALID) == 0)
        {
            
           if(CyBle_GetState() != CYBLE_STATE_INITIALIZING)
           {
                /* Put BLE sub system in DeepSleep mode when it is idle */
                 lpMode = CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP);
                
               /* Disable global interrupts to avoid any other tasks from interrupting this section of code*/
                InterruptsStatus = CyEnterCriticalSection();
                
                /* Get current state of BLE sub system to check if it has successfully entered deep sleep state */
                blessState = CyBle_GetBleSsState();

                /* If BLE sub system has entered deep sleep, put chip into deep sleep for reducing power consumption */
                if(lpMode == CYBLE_BLESS_DEEPSLEEP)
                {   
                    if(blessState == CYBLE_BLESS_STATE_ECO_ON || blessState == CYBLE_BLESS_STATE_DEEPSLEEP)
                    {
                       /* Put the chip into the deep sleep state as there are no pending tasks and BLE has also
                       ** successfully entered BLE DEEP SLEEP mode */
                       CySysPmDeepSleep();
                    }
                }
                
                /* BLE sub system has not entered deep sleep, wait for completion of radio operations */
                else if(blessState != CYBLE_BLESS_STATE_EVENT_CLOSE)
                {
                    
                    /* change HF clock source from IMO to ECO, as IMO can be stopped to save power */
                    CySysClkWriteHfclkDirect(CY_SYS_CLK_HFCLK_ECO); 
                    /* stop IMO for reducing power consumption */
                    CySysClkImoStop(); 
                    /* put the CPU to sleep */
                    CySysPmSleep();
                    /* starts execution after waking up, start IMO */
                    CySysClkImoStart();
                    /* change HF clock source back to IMO */
                    CySysClkWriteHfclkDirect(CY_SYS_CLK_HFCLK_IMO);
                    
                }
                
                /*Enable interrupts */
                CyExitCriticalSection(InterruptsStatus);
            
            }/*end of if(CyBle_GetState() != CYBLE_STATE_INITIALIZING)*/
             
            CyBle_ProcessEvents();
                        
        }   
    
    }
    
 }
Beispiel #16
0
Datei: main.c Projekt: bhwj/BLE
/*******************************************************************************
* Function Name: main
********************************************************************************
* Summary:
*        MyBeacon entry point. This calls the BLE and other peripheral Component
* APIs for achieving the desired system behaviour
*
* Parameters:
*  void
*
* Return:
*  int
*
*******************************************************************************/
int main()
{
    CyGlobalIntEnable;
    
    /* Set the divider for ECO, ECO will be used as source when IMO is switched off to save power, to drive the HFCLK */
    CySysClkWriteEcoDiv(CY_SYS_CLK_ECO_DIV8);
    
    /* If USE_WCO_FOR_TIMING is set, then do the following:
     * 1. Shut down the ECO (to reduce power consumption while WCO is starting)
     * 2. Enable WDT to wakeup the system after 500ms (WCO startup time). 
     * 3. Configure PSoC 4 BLE device in DeepSleep mode for the 500ms WCO startup time
     * 4. After WCO is enabled, restart the ECO so that BLESS interface can function */
#if USE_WCO_FOR_TIMING
    CySysClkEcoStop();
    
    WDT_Interrupt_StartEx(WDT_Handler);
    
    CySysClkWcoStart();
    
    CySysWdtUnlock(); /* Unlock the WDT registers for modification */
    
    CySysWdtWriteMode(SOURCE_COUNTER, CY_SYS_WDT_MODE_INT);
    
    CySysWdtWriteClearOnMatch(SOURCE_COUNTER, COUNTER_ENABLE);
    
    CySysWdtWriteMatch(SOURCE_COUNTER, COUNT_PERIOD);
    
    CySysWdtEnable(CY_SYS_WDT_COUNTER0_MASK);
    
    CySysWdtLock();
    
#if TIMING_DEBUG_ENABLE                    
    DeepSleep_Write(1);
#endif  

    CySysPmDeepSleep(); /* Wait for the WDT interrupt to wake up the device */
    
#if TIMING_DEBUG_ENABLE                    
    DeepSleep_Write(0);
#endif

    (void)CySysClkEcoStart(2000u);
    CyDelayUs(500u);

    (void)CySysClkWcoSetPowerMode(CY_SYS_CLK_WCO_LPM);    /* Switch to the low power mode */

    CySysClkSetLfclkSource(CY_SYS_CLK_LFCLK_SRC_WCO);

    CySysWdtUnlock();
    
    CySysWdtDisable(CY_SYS_WDT_COUNTER0_MASK);
    
    CySysWdtLock();
#endif
    
    CyBle_Start(BLE_AppEventHandler);
    
    for(;;)
    {
        CYBLE_LP_MODE_T pwrState;
        CYBLE_BLESS_STATE_T blessState;
        uint8 intStatus = 0;
        
        CyBle_ProcessEvents(); /* BLE stack processing state machine interface */
        
        pwrState  = CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP); /* Configure BLESS in Deep-Sleep mode */

        intStatus = CyEnterCriticalSection(); /* No interrupts allowed while entering system low power modes */
        
        blessState = CyBle_GetBleSsState();

        if(pwrState == CYBLE_BLESS_DEEPSLEEP) /* Make sure BLESS is in Deep-Sleep before configuring system in Deep-Sleep */
        {
            if(blessState == CYBLE_BLESS_STATE_ECO_ON || blessState == CYBLE_BLESS_STATE_DEEPSLEEP)
            {
#if TIMING_DEBUG_ENABLE                    
                DeepSleep_Write(1);
#endif                

                CySysPmDeepSleep(); /* System Deep-Sleep. 1.3uA mode */
                
#if TIMING_DEBUG_ENABLE                    
                DeepSleep_Write(0);
#endif                 
            }
        }
        else if (blessState != CYBLE_BLESS_STATE_EVENT_CLOSE)
        {
             /* Change HF clock source from IMO to ECO, as IMO can be stopped to save power */
            CySysClkWriteHfclkDirect(CY_SYS_CLK_HFCLK_ECO); 
            
            /* Stop IMO for reducing power consumption */
            CySysClkImoStop(); 
            
#if TIMING_DEBUG_ENABLE            
            Sleep_Write(1);
#endif            
            /* Put the CPU to Sleep. 1.1mA mode */
            CySysPmSleep();
            
#if TIMING_DEBUG_ENABLE            
            Sleep_Write(0);
#endif            
            
            /* Starts execution after waking up, start IMO */
            CySysClkImoStart();
            
            /* Change HF clock source back to IMO */
            CySysClkWriteHfclkDirect(CY_SYS_CLK_HFCLK_IMO);
        }
        
        CyExitCriticalSection(intStatus);
    }
}
Beispiel #17
0
int main()
{
    CYBLE_LP_MODE_T lpMode;
    CYBLE_BLESS_STATE_T blessState;

    CyGlobalIntEnable;

    UART_DEB_Start();               /* Start communication component */
    printf("BLE Secure Connection Example Project \r\n");

    Disconnect_LED_Write(LED_OFF);
    Advertising_LED_Write(LED_OFF);

    /* Start CYBLE component and register generic event handler */
    apiResult = CyBle_Start(AppCallBack);
    if(apiResult != CYBLE_ERROR_OK)
    {
        printf("CyBle_Start API Error: %x \r\n", apiResult);
    }

    /* Services initialization */
    HrsInit();

    /***************************************************************************
    * Main polling loop
    ***************************************************************************/
    while(1)
    {
        if(CyBle_GetState() != CYBLE_STATE_INITIALIZING)
        {
            /* Enter DeepSleep mode between connection intervals */
            lpMode = CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP);
            CyGlobalIntDisable;
            blessState = CyBle_GetBleSsState();

            if(lpMode == CYBLE_BLESS_DEEPSLEEP)
            {
                if(blessState == CYBLE_BLESS_STATE_ECO_ON || blessState == CYBLE_BLESS_STATE_DEEPSLEEP)
                {
                    /* Put the device into the Deep Sleep mode only when all debug information has been sent */
                    if((UART_DEB_SpiUartGetTxBufferSize() + UART_DEB_GET_TX_FIFO_SR_VALID) == 0u)
                    {
                        CySysPmDeepSleep();
                    }
                    else
                    {
                        CySysPmSleep();
                    }
                }
            }
            else
            {
                if(blessState != CYBLE_BLESS_STATE_EVENT_CLOSE)
                {
                    CySysPmSleep();
                }
            }
            CyGlobalIntEnable;
        }


        /***********************************************************************
        * Wait for connection established with Central device
        ***********************************************************************/
        if(CyBle_GetState() == CYBLE_STATE_CONNECTED)
        {
            /*******************************************************************
            *  Periodically simulates heart beat and sends the results to the Client
            *******************************************************************/
            mainTimer++;

            if(mainTimer == MAIN_LOOP_SIMULATION_THRESHOLD)
            {
                mainTimer = 0u;
                if(heartRateSimulation == ENABLED)
                {
                    SimulateHeartRate();
                    CyBle_ProcessEvents();
                }
            }
            else if((cyBle_pendingFlashWrite != 0u) &&
                    ((UART_DEB_SpiUartGetTxBufferSize() + UART_DEB_GET_TX_FIFO_SR_VALID) == 0u))
            {
                apiResult = CyBle_StoreBondingData(0u);
                printf("Store bonding data, status: %x \r\n", apiResult);
            }
            else
            {
                /* nothing else */
            }
        }

        /*******************************************************************
        *  Process all pending BLE events in the stack
        *******************************************************************/
        CyBle_ProcessEvents();
    }
}
Beispiel #18
0
int main()
{
    #ifdef LOW_POWER_MODE    
        CYBLE_LP_MODE_T         lpMode;
        CYBLE_BLESS_STATE_T     blessState;
    #endif
    
    CYBLE_API_RESULT_T      bleApiResult;
   
    CyGlobalIntEnable; 
    
    /* Start UART and BLE component and display project information */
    UART_Start();   
    bleApiResult = CyBle_Start(AppCallBack); 
    
    if(bleApiResult == CYBLE_ERROR_OK)
    {
        #ifdef PRINT_MESSAGE_LOG
            UART_UartPutString("\n\r************************************************************");
            UART_UartPutString("\n\r***************** BLE UART example project *****************");
            UART_UartPutString("\n\r************************************************************\n\r");
            UART_UartPutString("\n\rDevice role \t: CENTRAL");
            
            #ifdef LOW_POWER_MODE
                UART_UartPutString("\n\rLow Power Mode \t: ENABLED");
            #else
                UART_UartPutString("\n\rLow Power Mode \t: DISABLED");
            #endif
            
            #ifdef FLOW_CONTROL
                UART_UartPutString("\n\rFlow Control \t: ENABLED");  
            #else
                UART_UartPutString("\n\rFlow Control \t: DISABLED");
            #endif
            
        #endif
    }
    else
    {
        #ifdef PRINT_MESSAGE_LOG   
            UART_UartPutString("\n\r\t\tCyBle stack initilization FAILED!!! \n\r ");
        #endif
        
        /* Enter infinite loop */
        while(1);
    }
    
    CyBle_ProcessEvents();
    
    /***************************************************************************
    * Main polling loop
    ***************************************************************************/
    while(1)
    {               
        #ifdef LOW_POWER_MODE
            
            if((CyBle_GetState() != CYBLE_STATE_INITIALIZING) && (CyBle_GetState() != CYBLE_STATE_DISCONNECTED))
            {
                /* Enter DeepSleep mode between connection intervals */
                
                lpMode = CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP);
                CyGlobalIntDisable;
                blessState = CyBle_GetBleSsState();

                if(lpMode == CYBLE_BLESS_DEEPSLEEP) 
                {   
                    if((blessState == CYBLE_BLESS_STATE_ECO_ON || blessState == CYBLE_BLESS_STATE_DEEPSLEEP) && \
                            (UART_SpiUartGetTxBufferSize() + UART_GET_TX_FIFO_SR_VALID) == 0u)
                    {
                        #ifdef FLOW_CONTROL
                            EnableUartRxInt();
                        #endif
                        
                        CySysPmSleep();
                        
                        #ifdef FLOW_CONTROL
                            DisableUartRxInt();
                        #endif
                    }
                }
                else
                {
                    if((blessState != CYBLE_BLESS_STATE_EVENT_CLOSE) && \
                            (UART_SpiUartGetTxBufferSize() + UART_GET_TX_FIFO_SR_VALID) == 0u)
                    {
                        #ifdef FLOW_CONTROL
                            EnableUartRxInt();
                        #endif
                        
                        CySysPmSleep();
                        
                        #ifdef FLOW_CONTROL
                            DisableUartRxInt();
                        #endif
                    }
                }
                CyGlobalIntEnable;
                
                /* Handle advertising led blinking */
                HandleLeds();
            }
            
        #else
            HandleLeds();
        #endif
        
        /*******************************************************************
        *  Process all pending BLE events in the stack
        *******************************************************************/      
        HandleBleProcessing();
        CyBle_ProcessEvents();
    }
}
/*******************************************************************************
* Function Name: HandleLowPowerMode
********************************************************************************
* Summary:
*        This function puts the BLESS in deep sleep mode and CPU to sleep mode. 
* System will resume from here when it wakes from user button press.
*
* Parameters:
*  void
*
* Return:
*  void
*
*******************************************************************************/
void HandleLowPowerMode(uint8 lpmSel)
{
	#ifdef ENABLE_LOW_POWER_MODE
		/* Local variable to store the status of BLESS Hardware block */
		CYBLE_LP_MODE_T sleepMode;
		CYBLE_BLESS_STATE_T blessState;

        if (lpmSel == DEEPSLEEP)
        {
            /* Leave chip in Deep Sleep mode */
    		/* Put BLESS into Deep Sleep and check the return status */
    		sleepMode = CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP);
    		
    		/* Disable global interrupt to prevent changes from any other interrupt ISR */
    		CyGlobalIntDisable;
    	
    		/* Check the Status of BLESS */
    		blessState = CyBle_GetBleSsState();

    		if(sleepMode == CYBLE_BLESS_DEEPSLEEP)
    		{
    		    /* If the ECO has started or the BLESS can go to Deep Sleep, then place CPU 
    			* to Deep Sleep */
    			if(blessState == CYBLE_BLESS_STATE_ECO_ON || blessState == CYBLE_BLESS_STATE_DEEPSLEEP)
    		    {
    				/* Place CPU to Deep sleep */
                    #ifdef ENABLE_LED_NOTIFICATION
                    GREEN_SetDriveMode(GREEN_DM_STRONG);
                    GREEN_Write(0);
                    #endif
                    
    		        CySysPmDeepSleep();
                    
                    #ifdef ENABLE_LED_NOTIFICATION
                    GREEN_SetDriveMode(GREEN_DM_STRONG);
                    GREEN_Write(1);
                    #endif
    		 	}
    		}
    		
    		/* Re-enable global interrupt mask after wakeup */
    		CyGlobalIntEnable;        
        }
#if 0
        else if (lpmSel == SLEEP)
        {
            /* Leave chip in Sleep mode */
            /* Leave chip in Deep Sleep mode */
    		/* Put BLESS into Deep Sleep and check the return status */
    		sleepMode = CyBle_EnterLPM(CYBLE_BLESS_SLEEP);
    		
    		/* Disable global interrupt to prevent changes from any other interrupt ISR */
    		CyGlobalIntDisable;
    	
    		/* Check the Status of BLESS */
    		blessState = CyBle_GetBleSsState();

    		if(sleepMode == CYBLE_BLESS_SLEEP)
    		{
    		    if(blessState != CYBLE_BLESS_STATE_EVENT_CLOSE)
    		    {
    				/* If BLE Event has not 
    				* closed yet, then place CPU to Sleep */
                    #ifdef ENABLE_LED_NOTIFICATION                   
                    BLUE_Write(0);
                    BLUE_SetDriveMode(BLUE_DM_STRONG);
                    #endif
                    
    		        CySysPmSleep();
                    
                    #ifdef ENABLE_LED_NOTIFICATION
                    BLUE_SetDriveMode(BLUE_DM_STRONG);
                    BLUE_Write(1);
                    #endif
    		    }
    		}
    		
    		/* Re-enable global interrupt mask after wakeup */
    		CyGlobalIntEnable;        
        }
        else if (lpmSel == ACTIVE)
        {
            /* Leave chip in Active mode */
            #ifdef ENABLE_LED_NOTIFICATION
            RED_Write(0);
            RED_SetDriveMode(RED_DM_STRONG);
            #endif
        }
#endif        
	#endif
}