Skip to content

Commit 7bea5a4

Browse files
committed
Free the interupt from the array on enable/disable of the interrupt, added doxygen documentation to the functoins
1 parent d63d896 commit 7bea5a4

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

cores/esp32/esp32-hal-uart.c

+30
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@ static void IRAM_ATTR _uart_isr()
114114
}
115115
}
116116

117+
/**
118+
* @brief Enables the UART RX interrupt on the specified UART device.
119+
*
120+
* This function will register the interrupt user function with arguments, to be called when an RX interupt occurs.
121+
* The pointer to the uart_interrupt_t will be deleted when the interrupt is disabled, or another interrupt function is being registered.
122+
* Please check for NULL on the uart_interrupt_t pointer before using it.
123+
124+
* @param[in] uart The uart device to register the function for.
125+
* @param[out] arg The uart_interrupt description data that is returned when this function succeeds.
126+
* @param[in] func The function to be called when the RX interrupt is fired. (void rx_int(uint8_t c, void* user_arg))
127+
* @param[in] user_arg The user argument that will be passed to the user interrupt handler.
128+
*
129+
*/
117130
void uartEnableInterrupt(uart_t* uart, uart_interrupt_t **arg, void (*func)(uint8_t, void*), void* user_arg)
118131
{
119132
UART_MUTEX_LOCK();
@@ -130,13 +143,28 @@ void uartEnableInterrupt(uart_t* uart, uart_interrupt_t **arg, void (*func)(uint
130143
(*arg)->func = func;
131144
(*arg)->dev = uart;
132145
(*arg)->user_arg = user_arg;
146+
147+
if(_uart_interrupt_array[uart->num])
148+
free(_uart_interrupt_array[uart->num]);
149+
133150
_uart_interrupt_array[uart->num] = (*arg);
134151
}
135152

136153
esp_intr_alloc(UART_INTR_SOURCE(uart->num), (int)ESP_INTR_FLAG_IRAM, _uart_isr, NULL, &uart->intr_handle);
137154
UART_MUTEX_UNLOCK();
138155
}
139156

157+
/**
158+
* @brief Disables the UART RX interrupt on the specified UART device.
159+
*
160+
* This function disables the RX interrupt for the specified UART device.
161+
* This function will delete the uart_interrupt_t* that uartEnableInterrupt() creates.
162+
* The pointer to the uart_interrupt_t will be deleted when the interrupt is disabled, or another interrupt function is being registered.
163+
* Please check for NULL on the uart_interrupt_t pointer before using it.
164+
165+
* @param[in] uart The uart device to register the function for.
166+
*
167+
*/
140168
void uartDisableInterrupt(uart_t* uart)
141169
{
142170
UART_MUTEX_LOCK();
@@ -145,6 +173,8 @@ void uartDisableInterrupt(uart_t* uart)
145173
uart->dev->int_clr.val = 0xffffffff;
146174

147175
// Free uart rx interrupt
176+
if(_uart_interrupt_array[uart->num])
177+
free(_uart_interrupt_array[uart->num]);
148178
_uart_interrupt_array[uart->num] = NULL;
149179

150180
esp_intr_free(uart->intr_handle);

0 commit comments

Comments
 (0)