コード例 #1
0
ファイル: LowPower.c プロジェクト: Ahamedjee/PSoC-4-BLE
/*******************************************************************************
* 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);
}
コード例 #2
0
ファイル: BLE Connection.c プロジェクト: Charhong/PSoC-4-BLE
/*******************************************************************************
* Function Name: BLE_Run
********************************************************************************
*
* Summary:
*  BLE interface processing engine. This API should be continuously called by 
*  the application in its main loop.
*
* Parameters:  
*  None
*
* Return: 
*  None
*
*******************************************************************************/
uint8 BLE_Run(void)
{
#if (BLE_GATT_CLIENT_ENABLE)
    CYBLE_API_RESULT_T status;
    
    switch(bleStatus)
    {
        case BLE_CONNECTED:
            status = StartTimeServiceDiscovery();
            if(CYBLE_ERROR_OK == status)
            {            
                bleStatus = BLE_DISCOVEER_GATT_SERVICES;
            }
            else
            {
                bleStatus = BLE_INVALID_OPERATION;   
            }
#if(CONSOLE_LOG_ENABLED)
            printf("BLE connection established \r\n\n");
#endif /* End of #if(CONSOLE_LOG_ENABLED) */            
        break;
            
        case BLE_READ_TIME:
            if(CyBle_GetClientState() == CYBLE_CLIENT_STATE_DISCOVERED)
            {
                status = SyncTimeFromBleTimeServer();
                if(CYBLE_ERROR_OK == status)
                {
                    bleStatus = BLE_IDLE;
                }
                else
                {
                    bleStatus = BLE_INVALID_OPERATION;
                }
            }
        break;
            
        case BLE_INITIATE_AUTHENTICATION:
            CyBle_GapAuthReq(cyBle_connHandle.bdHandle, &cyBle_authInfo);
            bleStatus = BLE_AUTHENTICATION_IN_PROGRESS;
        break;    
        
        default:
        
        break;
    }
#endif
    
    CyBle_ProcessEvents();
    
    /* Store bonding data to flash only when all debug information has been sent */
    if((cyBle_pendingFlashWrite != 0u) 
#if(CONSOLE_LOG_ENABLED)    
       &&((Debug_Console_SpiUartGetTxBufferSize() + Debug_Console_GET_TX_FIFO_SR_VALID) == 0u)
#endif    
    )
    {
        status = CyBle_StoreBondingData(0u);
    }
    
#if DISCONNECT_BLE_AFTER_TIME_SYNC    
    if(BLE_IsDisconnectionRequestPending())
    {
        BLE_SendDisconnection();
    }
#endif    
    
    return bleStatus;
}