Skip to content

Commit 426df19

Browse files
M-ichae-ladbridge
authored andcommitted
rtl8195am: fix LogUART Tx interrupt crash
add Mask & UnMask Tx FIFO empty interrupt for LogUart fix LogUart interrupt enable fix LogUart interrupt handler coding style fix
1 parent addec7b commit 426df19

File tree

2 files changed

+44
-21
lines changed

2 files changed

+44
-21
lines changed

targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/log_uart_api.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,13 @@ void log_uart_irq_handler(log_uart_t *obj, loguart_irq_handler handler, uint32_t
210210

211211
pUartAdapter = &(obj->log_hal_uart);
212212
pUartAdapter->api_irq_handler = handler;
213-
pUartAdapter->api_irq_id = id;
213+
pUartAdapter->api_irq_id = id;
214214
}
215215

216216
void log_uart_irq_set(log_uart_t *obj, LOG_UART_INT_ID irq, uint32_t enable)
217217
{
218218
HAL_LOG_UART_ADAPTER *pUartAdapter;
219-
u8 int_en=0;
219+
u8 int_en = 0;
220220

221221
pUartAdapter = &(obj->log_hal_uart);
222222

@@ -241,7 +241,7 @@ void log_uart_irq_set(log_uart_t *obj, LOG_UART_INT_ID irq, uint32_t enable)
241241
DBG_UART_WARN("log_uart_irq_set: Unknown Irq Id\n");
242242
return;
243243
}
244-
244+
245245
if (enable) {
246246
pUartAdapter->IntEnReg |= int_en;
247247
} else {

targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/serial_api.c

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -284,32 +284,29 @@ static void SerialRxDoneCallBack(VOID *pAdapter)
284284
#ifdef CONFIG_MBED_ENABLED
285285
static void serial_loguart_irq_handler(uint32_t id, LOG_UART_INT_ID event)
286286
{
287-
if (event == IIR_RX_RDY || event == IIR_CHAR_TIMEOUT)
288-
{
289-
if (log_irq_handler) {
287+
log_uart_irq_set(&stdio_uart_log, event, 0);
288+
if (log_irq_handler) {
289+
if (event == IIR_RX_RDY || event == IIR_CHAR_TIMEOUT) {
290290
log_irq_handler(serial_log_irq_ids, RxIrq);
291-
}
292-
} else if (event == IIR_THR_EMPTY) {
293-
if (log_irq_handler) {
294-
log_irq_handler(serial_log_irq_ids, TxIrq);
295-
}
291+
} else if (event == IIR_THR_EMPTY) {
292+
log_irq_handler(serial_log_irq_ids, TxIrq);
293+
}
296294
}
297295
return;
298296
}
299297
#endif
300298

301299

302-
303300
void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
304301
{
305302

306303
#ifdef CONFIG_MBED_ENABLED
307-
if (obj->index == UART_3) {
308-
log_irq_handler = handler;
309-
serial_log_irq_ids = id;
310-
log_uart_irq_handler(&stdio_uart_log, serial_loguart_irq_handler, id);
311-
return;
312-
}
304+
if (obj->index == UART_3) {
305+
log_irq_handler = handler;
306+
serial_log_irq_ids = id;
307+
log_uart_irq_handler(&stdio_uart_log, serial_loguart_irq_handler, id);
308+
return;
309+
}
313310
#endif
314311
PHAL_RUART_ADAPTER pHalRuartAdapter;
315312
u8 uart_idx;
@@ -326,14 +323,33 @@ void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
326323
void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
327324
{
328325
#ifdef CONFIG_MBED_ENABLED
329-
if (obj->index == UART_3) {
326+
if (obj->index == UART_3) {
327+
if(enable) {
328+
if (irq == RxIrq) {
329+
log_uart_irq_set(&stdio_uart_log, IIR_RX_RDY, enable);
330+
serial_log_irq_en |= SERIAL_RX_IRQ_EN;
331+
} else {
332+
log_uart_irq_set(&stdio_uart_log, IIR_THR_EMPTY, enable);
333+
serial_log_irq_en |= SERIAL_TX_IRQ_EN;
334+
}
335+
} else {
330336
if (irq == RxIrq) {
331337
log_uart_irq_set(&stdio_uart_log, IIR_RX_RDY, enable);
338+
serial_log_irq_en &= ~SERIAL_RX_IRQ_EN;
332339
} else {
333340
log_uart_irq_set(&stdio_uart_log, IIR_THR_EMPTY, enable);
341+
serial_log_irq_en &= ~SERIAL_TX_IRQ_EN;
342+
}
343+
344+
log_uart_t *log_obj = &stdio_uart_log;
345+
HAL_LOG_UART_ADAPTER *pUartAdapter=(PHAL_LOG_UART_ADAPTER)&(log_obj->log_hal_uart);
346+
if (pUartAdapter->IntEnReg == 0) {
347+
InterruptUnRegister(&pUartAdapter->IrqHandle);
348+
InterruptDis(&pUartAdapter->IrqHandle);
334349
}
335-
return;
336350
}
351+
return;
352+
}
337353
#endif
338354
PHAL_RUART_ADAPTER pHalRuartAdapter;
339355
PHAL_RUART_OP pHalRuartOp;
@@ -352,7 +368,6 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
352368
}
353369

354370
pHalRuartOp->HalRuartRegIrq(pHalRuartAdapter);
355-
//log_uart
356371
pHalRuartOp->HalRuartIntEnable(pHalRuartAdapter);
357372
} else { // disable
358373
if (irq == RxIrq) {
@@ -394,6 +409,14 @@ void serial_putc(serial_t *obj, int c)
394409
#ifdef CONFIG_MBED_ENABLED
395410
if (obj->index == UART_3) {
396411
log_uart_putc(&stdio_uart_log, (char)c);
412+
413+
// UnMask LOG_UART TX FIFO empty IRQ
414+
if (serial_log_irq_en & SERIAL_TX_IRQ_EN) {
415+
log_uart_t *log_obj = &stdio_uart_log;
416+
HAL_LOG_UART_ADAPTER *pUartAdapter=(PHAL_LOG_UART_ADAPTER)&(log_obj->log_hal_uart);
417+
pUartAdapter->IntEnReg |= IER_ETBEI;
418+
HalLogUartSetIntEn(pUartAdapter);
419+
}
397420
return;
398421
}
399422
#endif

0 commit comments

Comments
 (0)