diff --git a/components/libraries/serial/nrf_serial.c b/components/libraries/serial/nrf_serial.c index e9aaceb2..66ae33db 100644 --- a/components/libraries/serial/nrf_serial.c +++ b/components/libraries/serial/nrf_serial.c @@ -43,17 +43,6 @@ #if defined (UART_PRESENT) -typedef struct { - volatile bool expired; -} nrf_serial_timeout_ctx_t; - - -static void serial_timeout_handler(void * p_context) -{ - nrf_serial_timeout_ctx_t * p_tout_ctx = p_context; - p_tout_ctx->expired = true; -} - static void event_handler(nrf_serial_t const * p_serial, nrf_serial_event_t event) { @@ -212,24 +201,10 @@ ret_code_t nrf_serial_init(nrf_serial_t const * p_serial, ASSERT(p_config->p_queues && p_config->p_buffers); } - ret = app_timer_create(p_serial->p_tx_timer, - APP_TIMER_MODE_SINGLE_SHOT, - serial_timeout_handler); - if (ret != NRF_SUCCESS) { - return ret; - } - - ret = app_timer_create(p_serial->p_rx_timer, - APP_TIMER_MODE_SINGLE_SHOT, - serial_timeout_handler); - if (ret != NRF_SUCCESS) { - return ret; - } - nrf_drv_uart_config_t drv_config; memcpy(&drv_config, p_drv_uart_config, sizeof(nrf_drv_uart_config_t)); drv_config.p_context = (void *)p_serial; -#if defined(NRF_DRV_UART_WITH_UARTE) && defined(NRF_DRV_UART_WITH_UART) +#if defined(UARTE_PRESENT) && defined(UART_PRESENT) drv_config.use_easy_dma = (p_config->mode == NRF_SERIAL_MODE_DMA); #endif ret = nrf_drv_uart_init(&p_serial->instance, @@ -311,6 +286,16 @@ ret_code_t nrf_serial_uninit(nrf_serial_t const * p_serial) return NRF_SUCCESS; } +typedef struct { + volatile bool expired; +} nrf_serial_timeout_ctx_t; + +static void serial_timeout_handler(void * p_context) +{ + nrf_serial_timeout_ctx_t * p_tout_ctx = p_context; + p_tout_ctx->expired = true; +} + static ret_code_t timeout_setup(nrf_serial_t const * p_serial, app_timer_id_t const * p_timer_id, @@ -325,6 +310,14 @@ static ret_code_t timeout_setup(nrf_serial_t const * p_serial, return NRF_SUCCESS; } + ret_code_t ret = app_timer_create(p_timer_id, + APP_TIMER_MODE_SINGLE_SHOT, + serial_timeout_handler); + if (ret != NRF_SUCCESS) + { + return ret; + } + return app_timer_start(*p_timer_id, ticks, p_tout_ctx); }