Guest User

Untitled

a guest
Jan 29th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.28 KB | None | 0 0
  1. void bleInit(void){
  2.     u32 err = 0;
  3.  
  4.     logt("NODE", "Initializing Softdevice");
  5.  
  6.     // Initialize the SoftDevice handler with the low frequency clock source
  7.     //And a reference to the previously allocated buffer
  8.     //No event handler is given because the event handling is done in the main loop
  9.     nrf_clock_lf_cfg_t xtal_cfg;
  10.     xtal_cfg.source = NRF_CLOCK_LF_SRC_XTAL;
  11.     xtal_cfg.xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_500_PPM;
  12.  
  13.     //SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL);
  14.     err = softdevice_handler_init(xtal_cfg, currentEventBuffer, sizeOfEvent, NULL);
  15.     APP_ERROR_CHECK(err);
  16.  
  17.     logt("NODE", "Softdevice Init OK");
  18.  
  19.     // Register with the SoftDevice handler module for System events.
  20.     err = softdevice_sys_evt_handler_set(sys_evt_dispatch);
  21.     APP_ERROR_CHECK(err);
  22.  
  23.     //Now we will enable the Softdevice. RAM usage depends on the values chosen
  24.     ble_enable_params_t params;
  25.     memset(&params, 0x00, sizeof(params));
  26.  
  27.     params.common_enable_params.vs_uuid_count = 5; //set the number of Vendor Specific UUIDs to 5
  28.  
  29.     //TODO: configure Bandwidth
  30.     //params.common_enable_params.p_conn_bw_counts->
  31.  
  32.     params.gap_enable_params.periph_conn_count = Config->meshMaxInConnections; //Number of connections as Peripheral
  33.     params.gap_enable_params.central_conn_count = Config->meshMaxOutConnections; //Number of connections as Central
  34.     params.gap_enable_params.central_sec_count = 1; //this application only needs to be able to pair in one central link at a time
  35.  
  36.     params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT; //we require the Service Changed characteristic
  37.     params.gatts_enable_params.attr_tab_size = BLE_GATTS_ATTR_TAB_SIZE_DEFAULT; //the default Attribute Table size is appropriate for our application
  38.  
  39.     //The base ram address is gathered from the linker
  40.     u32 app_ram_base = (u32)__application_ram_start_address;
  41.     /* enable the BLE Stack */
  42.     logt("ERROR", "Ram base at 0x%x", app_ram_base);
  43.     err = sd_ble_enable(&params, &app_ram_base);
  44.     if(err == NRF_SUCCESS){
  45.     /* Verify that __LINKER_APP_RAM_BASE matches the SD calculations */
  46.         if(app_ram_base != (u32)__application_ram_start_address){
  47.             logt("ERROR", "Warning: unused memory: 0x%x", ((u32)__application_ram_start_address) - app_ram_base);
  48.         }
  49.     } else if(err == NRF_ERROR_DATA_SIZE) {
  50.         /* Not enough memory for the SoftDevice. place a breakpoint here or output
  51.         app_ram_base */
  52.         logt("ERROR", "Fatal: Not enough memory for the selected configuration. Required:0x%x", app_ram_base);
  53.     } else {
  54.         APP_ERROR_CHECK(err); //OK
  55.     }
  56.  
  57.     //Enable DC/DC (needs external LC filter, cmp. nrf51 reference manual page 43)
  58.     err = sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);
  59.     APP_ERROR_CHECK(err); //OK
  60.  
  61.     //Set power mode
  62.     err = sd_power_mode_set(NRF_POWER_MODE_LOWPWR);
  63.     APP_ERROR_CHECK(err); //OK
  64.  
  65.     //Set preferred TX power
  66.     err = sd_ble_gap_tx_power_set(Config->radioTransmitPower);
  67.     APP_ERROR_CHECK(err); //OK
  68.  
  69. //  //Enable UART interrupt
  70. //  NRF_UART0->INTENSET = UART_INTENSET_RXDRDY_Enabled << UART_INTENSET_RXDRDY_Pos;
  71. //  //Enable interrupt forwarding for UART
  72. //  err = sd_nvic_SetPriority(UART0_IRQn, NRF_APP_PRIORITY_LOW);
  73. //  APP_ERROR_CHECK(err);
  74. //  err = sd_nvic_EnableIRQ(UART0_IRQn);
  75. //  APP_ERROR_CHECK(err);
  76. }
Add Comment
Please, Sign In to add comment