otError otPlatUartDisable(void) { otError error = OT_ERROR_NONE; otEXPECT_ACTION(sUartEnabled == true, error = OT_ERROR_ALREADY); // Disable NVIC interrupt. NVIC_DisableIRQ(UART_IRQN); NVIC_ClearPendingIRQ(UART_IRQN); NVIC_SetPriority(UART_IRQN, 0); // Disable interrupts for TX. nrf_uart_int_disable(UART_INSTANCE, NRF_UART_INT_MASK_TXDRDY); // Disable interrupts for RX. nrf_uart_int_disable(UART_INSTANCE, NRF_UART_INT_MASK_RXDRDY | NRF_UART_INT_MASK_ERROR); // Disable UART instance. nrf_uart_disable(UART_INSTANCE); // Release HF clock. nrf_drv_clock_hfclk_release(); sUartEnabled = false; exit: return error; }
otError otPlatUartDisable(void) { // Disable UART instance. nrf_uart_disable(UART_INSTANCE); // Release HF clock. nrf_drv_clock_hfclk_release(); return OT_ERROR_NONE; }
void nrfx_uart_uninit(nrfx_uart_t const * p_instance) { uart_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx]; nrf_uart_disable(p_instance->p_reg); if (p_cb->handler) { interrupts_disable(p_instance); } pins_to_default(p_instance); #if NRFX_CHECK(NRFX_PRS_ENABLED) nrfx_prs_release(p_instance->p_reg); #endif p_cb->state = NRFX_DRV_STATE_UNINITIALIZED; p_cb->handler = NULL; NRFX_LOG_INFO("Instance uninitialized: %d.", p_instance->drv_inst_idx); }
static rt_err_t _uart_cfg(struct rt_serial_device *serial, struct serial_configure *cfg) { nrf_drv_uart_config_t config = NRF_DRV_UART_DEFAULT_CONFIG; UART_CFG_T *instance = &uart0; RT_ASSERT(serial != RT_NULL); RT_ASSERT(cfg != RT_NULL); if (serial->parent.user_data != RT_NULL) { instance = (UART_CFG_T*)serial->parent.user_data; } nrf_uart_disable(instance->uart.reg.p_uart); switch (cfg->baud_rate) { case 115200: config.baudrate = NRF_UART_BAUDRATE_115200; break; case 9600: config.baudrate = NRF_UART_BAUDRATE_9600; break; default: config.baudrate = NRF_UART_BAUDRATE_115200; break; } if (cfg->parity == PARITY_NONE) { config.parity = NRF_UART_PARITY_EXCLUDED; } else { config.parity = NRF_UART_PARITY_INCLUDED; } config.hwfc = NRF_UART_HWFC_DISABLED; config.interrupt_priority = APP_IRQ_PRIORITY_LOWEST; config.pselcts = 0; config.pselrts = 0; config.pselrxd = instance->rx_pin; config.pseltxd = instance->tx_pin; nrf_gpio_pin_set(config.pseltxd); nrf_gpio_cfg_output(config.pseltxd); nrf_gpio_pin_clear(config.pseltxd); nrf_gpio_cfg_input(config.pselrxd, NRF_GPIO_PIN_NOPULL); nrf_uart_baudrate_set(instance->uart.reg.p_uart, config.baudrate); nrf_uart_configure(instance->uart.reg.p_uart, config.parity, config.hwfc); nrf_uart_txrx_pins_set(instance->uart.reg.p_uart, config.pseltxd, config.pselrxd); if (config.hwfc == NRF_UART_HWFC_ENABLED) { nrf_uart_hwfc_pins_set(instance->uart.reg.p_uart, config.pselrts, config.pselcts); } nrf_uart_event_clear(instance->uart.reg.p_uart, NRF_UART_EVENT_TXDRDY); 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); 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), config.interrupt_priority); nrf_uart_enable(instance->uart.reg.p_uart); // nrf_uart_task_trigger(instance->uart.reg.p_uart, NRF_UART_TASK_STARTRX); working_cfg = instance; return RT_EOK; }
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; }