@@ -114,6 +114,19 @@ static void IRAM_ATTR _uart_isr()
114
114
}
115
115
}
116
116
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
+ */
117
130
void uartEnableInterrupt (uart_t * uart , uart_interrupt_t * * arg , void (* func )(uint8_t , void * ), void * user_arg )
118
131
{
119
132
UART_MUTEX_LOCK ();
@@ -130,13 +143,28 @@ void uartEnableInterrupt(uart_t* uart, uart_interrupt_t **arg, void (*func)(uint
130
143
(* arg )-> func = func ;
131
144
(* arg )-> dev = uart ;
132
145
(* arg )-> user_arg = user_arg ;
146
+
147
+ if (_uart_interrupt_array [uart -> num ])
148
+ free (_uart_interrupt_array [uart -> num ]);
149
+
133
150
_uart_interrupt_array [uart -> num ] = (* arg );
134
151
}
135
152
136
153
esp_intr_alloc (UART_INTR_SOURCE (uart -> num ), (int )ESP_INTR_FLAG_IRAM , _uart_isr , NULL , & uart -> intr_handle );
137
154
UART_MUTEX_UNLOCK ();
138
155
}
139
156
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
+ */
140
168
void uartDisableInterrupt (uart_t * uart )
141
169
{
142
170
UART_MUTEX_LOCK ();
@@ -145,6 +173,8 @@ void uartDisableInterrupt(uart_t* uart)
145
173
uart -> dev -> int_clr .val = 0xffffffff ;
146
174
147
175
// Free uart rx interrupt
176
+ if (_uart_interrupt_array [uart -> num ])
177
+ free (_uart_interrupt_array [uart -> num ]);
148
178
_uart_interrupt_array [uart -> num ] = NULL ;
149
179
150
180
esp_intr_free (uart -> intr_handle );
0 commit comments