static void uart_event_handler(void * context, nrf_libuarte_async_evt_t * p_event) { cli_libuarte_internal_t * p_internal = mp_internal; ret_code_t err_code = NRF_SUCCESS; size_t len; UNUSED_VARIABLE(err_code); switch (p_event->type) { case NRF_LIBUARTE_ASYNC_EVT_ERROR: NRF_LOG_WARNING("(evt) ERROR"); break; case NRF_LIBUARTE_ASYNC_EVT_RX_DATA: { len = (size_t)((uint32_t)p_event->data.rxtx.length & 0x0000FFFF); err_code = nrf_ringbuf_cpy_put(p_internal->p_rx_ringbuf, p_event->data.rxtx.p_data, &len); ASSERT(err_code == NRF_SUCCESS); if (len != p_event->data.rxtx.length) { NRF_LOG_WARNING("Data lost, no room in RX ringbuf"); } nrf_libuarte_async_rx_free(&libuarte, p_event->data.rxtx.p_data, p_event->data.rxtx.length); if (p_event->data.rxtx.length) { NRF_LOG_DEBUG("(evt) RXRDY length:%d", p_event->data.rxtx.length); NRF_LOG_HEXDUMP_DEBUG(p_event->data.rxtx.p_data, p_event->data.rxtx.length); p_internal->p_cb->handler(NRF_CLI_TRANSPORT_EVT_RX_RDY, p_internal->p_cb->p_context); } break; } case NRF_LIBUARTE_ASYNC_EVT_TX_DONE: err_code = nrf_ringbuf_free(p_internal->p_tx_ringbuf, p_event->data.rxtx.length); ASSERT(err_code == NRF_SUCCESS); uint8_t * p_data; len = 255; err_code = nrf_ringbuf_get(p_internal->p_tx_ringbuf, &p_data, &len, true); ASSERT(err_code == NRF_SUCCESS); if (len) { NRF_LOG_DEBUG("(evt) Started TX (%d).", len); err_code = nrf_libuarte_async_tx(&libuarte, p_data, len); ASSERT(err_code == NRF_SUCCESS); } else { m_uart_busy = false; } p_internal->p_cb->handler(NRF_CLI_TRANSPORT_EVT_TX_RDY, p_internal->p_cb->p_context); NRF_LOG_DEBUG("(evt) TX completed (%d)", p_event->data.rxtx.length); break; default: NRF_LOG_ERROR("(evt) Unknown event"); ASSERT(false); break; } }
/*lint --e{10} --e{19} --e{27} --e{40} --e{529} -save suppress Error 27: Illegal character */ uint32_t sd_check_ram_start(uint32_t sd_req_ram_start) { #if (defined(S130) || defined(S132) || defined(S332)) #if defined ( __CC_ARM ) extern uint32_t Image$$RW_IRAM1$$Base; const volatile uint32_t ram_start = (uint32_t) &Image$$RW_IRAM1$$Base; #elif defined ( __ICCARM__ ) extern uint32_t __ICFEDIT_region_RAM_start__; volatile uint32_t ram_start = (uint32_t) &__ICFEDIT_region_RAM_start__; #elif defined ( __GNUC__ ) extern uint32_t __data_start__; volatile uint32_t ram_start = (uint32_t) &__data_start__; #endif//__CC_ARM if (ram_start != sd_req_ram_start) { NRF_LOG_WARNING("RAM START ADDR 0x%x should be adjusted to 0x%x\r\n", ram_start, sd_req_ram_start); NRF_LOG_WARNING("RAM SIZE should be adjusted to 0x%x \r\n", ram_end_address_get() - sd_req_ram_start); return NRF_SUCCESS; } #endif//defined(S130) || defined(S132) || defined(S332) return NRF_SUCCESS; }
nrf_dfu_result_t nrf_dfu_ver_validation_check(dfu_init_command_t const * p_init) { nrf_dfu_result_t ret_val = NRF_DFU_RES_CODE_SUCCESS; if (!fw_type_ok(p_init)) { NRF_LOG_ERROR("Invalid firmware type."); ret_val = EXT_ERR(NRF_DFU_EXT_ERROR_INIT_COMMAND_INVALID); } else if (!fw_hash_type_ok(p_init)) { NRF_LOG_ERROR("Invalid hash type."); ret_val = EXT_ERR(NRF_DFU_EXT_ERROR_WRONG_HASH_TYPE); } else if (!NRF_DFU_DEBUG || (NRF_DFU_DEBUG && ((p_init->has_is_debug == false) || (p_init->is_debug == false)))) { if (p_init->has_hw_version == false) { NRF_LOG_ERROR("No HW version."); ret_val = EXT_ERR(NRF_DFU_EXT_ERROR_INIT_COMMAND_INVALID); } else if (p_init->hw_version != NRF_DFU_HW_VERSION) { NRF_LOG_WARNING("Faulty HW version."); ret_val = EXT_ERR( NRF_DFU_EXT_ERROR_HW_VERSION_FAILURE); } else if (!sd_req_ok(p_init)) { NRF_LOG_WARNING("SD req not met."); ret_val = EXT_ERR(NRF_DFU_EXT_ERROR_SD_VERSION_FAILURE); } else if (p_init->has_fw_version) { if (!fw_version_ok(p_init)) { NRF_LOG_WARNING("FW version too low."); ret_val = EXT_ERR(NRF_DFU_EXT_ERROR_FW_VERSION_FAILURE); } } else { if (fw_version_required(p_init->type)) { NRF_LOG_ERROR("FW version missing."); ret_val = EXT_ERR(NRF_DFU_EXT_ERROR_INIT_COMMAND_INVALID); } } } return ret_val; }
uint32_t nrf_drv_ppi_channel_fork_assign(nrf_ppi_channel_t channel, uint32_t fork_tep) { ret_code_t err_code = NRF_SUCCESS; #ifdef PPI_FEATURE_FORKS_PRESENT if (!is_programmable_app_channel(channel)) { err_code = NRF_ERROR_INVALID_PARAM; } else if (!is_allocated_channel(channel)) { err_code = NRF_ERROR_INVALID_STATE; } else { nrf_ppi_fork_endpoint_setup(channel, fork_tep); NRF_LOG_INFO("Fork assigned channel: %d, task end point: %d.\r\n", channel, fork_tep); } NRF_LOG_INFO("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; #else err_code = NRF_ERROR_NOT_SUPPORTED; NRF_LOG_WARNING("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; #endif }
ret_code_t nrf_drv_clock_calibration_abort(void) { ret_code_t err_code = NRF_SUCCESS; #if CALIBRATION_SUPPORT CRITICAL_REGION_ENTER(); switch (m_clock_cb.cal_state) { case CAL_STATE_CT: nrf_clock_int_disable(NRF_CLOCK_INT_CTTO_MASK); nrf_clock_task_trigger(NRF_CLOCK_TASK_CTSTOP); m_clock_cb.cal_state = CAL_STATE_IDLE; if (m_clock_cb.cal_done_handler) { m_clock_cb.cal_done_handler(NRF_DRV_CLOCK_EVT_CAL_ABORTED); } break; case CAL_STATE_HFCLK_REQ: /* fall through. */ case CAL_STATE_CAL: m_clock_cb.cal_state = CAL_STATE_ABORT; break; default: break; } CRITICAL_REGION_EXIT(); NRF_LOG_INFO("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; #else err_code = NRF_ERROR_FORBIDDEN; NRF_LOG_WARNING("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; #endif // CALIBRATION_SUPPORT }
uint32_t nrf_drv_ppi_uninit(void) { ret_code_t err_code = NRF_SUCCESS; uint32_t mask = NRF_PPI_ALL_APP_GROUPS_MASK; nrf_ppi_channel_group_t group; if (m_drv_state == NRF_DRV_STATE_UNINITIALIZED) { err_code = NRF_ERROR_INVALID_STATE; NRF_LOG_WARNING("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; } m_drv_state = NRF_DRV_STATE_UNINITIALIZED; // Disable all channels and groups nrf_ppi_channels_disable(NRF_PPI_ALL_APP_CHANNELS_MASK); for (group = NRF_PPI_CHANNEL_GROUP0; mask != 0; mask &= ~group_to_mask(group), group++) { if (mask & group_to_mask(group)) { nrf_ppi_channel_group_clear(group); } } channel_allocated_clr_all(); group_allocated_clr_all(); NRF_LOG_INFO("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; }
ret_code_t nrf_drv_i2s_init(nrf_drv_i2s_config_t const * p_config, nrf_drv_i2s_data_handler_t handler) { ASSERT(handler); ret_code_t err_code; if (m_cb.state != NRF_DRV_STATE_UNINITIALIZED) { err_code = NRF_ERROR_INVALID_STATE; NRF_LOG_WARNING("Function: %s, error code: %s.", (uint32_t)__func__, (uint32_t)NRF_LOG_ERROR_STRING_GET(err_code)); return err_code; } if (p_config == NULL) { p_config = &m_default_config; } if (!nrf_i2s_configure(NRF_I2S, p_config->mode, p_config->format, p_config->alignment, p_config->sample_width, p_config->channels, p_config->mck_setup, p_config->ratio)) { err_code = NRF_ERROR_INVALID_PARAM; NRF_LOG_WARNING("Function: %s, error code: %s.", (uint32_t)__func__, (uint32_t)NRF_LOG_ERROR_STRING_GET(err_code)); return err_code; } configure_pins(p_config); m_cb.handler = handler; nrf_drv_common_irq_enable(I2S_IRQn, p_config->irq_priority); m_cb.state = NRF_DRV_STATE_INITIALIZED; err_code = NRF_SUCCESS; NRF_LOG_INFO("Function: %s, error code: %s.", (uint32_t)__func__, (uint32_t)NRF_LOG_ERROR_STRING_GET(err_code)); return err_code; }
uint32_t ble_nus_c_string_send(ble_nus_c_t * p_ble_nus_c, uint8_t * p_string, uint16_t length) { VERIFY_PARAM_NOT_NULL(p_ble_nus_c); if (length > BLE_NUS_MAX_DATA_LEN) { NRF_LOG_WARNING("Content too long.\r\n"); return NRF_ERROR_INVALID_PARAM; } if (p_ble_nus_c->conn_handle == BLE_CONN_HANDLE_INVALID) { NRF_LOG_WARNING("Connection handle invalid.\r\n"); return NRF_ERROR_INVALID_STATE; } ble_gattc_write_params_t const write_params = { .write_op = BLE_GATT_OP_WRITE_CMD, .flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE, .handle = p_ble_nus_c->handles.nus_rx_handle, .offset = 0, .len = length, .p_value = p_string }; return sd_ble_gattc_write(p_ble_nus_c->conn_handle, &write_params); } uint32_t ble_nus_c_handles_assign(ble_nus_c_t * p_ble_nus, const uint16_t conn_handle, const ble_nus_c_handles_t * p_peer_handles) { VERIFY_PARAM_NOT_NULL(p_ble_nus); p_ble_nus->conn_handle = conn_handle; if (p_peer_handles != NULL) { p_ble_nus->handles.nus_tx_cccd_handle = p_peer_handles->nus_tx_cccd_handle; p_ble_nus->handles.nus_tx_handle = p_peer_handles->nus_tx_handle; p_ble_nus->handles.nus_rx_handle = p_peer_handles->nus_rx_handle; } return NRF_SUCCESS; }
/** * Function is implemented as weak so that it can be overwritten by custom application error handler * when needed. */ __WEAK void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info) { __disable_irq(); NRF_LOG_FINAL_FLUSH(); #ifndef DEBUG NRF_LOG_ERROR("Fatal error"); #else switch (id) { #if defined(SOFTDEVICE_PRESENT) && SOFTDEVICE_PRESENT case NRF_FAULT_ID_SD_ASSERT: NRF_LOG_ERROR("SOFTDEVICE: ASSERTION FAILED"); break; case NRF_FAULT_ID_APP_MEMACC: NRF_LOG_ERROR("SOFTDEVICE: INVALID MEMORY ACCESS"); break; #endif case NRF_FAULT_ID_SDK_ASSERT: { assert_info_t * p_info = (assert_info_t *)info; NRF_LOG_ERROR("ASSERTION FAILED at %s:%u", p_info->p_file_name, p_info->line_num); break; } case NRF_FAULT_ID_SDK_ERROR: { error_info_t * p_info = (error_info_t *)info; NRF_LOG_ERROR("ERROR %u [%s] at %s:%u\r\nPC at: 0x%08x", p_info->err_code, nrf_strerror_get(p_info->err_code), p_info->p_file_name, p_info->line_num, pc); NRF_LOG_ERROR("End of error report"); break; } default: NRF_LOG_ERROR("UNKNOWN FAULT at 0x%08X", pc); break; } #endif NRF_BREAKPOINT_COND; // On assert, the system can only recover with a reset. #ifndef DEBUG NRF_LOG_WARNING("System reset"); NVIC_SystemReset(); #else app_error_save_and_stop(id, pc, info); #endif // DEBUG }
uint32_t softdevice_enable(ble_enable_params_t * p_ble_enable_params) { #if (defined(S130) || defined(S132) || defined(S332)) uint32_t err_code; uint32_t app_ram_base; #if defined ( __CC_ARM ) extern uint32_t Image$$RW_IRAM1$$Base; const volatile uint32_t ram_start = (uint32_t) &Image$$RW_IRAM1$$Base; #elif defined ( __ICCARM__ ) extern uint32_t __ICFEDIT_region_RAM_start__; volatile uint32_t ram_start = (uint32_t) &__ICFEDIT_region_RAM_start__; #elif defined ( __GNUC__ ) extern uint32_t __data_start__; volatile uint32_t ram_start = (uint32_t) &__data_start__; #endif app_ram_base = ram_start; NRF_LOG_DEBUG("sd_ble_enable: RAM start at 0x%x\r\n", app_ram_base); err_code = sd_ble_enable(p_ble_enable_params, &app_ram_base); if (app_ram_base != ram_start) { NRF_LOG_WARNING("sd_ble_enable: RAM start should be adjusted to 0x%x\r\n", app_ram_base); NRF_LOG_WARNING("RAM size should be adjusted to 0x%x \r\n", ram_end_address_get() - app_ram_base); } else if (err_code != NRF_SUCCESS) { NRF_LOG_ERROR("sd_ble_enable: error 0x%x\r\n", err_code); } return err_code; #else return NRF_SUCCESS; #endif //defined(S130) || defined(S132) || defined(S332) }
ret_code_t nrf_drv_clock_calibration_start(uint8_t interval, nrf_drv_clock_event_handler_t handler) { ret_code_t err_code = NRF_SUCCESS; #if CALIBRATION_SUPPORT ASSERT(m_clock_cb.cal_state == CAL_STATE_IDLE); if (m_clock_cb.lfclk_on == false) { err_code = NRF_ERROR_INVALID_STATE; } else if (m_clock_cb.cal_state == CAL_STATE_IDLE) { m_clock_cb.cal_done_handler = handler; m_clock_cb.cal_hfclk_started_handler_item.event_handler = clock_calibration_hf_started; if (interval == 0) { m_clock_cb.cal_state = CAL_STATE_HFCLK_REQ; nrf_drv_clock_hfclk_request(&m_clock_cb.cal_hfclk_started_handler_item); } else { m_clock_cb.cal_state = CAL_STATE_CT; nrf_clock_cal_timer_timeout_set(interval); nrf_clock_event_clear(NRF_CLOCK_EVENT_CTTO); nrf_clock_int_enable(NRF_CLOCK_INT_CTTO_MASK); nrf_clock_task_trigger(NRF_CLOCK_TASK_CTSTART); } } else { err_code = NRF_ERROR_BUSY; } NRF_LOG_WARNING("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; #else err_code = NRF_ERROR_FORBIDDEN; NRF_LOG_WARNING("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; #endif // CALIBRATION_SUPPORT }
ret_code_t nrf_drv_clock_is_calibrating(bool * p_is_calibrating) { ret_code_t err_code = NRF_SUCCESS; #if CALIBRATION_SUPPORT ASSERT(m_clock_cb.module_initialized); *p_is_calibrating = (m_clock_cb.cal_state != CAL_STATE_IDLE); NRF_LOG_INFO("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; #else err_code = NRF_ERROR_FORBIDDEN; NRF_LOG_WARNING("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; #endif // CALIBRATION_SUPPORT }
ret_code_t nrf_drv_spis_buffers_set(nrf_drv_spis_t const * const p_instance, const uint8_t * p_tx_buffer, uint8_t tx_buffer_length, uint8_t * p_rx_buffer, uint8_t rx_buffer_length) { spis_cb_t * p_cb = &m_cb[p_instance->instance_id]; uint32_t err_code; VERIFY_PARAM_NOT_NULL(p_rx_buffer); VERIFY_PARAM_NOT_NULL(p_tx_buffer); // EasyDMA requires that transfer buffers are placed in Data RAM region; // signal error if they are not. if ((p_tx_buffer != NULL && !nrf_drv_is_in_RAM(p_tx_buffer)) || (p_rx_buffer != NULL && !nrf_drv_is_in_RAM(p_rx_buffer))) { err_code = NRF_ERROR_INVALID_ADDR; NRF_LOG_WARNING("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; } switch (p_cb->spi_state) { case SPIS_STATE_INIT: case SPIS_XFER_COMPLETED: case SPIS_BUFFER_RESOURCE_CONFIGURED: p_cb->tx_buffer = p_tx_buffer; p_cb->rx_buffer = p_rx_buffer; p_cb->tx_buffer_size = tx_buffer_length; p_cb->rx_buffer_size = rx_buffer_length; err_code = NRF_SUCCESS; spis_state_change(p_instance->p_reg, p_cb, SPIS_BUFFER_RESOURCE_REQUESTED); break; case SPIS_BUFFER_RESOURCE_REQUESTED: err_code = NRF_ERROR_INVALID_STATE; break; default: // @note: execution of this code path would imply internal error in the design. err_code = NRF_ERROR_INTERNAL; break; } NRF_LOG_INFO("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; }
/**@brief Function runs the shutdown procedure. */ static void shutdown_process(void) { NRF_LOG_INFO("Shutdown started. Type %d\r\n", m_pwr_mgmt_evt); // Executing all callbacks. while (m_next_handler < PWR_MGMT_SECTION_VARS_COUNT) { if ((*PWR_MGMT_SECTION_VARS_GET(m_next_handler))(m_pwr_mgmt_evt)) { NRF_LOG_INFO("SysOff handler 0x%08X => ready\r\n", (unsigned int)*PWR_MGMT_SECTION_VARS_GET(m_next_handler)); } else { // One of the modules is not ready. NRF_LOG_INFO("SysOff handler 0x%08X => blocking\r\n", (unsigned int)*PWR_MGMT_SECTION_VARS_GET(m_next_handler)); return; } // Mark handler as executed. m_next_handler++; } #if NRF_PWR_MGMT_CONFIG_CPU_USAGE_MONITOR_ENABLED NRF_LOG_INFO("Maximum CPU usage: %u%%\r\n", m_max_cpu_usage); #endif // NRF_PWR_MGMT_CONFIG_CPU_USAGE_MONITOR_ENABLED NRF_LOG_WARNING("Shutdown\r\n"); NRF_LOG_FINAL_FLUSH(); // Enter System OFF. #ifdef SOFTDEVICE_PRESENT ret_code_t ret_code = sd_power_system_off(); if (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED) { NRF_POWER->SYSTEMOFF = POWER_SYSTEMOFF_SYSTEMOFF_Enter; } else { APP_ERROR_CHECK(ret_code); } #else NRF_POWER->SYSTEMOFF = POWER_SYSTEMOFF_SYSTEMOFF_Enter; #endif // SOFTDEVICE_PRESENT }
ret_code_t nrf_drv_rng_rand(uint8_t * p_buff, uint8_t length) { ret_code_t err_code = NRF_SUCCESS; ASSERT(m_rng_cb.state == NRFX_DRV_STATE_INITIALIZED); #ifdef SOFTDEVICE_PRESENT do { bool sd_is_enabled; NRF_DRV_RNG_LOCK(); sd_is_enabled = NRF_DRV_RNG_SD_IS_ENABLED(); if (!sd_is_enabled) #endif // SOFTDEVICE_PRESENT { err_code = nrf_queue_read(&m_rand_pool, p_buff, (uint32_t)length); nrfx_rng_start(); } #ifdef SOFTDEVICE_PRESENT NRF_DRV_RNG_RELEASE(); if (sd_is_enabled) { err_code = sd_rand_application_vector_get(p_buff, length); if (err_code == NRF_ERROR_SOC_RAND_NOT_ENOUGH_VALUES) { err_code = NRF_ERROR_NOT_FOUND; } } } while (err_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED); #endif // SOFTDEVICE_PRESENT ASSERT((err_code == NRF_SUCCESS) || (err_code == NRF_ERROR_NOT_FOUND)); #if defined(RNG_CONFIG_RANDOM_NUMBER_LOG_ENABLED) && (RNG_CONFIG_RANDOM_NUMBER_LOG_ENABLED != 0) NRF_LOG_DEBUG("Rand buffer data:"); NRF_LOG_HEXDUMP_DEBUG((uint8_t *)p_buff, length); #endif // RNG_CONFIG_RANDOM_NUMBER_LOG_ENABLED NRF_LOG_WARNING("Function: %s, error code: %s.", (uint32_t)__func__, (uint32_t)NRF_LOG_ERROR_STRING_GET(err_code)); return err_code; }
int main(void) { ret_code_t err_code; gpio_init(); err_code = NRF_LOG_INIT(NULL); APP_ERROR_CHECK(err_code); clocks_start(); err_code = esb_init(); APP_ERROR_CHECK(err_code); LEDS_CONFIGURE(LEDS_MASK); NRF_LOG_DEBUG("Enhanced ShockBurst Transmitter Example running.\r\n"); while (true) { NRF_LOG_DEBUG("Transmitting packet %02x\r\n", tx_payload.data[1]); tx_payload.noack = false; if (nrf_esb_write_payload(&tx_payload) == NRF_SUCCESS) { // Toggle one of the LEDs. nrf_gpio_pin_write(LED_1, !(tx_payload.data[1]%8>0 && tx_payload.data[1]%8<=4)); nrf_gpio_pin_write(LED_2, !(tx_payload.data[1]%8>1 && tx_payload.data[1]%8<=5)); nrf_gpio_pin_write(LED_3, !(tx_payload.data[1]%8>2 && tx_payload.data[1]%8<=6)); nrf_gpio_pin_write(LED_4, !(tx_payload.data[1]%8>3)); tx_payload.data[1]++; } else { NRF_LOG_WARNING("Sending packet failed\r\n"); } nrf_delay_us(50000); } }
ret_code_t nrf_drv_wdt_init(nrf_drv_wdt_config_t const * p_config, nrf_wdt_event_handler_t wdt_event_handler) { ASSERT(wdt_event_handler != NULL); ret_code_t err_code; m_wdt_event_handler = wdt_event_handler; if (m_state == NRF_DRV_STATE_UNINITIALIZED) { m_state = NRF_DRV_STATE_INITIALIZED; } else { err_code = NRF_ERROR_INVALID_STATE; NRF_LOG_WARNING("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; } if (p_config == NULL) { p_config = &m_default_config; } nrf_wdt_behaviour_set(p_config->behaviour); nrf_wdt_reload_value_set((p_config->reload_value * 32768) / 1000); nrf_drv_common_irq_enable(WDT_IRQn, p_config->interrupt_priority); err_code = NRF_SUCCESS; NRF_LOG_INFO("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; }
/** * Stores current mode to flash, given in parameters. * * Data is address of the tag_mode. * length is length of the address, not data. * */ static void store_mode(void* data, uint16_t length) { // Point the record directly to word-aligned tag mode rather than data pointer passed as context. ret_code_t err_code = flash_record_set(FDS_FILE_ID, FDS_RECORD_ID, sizeof(tag_mode), &tag_mode); if(err_code) { NRF_LOG_WARNING("Error in flash write %X\r\n", err_code); } else { size_t flash_space_remaining; flash_free_size_get(&flash_space_remaining); NRF_LOG_INFO("Stored mode in flash, Largest continuous space remaining %d bytes\r\n", flash_space_remaining); if(4000 > flash_space_remaining) { NRF_LOG_INFO("Flash space is almost used, running gc\r\n") flash_gc_run(); flash_free_size_get(&flash_space_remaining); NRF_LOG_INFO("Continuous space remaining after gc %d bytes\r\n", flash_space_remaining); } } }
static void on_packet_received(serial_dfu_t * p_dfu) { nrf_dfu_req_t dfu_req; nrf_dfu_res_t dfu_res = {{{0}}}; serial_dfu_response_t serial_response; memset(&dfu_req, 0, sizeof(nrf_dfu_req_t)); const serial_dfu_op_code_t op_code = (serial_dfu_op_code_t)p_dfu->recv_buffer[0]; const uint16_t packet_payload_len = p_dfu->slip.current_index - 1; uint8_t * p_payload = &p_dfu->recv_buffer[1]; serial_response.op_code = op_code; nrf_gpio_pin_clear(CONNECTED_LED_PIN_NO); nrf_gpio_pin_set(AVAILABLE_LED_PIN_NO); switch (op_code) { case SERIAL_DFU_OP_CODE_CREATE_OBJECT: if (packet_payload_len != CREATE_OBJECT_REQUEST_LEN) { serial_response.resp_val = NRF_DFU_RES_CODE_INVALID_PARAMETER; break; } NRF_LOG_DEBUG("Received create object\r\n"); // Reset the packet receipt notification on create object p_dfu->pkt_notif_target_count = p_dfu->pkt_notif_target; // Get type parameter dfu_req.obj_type = p_payload[0]; // Get length value dfu_req.object_size = uint32_decode(&p_payload[1]); // Set req type dfu_req.req_type = NRF_DFU_OBJECT_OP_CREATE; serial_response.resp_val = nrf_dfu_req_handler_on_req(NULL, &dfu_req, &dfu_res); break; case SERIAL_DFU_OP_CODE_SET_RECEIPT_NOTIF: NRF_LOG_DEBUG("Set receipt notif\r\n"); if (packet_payload_len != SET_RECEIPT_NOTIF_REQUEST_LEN) { serial_response.resp_val = NRF_DFU_RES_CODE_INVALID_PARAMETER; break; } p_dfu->pkt_notif_target = uint16_decode(&p_payload[0]); p_dfu->pkt_notif_target_count = p_dfu->pkt_notif_target; serial_response.resp_val = NRF_DFU_RES_CODE_SUCCESS; break; case SERIAL_DFU_OP_CODE_CALCULATE_CRC: NRF_LOG_DEBUG("Received calculate CRC\r\n"); dfu_req.req_type = NRF_DFU_OBJECT_OP_CRC; serial_response.resp_val = nrf_dfu_req_handler_on_req(NULL, &dfu_req, &dfu_res); serial_response.crc_response.offset = dfu_res.offset; serial_response.crc_response.crc = dfu_res.crc; break; case SERIAL_DFU_OP_CODE_EXECUTE_OBJECT: NRF_LOG_DEBUG("Received execute object\r\n"); // Set req type dfu_req.req_type = NRF_DFU_OBJECT_OP_EXECUTE; serial_response.resp_val = nrf_dfu_req_handler_on_req(NULL, &dfu_req, &dfu_res); break; case SERIAL_DFU_OP_CODE_SELECT_OBJECT: NRF_LOG_DEBUG("Received select object\r\n"); if (packet_payload_len != SELECT_OBJECT_REQUEST_LEN) { serial_response.resp_val = NRF_DFU_RES_CODE_INVALID_PARAMETER; break; } // Set object type to read info about dfu_req.obj_type = p_payload[0]; dfu_req.req_type = NRF_DFU_OBJECT_OP_SELECT; serial_response.resp_val = nrf_dfu_req_handler_on_req(NULL, &dfu_req, &dfu_res); serial_response.select_response.max_size = dfu_res.max_size; serial_response.select_response.offset = dfu_res.offset; serial_response.select_response.crc = dfu_res.crc; break; case SERIAL_DFU_OP_CODE_GET_SERIAL_MTU: NRF_LOG_DEBUG("Received get serial mtu\r\n"); serial_response.resp_val = NRF_DFU_RES_CODE_SUCCESS; serial_response.serial_mtu_response.mtu = sizeof(p_dfu->recv_buffer); break; case SERIAL_DFU_OP_CODE_WRITE_OBJECT: // Set req type dfu_req.req_type = NRF_DFU_OBJECT_OP_WRITE; // Set data and length dfu_req.p_req = &p_payload[0]; dfu_req.req_len = packet_payload_len; serial_response.resp_val = nrf_dfu_req_handler_on_req(NULL, &dfu_req, &dfu_res); if(serial_response.resp_val != NRF_DFU_RES_CODE_SUCCESS) { NRF_LOG_ERROR("Failure to run packet write\r\n"); } // Check if a packet receipt notification is needed to be sent. if (p_dfu->pkt_notif_target != 0 && --p_dfu->pkt_notif_target_count == 0) { serial_response.op_code = SERIAL_DFU_OP_CODE_CALCULATE_CRC; serial_response.crc_response.offset = dfu_res.offset; serial_response.crc_response.crc = dfu_res.crc; // Reset the counter for the number of firmware packets. p_dfu->pkt_notif_target_count = p_dfu->pkt_notif_target; } break; default: // Unsupported op code. NRF_LOG_WARNING("Received unsupported OP code\r\n"); serial_response.resp_val = NRF_DFU_RES_CODE_INVALID_PARAMETER; break; } if (op_code != SERIAL_DFU_OP_CODE_WRITE_OBJECT) { response_send(p_dfu, &serial_response); } }
ret_code_t nrf_drv_i2s_start(uint32_t * p_rx_buffer, uint32_t * p_tx_buffer, uint16_t buffer_size, uint8_t flags) { ASSERT((p_rx_buffer != NULL) || (p_tx_buffer != NULL)); uint16_t buffer_half_size = buffer_size / 2; ASSERT(buffer_half_size != 0); VERIFY_MODULE_INITIALIZED(); ret_code_t err_code; if ((p_rx_buffer != NULL) && !nrf_drv_is_in_RAM(p_rx_buffer)) { err_code = NRF_ERROR_INVALID_ADDR; NRF_LOG_WARNING("Function: %s, error code: %s.", (uint32_t)__func__, (uint32_t)NRF_LOG_ERROR_STRING_GET(err_code)); return err_code; } if ((p_tx_buffer != NULL) && !nrf_drv_is_in_RAM(p_tx_buffer)) { err_code = NRF_ERROR_INVALID_ADDR; NRF_LOG_WARNING("Function: %s, error code: %s.", (uint32_t)__func__, (uint32_t)NRF_LOG_ERROR_STRING_GET(err_code)); return err_code; } // Initially we set up the peripheral to use the first half of each buffer, // then in 'I2S_IRQHandler' we will switch to the second half. nrf_i2s_transfer_set(NRF_I2S, buffer_half_size, p_rx_buffer, p_tx_buffer); m_cb.p_rx_buffer = p_rx_buffer; m_cb.p_tx_buffer = p_tx_buffer; m_cb.buffer_half_size = buffer_half_size; m_cb.just_started = true; if ((flags & NRF_DRV_I2S_FLAG_SYNCHRONIZED_MODE) && // [synchronized mode makes sense only when both RX and TX are enabled] (m_cb.p_rx_buffer != NULL) && (m_cb.p_tx_buffer != NULL)) { m_cb.synchronized_mode = true; m_cb.rx_ready = false; m_cb.tx_ready = false; } else { m_cb.synchronized_mode = false; } nrf_i2s_enable(NRF_I2S); m_cb.state = NRF_DRV_STATE_POWERED_ON; if (m_cb.p_tx_buffer != NULL) { // Get from the application the first portion of data to be sent - we // need to have it in the transmit buffer before we start the transfer. // Unless the synchronized mode is active. In this mode we must wait // with this until the first portion of data is received, so here we // just make sure that there will be silence on the SDOUT line prior // to that moment. if (m_cb.synchronized_mode) { memset(m_cb.p_tx_buffer, 0, m_cb.buffer_half_size * sizeof(uint32_t)); } else { m_cb.handler(NULL, m_cb.p_tx_buffer, m_cb.buffer_half_size); } } nrf_i2s_event_clear(NRF_I2S, NRF_I2S_EVENT_RXPTRUPD); nrf_i2s_event_clear(NRF_I2S, NRF_I2S_EVENT_TXPTRUPD); nrf_i2s_int_enable(NRF_I2S, NRF_I2S_INT_RXPTRUPD_MASK | NRF_I2S_INT_TXPTRUPD_MASK); nrf_i2s_task_trigger(NRF_I2S, NRF_I2S_TASK_START); err_code = NRF_SUCCESS; NRF_LOG_INFO("Function: %s, error code: %s.", (uint32_t)__func__, (uint32_t)NRF_LOG_ERROR_STRING_GET(err_code)); return err_code; }
/** This is where it all starts ++++++++++++++++++++++++++++++++++++++++++ main is entered as a result of one of SEVERAL events: - Normal startup from press of reset button. - Battery inserted. - After DFU (Device Firmware Upgrade) at manufacturing Quality Assurance or user DFU. - WatchDogTimer expiration and its interrupt handler didn't feed new value. - Some error occured and - Spontenous unknown reset. All subsystems are initalized and any failures are noted and available later in init_status Since some events occur after tag is deployed and no one can see the LEDs the system continues operating. After initalizition (including setting up interrupts) we loop here calling app_sched_execute and sd_app_evt_wait */ int main(void) { // LEDs first (they're easy and cannot fail) drivers/init/init.c init_leds(); RED_LED_ON; if( init_log() ) { init_status |=LOG_FAILED_INIT; } else { NRF_LOG_INFO("LOG initalized \r\n"); } // subsequent initalizations assume log is working // start watchdog now in case program hangs up. // watchdog_default_handler logs error and resets the tag. init_watchdog(NULL); // Battery voltage initialization cannot fail under any reasonable circumstance. battery_voltage_init(); vbat = getBattery(); if( vbat < BATTERY_MIN_V ) { init_status |=BATTERY_FAILED_INIT; } else NRF_LOG_INFO("BATTERY initalized \r\n"); if(init_sensors() == NRF_SUCCESS ) { model_plus = true; NRF_LOG_INFO("Sensors initialized \r\n"); } // Init NFC ASAP in case we're waking from deep sleep via NFC (todo) // outputs ID:DEVICEID ,MAC:DEVICEADDR, SW:REVision set_nfc_callback(app_nfc_callback); if( init_nfc() ) { init_status |= NFC_FAILED_INIT; } else { NRF_LOG_INFO("NFC init \r\n"); } pin_interrupt_init(); if( pin_interrupt_enable(BSP_BUTTON_0, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIO_PIN_PULLUP, button_press_handler) ) { init_status |= BUTTON_FAILED_INIT; } // Initialize BLE Stack. Starts LFCLK required for timer operation. if( init_ble() ) { init_status |= BLE_FAILED_INIT; } bluetooth_configure_advertisement_type(STARTUP_ADVERTISEMENT_TYPE); bluetooth_tx_power_set(BLE_TX_POWER); bluetooth_configure_advertising_interval(ADVERTISING_INTERVAL_STARTUP); advertisement_delay = NRF_FICR->DEVICEID[0]&0x0F; // Priorities 2 and 3 are after SD timing critical events. // 6, 7 after SD non-critical events. // Triggers ADC, so use 3. ble_radio_notification_init(3, NRF_RADIO_NOTIFICATION_DISTANCE_800US, on_radio_evt); // If GATT is enabled BLE init inits peer manager which uses flash. // BLE init should handle insufficient space gracefully (i.e. erase flash and proceed). // Flash must be initialized after softdevice. if(flash_init()) { NRF_LOG_ERROR("Failed to init flash \r\n"); } size_t flash_space_remaining = 0; flash_free_size_get(&flash_space_remaining); NRF_LOG_INFO("Largest continuous space remaining %d bytes\r\n", flash_space_remaining); if(4000 > flash_space_remaining) { NRF_LOG_INFO("Flash space is almost used, running gc\r\n") flash_gc_run(); flash_free_size_get(&flash_space_remaining); NRF_LOG_INFO("Continuous space remaining after gc %d bytes\r\n", flash_space_remaining); } else if (flash_record_get(FDS_FILE_ID, FDS_RECORD_ID, sizeof(tag_mode), &tag_mode)) { NRF_LOG_INFO("Did not find mode in flash, is this first boot? \r\n"); } else { NRF_LOG_INFO("Loaded mode %d from flash\r\n", tag_mode); } if( init_rtc() ) { init_status |= RTC_FAILED_INIT; } else { NRF_LOG_INFO("RTC initialized \r\n"); } // Initialize lis2dh12 and BME280 - TODO: Differentiate LIS2DH12 and BME280 if (model_plus) { lis2dh12_reset(); // Clear memory. // Enable Low-To-Hi rising edge trigger interrupt on nRF52 to detect acceleration events. if (pin_interrupt_enable(INT_ACC2_PIN, NRF_GPIOTE_POLARITY_LOTOHI, NRF_GPIO_PIN_NOPULL, lis2dh12_int2_handler) ) { init_status |= ACC_INT_FAILED_INIT; } nrf_delay_ms(10); // Wait for LIS reboot. // Enable XYZ axes. lis2dh12_enable(); lis2dh12_set_scale(LIS2DH12_SCALE); lis2dh12_set_sample_rate(LIS2DH12_SAMPLERATE_RAWv1); lis2dh12_set_resolution(LIS2DH12_RESOLUTION); lis2dh12_set_activity_interrupt_pin_2(LIS2DH12_ACTIVITY_THRESHOLD); NRF_LOG_INFO("Accelerometer configuration done \r\n"); // oversampling must be set for each used sensor. bme280_set_oversampling_hum (BME280_HUMIDITY_OVERSAMPLING); bme280_set_oversampling_temp (BME280_TEMPERATURE_OVERSAMPLING); bme280_set_oversampling_press(BME280_PRESSURE_OVERSAMPLING); bme280_set_iir(BME280_IIR); bme280_set_interval(BME280_DELAY); bme280_set_mode(BME280_MODE_NORMAL); NRF_LOG_INFO("BME280 configuration done \r\n"); } // Enter stored mode after boot - or default mode if store mode was not found app_sched_event_put (&tag_mode, sizeof(&tag_mode), change_mode); // Initialize repeated timer for sensor read and single-shot timer for button reset if( init_timer(main_timer_id, APP_TIMER_MODE_REPEATED, MAIN_LOOP_INTERVAL_RAW, main_timer_handler) ) { init_status |= TIMER_FAILED_INIT; } if( init_timer(reset_timer_id, APP_TIMER_MODE_SINGLE_SHOT, BUTTON_RESET_TIME, reboot) ) { init_status |= TIMER_FAILED_INIT; } // Init starts timers, stop the reset app_timer_stop(reset_timer_id); // Log errors, add a note to NFC, blink RED to visually indicate the problem if (init_status) { snprintf((char* )NFC_message, NFC_message_length, "Error: %X", init_status); NRF_LOG_WARNING (" -- Initalization error : %X \r\n", init_status); for ( int16_t i=0; i<13; i++) { RED_LED_ON; nrf_delay_ms(500u); RED_LED_OFF; nrf_delay_ms(500u); } } // Turn green led on if model+ with no errors. // Power manage turns led off if (model_plus & !init_status) { GREEN_LED_ON; } // Turn off red led, leave green on to signal model+ without errors RED_LED_OFF; // Wait for sensors to take first sample nrf_delay_ms(1000); // Get first sample from sensors app_sched_event_put (NULL, 0, main_sensor_task); app_sched_execute(); // Start advertising bluetooth_advertising_start(); NRF_LOG_INFO("Advertising started\r\n"); // Enter main loop. Executes tasks scheduled by timers and interrupts. for (;;) { app_sched_execute(); // Sleep until next event. power_manage(); } }
ret_code_t nrf_drv_lpcomp_init(const nrf_drv_lpcomp_config_t * p_config, lpcomp_events_handler_t events_handler) { ASSERT(p_config); ret_code_t err_code; if (m_state != NRF_DRV_STATE_UNINITIALIZED) { // LPCOMP driver is already initialized err_code = NRF_ERROR_INVALID_STATE; NRF_LOG_WARNING("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; } #if NRF_MODULE_ENABLED(PERIPHERAL_RESOURCE_SHARING) if (nrf_drv_common_per_res_acquire(NRF_LPCOMP, IRQ_HANDLER_NAME) != NRF_SUCCESS) { err_code = NRF_ERROR_BUSY; NRF_LOG_WARNING("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; } #endif nrf_lpcomp_configure(&(p_config->hal) ); if (events_handler) { m_lpcomp_events_handler = events_handler; } else { err_code = NRF_ERROR_INVALID_PARAM; NRF_LOG_WARNING("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; } nrf_lpcomp_input_select(p_config->input); switch (p_config->hal.detection) { case NRF_LPCOMP_DETECT_UP: nrf_lpcomp_int_enable(LPCOMP_INTENSET_UP_Msk); break; case NRF_LPCOMP_DETECT_DOWN: nrf_lpcomp_int_enable(LPCOMP_INTENSET_DOWN_Msk); break; case NRF_LPCOMP_DETECT_CROSS: nrf_lpcomp_int_enable(LPCOMP_INTENSET_CROSS_Msk); break; default: break; } nrf_lpcomp_shorts_enable(NRF_LPCOMP_SHORT_READY_SAMPLE_MASK); nrf_drv_common_irq_enable(LPCOMP_IRQn, p_config->interrupt_priority); m_state = NRF_DRV_STATE_INITIALIZED; err_code = NRF_SUCCESS; NRF_LOG_INFO("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; }
ret_code_t nrf_drv_timer_init(nrf_drv_timer_t const * const p_instance, nrf_drv_timer_config_t const * p_config, nrf_timer_event_handler_t timer_event_handler) { timer_control_block_t * p_cb = &m_cb[p_instance->instance_id]; ASSERT(((p_instance->p_reg == NRF_TIMER0) && TIMER0_ENABLED) || (p_instance->p_reg != NRF_TIMER0)); ASSERT(((p_instance->p_reg == NRF_TIMER1) && TIMER1_ENABLED) || (p_instance->p_reg != NRF_TIMER1)); ASSERT(((p_instance->p_reg == NRF_TIMER2) && TIMER2_ENABLED) || (p_instance->p_reg != NRF_TIMER2)); #if TIMER_COUNT == 5 ASSERT(((p_instance->p_reg == NRF_TIMER3) && TIMER3_ENABLED) || (p_instance->p_reg != NRF_TIMER3)); ASSERT(((p_instance->p_reg == NRF_TIMER4) && TIMER4_ENABLED) || (p_instance->p_reg != NRF_TIMER4)); #endif //TIMER_COUNT #ifdef SOFTDEVICE_PRESENT ASSERT(p_instance->p_reg != NRF_TIMER0); ASSERT(p_config); #endif ret_code_t err_code; if (p_cb->state != NRF_DRV_STATE_UNINITIALIZED) { err_code = NRF_ERROR_INVALID_STATE; NRF_LOG_WARNING("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; } if (timer_event_handler == NULL) { err_code = NRF_ERROR_INVALID_PARAM; NRF_LOG_WARNING("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; } /* Warning 685: Relational operator '<=' always evaluates to 'true'" * Warning in NRF_TIMER_IS_BIT_WIDTH_VALID macro. Macro validate timers resolution. * Not necessary in nRF52 based systems. Obligatory in nRF51 based systems. */ /*lint -save -e685 */ ASSERT(NRF_TIMER_IS_BIT_WIDTH_VALID(p_instance->p_reg, p_config->bit_width)); //lint -restore p_cb->handler = timer_event_handler; p_cb->context = p_config->p_context; uint8_t i; for (i = 0; i < p_instance->cc_channel_count; ++i) { nrf_timer_event_clear(p_instance->p_reg, nrf_timer_compare_event_get(i)); } nrf_drv_common_irq_enable(nrf_drv_get_IRQn(p_instance->p_reg), p_config->interrupt_priority); nrf_timer_mode_set(p_instance->p_reg, p_config->mode); nrf_timer_bit_width_set(p_instance->p_reg, p_config->bit_width); nrf_timer_frequency_set(p_instance->p_reg, p_config->frequency); p_cb->state = NRF_DRV_STATE_INITIALIZED; err_code = NRF_SUCCESS; NRF_LOG_INFO("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; }
/** * Reboots tag. Enters bootloader as button is pressed on boot */ static void reboot(void* p_context) { NRF_LOG_WARNING("Rebooting\r\n") NVIC_SystemReset(); }
ret_code_t nrf_drv_spis_init(nrf_drv_spis_t const * const p_instance, nrf_drv_spis_config_t const * p_config, nrf_drv_spis_event_handler_t event_handler) { ASSERT(p_config); spis_cb_t * p_cb = &m_cb[p_instance->instance_id]; ret_code_t err_code; NRF_SPIS_Type * p_spis = p_instance->p_reg; if (p_cb->state != NRF_DRV_STATE_UNINITIALIZED) { err_code = NRF_ERROR_INVALID_STATE; NRF_LOG_WARNING("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; } if ((uint32_t)p_config->mode > (uint32_t)NRF_DRV_SPIS_MODE_3) { err_code = NRF_ERROR_INVALID_PARAM; NRF_LOG_WARNING("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; } if (!event_handler) { err_code = NRF_ERROR_NULL; NRF_LOG_WARNING("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; } #if NRF_MODULE_ENABLED(PERIPHERAL_RESOURCE_SHARING) if (nrf_drv_common_per_res_acquire(p_spis, m_irq_handlers[p_instance->instance_id]) != NRF_SUCCESS) { err_code = NRF_ERROR_BUSY; NRF_LOG_WARNING("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; } #endif // Configure the SPI pins for input. uint32_t mosi_pin; uint32_t miso_pin; if (p_config->miso_pin != NRF_DRV_SPIS_PIN_NOT_USED) { nrf_gpio_cfg(p_config->miso_pin, NRF_GPIO_PIN_DIR_INPUT, NRF_GPIO_PIN_INPUT_CONNECT, NRF_GPIO_PIN_NOPULL, p_config->miso_drive, NRF_GPIO_PIN_NOSENSE); miso_pin = p_config->miso_pin; } else { miso_pin = NRF_SPIS_PIN_NOT_CONNECTED; } if (p_config->mosi_pin != NRF_DRV_SPIS_PIN_NOT_USED) { nrf_gpio_cfg(p_config->mosi_pin, NRF_GPIO_PIN_DIR_INPUT, NRF_GPIO_PIN_INPUT_CONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE); mosi_pin = p_config->mosi_pin; } else { mosi_pin = NRF_SPIS_PIN_NOT_CONNECTED; } nrf_gpio_cfg(p_config->csn_pin, NRF_GPIO_PIN_DIR_INPUT, NRF_GPIO_PIN_INPUT_CONNECT, p_config->csn_pullup, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE); nrf_gpio_cfg(p_config->sck_pin, NRF_GPIO_PIN_DIR_INPUT, NRF_GPIO_PIN_INPUT_CONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE); nrf_spis_pins_set(p_spis, p_config->sck_pin, mosi_pin, miso_pin, p_config->csn_pin); nrf_spis_rx_buffer_set(p_spis, NULL, 0); nrf_spis_tx_buffer_set(p_spis, NULL, 0); // Configure SPI mode. nrf_spis_configure(p_spis, (nrf_spis_mode_t) p_config->mode, (nrf_spis_bit_order_t) p_config->bit_order); // Configure DEF and ORC characters. nrf_spis_def_set(p_spis, p_config->def); nrf_spis_orc_set(p_spis, p_config->orc); // Clear possible pending events. nrf_spis_event_clear(p_spis, NRF_SPIS_EVENT_END); nrf_spis_event_clear(p_spis, NRF_SPIS_EVENT_ACQUIRED); // Enable END_ACQUIRE shortcut. nrf_spis_shorts_enable(p_spis, NRF_SPIS_SHORT_END_ACQUIRE); m_cb[p_instance->instance_id].spi_state = SPIS_STATE_INIT; m_cb[p_instance->instance_id].handler = event_handler; // Enable IRQ. nrf_spis_int_enable(p_spis, NRF_SPIS_INT_ACQUIRED_MASK | NRF_SPIS_INT_END_MASK); nrf_drv_common_irq_enable(p_instance->irq, p_config->irq_priority); p_cb->state = NRF_DRV_STATE_INITIALIZED; // Enable SPI slave device. nrf_spis_enable(p_spis); err_code = NRF_SUCCESS; NRF_LOG_INFO("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code)); return err_code; }
__WEAK ret_code_t nrf_dfu_settings_additional_erase(void) { NRF_LOG_WARNING("No additional data erased"); return NRF_SUCCESS; }