Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void bleInit(void){
- u32 err = 0;
- logt("NODE", "Initializing Softdevice");
- // Initialize the SoftDevice handler with the low frequency clock source
- //And a reference to the previously allocated buffer
- //No event handler is given because the event handling is done in the main loop
- nrf_clock_lf_cfg_t xtal_cfg;
- xtal_cfg.source = NRF_CLOCK_LF_SRC_XTAL;
- xtal_cfg.xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_500_PPM;
- //SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL);
- err = softdevice_handler_init(xtal_cfg, currentEventBuffer, sizeOfEvent, NULL);
- APP_ERROR_CHECK(err);
- logt("NODE", "Softdevice Init OK");
- // Register with the SoftDevice handler module for System events.
- err = softdevice_sys_evt_handler_set(sys_evt_dispatch);
- APP_ERROR_CHECK(err);
- //Now we will enable the Softdevice. RAM usage depends on the values chosen
- ble_enable_params_t params;
- memset(¶ms, 0x00, sizeof(params));
- params.common_enable_params.vs_uuid_count = 5; //set the number of Vendor Specific UUIDs to 5
- //TODO: configure Bandwidth
- //params.common_enable_params.p_conn_bw_counts->
- params.gap_enable_params.periph_conn_count = Config->meshMaxInConnections; //Number of connections as Peripheral
- params.gap_enable_params.central_conn_count = Config->meshMaxOutConnections; //Number of connections as Central
- params.gap_enable_params.central_sec_count = 1; //this application only needs to be able to pair in one central link at a time
- params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT; //we require the Service Changed characteristic
- params.gatts_enable_params.attr_tab_size = BLE_GATTS_ATTR_TAB_SIZE_DEFAULT; //the default Attribute Table size is appropriate for our application
- //The base ram address is gathered from the linker
- u32 app_ram_base = (u32)__application_ram_start_address;
- /* enable the BLE Stack */
- logt("ERROR", "Ram base at 0x%x", app_ram_base);
- err = sd_ble_enable(¶ms, &app_ram_base);
- if(err == NRF_SUCCESS){
- /* Verify that __LINKER_APP_RAM_BASE matches the SD calculations */
- if(app_ram_base != (u32)__application_ram_start_address){
- logt("ERROR", "Warning: unused memory: 0x%x", ((u32)__application_ram_start_address) - app_ram_base);
- }
- } else if(err == NRF_ERROR_DATA_SIZE) {
- /* Not enough memory for the SoftDevice. place a breakpoint here or output
- app_ram_base */
- logt("ERROR", "Fatal: Not enough memory for the selected configuration. Required:0x%x", app_ram_base);
- } else {
- APP_ERROR_CHECK(err); //OK
- }
- //Enable DC/DC (needs external LC filter, cmp. nrf51 reference manual page 43)
- err = sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);
- APP_ERROR_CHECK(err); //OK
- //Set power mode
- err = sd_power_mode_set(NRF_POWER_MODE_LOWPWR);
- APP_ERROR_CHECK(err); //OK
- //Set preferred TX power
- err = sd_ble_gap_tx_power_set(Config->radioTransmitPower);
- APP_ERROR_CHECK(err); //OK
- // //Enable UART interrupt
- // NRF_UART0->INTENSET = UART_INTENSET_RXDRDY_Enabled << UART_INTENSET_RXDRDY_Pos;
- // //Enable interrupt forwarding for UART
- // err = sd_nvic_SetPriority(UART0_IRQn, NRF_APP_PRIORITY_LOW);
- // APP_ERROR_CHECK(err);
- // err = sd_nvic_EnableIRQ(UART0_IRQn);
- // APP_ERROR_CHECK(err);
- }
Add Comment
Please, Sign In to add comment