/**@brief Function for initializing the DTM mode. */ static void dtm_init(void) { uint32_t err_code; app_uart_stream_comm_params_t uart_params; uart_params.baud_rate = UART_BAUD_RATE_19200; uart_params.rx_pin_no = DTM_RX_PIN_NO; uart_params.tx_pin_no = DTM_TX_PIN_NO; err_code = ble_dtm_init(&uart_params); if (err_code == NRF_SUCCESS) { err_code = bsp_indication_set(BSP_INDICATE_USER_STATE_OFF); APP_ERROR_CHECK(err_code); // Close serialization transport layer. err_code = sd_softdevice_disable(); APP_ERROR_CHECK(err_code); // Enter to infinite loop. for (;;) { err_code = sd_app_evt_wait(); APP_ERROR_CHECK(err_code); } } APP_ERROR_CHECK(err_code); }
/**@brief Function for preparing the reset, disabling SoftDevice, and jumping to the bootloader. * * @param[in] conn_handle Connection handle for peer requesting to enter DFU mode. */ static void bootloader_start(uint16_t conn_handle) { uint32_t err_code; uint16_t sys_serv_attr_len = sizeof(m_peer_data.sys_serv_attr); err_code = sd_ble_gatts_sys_attr_get(conn_handle, m_peer_data.sys_serv_attr, &sys_serv_attr_len, BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS); if (err_code != NRF_SUCCESS) { // Any error at this stage means the system service attributes could not be fetched. // This means the service changed indication cannot be sent in DFU mode, but connection // is still possible to establish. } m_reset_prepare(); err_code = sd_power_gpregret_set(BOOTLOADER_DFU_START); APP_ERROR_CHECK(err_code); err_code = sd_softdevice_disable(); APP_ERROR_CHECK(err_code); err_code = sd_softdevice_vector_table_base_set(NRF_UICR->BOOTLOADERADDR); APP_ERROR_CHECK(err_code); dfu_app_peer_data_set(conn_handle); NVIC_ClearPendingIRQ(SWI2_IRQn); interrupts_disable(); bootloader_util_app_start(NRF_UICR->BOOTLOADERADDR); }
uint32_t softdevice_handler_sd_disable(void) { uint32_t err_code = sd_softdevice_disable(); m_softdevice_enabled = !(err_code == NRF_SUCCESS); return err_code; }
void bootloader_app_start(uint32_t app_addr) { // If the applications CRC has been checked and passed, the magic number will be written and we // can start the application safely. uint32_t err_code = sd_softdevice_disable(); APP_ERROR_CHECK(err_code); interrupts_disable(); err_code = sd_softdevice_vector_table_base_set(CODE_REGION_1_START); APP_ERROR_CHECK(err_code); bootloader_util_app_start(CODE_REGION_1_START); }
void ser_conn_is_ready_to_enter_dtm(void) { if (m_is_ready_to_enter_dtm) { /* Disable SoftDevice. */ (void)sd_softdevice_disable(); /* Close HAL Transport Layer. */ ser_hal_transport_close(); /* Start DTM mode. */ (void)dtm_start(m_comm_params); } }
uint32_t softdevice_handler_sd_disable(void) { uint32_t err_code = sd_softdevice_disable(); if (err_code == NRF_SUCCESS) { m_softdevice_enabled = false; #if (NRF_MODULE_ENABLED(CLOCK) && defined(SOFTDEVICE_PRESENT)) nrf_drv_clock_on_sd_disable(); #endif #if (NRF_MODULE_ENABLED(RNG) && defined(SOFTDEVICE_PRESENT)) nrf_drv_rng_on_sd_disable(); #endif } return err_code; }
void nRF51822::end() { sd_softdevice_disable(); if (this->_remoteCharacteristicInfo) { free(this->_remoteCharacteristicInfo); } if (this->_remoteServiceInfo) { free(this->_remoteServiceInfo); } if (this->_localCharacteristicInfo) { free(this->_localCharacteristicInfo); } this->_numLocalCharacteristics = 0; this->_numRemoteServices = 0; this->_numRemoteCharacteristics = 0; }
/**@brief Function for waiting for events. * * @details This function will place the chip in low power mode while waiting for events from * the BLE stack or other peripherals. When interrupted by an event, it will call the @ref * app_sched_execute function to process the received event. This function will return * when the final state of the firmware update is reached OR when a tear down is in * progress. */ static void wait_for_events(void) { for (;;) { // Wait in low power state for any events. uint32_t err_code = sd_app_event_wait(); APP_ERROR_CHECK(err_code); // Event received. Process it from the scheduler. app_sched_execute(); if (m_tear_down_in_progress) { // Wait until disconnected event is received. Once the disconnected event is received // from the stack, the macro IS_CONNECTED will return false. if (!IS_CONNECTED()) { err_code = sd_softdevice_disable(); APP_ERROR_CHECK(err_code); if (m_activate_img_after_tear_down) { // Start the currently valid application. (void)dfu_image_activate(); // Ignoring the error code returned by dfu_image_activate because if the // function fails, there is nothing that can be done to recover, other than // returning and letting the system go under reset. Also since the // tear down of the BLE Transport is already complete and the connection // with the DFU Controller is down. Hence the DFU Controller cannot be informed // about this failure. It is assumed that the DFU Controller is already // aware of a failed update procedure from errors returned by earlier // operations (eg. Validate operation would have returned a failure if there // was a failed image transfer). } return; } } } }
/**@brief Function for preparing the reset, disabling SoftDevice and jump to the bootloader. */ static void bootloader_start(void) { m_reset_prepare(); uint32_t err_code = sd_power_gpregret_set(BOOTLOADER_DFU_START); APP_ERROR_CHECK(err_code); err_code = sd_softdevice_disable(); APP_ERROR_CHECK(err_code); err_code = sd_softdevice_vector_table_base_set(NRF_UICR->BOOTLOADERADDR); APP_ERROR_CHECK(err_code); if (m_dm_handle_valid) { dfu_app_set_peer_data(); } NVIC_ClearPendingIRQ(SWI2_IRQn); interrupts_disable(); bootloader_util_app_start(NRF_UICR->BOOTLOADERADDR); }
int main() { simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, 0); xprintf("\n\n\n\n\n\r\n region2 start..\r\n"); if(region1_is_valid()) { xprintf("dump to region11111\r\n"); bootloader_app_start(); } system_app_pages_erase(CODE_REGION_1_START, CODE_REGION_1_SIZE); xprintf(" app area has eased..\r\n"); ble_start(); for( ; ;) { ble_rec_handle(); if(get_dfu_state() == SYSTEM_UPDATE_END) { xprintf("system update end.\r\n"); sd_softdevice_disable(); flash_specword_write((uint32_t*)BOOTLOADER_SETTINGS_ADDRESS, SYSTEM_APP_VALID_OFFSET, SYSTEM_APP_VALID); NVIC_SystemReset(); } if(get_dfu_state() == SYSTEM_UPDATE_FAILURE) { xprintf("system update failed.\r\n"); NVIC_SystemReset(); } } }
/**@brief Function for preparing the reset, disabling SoftDevice and jump to the bootloader. */ void bootloader_start(void) { m_reset_prepare(); uint32_t err_code = sd_power_gpregret_set(BOOTLOADER_DFU_START); APP_ERROR_CHECK(err_code); err_code = sd_softdevice_disable(); APP_ERROR_CHECK(err_code); err_code = sd_softdevice_vector_table_base_set(NRF_UICR->BOOTLOADERADDR); APP_ERROR_CHECK(err_code); // Commenting out the following block because it brings in unwanted dependencies from bonding. // TODO: discuss this with Nordic. // if (m_dm_handle_valid) // { // dfu_app_set_peer_data(); // } NVIC_ClearPendingIRQ(SWI2_IRQn); interrupts_disable(); bootloader_util_app_start(NRF_UICR->BOOTLOADERADDR); }
int main(){ initialize_all(); char buf[30]; uint8_t uart_data; // Print Device ID uint64_t this_device_id = (((uint64_t) NRF_FICR->DEVICEID[1] << 32) | ((uint64_t) NRF_FICR->DEVICEID[0])); sprintf((char*)buf, "ID: %llx\n", this_device_id); simple_uart_putstring(buf); uint8_t availability; bool radio_executed = false; // main application loop while (1) { //All the mugs that will be invited have been set if (is_connected()) { // Deal with radios sd_softdevice_disable(); radio_configure(); // simple_uart_putstring("Configured radio\n"); // simple_uart_putstring("Disabled soft device\n"); // END - Deal with radios bool disovery_complete = false; bool all_final_state = true; int8_t current_mug = 0; while (!disovery_complete){ uint64_t device_id = 0; // vibration_update(); if (receive_packet(20)){ device_id = packet[1]; if (this_device_id == device_id){ if (packet[0] == 0xcfcf){ // Master init sequence simple_uart_putstring("Got init!\n"); packet[0] = 0xaf; // Send ACK to Master send_packet(1); // ... 3 times ... simple_uart_putstring("[a]ccept or [r]eject:\n"); uart_data = simple_uart_get(); switch (uart_data) { case 'a': availability = 0xaa; simple_uart_putstring("Accepted\n"); break; case 'r': availability = 0xff; simple_uart_putstring("Rejected\n"); break; } uart_data = simple_uart_get(); } else if (packet[0] == 0xabab) { // Master poll availability simple_uart_putstring("Sent availability status!\n"); packet[0] = availability; // Send ACK to Master send_packet(1); } else if (packet[0] == 0xdede) { // Master kettle boiling simple_uart_putstring("Got invitation!\n"); packet[0] = 0xaf; // Send ACK to Master send_packet(1); // ... 3 times ... for (uint8_t i=0; i<100; i++){ nrf_gpio_pin_toggle(0); nrf_delay_ms(200); } } else { sprintf((char*)buf, "Brocken command: %llx\n", packet[0]); simple_uart_putstring(buf); } } else { simple_uart_putstring("Not applicable packet\n"); sprintf((char*)buf, "Target: %llx\n", packet[1]); simple_uart_putstring(buf); sprintf((char*)buf, "Command: %llx\n", packet[0]); simple_uart_putstring(buf); } } if (bump_action()) { disovery_complete = true; // uint8_t bump_evt = 1; // ble_update_bump(&bump_evt) } } // Deal with radios sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_RC_250_PPM_1000MS_CALIBRATION,app_error_handler); // simple_uart_putstring("Enabled soft device\n"); // END - Deal with radios // uint8_t bump_val = 1; // ble_update_bump(&bump_val); // simple_uart_putstring("They see me bumpin', I see 'em hatin'!\n"); disovery_complete = false; // RSVP_App(); //sends MUG information back to app via ble, defined in slip_ble.c } //debug_ble_ids(); // vibration_update(); app_sched_execute(); nrf_delay_ms(500); } }