Skip to content

Commit b89ef1f

Browse files
committed
fix for serial issue #5805
1 parent 3e5fafd commit b89ef1f

File tree

1 file changed

+81
-9
lines changed
  • targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A

1 file changed

+81
-9
lines changed

targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/serial_api.c

Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,13 @@ static HAL_GDMA_OP UartGdmaOp;
6868

6969
#ifdef CONFIG_MBED_ENABLED
7070
#include "log_uart_api.h"
71+
#include "hal_log_uart.h"
7172
int stdio_uart_inited = 0;
7273
serial_t stdio_uart;
7374
log_uart_t stdio_uart_log;
75+
static uint32_t serial_log_irq_ids;
76+
static uart_irq_handler log_irq_handler;
77+
static uint32_t serial_log_irq_en;
7478
#endif
7579

7680
static void SerialTxDoneCallBack(VOID *pAdapter);
@@ -256,7 +260,8 @@ static void SerialTxDoneCallBack(VOID *pAdapter)
256260
pHalRuartAdapter->Interrupts &= ~RUART_IER_ETBEI;
257261
HalRuartSetIMRRtl8195a (pHalRuartAdapter);
258262

259-
if (irq_handler[uart_idx] != NULL) {
263+
if (irq_handler[uart_idx] != NULL)
264+
{
260265
irq_handler[uart_idx](serial_irq_ids[uart_idx], TxIrq);
261266
}
262267
}
@@ -266,13 +271,49 @@ static void SerialRxDoneCallBack(VOID *pAdapter)
266271
PHAL_RUART_ADAPTER pHalRuartAdapter = pAdapter;
267272
u8 uart_idx = pHalRuartAdapter->UartIndex;
268273

269-
if (irq_handler[uart_idx] != NULL) {
274+
if (irq_handler[uart_idx] != NULL)
275+
{
270276
irq_handler[uart_idx](serial_irq_ids[uart_idx], RxIrq);
271277
}
272278
}
273279

280+
281+
#ifdef CONFIG_MBED_ENABLED
282+
static void serial_loguart_irq_handler(uint32_t id, LOG_UART_INT_ID event)
283+
{
284+
if(event == IIR_RX_RDY || event == IIR_CHAR_TIMEOUT)
285+
{
286+
if (log_irq_handler){
287+
log_irq_handler(serial_log_irq_ids, RxIrq);
288+
}
289+
}
290+
else if(event == IIR_THR_EMPTY)
291+
{
292+
if (log_irq_handler){
293+
log_irq_handler(serial_log_irq_ids, TxIrq);
294+
}
295+
}
296+
return;
297+
}
298+
#endif
299+
300+
301+
274302
void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
275303
{
304+
305+
#ifdef CONFIG_MBED_ENABLED
306+
if(obj->index == UART_3)
307+
{
308+
log_irq_handler = handler;
309+
serial_log_irq_ids = id;
310+
311+
log_uart_irq_handler(&stdio_uart_log, serial_loguart_irq_handler, id);
312+
return;
313+
}
314+
#endif
315+
316+
276317
PHAL_RUART_ADAPTER pHalRuartAdapter;
277318
u8 uart_idx;
278319

@@ -291,34 +332,65 @@ void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
291332

292333
void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
293334
{
335+
336+
#ifdef CONFIG_MBED_ENABLED
337+
if(obj->index == UART_3)
338+
{
339+
if(irq == RxIrq)
340+
{
341+
log_uart_irq_set(&stdio_uart_log, IIR_RX_RDY, enable);
342+
}
343+
else
344+
{
345+
log_uart_irq_set(&stdio_uart_log, IIR_THR_EMPTY, enable);
346+
}
347+
return;
348+
}
349+
#endif
350+
294351
PHAL_RUART_ADAPTER pHalRuartAdapter;
295352
PHAL_RUART_OP pHalRuartOp;
296353
u8 uart_idx;
297354

298355
pHalRuartAdapter = &(obj->hal_uart_adp);
299356
pHalRuartOp = &(obj->hal_uart_op);
300357
uart_idx = pHalRuartAdapter->UartIndex;
358+
301359

302-
if (enable) {
303-
if (irq == RxIrq) {
360+
if (enable)
361+
{
362+
if (irq == RxIrq)
363+
{
304364
pHalRuartAdapter->Interrupts |= RUART_IER_ERBI | RUART_IER_ELSI;
305365
serial_irq_en[uart_idx] |= SERIAL_RX_IRQ_EN;
306366
HalRuartSetIMRRtl8195a (pHalRuartAdapter);
307-
} else {
367+
}
368+
else
369+
{
308370
serial_irq_en[uart_idx] |= SERIAL_TX_IRQ_EN;
309371
}
372+
310373
pHalRuartOp->HalRuartRegIrq(pHalRuartAdapter);
374+
375+
//log_uart
311376
pHalRuartOp->HalRuartIntEnable(pHalRuartAdapter);
312-
} else { // disable
313-
if (irq == RxIrq) {
377+
}
378+
else
379+
{ // disable
380+
if (irq == RxIrq)
381+
{
314382
pHalRuartAdapter->Interrupts &= ~(RUART_IER_ERBI | RUART_IER_ELSI);
315383
serial_irq_en[uart_idx] &= ~SERIAL_RX_IRQ_EN;
316-
} else {
384+
}
385+
else
386+
{
317387
pHalRuartAdapter->Interrupts &= ~RUART_IER_ETBEI;
318388
serial_irq_en[uart_idx] &= ~SERIAL_TX_IRQ_EN;
319389
}
320390
HalRuartSetIMRRtl8195a (pHalRuartAdapter);
321-
if (pHalRuartAdapter->Interrupts == 0) {
391+
392+
if (pHalRuartAdapter->Interrupts == 0)
393+
{
322394
InterruptUnRegister(&pHalRuartAdapter->IrqHandle);
323395
InterruptDis(&pHalRuartAdapter->IrqHandle);
324396
}

0 commit comments

Comments
 (0)