/**@brief Function for initializing the BLE stack. * * @details Initializes the SoftDevice and the BLE event interrupt. */ static void ble_stack_init(void) { uint32_t err_code; // Initialize the SoftDevice handler module. SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL); ble_enable_params_t ble_enable_params; err_code = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT, &ble_enable_params); APP_ERROR_CHECK(err_code); //Check the ram settings against the used number of links CHECK_RAM_START_ADDR(CENTRAL_LINK_COUNT,PERIPHERAL_LINK_COUNT); // Enable BLE stack. err_code = softdevice_enable(&ble_enable_params); APP_ERROR_CHECK(err_code); // Register with the SoftDevice handler module for BLE events. err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch); APP_ERROR_CHECK(err_code); // Register with the SoftDevice handler module for BLE events. err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch); APP_ERROR_CHECK(err_code); }
/**@brief Function for initializing the BLE stack. * * @details Initializes the SoftDevice and the BLE event interrupt. */ static void ble_stack_init(void) { uint32_t err_code; // Initialize the SoftDevice handler library. nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC; SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL); // Retrieve default BLE stack configuration parameters. ble_enable_params_t ble_enable_params; (void) softdevice_enable_get_default_config(NRF_BLE_CENTRAL_LINK_COUNT, NRF_BLE_PERIPHERAL_LINK_COUNT, &ble_enable_params); // Manually override the default ATT MTU size. ble_enable_params.gatt_enable_params.att_mtu = NRF_BLE_GATT_MAX_MTU_SIZE; // Enable BLE stack. err_code = softdevice_enable(&ble_enable_params); APP_ERROR_CHECK(err_code); // Register a BLE event handler with the SoftDevice handler library. err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch); APP_ERROR_CHECK(err_code); }
/**@brief Function for initializing the BLE stack. * * @details Initializes the SoftDevice and the BLE event interrupt. */ static void ble_stack_init(void) { uint32_t err_code; nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC; // Initialize the SoftDevice handler module. SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL); ble_enable_params_t ble_enable_params; err_code = softdevice_enable_get_default_config(NRF_BLE_CENTRAL_LINK_COUNT, NRF_BLE_PERIPHERAL_LINK_COUNT, &ble_enable_params); APP_ERROR_CHECK(err_code); // Check the ram settings against the used number of links CHECK_RAM_START_ADDR(NRF_BLE_CENTRAL_LINK_COUNT, NRF_BLE_PERIPHERAL_LINK_COUNT); // Enable BLE stack. #if (NRF_SD_BLE_API_VERSION == 3) ble_enable_params.gatt_enable_params.att_mtu = NRF_BLE_GATT_MAX_MTU_SIZE; #endif err_code = softdevice_enable(&ble_enable_params); APP_ERROR_CHECK(err_code); // Register with the SoftDevice handler module for BLE events. err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch); APP_ERROR_CHECK(err_code); // Register with the SoftDevice handler module for BLE events. err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch); APP_ERROR_CHECK(err_code); }
/**@brief Function for initializing the BLE stack. * * @details Initializes the SoftDevice and the BLE event interrupt. */ static void ble_stack_init(void) { uint32_t err_code; nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC; // Initialize the SoftDevice handler module. SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL); ble_enable_params_t ble_enable_params; err_code = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT, &ble_enable_params); APP_ERROR_CHECK(err_code); #ifdef BLE_DFU_APP_SUPPORT ble_enable_params.gatts_enable_params.service_changed = 1; #endif // BLE_DFU_APP_SUPPORT //Check the ram settings against the used number of links CHECK_RAM_START_ADDR(CENTRAL_LINK_COUNT,PERIPHERAL_LINK_COUNT); // Enable BLE stack. err_code = softdevice_enable(&ble_enable_params); APP_ERROR_CHECK(err_code); // Register with the SoftDevice handler module for BLE events. err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch); APP_ERROR_CHECK(err_code); // Register with the SoftDevice handler module for BLE events. err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch); APP_ERROR_CHECK(err_code); }
static uint32_t ble_stack_init(bool init_softdevice) { uint32_t err_code; nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC; if (init_softdevice) { err_code = nrf_dfu_mbr_init_sd(); VERIFY_SUCCESS(err_code); } NRF_LOG_INFO("vector table: 0x%08x\r\n", BOOTLOADER_START_ADDR); err_code = sd_softdevice_vector_table_base_set(BOOTLOADER_START_ADDR); VERIFY_SUCCESS(err_code); SOFTDEVICE_HANDLER_APPSH_INIT(&clock_lf_cfg, true); ble_enable_params_t ble_enable_params; // Only one connection as a central is used when performing dfu. err_code = softdevice_enable_get_default_config(1, 1, &ble_enable_params); VERIFY_SUCCESS(err_code); #if (NRF_SD_BLE_API_VERSION == 3) ble_enable_params.gatt_enable_params.att_mtu = NRF_BLE_MAX_MTU_SIZE; #endif // Enable BLE stack. err_code = softdevice_enable(&ble_enable_params); return err_code; }
/**@brief Function for the SoftDevice initialization. * * @details This function initializes the SoftDevice and the BLE event interrupt. */ static void ble_stack_init(void) { uint32_t err_code; // Initialize SoftDevice. // SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL); SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_8000MS_CALIBRATION, false); ble_enable_params_t ble_enable_params; err_code = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT, &ble_enable_params); APP_ERROR_CHECK(err_code); //Check the ram settings against the used number of links CHECK_RAM_START_ADDR(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT); extern void __data_start__; if (IDEAL_RAM_START_ADDRESS(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT) != (uint32_t)&__data_start__) { jsiConsolePrintf("WARNING: BLE RAM start address not correct - is 0x%x, should be 0x%x", (uint32_t)&__data_start__, IDEAL_RAM_START_ADDRESS(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT)); jshTransmitFlush(); } // Enable BLE stack. err_code = softdevice_enable(&ble_enable_params); APP_ERROR_CHECK(err_code); // Subscribe for BLE events. err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch); APP_ERROR_CHECK(err_code); }
/**@brief Function for initializing the BLE stack. * * @details Initializes the SoftDevice and the BLE event interrupt. * * @param[in] init_softdevice true if SoftDevice should be initialized. The SoftDevice must only * be initialized if a chip reset has occured. Soft reset from * application must not reinitialize the SoftDevice. */ static void ble_stack_init(bool init_softdevice) { uint32_t err_code; sd_mbr_command_t com = {SD_MBR_COMMAND_INIT_SD, }; nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC; if (init_softdevice) { err_code = sd_mbr_command(&com); APP_ERROR_CHECK(err_code); } err_code = sd_softdevice_vector_table_base_set(BOOTLOADER_REGION_START); APP_ERROR_CHECK(err_code); SOFTDEVICE_HANDLER_APPSH_INIT(&clock_lf_cfg, true); // Enable BLE stack. ble_enable_params_t ble_enable_params; // Only one connection as a central is used when performing dfu. err_code = softdevice_enable_get_default_config(1, 1, &ble_enable_params); APP_ERROR_CHECK(err_code); ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT; err_code = softdevice_enable(&ble_enable_params); APP_ERROR_CHECK(err_code); err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch); APP_ERROR_CHECK(err_code); }
/**@brief Function for initializing the BLE stack. * * @details Initializes the SoftDevice and the BLE event interrupts. */ static void ble_stack_init(void) { ret_code_t err_code; nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC; // Initialize the SoftDevice handler module. SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL); ble_enable_params_t ble_enable_params; err_code = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT, &ble_enable_params); APP_ERROR_CHECK(err_code); // Stack checks first if there are still entries in the table before checking if a vendor // specific UUID is already in the table thus to be able to call sd_ble_uuid_vs_add several // times with the same entry, vs_uuid_count has to be 1 bigger than what is actually needed. ble_enable_params.common_enable_params.vs_uuid_count = 2; // Check the ram settings against the used number of links CHECK_RAM_START_ADDR(CENTRAL_LINK_COUNT,PERIPHERAL_LINK_COUNT); // Enable BLE stack. err_code = softdevice_enable(&ble_enable_params); APP_ERROR_CHECK(err_code); // Register with the SoftDevice handler module for BLE events. err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch); APP_ERROR_CHECK(err_code); }
/**@brief Function for the SoftDevice initialization. * * @details This function initializes the SoftDevice and the BLE event interrupt. */ static void ble_stack_init(void) { uint32_t err_code; nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC; // Initialize SoftDevice. SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL); ble_enable_params_t ble_enable_params; err_code = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT, &ble_enable_params); APP_ERROR_CHECK(err_code); //Check the ram settings against the used number of links CHECK_RAM_START_ADDR(CENTRAL_LINK_COUNT,PERIPHERAL_LINK_COUNT); // Enable BLE stack. err_code = softdevice_enable(&ble_enable_params); APP_ERROR_CHECK(err_code); // Subscribe for BLE events. err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch); APP_ERROR_CHECK(err_code); }
error_t btle_init(void) { nrf_clock_lf_cfg_t clockConfiguration; // Configure the LF clock according to values provided by btle_clock.h. // It is input from the chain of the yotta configuration system. clockConfiguration.source = LFCLK_CONF_SOURCE; clockConfiguration.xtal_accuracy = LFCLK_CONF_ACCURACY; clockConfiguration.rc_ctiv = LFCLK_CONF_RC_CTIV; clockConfiguration.rc_temp_ctiv = LFCLK_CONF_RC_TEMP_CTIV; SOFTDEVICE_HANDLER_INIT(&clockConfiguration, signalEvent); // Enable BLE stack /** * Using this call, the application can select whether to include the * Service Changed characteristic in the GATT Server. The default in all * previous releases has been to include the Service Changed characteristic, * but this affects how GATT clients behave. Specifically, it requires * clients to subscribe to this attribute and not to cache attribute handles * between connections unless the devices are bonded. If the application * does not need to change the structure of the GATT server attributes at * runtime this adds unnecessary complexity to the interaction with peer * clients. If the SoftDevice is enabled with the Service Changed * Characteristics turned off, then clients are allowed to cache attribute * handles making applications simpler on both sides. */ static const bool IS_SRVC_CHANGED_CHARACT_PRESENT = true; ble_enable_params_t ble_enable_params; uint32_t err_code = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT, &ble_enable_params); ble_enable_params.gatts_enable_params.attr_tab_size = GATTS_ATTR_TAB_SIZE; ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT; ble_enable_params.common_enable_params.vs_uuid_count = UUID_TABLE_MAX_ENTRIES; if(err_code != NRF_SUCCESS) { return ERROR_INVALID_PARAM; } if (softdevice_enable(&ble_enable_params) != NRF_SUCCESS) { return ERROR_INVALID_PARAM; } ble_gap_addr_t addr; if (sd_ble_gap_address_get(&addr) != NRF_SUCCESS) { return ERROR_INVALID_PARAM; } if (sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &addr) != NRF_SUCCESS) { return ERROR_INVALID_PARAM; } ASSERT_STATUS( softdevice_ble_evt_handler_set(btle_handler)); ASSERT_STATUS( softdevice_sys_evt_handler_set(sys_evt_dispatch)); return btle_gap_init(); }
/**@brief Function for initializing the BLE stack. * * @details Initializes the SoftDevice and the BLE event interrupt. * * @param[in] init_softdevice true if SoftDeviceshould be initialized. The SoftDevice must only * be initialized if a chip reset has occured. Soft reset from * application must not reinitialize the SoftDevice. */ static void ble_stack_init(bool init_softdevice) { uint32_t err_code; sd_mbr_command_t com = {SD_MBR_COMMAND_INIT_SD, }; if (init_softdevice) { err_code = sd_mbr_command(&com); APP_ERROR_CHECK(err_code); } err_code = sd_softdevice_vector_table_base_set(BOOTLOADER_REGION_START); APP_ERROR_CHECK(err_code); // TODO: enable if we're on a device with 32kHz xtal /*nrf_clock_lf_cfg_t clock_lf_cfg = { .source = NRF_CLOCK_LF_SRC_XTAL, .rc_ctiv = 0, .rc_temp_ctiv = 0, .xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM};*/ nrf_clock_lf_cfg_t clock_lf_cfg = { .source = NRF_CLOCK_LF_SRC_RC, .rc_ctiv = 16, // recommended for nRF52 .rc_temp_ctiv = 2, // recommended for nRF52 .xtal_accuracy = 0}; SOFTDEVICE_HANDLER_APPSH_INIT(&clock_lf_cfg, true); // Enable BLE stack. ble_enable_params_t ble_enable_params; // Only one connection as a central is used when performing dfu. err_code = softdevice_enable_get_default_config(1, 1, &ble_enable_params); APP_ERROR_CHECK(err_code); ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT; err_code = softdevice_enable(&ble_enable_params); APP_ERROR_CHECK(err_code); err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch); APP_ERROR_CHECK(err_code); } /**@brief Function for event scheduler initialization. */ static void scheduler_init(void) { APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE); }
/**@brief Function for the SoftDevice initialization. * * @details This function initializes the SoftDevice and the BLE event interrupt. */ static void ble_stack_init(void) { uint32_t err_code; nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC; // Initialize SoftDevice. SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL); // Fetch the start address of the application RAM. uint32_t ram_start = 0; err_code = softdevice_app_ram_start_get(&ram_start); APP_ERROR_CHECK(err_code); // Overwrite some of the default configurations for the BLE stack. ble_cfg_t ble_cfg; // Configure the maximum number of connections. memset(&ble_cfg, 0, sizeof(ble_cfg)); ble_cfg.gap_cfg.role_count_cfg.periph_role_count = BLE_GAP_ROLE_COUNT_PERIPH_DEFAULT; ble_cfg.gap_cfg.role_count_cfg.central_role_count = 0; ble_cfg.gap_cfg.role_count_cfg.central_sec_count = 0; err_code = sd_ble_cfg_set(BLE_GAP_CFG_ROLE_COUNT, &ble_cfg, ram_start); APP_ERROR_CHECK(err_code); // Configure the maximum ATT MTU. memset(&ble_cfg, 0x00, sizeof(ble_cfg)); ble_cfg.conn_cfg.conn_cfg_tag = CONN_CFG_TAG; ble_cfg.conn_cfg.params.gatt_conn_cfg.att_mtu = NRF_BLE_GATT_MAX_MTU_SIZE; err_code = sd_ble_cfg_set(BLE_CONN_CFG_GATT, &ble_cfg, ram_start); APP_ERROR_CHECK(err_code); // Configure the maximum event length. memset(&ble_cfg, 0x00, sizeof(ble_cfg)); ble_cfg.conn_cfg.conn_cfg_tag = CONN_CFG_TAG; ble_cfg.conn_cfg.params.gap_conn_cfg.event_length = 320; ble_cfg.conn_cfg.params.gap_conn_cfg.conn_count = BLE_GAP_CONN_COUNT_DEFAULT; err_code = sd_ble_cfg_set(BLE_CONN_CFG_GAP, &ble_cfg, ram_start); APP_ERROR_CHECK(err_code); // Enable BLE stack. err_code = softdevice_enable(&ram_start); APP_ERROR_CHECK(err_code); // Subscribe for BLE events. err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch); APP_ERROR_CHECK(err_code); }
void ble_stack_start(void) { uint32_t err_code; nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC; SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL); // Enable BLE stack ble_enable_params_t ble_enable_params; err_code = softdevice_enable_get_default_config(0, 1, &ble_enable_params); APP_ERROR_CHECK(err_code); err_code = softdevice_enable(&ble_enable_params); APP_ERROR_CHECK(err_code); err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch); APP_ERROR_CHECK(err_code); }
/**@brief Function for initializing the BLE stack. * * @details Initializes the SoftDevice and the BLE event interrupt. * * @param[in] init_softdevice true if SoftDevice should be initialized. The SoftDevice must only * be initialized if a chip reset has occured. Soft reset from * application must not reinitialize the SoftDevice. */ static void ble_stack_init(bool init_softdevice) { uint32_t err_code; sd_mbr_command_t com = {SD_MBR_COMMAND_INIT_SD, }; // Initialize the SoftDevice handler module. nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC; // Check if the 32 bit crystal does Exist or Not. if((DFU_DEVICE_INFO->device_type & 0x8000) == 0) { clock_lf_cfg.source = NRF_CLOCK_LF_SRC_RC; clock_lf_cfg.rc_ctiv = 16; clock_lf_cfg.rc_temp_ctiv = 2; } if (init_softdevice) { err_code = sd_mbr_command(&com); APP_ERROR_CHECK(err_code); } err_code = sd_softdevice_vector_table_base_set(BOOTLOADER_REGION_START); APP_ERROR_CHECK(err_code); SOFTDEVICE_HANDLER_APPSH_INIT(&clock_lf_cfg, true); // Enable BLE stack. ble_enable_params_t ble_enable_params; // Only one connection as a central is used when performing dfu. err_code = softdevice_enable_get_default_config(1, 1, &ble_enable_params); APP_ERROR_CHECK(err_code); ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT; err_code = softdevice_enable(&ble_enable_params); APP_ERROR_CHECK(err_code); err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch); APP_ERROR_CHECK(err_code); }
/**@brief Function for initializing the BLE stack. * * @details Initializes the SoftDevice and the BLE event interrupt. */ void ble_stack_init(void) { uint32_t err_code; //Copied from pca10028.h to cut dependence on bsp/ #define NRF_CLOCK_LFCLKSRC {.source = NRF_CLOCK_LF_SRC_XTAL, \ .rc_ctiv = 0, \ .rc_temp_ctiv = 0, \ .xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM} nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC; // Initialize the SoftDevice handler module. SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL); ble_enable_params_t ble_enable_params; err_code = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT, &ble_enable_params); APP_ERROR_CHECK(err_code); ble_enable_params.common_enable_params.vs_uuid_count = VENDOR_SPECIFIC_UUID_COUNT; //Check the ram settings against the used number of links CHECK_RAM_START_ADDR(CENTRAL_LINK_COUNT,PERIPHERAL_LINK_COUNT); // Enable BLE stack. err_code = softdevice_enable(&ble_enable_params); APP_ERROR_CHECK(err_code); // Register with the SoftDevice handler module for BLE events. err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch); APP_ERROR_CHECK(err_code); // Register with the SoftDevice handler module for System events. err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch); APP_ERROR_CHECK(err_code); }
static uint32_t ble_stack_init(bool init_softdevice) { uint32_t err_code; nrf_clock_lf_cfg_t clock_lf_cfg = { .source = NRF_CLOCK_LF_SRC_RC, .rc_ctiv = 16, // recommended for nRF52 .rc_temp_ctiv = 2, // recommended for nRF52 .xtal_accuracy = 0}; if (init_softdevice) { err_code = nrf_dfu_mbr_init_sd(); VERIFY_SUCCESS(err_code); } NRF_LOG_INFO("vector table: 0x%08x\r\n", BOOTLOADER_START_ADDR); err_code = sd_softdevice_vector_table_base_set(BOOTLOADER_START_ADDR); VERIFY_SUCCESS(err_code); SOFTDEVICE_HANDLER_APPSH_INIT(&clock_lf_cfg, true); ble_enable_params_t ble_enable_params; // Only one connection as a central is used when performing dfu. err_code = softdevice_enable_get_default_config(1, 1, &ble_enable_params); VERIFY_SUCCESS(err_code); #if (NRF_SD_BLE_API_VERSION == 3) ble_enable_params.gatt_enable_params.att_mtu = NRF_BLE_MAX_MTU_SIZE; #endif // Enable BLE stack. err_code = softdevice_enable(&ble_enable_params); return err_code; } /**@brief Function for adding DFU Packet characteristic to the BLE Stack. * * @param[in] p_dfu DFU Service structure. * * @return NRF_SUCCESS on success. Otherwise an error code. */ static uint32_t dfu_pkt_char_add(ble_dfu_t * const p_dfu) { ble_gatts_char_md_t char_md = {{0}}; ble_gatts_attr_t attr_char_value = {0}; ble_gatts_attr_md_t attr_md = {{0}}; ble_uuid_t char_uuid; char_md.char_props.write_wo_resp = 1; char_uuid.type = p_dfu->uuid_type; char_uuid.uuid = BLE_DFU_PKT_CHAR_UUID; BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.read_perm); BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm); attr_md.vloc = BLE_GATTS_VLOC_STACK; attr_md.vlen = 1; attr_char_value.p_uuid = &char_uuid; attr_char_value.p_attr_md = &attr_md; attr_char_value.max_len = MAX_DFU_PKT_LEN; attr_char_value.p_value = NULL; return sd_ble_gatts_characteristic_add(p_dfu->service_handle, &char_md, &attr_char_value, &p_dfu->dfu_pkt_handles); }
/**@brief Function for initializing the BLE stack. * * @details Initializes the SoftDevice and the BLE event interrupt. */ static void ble_stack_init(void) { uint32_t err_code; // Initialize the SoftDevice handler module. SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL); ble_enable_params_t ble_enable_params; err_code = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT, &ble_enable_params); if (err_code == NRF_SUCCESS) debug_printf("Softdevice configured with links and ble parameters!\r\n"); else { debug_printf("Ooops.. Something is wrong with setting softdevice parameters..\r\n"); APP_ERROR_CHECK(err_code); } #ifdef BLE_DFU_APP_SUPPORT ble_enable_params.gatts_enable_params.service_changed = 1; #endif // BLE_DFU_APP_SUPPORT //Check the ram settings against the used number of links CHECK_RAM_START_ADDR(CENTRAL_LINK_COUNT,PERIPHERAL_LINK_COUNT); //memset(&ble_enable_params, 0, sizeof(ble_enable_params)); ble_enable_params.common_enable_params.vs_uuid_count = 2; //ble_enable_params.gatts_enable_params.attr_tab_size = 0x0900; //changing stack size? // Enable BLE stack. err_code = softdevice_enable(&ble_enable_params); if (err_code == NRF_SUCCESS) debug_printf("Softdevice enabled successfully!\r\n"); else { debug_printf("Ooops.. Something is wrong with enabling softdevice..\r\n"); APP_ERROR_CHECK(err_code); } // Register with the SoftDevice handler module for BLE events. err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch); if (err_code == NRF_SUCCESS) debug_printf("Softdevice registered for BLE events!\r\n"); else { debug_printf("Ooops.. Something went wrong with registering to BLE events..\r\n"); APP_ERROR_CHECK(err_code); } // Register with the SoftDevice handler module for SYS events. err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch); if (err_code == NRF_SUCCESS) debug_printf("Softdevice registered for SYS events!\r\n"); else { debug_printf("Ooops.. Something went wrong with registering to SYS events..\r\n"); APP_ERROR_CHECK(err_code); } }