void nrf_drv_saadc_uninit(void) { ASSERT(m_cb.state != NRF_DRV_STATE_UNINITIALIZED); nrf_saadc_int_disable(NRF_SAADC_INT_ALL); nrf_drv_common_irq_disable(SAADC_IRQn); nrf_saadc_task_trigger(NRF_SAADC_TASK_STOP); // Wait for ADC being stopped. uint32_t timeout = HW_TIMEOUT; while (nrf_saadc_event_check(NRF_SAADC_EVENT_STOPPED) == 0 && timeout > 0) { --timeout; } ASSERT(timeout > 0); nrf_saadc_disable(); m_cb.adc_state = NRF_SAADC_STATE_IDLE; for (uint8_t channel = 0; channel < NRF_SAADC_CHANNEL_COUNT; ++channel) { if (m_cb.psel[channel].pselp != NRF_SAADC_INPUT_DISABLED) { (void)nrf_drv_saadc_channel_uninit(channel); } } m_cb.state = NRF_DRV_STATE_UNINITIALIZED; }
void nrf_drv_timer_uninit(nrf_drv_timer_t const * const p_instance) { uint32_t i; nrf_drv_common_irq_disable(p_instance->irq); m_timer_event_handlers[p_instance->instance_id] = NULL; nrf_drv_timer_disable(p_instance); //lint -save -e655 nrf_timer_shorts_clear(p_instance->p_reg, NRF_TIMER_SHORTS_COMPARE0_STOP_MASK | NRF_TIMER_SHORTS_COMPARE1_STOP_MASK | NRF_TIMER_SHORTS_COMPARE2_STOP_MASK | NRF_TIMER_SHORTS_COMPARE3_STOP_MASK | NRF_TIMER_SHORTS_COMPARE0_CLEAR_MASK | NRF_TIMER_SHORTS_COMPARE1_CLEAR_MASK | NRF_TIMER_SHORTS_COMPARE2_CLEAR_MASK | NRF_TIMER_SHORTS_COMPARE3_CLEAR_MASK); //lint -restore for(i=0; i<TIMER_CHANNEL_NUMBER; i++) { nrf_timer_int_disable(p_instance->p_reg, NRF_TIMER_INT_COMPARE0_MASK << i); } m_cb[p_instance->instance_id].state = NRF_DRV_STATE_UNINITIALIZED; }
void nrf_drv_qdec_uninit(void) { ASSERT(m_state != NRF_DRV_STATE_UNINITIALIZED); nrf_drv_qdec_disable(); nrf_drv_common_irq_disable(QDEC_IRQn); m_state = NRF_DRV_STATE_UNINITIALIZED; }
void nrf_drv_lpcomp_uninit(void) { ASSERT(m_state != NRF_DRV_STATE_UNINITIALIZED); nrf_drv_common_irq_disable(LPCOMP_IRQn); nrf_drv_lpcomp_disable(); m_state = NRF_DRV_STATE_UNINITIALIZED; m_lpcomp_events_handler = NULL; }
void nrf_drv_rng_uninit(void) { ASSERT(m_rng_cb.state == NRF_DRV_STATE_INITIALIZED); m_rng_cb.state = NRF_DRV_STATE_UNINITIALIZED; #ifndef SOFTDEVICE_PRESENT rng_stop(); nrf_drv_common_irq_disable(RNG_IRQn); #endif // SOFTDEVICE_PRESENT }
void nrf_drv_i2s_uninit(void) { ASSERT(m_cb.state != NRF_DRV_STATE_UNINITIALIZED); nrf_drv_i2s_stop(); nrf_drv_common_irq_disable(I2S_IRQn); m_cb.state = NRF_DRV_STATE_UNINITIALIZED; }
void nrf_drv_clock_uninit(void) { ASSERT(m_clock_cb.module_initialized); #ifndef SOFTDEVICE_PRESENT nrf_drv_common_irq_disable(POWER_CLOCK_IRQn); nrf_clock_int_disable(0xFFFFFFFF); lfclk_stop(); #endif hfclk_stop(); m_clock_cb.module_initialized = false; }
void nrf_drv_pwm_uninit(nrf_drv_pwm_t const * const p_instance) { pwm_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx]; ASSERT(p_cb->state != NRF_DRV_STATE_UNINITIALIZED); nrf_drv_common_irq_disable(nrf_drv_get_IRQn(p_instance->p_registers)); nrf_pwm_disable(p_instance->p_registers); p_cb->state = NRF_DRV_STATE_UNINITIALIZED; }
void nrf_drv_lpcomp_uninit(void) { ASSERT(m_state != NRF_DRV_STATE_UNINITIALIZED); nrf_drv_common_irq_disable(LPCOMP_IRQn); nrf_drv_lpcomp_disable(); #if NRF_MODULE_ENABLED(PERIPHERAL_RESOURCE_SHARING) nrf_drv_common_per_res_release(NRF_LPCOMP); #endif m_state = NRF_DRV_STATE_UNINITIALIZED; m_lpcomp_events_handler = NULL; NRF_LOG_INFO("Uninitialized.\r\n"); }
void nrf_drv_timer_uninit(nrf_drv_timer_t const * const p_instance) { nrf_drv_common_irq_disable(nrf_drv_get_IRQn(p_instance->p_reg)); #define DISABLE_ALL UINT32_MAX nrf_timer_shorts_disable(p_instance->p_reg, DISABLE_ALL); nrf_timer_int_disable(p_instance->p_reg, DISABLE_ALL); #undef DISABLE_ALL nrf_drv_timer_disable(p_instance); m_cb[p_instance->instance_id].state = NRF_DRV_STATE_UNINITIALIZED; }
void nrf_drv_twi_uninit(nrf_drv_twi_t const * const p_instance) { ASSERT(m_cb[p_instance->instance_id].state != NRF_DRV_STATE_UNINITIALIZED); if (m_handlers[p_instance->instance_id]) { nrf_drv_common_irq_disable(p_instance->irq); } nrf_drv_twi_disable(p_instance); nrf_twi_shorts_clear(p_instance->p_reg, DISABLE_MASK); m_cb[p_instance->instance_id].state = NRF_DRV_STATE_UNINITIALIZED; }
void nrf_drv_qspi_uninit(void) { ASSERT(m_cb.state != NRF_DRV_STATE_UNINITIALIZED); nrf_qspi_int_disable(NRF_QSPI, NRF_QSPI_INT_READY_MASK); nrf_qspi_disable(NRF_QSPI); nrf_drv_common_irq_disable(QSPI_IRQn); nrf_qspi_event_clear(NRF_QSPI, NRF_QSPI_EVENT_READY); m_cb.state = NRF_DRV_STATE_UNINITIALIZED; }
void nrf_drv_timer_uninit(nrf_drv_timer_t const * const p_instance) { nrf_drv_common_irq_disable(nrf_drv_get_IRQn(p_instance->p_reg)); #define DISABLE_ALL UINT32_MAX nrf_timer_shorts_disable(p_instance->p_reg, DISABLE_ALL); nrf_timer_int_disable(p_instance->p_reg, DISABLE_ALL); #undef DISABLE_ALL if (m_cb[p_instance->instance_id].state == NRF_DRV_STATE_POWERED_ON) { nrf_drv_timer_disable(p_instance); } m_cb[p_instance->instance_id].state = NRF_DRV_STATE_UNINITIALIZED; NRF_LOG_INFO("Uninitialized instance: %d.\r\n", p_instance->instance_id); }
void nrf_drv_rtc_uninit(nrf_drv_rtc_t const * const p_instance) { uint32_t mask = NRF_RTC_INT_TICK_MASK | NRF_RTC_INT_OVERFLOW_MASK | NRF_RTC_INT_COMPARE0_MASK | NRF_RTC_INT_COMPARE1_MASK | NRF_RTC_INT_COMPARE2_MASK | NRF_RTC_INT_COMPARE3_MASK; ASSERT(m_cb[p_instance->instance_id].state != NRF_DRV_STATE_UNINITIALIZED); nrf_drv_common_irq_disable(p_instance->irq); nrf_rtc_task_trigger(p_instance->p_reg, NRF_RTC_TASK_STOP); nrf_rtc_event_disable(p_instance->p_reg, mask); nrf_rtc_int_disable(p_instance->p_reg, mask); m_cb[p_instance->instance_id].state = NRF_DRV_STATE_UNINITIALIZED; }
void nrf_drv_spis_uninit(nrf_drv_spis_t const * const p_instance) { spis_cb_t * p_cb = &m_cb[p_instance->instance_id]; ASSERT(p_cb->state != NRF_DRV_STATE_UNINITIALIZED); NRF_SPIS_Type * p_spis = p_instance->p_reg; #define DISABLE_ALL 0xFFFFFFFF nrf_spis_disable(p_spis); nrf_drv_common_irq_disable(p_instance->irq); nrf_spis_int_disable(p_spis, DISABLE_ALL); #undef DISABLE_ALL #if PERIPHERAL_RESOURCE_SHARING_ENABLED nrf_drv_common_per_res_release(p_spis); #endif p_cb->state = NRF_DRV_STATE_UNINITIALIZED; }
static rt_err_t _uart_ctrl(struct rt_serial_device *serial, int cmd, void *arg) { UART_CFG_T *instance = working_cfg; RT_ASSERT(serial != RT_NULL); if (serial->parent.user_data != RT_NULL) { instance = (UART_CFG_T*)serial->parent.user_data; } switch (cmd) { /* disable interrupt */ case RT_DEVICE_CTRL_CLR_INT: nrf_uart_task_trigger(instance->uart.reg.p_uart, NRF_UART_TASK_STOPRX); nrf_uart_int_disable(instance->uart.reg.p_uart, NRF_UART_INT_MASK_RXDRDY | NRF_UART_INT_MASK_RXTO | NRF_UART_INT_MASK_ERROR); nrf_drv_common_irq_disable(nrf_drv_get_IRQn((void *)instance->uart.reg.p_uart)); break; /* enable interrupt */ case RT_DEVICE_CTRL_SET_INT: nrf_uart_event_clear(instance->uart.reg.p_uart, NRF_UART_EVENT_RXDRDY); nrf_uart_event_clear(instance->uart.reg.p_uart, NRF_UART_EVENT_RXTO); nrf_uart_event_clear(instance->uart.reg.p_uart, NRF_UART_EVENT_ERROR); /* Enable RX interrupt. */ nrf_uart_int_enable(instance->uart.reg.p_uart, NRF_UART_INT_MASK_RXDRDY | NRF_UART_INT_MASK_RXTO | NRF_UART_INT_MASK_ERROR); nrf_drv_common_irq_enable(nrf_drv_get_IRQn((void *)instance->uart.reg.p_uart), APP_IRQ_PRIORITY_LOWEST); nrf_uart_task_trigger(instance->uart.reg.p_uart, NRF_UART_TASK_STARTRX); break; case RT_DEVICE_CTRL_CUSTOM: if ((rt_uint32_t)(arg) == UART_CONFIG_BAUD_RATE_9600) { instance->serial->config.baud_rate = 9600; nrf_uart_baudrate_set(instance->uart.reg.p_uart, NRF_UART_BAUDRATE_9600); } else if ((rt_uint32_t)(arg) == UART_CONFIG_BAUD_RATE_115200) { instance->serial->config.baud_rate = 115200; nrf_uart_baudrate_set(instance->uart.reg.p_uart, NRF_UART_BAUDRATE_115200); } // _uart_cfg(instance->serial, &(instance->serial->config)); // nrf_uart_task_trigger(instance->uart.reg.p_uart, NRF_UART_TASK_STARTRX); break; case RT_DEVICE_CTRL_PIN: if (working_cfg != instance) { _uart_cfg(instance->serial, &(instance->serial->config)); } break; case RT_DEVICE_POWERSAVE: nrf_uart_disable(instance->uart.reg.p_uart); nrf_uart_txrx_pins_disconnect(instance->uart.reg.p_uart); nrf_gpio_pin_clear(instance->rx_pin); nrf_gpio_cfg_output(instance->rx_pin); nrf_gpio_pin_clear(instance->tx_pin); nrf_gpio_cfg_output(instance->tx_pin); break; case RT_DEVICE_WAKEUP: _uart_cfg(instance->serial, &(instance->serial->config)); break; default: return RT_ERROR; } return RT_EOK; }