From 0eb59844bbd72931b3fcf2bb55f6a2bde7c54402 Mon Sep 17 00:00:00 2001 From: Nilay Sheth Date: Tue, 20 Jun 2017 10:53:29 +0530 Subject: [PATCH] bugfix(driver): fix RMT issues from github 1. Rename api from rmt_get_ringbuf_handler to rmt_get_ringbuf_handle (Github Issue #274) 2. doxygen param rename 3. change API rmt_wait_tx_done to specify maximum waiting time 4.Change return type of rmt_wait_tx_done API from bool to esp_err_t 5. update doc --- components/driver/include/driver/rmt.h | 12 ++++++++---- components/driver/rmt.c | 19 ++++++++++++------- .../rmt_nec_tx_rx/main/infrared_nec_main.c | 4 ++-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/components/driver/include/driver/rmt.h b/components/driver/include/driver/rmt.h index 0a958688cb..56c5ed4952 100644 --- a/components/driver/include/driver/rmt.h +++ b/components/driver/include/driver/rmt.h @@ -677,11 +677,15 @@ esp_err_t rmt_write_items(rmt_channel_t channel, const rmt_item32_t* rmt_item, i * * @param channel RMT channel (0 - 7) * + * @param wait_time Maximum time to wait for transmission to be complete + * * @return + * - ESP_OK RMT Tx done successfully + * - ESP_ERR_TIMEOUT Crossed the 'wait_time' given * - ESP_ERR_INVALID_ARG Parameter error - * - ESP_OK Success + * - ESP_FAIL Driver not installed */ -esp_err_t rmt_wait_tx_done(rmt_channel_t channel); +esp_err_t rmt_wait_tx_done(rmt_channel_t channel, TickType_t wait_time); /** * @brief Get ringbuffer from UART. @@ -690,13 +694,13 @@ esp_err_t rmt_wait_tx_done(rmt_channel_t channel); * * @param channel RMT channel (0 - 7) * - * @param buf_handler Pointer to buffer handler to accept RX ringbuffer handler. + * @param buf_handle Pointer to buffer handler to accept RX ringbuffer handler. * * @return * - ESP_ERR_INVALID_ARG Parameter error * - ESP_OK Success */ -esp_err_t rmt_get_ringbuf_handler(rmt_channel_t channel, RingbufHandle_t* buf_handler); +esp_err_t rmt_get_ringbuf_handle(rmt_channel_t channel, RingbufHandle_t* buf_handle); /***************************EXAMPLE********************************** * diff --git a/components/driver/rmt.c b/components/driver/rmt.c index e328e4521e..7386aa2e64 100644 --- a/components/driver/rmt.c +++ b/components/driver/rmt.c @@ -748,21 +748,26 @@ esp_err_t rmt_write_items(rmt_channel_t channel, const rmt_item32_t* rmt_item, i return ESP_OK; } -esp_err_t rmt_wait_tx_done(rmt_channel_t channel) +esp_err_t rmt_wait_tx_done(rmt_channel_t channel, TickType_t wait_time) { RMT_CHECK(channel < RMT_CHANNEL_MAX, RMT_CHANNEL_ERROR_STR, ESP_ERR_INVALID_ARG); RMT_CHECK(p_rmt_obj[channel] != NULL, RMT_DRIVER_ERROR_STR, ESP_FAIL); - xSemaphoreTake(p_rmt_obj[channel]->tx_sem, portMAX_DELAY); - xSemaphoreGive(p_rmt_obj[channel]->tx_sem); - return ESP_OK; + if(xSemaphoreTake(p_rmt_obj[channel]->tx_sem, wait_time) == pdTRUE) { + xSemaphoreGive(p_rmt_obj[channel]->tx_sem); + return ESP_OK; + } + else { + ESP_LOGE(RMT_TAG, "Timeout on wait_tx_done"); + return ESP_ERR_TIMEOUT; + } } -esp_err_t rmt_get_ringbuf_handler(rmt_channel_t channel, RingbufHandle_t* buf_handler) +esp_err_t rmt_get_ringbuf_handle(rmt_channel_t channel, RingbufHandle_t* buf_handle) { RMT_CHECK(channel < RMT_CHANNEL_MAX, RMT_CHANNEL_ERROR_STR, ESP_ERR_INVALID_ARG); RMT_CHECK(p_rmt_obj[channel] != NULL, RMT_DRIVER_ERROR_STR, ESP_FAIL); - RMT_CHECK(buf_handler != NULL, RMT_ADDR_ERROR_STR, ESP_ERR_INVALID_ARG); - *buf_handler = p_rmt_obj[channel]->rx_buf; + RMT_CHECK(buf_handle != NULL, RMT_ADDR_ERROR_STR, ESP_ERR_INVALID_ARG); + *buf_handle = p_rmt_obj[channel]->rx_buf; return ESP_OK; } diff --git a/examples/peripherals/rmt_nec_tx_rx/main/infrared_nec_main.c b/examples/peripherals/rmt_nec_tx_rx/main/infrared_nec_main.c index 1bc01a3862..3e357a726d 100644 --- a/examples/peripherals/rmt_nec_tx_rx/main/infrared_nec_main.c +++ b/examples/peripherals/rmt_nec_tx_rx/main/infrared_nec_main.c @@ -284,7 +284,7 @@ static void rmt_example_nec_rx_task() nec_rx_init(); RingbufHandle_t rb = NULL; //get RMT RX ringbuffer - rmt_get_ringbuf_handler(channel, &rb); + rmt_get_ringbuf_handle(channel, &rb); rmt_rx_start(channel, 1); while(rb) { size_t rx_size = 0; @@ -349,7 +349,7 @@ static void rmt_example_nec_tx_task() //To send data according to the waveform items. rmt_write_items(channel, item, item_num, true); //Wait until sending is done. - rmt_wait_tx_done(channel); + rmt_wait_tx_done(channel, portMAX_DELAY); //before we free the data, make sure sending is already done. free(item); vTaskDelay(2000 / portTICK_PERIOD_MS);