void initializeSystem(void) { CyGlobalIntEnable; UART_Start(); PrISM_1_Start(); PrISM_2_Start(); Opamp_1_Start(); // Start the Bluetooth Stack CyBle_Start(CustomEventHandler); // Set up the LED. First set its output to be off so that the LED doesn't blink on. // Then set the drive mode to strong. PrISM_1_WritePulse0(255); PrISM_1_WritePulse1(255); PrISM_2_WritePulse0(255); RED_SetDriveMode(RED_DM_STRONG); GREEN_SetDriveMode(GREEN_DM_STRONG); BLUE_SetDriveMode(BLUE_DM_STRONG); // Start the ADC ADC_SAR_Seq_Start(); ADC_SAR_Seq_StartConvert(); ADC_SAR_Seq_IRQ_Enable(); // Enable an interupt for when the ADC has data ADC_SAR_Seq_IRQ_StartEx(ADC_SAR_Seq_ISR_LOC); // Start the Timer for the ADC ADC_Timer_Start(); elapsed = 0; }
/******************************************************************************* * Function Name: InitializeSystem ******************************************************************************** * Summary: * Start the components and initialize system. * * Parameters: * void * * Return: * void * *******************************************************************************/ void InitializeSystem(void) { /* Enable global interrupt mask */ CyGlobalIntEnable; /* Start BLE component and register the CustomEventHandler function. This * function exposes the events from BLE component for application use */ CyBle_Start(CustomEventHandler); /* Start both the PrISM components for LED control*/ PRS_1_Start(); PRS_2_Start(); /* The RGB LED on BLE Pioneer kit are active low. Drive HIGH on * pin for OFF and drive LOW on pin for ON*/ PRS_1_WritePulse0(RGB_LED_OFF); PRS_1_WritePulse1(RGB_LED_OFF); PRS_2_WritePulse0(RGB_LED_OFF); /* Set Drive mode of output pins from HiZ to Strong */ RED_SetDriveMode(RED_DM_STRONG); GREEN_SetDriveMode(GREEN_DM_STRONG); BLUE_SetDriveMode(BLUE_DM_STRONG); /* Initialize CapSense component and initialize baselines*/ CapSense_Start(); CapSense_InitializeAllBaselines(); }
/***************************************************************************** * Function Name: _BLE_Init() ****************************************************************************** * Summary: * Initialize the Bluetooth Low Energy module. * * Parameters: * None. * * Return: * None. * * Note: * *****************************************************************************/ void _BLE_Init(void) { // Enable the BLE module and register the callback function for all the events. CyBle_Start(EventHandler); // Initialize the busy status flag. _BLE_busyStatus = CYBLE_STACK_STATE_FREE; // Initialize the connection status flag. _BLE_deviceConnected = FALSE; // Initialize the MTU used during BLE communication. negotiatedMtu = DEFAULT_MTU_SIZE; // Initialize flags. sendDataNotifications = FALSE; sendDataIndications = FALSE; sendStatusNotifications = FALSE; sendStatusIndications = FALSE; updateSensorsCCCDreq = FALSE; updateStatusCCCDreq = FALSE; updateControlValuesReq = FALSE; _BLE_acquireData = FALSE; _BLE_sendData = FALSE; _BLE_sendStatus = FALSE; _BLE_sendDataSynchronously = FALSE; _BLE_restartAdvertisement = FALSE; _BLE_resetNeeded = FALSE; }
void Initialization(void) { /* 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); /* Do the following for achieving lowest possible WCO & ECO startup current: * 1. Shut down the ECO (to reduce power consumption while WCO is starting) * 2. Enable WDT counter 0 to wakeup the system after 500ms (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 * 5. Enable WDT counter 1 to wakeup the system after 1ms (1ms = ECO startup time) * 5. Configure PSoC 4 BLE device in DeepSleep mode for the 1ms ECO startup time */ CySysClkEcoStop(); /* Shutdown the ECO and later re-start in low power mode after WCO is turned on */ WDT_Interrupt_StartEx(WDT_Handler); /* Initialize WDT interrupt */ WCO_ECO_LowPowerStart(); /* Enable WCO & ECO in low power mode using WDT counter 0/1 as system wakeup sources respectively */ CyBle_Start(BLE_AppEventHandler); while (CyBle_GetState() == CYBLE_STATE_INITIALIZING) { CyBle_ProcessEvents(); } }
/****************************************************************************** Function Name: main ******************************************************************************* Summary: Main routine of this firmware. Initializes the components once and hanles the BLE events and UART data in a loop forever. Parameters: None. Return: None. ******************************************************************************/ int main() { /* This start-up delay is for the Android app to open when the locator * device is plugged into the phone's USB port so that the first printf * message will not be missed. */ CyDelay(3000); CyGlobalIntEnable; UART_DEB_Start(); /* Start communication component */ printf("PSoC: BLE Find Me Locator is Connected\r\n"); Disconnect_LED_Write(LED_OFF); apiResult = CyBle_Start(AppCallBack); if(apiResult != CYBLE_ERROR_OK) { printf("PSoC: CyBle_Start API Error: 0x%x \r\n", apiResult); } while(1) { /******************************************************************* * Processes all pending BLE events in the stack *******************************************************************/ CyBle_ProcessEvents(); /* Process the received UART data */ ProcessUartData(); } }
int main() { CYBLE_API_RESULT_T apiResult; uint32 count = 0; uint8 triggerNotification = 0; // Enable global interrupts CyGlobalIntEnable; // Initialize the watchdog timer CySysWdtSetIsrCallback(CY_SYS_WDT_COUNTER0, Watchdog0_cb); // Initialize the BLE device. apiResult = CyBle_Start(StackEventHandler); // Validate BLE stack initialization successed CYASSERT(apiResult == CYBLE_ERROR_OK); for (;;) { // Service all the BLE stack events. // Must be called at least once in a BLE connection interval CyBle_ProcessEvents(); if (deviceConnected) { if (counterCccDescriptor.dirty) { // Update Counter CCCD updateCounterCccDescriptor(); } else if (triggerNotification) { // Send notification if required if (enableCounterNotification) { sendCounterNotification(count); } triggerNotification = 0; } else if (triggerUpdateCounter) { // Update counter value count++; updateCounter(count); triggerNotification = ((count & 0x0000000F) == 0); triggerUpdateCounter = 0; } } // Scan update queue if (rgbDescriptor.dirty) { // Update RGB Descriptor updateRgbDescriptor(); } // Enter to deep sleep mode { CYBLE_LP_MODE_T state; state = CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP); if (state == CYBLE_BLESS_DEEPSLEEP) { CySysPmDeepSleep(); } } } }
/******************************************************************************* * Function Name: BLE_Interface_Start ******************************************************************************** * * Summary: * Initialization the BLE interface. * * Parameters: * None * * Return: * state returned by the BLE interface start API * *******************************************************************************/ CYBLE_API_RESULT_T BLE_Interface_Start(void) { CYBLE_API_RESULT_T apiResult; BLE_Interface_Init(); apiResult = CyBle_Start(BLE_StackEventHandler); return apiResult; }
/******************************************************************************* * Function Name: InitializeSystem ******************************************************************************** * Summary: * Start the components and initialize system * * Parameters: * void * * Return: * void * *******************************************************************************/ void InitializeSystem(void) { /* Enable global interrupt mask */ CyGlobalIntEnable; /* Start BLE component and register the CustomEventHandler function. This * function exposes the events from BLE component for application use */ CyBle_Start(CustomEventHandler); /* Initialize NEC pin to high state */ NecOutPin_Write(TRUE); }
/******************************************************************************* * Function Name: BLE_Engine_Start ******************************************************************************** * * Summary: * Application level API for starting the BLE interface. The API internally calls * other BLE interface init APIs to setup the system. * * Parameters: * None * * Return: * None * *******************************************************************************/ CYBLE_API_RESULT_T BLE_Engine_Start(void) { CYBLE_API_RESULT_T apiResult; apiResult = CyBle_Start(BLE_StackEventHandler); if(apiResult != CYBLE_ERROR_OK) { CYASSERT(0); } /* ADD YOUR CODE TO REGISTER OTHER BLE SERVICE SPECIFIC EVENT HANDLERS */ return apiResult; }
/******************************************************************************* * Function Name: InitializeSystems ******************************************************************************** * * Summary: * Starts all components and initializes as required. * * Parameters: * None * * Return: * None * *******************************************************************************/ void InitializeSystems(void) { /* Enable Global Interrupt */ CyGlobalIntEnable; /* Start PWM. This PWM controls the LED status */ LED_PWM_Start(); /* Start CYBLE component and register generic event handler */ CyBle_Start(GenericAppEventHandler); /* register the event handler for IAS specific events */ CyBle_IasRegisterAttrCallback(iasEventHandler); /* Set drive mode of Alert LED pin to High-Z to shutdown LED */ Alert_LED_SetDriveMode(Alert_LED_DM_ALG_HIZ); }
int main() { CyGlobalIntEnable; /* Enable global interrupts. */ /* Place your initialization/startup code here (e.g. MyInst_Start()) */ Advertising_Led_Write(LED_OFF); Error_Led_Write(LED_OFF); apiResult = CyBle_Start(bleCallBack); if (apiResult != CYBLE_ERROR_OK) { printf("CyBle_Start API error: %x \r\n", apiResult); Error_Led_Write(LED_ON); } for(;;) { /* Place your application code here. */ CyBle_ProcessEvents(); } }
/******************************************************************************* * 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 */ } } }
/******************************************************************************* * Function Name: InitializeSystem ******************************************************************************** * * Summary: * This routine initializes all the componnets and firmware state. * * Parameters: * None * * Return: * None * *******************************************************************************/ void InitializeSystem(void) { CYBLE_API_RESULT_T apiResult; CyGlobalIntEnable; apiResult = CyBle_Start(StackEventHandler); /* Init the BLE stack and register an applicaiton callback */ if(apiResult != CYBLE_ERROR_OK) { /* BLE stack initialization failed, check your configuration */ CYASSERT(0); } /* Set XTAL divider to 3MHz mode */ CySysClkWriteEcoDiv(CY_SYS_CLK_ECO_DIV8); /* ILO is no longer required, shut it down */ CySysClkIloStop(); }
int main() { /* Enabling Global interrupts */ CyGlobalIntEnable; /* Start BLE component with appropriate Event handler function */ CyBle_Start(ApplicationEventHandler); /* Turn OFF All the LEDs */ ALL_LED_OFF(); /* Loop For Ever */ for(;;) { /* Function to handle the state of the Client */ handle_ble_CAR_Client_State(); /* This function checks the internal task queue in the BLE Stack, and pending operation of the BLE Stack, if any */ CyBle_ProcessEvents(); } }
/******************************************************************************* * Function Name: InitializeSystem ******************************************************************************** * Summary: * Start the components and initialize system * * Parameters: * void * * Return: * void * *******************************************************************************/ void InitializeSystem(void) { /* Enable global interrupt mask */ CyGlobalIntEnable; /* Start BLE component and register the CustomEventHandler function. This * function exposes the events from BLE component for application use */ CyBle_Start(CustomEventHandler); /* Set Drive mode of output pins from HiZ to Strong */ RED_SetDriveMode(RED_DM_STRONG); GREEN_SetDriveMode(GREEN_DM_STRONG); BLUE_SetDriveMode(BLUE_DM_STRONG); /* Start the Button ISR to allow wakeup from sleep */ isr_button_StartEx(MyISR); /* Set the Watchdog Interrupt vector to the address of Interrupt routine * WDT_INT_Handler. This routine counts the 3 seconds for LED ON state during * connection. */ CyIntSetVector(WATCHDOG_INT_VEC_NUM, &WDT_INT_Handler); }
int main() { hkj_timer t; const uint16 myCharHandle = 0x0E; uint8 writeData = 0; CYBLE_GATT_VALUE_T writeValue = \ { &writeData, sizeof(writeData), sizeof(writeData) }; CYBLE_GATTC_WRITE_REQ_T writeReqParam = \ { .value = writeValue, .attrHandle = myCharHandle }; CYBLE_STACK_LIB_VERSION_T stackVersion; CyGlobalIntEnable; UART_Start(); hkj_debug_init(); CyBle_GetStackLibraryVersion(&stackVersion); debug_print("Latency Central Stack: %u.%u.%u.%u\r\n", \ stackVersion.majorVersion, stackVersion.minorVersion, \ stackVersion.patch, stackVersion.buildNumber); CyBle_Start(BleEventHandler); hkj_timer_ms_init(&t); while(1) { CyBle_ProcessEvents(); if (connHandle.bdHandle != 0) { if (hkj_timer_ms_get_delta(&t) > 500) { WRITE_CMD_PIN_Write(1); CyBle_GattcWriteWithoutResponse(connHandle, &writeReqParam); hkj_timer_ms_reset_delta(&t); CyDelay(2); WRITE_CMD_PIN_Write(0); } } hkj_ble_events_log_debug_print(); } }
int main() { CyGlobalIntEnable; CyBle_Start(BleEventHandler); while(connHandle.bdHandle == 0) /* Wait for connection to GATT server */ CyBle_ProcessEvents(); CyBle_GattcStartDiscovery(connHandle); /* Attempt discovery of configured services */ while(ledStateHandle == 0) /* Wait for discovery */ CyBle_ProcessEvents(); writeData = 0x01; /* Turn on LED on Minimal_Peripheral dongle */ writeValue.val = &writeData; writeValue.len = sizeof(writeData); writeValue.actualLen = sizeof(writeData); writeReqParam.value = writeValue; writeReqParam.attrHandle = ledStateHandle; /* Use discovered handle */ CyBle_GattcWriteWithoutResponse(connHandle, &writeReqParam); /* Write to server */ CyBle_ProcessEvents(); return 0; }
int main() { /* Initializing all the Flags and Indexes to 0 */ ALL_LED_OFF (); Count = 0; Index = 0; AddRequest = 0; DelRequest = 0; CyGlobalIntEnable; /* Comment this line to disable global interrupts. */ /* Start BLE component and register Event handler function */ CyBle_Start(StackEventHandler); /* Start UART Component which is used for receiving inputs and Debugging */ UART_Start(); printf("BLE WhiteList Example \r\n"); printf("Press A to add a Device to WhiteList. R to remove the Device from Whitelist \r\n"); /* Continuous loop scans for inputs from UART Terminal and accordingly handles Addition to and Removal from Whitelist. Also processes BLE events */ for(;;) { //Checks the internal task queue in the BLE Stack CyBle_ProcessEvents(); if(UART_SpiUartGetRxBufferSize()) { UartRxDataSim = UART_UartGetChar(); if (UartRxDataSim == 'A' || UartRxDataSim == 'a') // The user has to Enter D for disconnection { printf ("Enter the Address of the Device. Press Z to Go Back \r\n"); for (;;) { if (Count ==12) { //If the user had entered the full address, stop advertisement //for addition process CyBle_GappStopAdvertisement (); /*Once We stop advertisement, the CYBLE_EVT_GAPP_ADVERTISEMENT_START_STOP event is invoked. After this, the API for adding the device to whitelist is invoked in the StackEventHandler*/ RED_LED_ON (); AddRequest = 1; printf ("\r\n"); printf ("Address is 0x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x \r\n", whitelistdeviceaddress.bdAddr[5], whitelistdeviceaddress.bdAddr[4], whitelistdeviceaddress.bdAddr[3], whitelistdeviceaddress.bdAddr[2], whitelistdeviceaddress.bdAddr[1], whitelistdeviceaddress.bdAddr[0]); printf ("Attempting to Add to whitelist \r \n"); Count = 0; break; } if(UART_SpiUartGetRxBufferSize()) { UartRxDataSim = UART_UartGetChar(); if (UartRxDataSim == 'Z' || UartRxDataSim == 'z') { Count = 0; printf("Press A to add a Device to WhiteList \r\n"); break; } else { if ((UartRxDataSim >= '0') && (UartRxDataSim <= '9' )) { AddrNibble = UartRxDataSim - '0'; UART_UartPutChar (UartRxDataSim); } else if ((UartRxDataSim >= 'A') && (UartRxDataSim <= 'F' )) { AddrNibble = UartRxDataSim - 'A' + 0xA; UART_UartPutChar (UartRxDataSim); } else if ((UartRxDataSim >= 'a') && (UartRxDataSim <= 'f' )) { AddrNibble = UartRxDataSim - 'a' + 0xA; UART_UartPutChar (UartRxDataSim); } else { printf ("\nplease Enter a Valid Address. Press A to Enter a New Address. R ro remove the Device\r\n"); Count = 0; break; } //Receiving the addresss Nibble by Nibble whitelistdeviceaddress.bdAddr[5 - (Count/2)] = (whitelistdeviceaddress.bdAddr[5 - (Count/2)]<<4)|AddrNibble; Count ++; } } } } else if (UartRxDataSim == 'R' || UartRxDataSim == 'r') { if (Index == 0) { printf ("No Devices in WhiteList. press A to Add \r\n"); } else { printf (" The List of Devices are given below \4\n"); uint8 i = 0; // Retrieving the list of added devices for user to choose for (i = 0; i< Index; i++) { printf ("Device %d 0x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x \r\n",i + 1, whitelistdeviceaddressBackup[i].bdAddr[5], whitelistdeviceaddressBackup[i].bdAddr[4], whitelistdeviceaddressBackup[i].bdAddr[3], whitelistdeviceaddressBackup[i].bdAddr[2], whitelistdeviceaddressBackup[i].bdAddr[1], whitelistdeviceaddressBackup[i].bdAddr[0]); } printf ("Enter the Index of the device to be removed. Press Z to go back \r\n"); for (;;) { if(UART_SpiUartGetRxBufferSize()) { UartRxDataSim = UART_UartGetChar(); if (UartRxDataSim == 'Z' || UartRxDataSim == 'z') { printf("Press A to add a Device to WhiteList. R to remove \r\n"); break; } else if (UartRxDataSim >= '1' || UartRxDataSim <= '0' + Index) { RemoveIndex = UartRxDataSim - '1'; if(RemoveIndex < Index) { CyBle_GappStopAdvertisement (); /*Once We stop advertisement, the CYBLE_EVT_GAPP_ADVERTISEMENT_START_STOP event is invoked. After this, the API for removing the device from whitelist is invoked in the StackEventHandler*/ DelRequest = 1; break; } else { printf("There is no device with that number.\r\n"); } } else { printf ("Invaid Index. Press A to Add and R to remove a Device"); break; } } } } } } } }
int main() { CyGlobalIntEnable; SCB_Start(); UART_DEB_Start(); DBG_PRINTF("BLE HID Keyboard Example Project \r\n"); LED_RED_Write(LED_OFF); LED_GRN_Write(LED_OFF); LED_BLU_Write(LED_OFF); /* Start CYBLE component and register generic event handler */ CyBle_Start(AppCallBack); Sup_Pdu_t i2c_inbox; while(1) { SCB_I2CMasterClearStatus(); /* CyBle_ProcessEvents() allows BLE stack to process pending events */ CyBle_ProcessEvents(); /* uint8_t buf; uint32_t result = SCB_I2CMasterReadBuf(8, &buf, 1, SCB_I2C_MODE_COMPLETE_XFER); if (0 == (result & SCB_I2C_MSTR_NOT_READY)) { uint32_t cnt = 100; while (--cnt && 0 == (SCB_I2CMasterStatus() & SCB_I2C_MSTAT_RD_CMPLT)) {} if (!cnt) { uint32_t tmp = SCB_I2CMasterStatus(); DBG_PRINTF("stuck in I2C RX: %d\r\n", tmp); } else { if (0 == (SCB_I2CMasterStatus() & SCB_I2C_MSTAT_ERR_MASK) && buf != 0xff) { i2c_inbox.command = buf; result = SCB_I2C_MSTR_NOT_READY; while (result & SCB_I2C_MSTR_NOT_READY) { result = SCB_I2CMasterReadBuf(8, &buf, 1, SCB_I2C_MODE_COMPLETE_XFER); } while (0 == (SCB_I2CMasterStatus() & SCB_I2C_MSTAT_RD_CMPLT)) {} if (0 == (SCB_I2CMasterStatus() & SCB_I2C_MSTAT_ERR_MASK)) { i2c_inbox.data = buf; process_inbox(&i2c_inbox); } } } } */ /* To achieve low power in the device */ LowPowerImplementation(); if((CyBle_GetState() == CYBLE_STATE_CONNECTED) && (suspend != CYBLE_HIDS_CP_SUSPEND)) { if(mainTimer != 0u) { mainTimer = 0u; } /* Store bonding data to flash only when all debug information has been sent */ #if(CYBLE_BONDING_REQUIREMENT == CYBLE_BONDING_YES) #if (DEBUG_UART_ENABLED == ENABLED) if((cyBle_pendingFlashWrite != 0u) && ((UART_DEB_SpiUartGetTxBufferSize() + UART_DEB_GET_TX_FIFO_SR_VALID) == 0u)) #else if(cyBle_pendingFlashWrite != 0u) #endif /* (DEBUG_UART_ENABLED == ENABLED) */ { CYBLE_API_RESULT_T apiResult; apiResult = CyBle_StoreBondingData(0u); (void)apiResult; DBG_PRINTF("Store bonding data, status: %x \r\n", apiResult); } #endif /* CYBLE_BONDING_REQUIREMENT == CYBLE_BONDING_YES */ } } }
*******************************************************************************/int main() { CyGlobalIntEnable; #if (DEBUG_UART_ENABLED == ENABLED) UART_DEB_Start(); #endif /* (DEBUG_UART_ENABLED == ENABLED) */ DBG_PRINTF("BLE HID Keyboard Example Project \r\n"); LED_RED_Write(LED_OFF); LED_BLU_Write(LED_OFF); LED_GRN_Write(LED_OFF); /* Start CYBLE component and register generic event handler */ CyBle_Start(AppCallBack); #if (BAS_MEASURE_ENABLE != 0) ADC_Start(); #endif /* BAS_MEASURE_ENABLE != 0 */ while(1) { /* CyBle_ProcessEvents() allows BLE stack to process pending events */ CyBle_ProcessEvents(); /* To achieve low power in the device */ LowPowerImplementation(); if((CyBle_GetState() == CYBLE_STATE_CONNECTED) && (suspend != CYBLE_HIDS_CP_SUSPEND)) { if(mainTimer != 0u) { mainTimer = 0u; #if (BAS_SIMULATE_ENABLE != 0) SimulateBattery(); CyBle_ProcessEvents(); #endif /* BAS_SIMULATE_ENABLE != 0 */ #if (BAS_MEASURE_ENABLE != 0) MeasureBattery(); CyBle_ProcessEvents(); #endif /* BAS_MEASURE_ENABLE != 0 */ if(keyboardSimulation == ENABLED) { SimulateKeyboard(); } } /* Store bonding data to flash only when all debug information has been sent */ #if(CYBLE_BONDING_REQUIREMENT == CYBLE_BONDING_YES) #if (DEBUG_UART_ENABLED == ENABLED) if((cyBle_pendingFlashWrite != 0u) && ((UART_DEB_SpiUartGetTxBufferSize() + UART_DEB_GET_TX_FIFO_SR_VALID) == 0u)) #else if(cyBle_pendingFlashWrite != 0u) #endif /* (DEBUG_UART_ENABLED == ENABLED) */ { CYBLE_API_RESULT_T apiResult; apiResult = CyBle_StoreBondingData(0u); (void)apiResult; DBG_PRINTF("Store bonding data, status: %x \r\n", apiResult); } #endif /* CYBLE_BONDING_REQUIREMENT == CYBLE_BONDING_YES */ } } }
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(); } }
/******************************************************************************* * Function Name: main() ******************************************************************************** * Summary: * Main function for the project. * * Parameters: * None * * Return: * None * * Theory: * The function starts BLE and UART components. * This function process all BLE events and also implements the low power * functionality. * *******************************************************************************/ int main() { CyGlobalIntEnable; #if (DEBUG_UART_ENABLED == ENABLED) UART_DEB_Start(); #endif /* (DEBUG_UART_ENABLED == ENABLED) */ DBG_PRINTF("BLE Cycling Sensor Example Project \r\n"); Disconnect_LED_Write(LED_OFF); Advertising_LED_Write(LED_OFF); CyBle_Start(AppCallback); /* Start CYBLE component and register generic event handler */ CyBle_Start(AppCallback); /* Register service specific callback functions */ CscsInit(); CpsInit(); WDT_Start(); /*************************************************************************** * Main polling loop ***************************************************************************/ while(1) { /* CyBle_ProcessEvents() allows BLE stack to process pending events */ CyBle_ProcessEvents(); /* To achieve low power in the device */ LowPowerImplementation(); /*********************************************************************** * Wait for connection established with Central device ***********************************************************************/ if(CyBle_GetState() == CYBLE_STATE_CONNECTED) { /******************************************************************* * Periodically simulate Cycling characteristics and send * results to the Client *******************************************************************/ if(mainTimer != 0u) { mainTimer = 0u; SimulateCyclingPower(); CyBle_ProcessEvents(); SimulateCyclingSpeed(); } /* Store bounding data to flash only when all debug information has been sent */ #if (DEBUG_UART_ENABLED == ENABLED) if((cyBle_pendingFlashWrite != 0u) && ((UART_DEB_SpiUartGetTxBufferSize() + UART_DEB_GET_TX_FIFO_SR_VALID) == 0u)) #else if(cyBle_pendingFlashWrite != 0u) #endif /* (DEBUG_UART_ENABLED == ENABLED) */ { CYBLE_API_RESULT_T apiResult; apiResult = CyBle_StoreBondingData(0u); (void)apiResult; DBG_PRINTF("Store bonding data, status: %x \r\n", apiResult); } } } }
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(); } }
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(); } }
/******************************************************************************* * Function Name: main ******************************************************************************** * * Summary: * Main function. * * Parameters: * None * * Return: * None * *******************************************************************************/ int main() { /* Local variables */ char8 command; int8 intTxPowerLevel; CYBLE_API_RESULT_T apiResult; CYBLE_BLESS_PWR_IN_DB_T txPower; CyGlobalIntEnable; isr_DIS_StartEx(DIS_Interrupt); UART_Start(); CyBle_Start(StackEventHandler); /*Start BLE*/ /* Register the event handler for DIS specific events */ CyBle_DisRegisterAttrCallback(DisEventHandler); /* Register the event handler for TPS specific events */ CyBle_TpsRegisterAttrCallback(TpsServiceAppEventHandler); for(;;) { CyBle_ProcessEvents(); HandleLeds(); /*If SW2 is pressed then start to discover the services of server*/ if(discoverServer==TRUE) { CyBle_GattcStartDiscovery(cyBle_connHandle); discoverServer=FALSE; } command = UART_UartGetChar(); if( command != 0u) {/*Client related functions*/ switch(command) { if(disSupport) { case '1': /*To read the Manufacturer Name */ printf("Manufacturer Name:"); CyBle_DiscGetCharacteristicValue(cyBle_connHandle,CYBLE_DIS_MANUFACTURER_NAME); break; case '2': /*To read the Model number*/ printf("Model Number:"); CyBle_DiscGetCharacteristicValue(cyBle_connHandle,CYBLE_DIS_MODEL_NUMBER); break; case '3': /*To read the serial number*/ printf("Serial Number:"); CyBle_DiscGetCharacteristicValue(cyBle_connHandle,CYBLE_DIS_SERIAL_NUMBER); break; case '4': /*To read hardware Revision*/ printf("Hardware Rev:"); CyBle_DiscGetCharacteristicValue(cyBle_connHandle,CYBLE_DIS_HARDWARE_REV); break; case '5': /*To read Firmware Revision*/ printf("Firmware Rev:"); CyBle_DiscGetCharacteristicValue(cyBle_connHandle,CYBLE_DIS_FIRMWARE_REV); break; case '6': /*To read Software Revision*/ printf("Software Rev:"); CyBle_DiscGetCharacteristicValue(cyBle_connHandle,CYBLE_DIS_SOFTWARE_REV); break; case '7': /*To read System ID*/ printf("System ID:"); CyBle_DiscGetCharacteristicValue(cyBle_connHandle,CYBLE_DIS_SYSTEM_ID); break; case '8': /*To read IEEE 11073 -20601 certifications details*/ printf("IEEE 11073-20601:"); CyBle_DiscGetCharacteristicValue(cyBle_connHandle,CYBLE_DIS_REG_CERT_DATA); break; case '9': /*To read PNP ID*/ printf("PNP ID:"); CyBle_DiscGetCharacteristicValue(cyBle_connHandle,CYBLE_DIS_PNP_ID); break; } else { printf("Client hasn't discovered the services of server or server doesn't support DIS service\r\n"); } /*Server related fucntions*/ /* Decrease Tx power level of BLE radio if button is pressed */ case'd': /* Specify connection channel for reading Tx power level */ txPower.bleSsChId = CYBLE_LL_CONN_CH_TYPE; /* Get current Tx power level */ CyBle_GetTxPowerLevel(&txPower); /* Decrease the Tx power level by one scale */ DecreaseTxPowerLevelValue(&txPower.blePwrLevelInDbm); /* Set the new Tx power level */ apiResult = CyBle_SetTxPowerLevel(&txPower); if(CYBLE_ERROR_OK == apiResult) { /* Convert power level to numeric int8 value */ intTxPowerLevel = ConvertTxPowerlevelToInt8(txPower.blePwrLevelInDbm); (void) CyBle_TpssSetCharacteristicValue(CYBLE_TPS_TX_POWER_LEVEL, CYBLE_TPS_TX_POWER_LEVEL_SIZE, &intTxPowerLevel); /* Display new Tx Power Level value */ printf("Tx power level is set to %d dBm\r\n", intTxPowerLevel); } break; case 'n': /*Send notification to the client about the TX power level*/ CyBle_TpssSendNotification(cyBle_connHandle,CYBLE_TPS_TX_POWER_LEVEL,CYBLE_TPS_TX_POWER_LEVEL_SIZE,&intTxPowerLevel); break; } } } }
int main() { CYBLE_STACK_LIB_VERSION_T stackVersion; CyGlobalIntEnable; UART_DEB_Start(); /* Start communication component */ printf("BLE Heart Rate Sensor 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); } 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); } /* Services initialization */ HrsInit(); WDT_Start(); /*************************************************************************** * Main polling loop ***************************************************************************/ while(1) { /*********************************************************************** * Wait for connection established with Central device ***********************************************************************/ if(CyBle_GetState() == CYBLE_STATE_CONNECTED) { /******************************************************************* * Periodically simulate heart rate and measure a battery level * and send results to the Client *******************************************************************/ if(mainTimer != 0u) { mainTimer = 0u; if(heartRateSimulation == ENABLED) { SimulateHeartRate(); } } } /******************************************************************* * Process all pending BLE events in the stack *******************************************************************/ CyBle_ProcessEvents(); } }
/******************************************************************************* * 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); } }
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(); } } } }
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(); } }
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(); } } }