Skip to content

Commit 8ed53a9

Browse files
authored
Merge pull request #6009 from prashantrar/mbed-os-serial-fix-pr
fix for issue "serial example callback not working"
2 parents 06b6184 + 011dbff commit 8ed53a9

File tree

1 file changed

+62
-25
lines changed
  • targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A

1 file changed

+62
-25
lines changed

targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/serial_api.c

Lines changed: 62 additions & 25 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);
@@ -99,7 +103,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
99103
return;
100104
}
101105
#ifdef CONFIG_MBED_ENABLED
102-
else if(uart_idx == UART_3){
106+
else if (uart_idx == UART_3) {
103107
obj->index = UART_3;
104108
goto init_stdio;
105109
}
@@ -158,11 +162,11 @@ void serial_free(serial_t *obj)
158162
{
159163
PHAL_RUART_ADAPTER pHalRuartAdapter;
160164
#ifdef CONFIG_GDMA_EN
161-
u8 uart_idx;
165+
u8 uart_idx;
162166
PUART_DMA_CONFIG pHalRuartDmaCfg;
163167
#endif
164168
#ifdef CONFIG_MBED_ENABLED
165-
if(obj->index == UART_3){
169+
if (obj->index == UART_3) {
166170
log_uart_free(&stdio_uart_log);
167171
return;
168172
}
@@ -189,7 +193,7 @@ void serial_free(serial_t *obj)
189193
void serial_baud(serial_t *obj, int baudrate)
190194
{
191195
#ifdef CONFIG_MBED_ENABLED
192-
if(obj->index == UART_3){
196+
if (obj->index == UART_3) {
193197
return;
194198
}
195199
#endif
@@ -204,7 +208,7 @@ void serial_baud(serial_t *obj, int baudrate)
204208
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits)
205209
{
206210
#ifdef CONFIG_MBED_ENABLED
207-
if(obj->index == UART_3){
211+
if (obj->index == UART_3) {
208212
log_uart_format(&stdio_uart_log, data_bits, parity, stop_bits);
209213
return;
210214
}
@@ -271,30 +275,64 @@ static void SerialRxDoneCallBack(VOID *pAdapter)
271275
}
272276
}
273277

278+
279+
#ifdef CONFIG_MBED_ENABLED
280+
static void serial_loguart_irq_handler(uint32_t id, LOG_UART_INT_ID event)
281+
{
282+
if (event == IIR_RX_RDY || event == IIR_CHAR_TIMEOUT)
283+
{
284+
if (log_irq_handler) {
285+
log_irq_handler(serial_log_irq_ids, RxIrq);
286+
}
287+
} else if (event == IIR_THR_EMPTY) {
288+
if (log_irq_handler) {
289+
log_irq_handler(serial_log_irq_ids, TxIrq);
290+
}
291+
}
292+
return;
293+
}
294+
#endif
295+
296+
297+
274298
void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
275299
{
300+
301+
#ifdef CONFIG_MBED_ENABLED
302+
if (obj->index == UART_3) {
303+
log_irq_handler = handler;
304+
serial_log_irq_ids = id;
305+
log_uart_irq_handler(&stdio_uart_log, serial_loguart_irq_handler, id);
306+
return;
307+
}
308+
#endif
276309
PHAL_RUART_ADAPTER pHalRuartAdapter;
277310
u8 uart_idx;
278-
279-
pHalRuartAdapter = &(obj->hal_uart_adp);
311+
pHalRuartAdapter = &(obj->hal_uart_adp);
280312
uart_idx = pHalRuartAdapter->UartIndex;
281-
282313
irq_handler[uart_idx] = handler;
283-
serial_irq_ids[uart_idx] = id;
284-
314+
serial_irq_ids[uart_idx] = id;
285315
pHalRuartAdapter->TxTDCallback = SerialTxDoneCallBack;
286316
pHalRuartAdapter->TxTDCbPara = (void*)pHalRuartAdapter;
287317
pHalRuartAdapter->RxDRCallback = SerialRxDoneCallBack;
288318
pHalRuartAdapter->RxDRCbPara = (void*)pHalRuartAdapter;
289319
}
290320

291-
292321
void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
293322
{
323+
#ifdef CONFIG_MBED_ENABLED
324+
if (obj->index == UART_3) {
325+
if (irq == RxIrq) {
326+
log_uart_irq_set(&stdio_uart_log, IIR_RX_RDY, enable);
327+
} else {
328+
log_uart_irq_set(&stdio_uart_log, IIR_THR_EMPTY, enable);
329+
}
330+
return;
331+
}
332+
#endif
294333
PHAL_RUART_ADAPTER pHalRuartAdapter;
295334
PHAL_RUART_OP pHalRuartOp;
296335
u8 uart_idx;
297-
298336
pHalRuartAdapter = &(obj->hal_uart_adp);
299337
pHalRuartOp = &(obj->hal_uart_op);
300338
uart_idx = pHalRuartAdapter->UartIndex;
@@ -304,10 +342,12 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
304342
pHalRuartAdapter->Interrupts |= RUART_IER_ERBI | RUART_IER_ELSI;
305343
serial_irq_en[uart_idx] |= SERIAL_RX_IRQ_EN;
306344
HalRuartSetIMRRtl8195a (pHalRuartAdapter);
307-
} else {
345+
} else {
308346
serial_irq_en[uart_idx] |= SERIAL_TX_IRQ_EN;
309347
}
348+
310349
pHalRuartOp->HalRuartRegIrq(pHalRuartAdapter);
350+
//log_uart
311351
pHalRuartOp->HalRuartIntEnable(pHalRuartAdapter);
312352
} else { // disable
313353
if (irq == RxIrq) {
@@ -318,6 +358,7 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
318358
serial_irq_en[uart_idx] &= ~SERIAL_TX_IRQ_EN;
319359
}
320360
HalRuartSetIMRRtl8195a (pHalRuartAdapter);
361+
321362
if (pHalRuartAdapter->Interrupts == 0) {
322363
InterruptUnRegister(&pHalRuartAdapter->IrqHandle);
323364
InterruptDis(&pHalRuartAdapter->IrqHandle);
@@ -332,7 +373,7 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
332373
int serial_getc(serial_t *obj)
333374
{
334375
#ifdef CONFIG_MBED_ENABLED
335-
if(obj->index == UART_3){
376+
if (obj->index == UART_3) {
336377
return log_uart_getc(&stdio_uart_log);
337378
}
338379
#endif
@@ -346,7 +387,7 @@ int serial_getc(serial_t *obj)
346387
void serial_putc(serial_t *obj, int c)
347388
{
348389
#ifdef CONFIG_MBED_ENABLED
349-
if(obj->index == UART_3){
390+
if (obj->index == UART_3) {
350391
log_uart_putc(&stdio_uart_log, (char)c);
351392
return;
352393
}
@@ -367,7 +408,7 @@ void serial_putc(serial_t *obj, int c)
367408
int serial_readable(serial_t *obj)
368409
{
369410
#ifdef CONFIG_MBED_ENABLED
370-
if(obj->index == UART_3){
411+
if (obj->index == UART_3) {
371412
return log_uart_readable(&stdio_uart_log);
372413
}
373414
#endif
@@ -385,16 +426,15 @@ int serial_readable(serial_t *obj)
385426
int serial_writable(serial_t *obj)
386427
{
387428
#ifdef CONFIG_MBED_ENABLED
388-
if(obj->index == UART_3){
429+
if (obj->index == UART_3) {
389430
return log_uart_writable(&stdio_uart_log);
390431
}
391432
#endif
392433

393434
PHAL_RUART_ADAPTER pHalRuartAdapter=(PHAL_RUART_ADAPTER)&(obj->hal_uart_adp);
394435
u8 uart_idx = pHalRuartAdapter->UartIndex;
395436

396-
if (HAL_RUART_READ32(uart_idx, RUART_LINE_STATUS_REG_OFF) &
397-
(RUART_LINE_STATUS_REG_THRE)) {
437+
if (HAL_RUART_READ32(uart_idx, RUART_LINE_STATUS_REG_OFF) & (RUART_LINE_STATUS_REG_THRE)) {
398438
return 1;
399439
} else {
400440
return 0;
@@ -404,7 +444,7 @@ int serial_writable(serial_t *obj)
404444
void serial_clear(serial_t *obj)
405445
{
406446
#ifdef CONFIG_MBED_ENABLED
407-
if(obj->index == UART_3){
447+
if (obj->index == UART_3) {
408448
log_uart_clear(&stdio_uart_log);
409449
return;
410450
}
@@ -419,7 +459,7 @@ void serial_clear(serial_t *obj)
419459
void serial_break_set(serial_t *obj)
420460
{
421461
#ifdef CONFIG_MBED_ENABLED
422-
if(obj->index == UART_3){
462+
if (obj->index == UART_3) {
423463
log_uart_break_set(&stdio_uart_log);
424464
return;
425465
}
@@ -428,7 +468,6 @@ void serial_break_set(serial_t *obj)
428468
PHAL_RUART_ADAPTER pHalRuartAdapter=(PHAL_RUART_ADAPTER)&(obj->hal_uart_adp);
429469
u8 uart_idx = pHalRuartAdapter->UartIndex;
430470
u32 RegValue;
431-
432471
RegValue = HAL_RUART_READ32(uart_idx, RUART_LINE_CTL_REG_OFF);
433472
RegValue |= BIT_UART_LCR_BREAK_CTRL;
434473
HAL_RUART_WRITE32(uart_idx, RUART_LINE_CTL_REG_OFF, RegValue);
@@ -437,16 +476,14 @@ void serial_break_set(serial_t *obj)
437476
void serial_break_clear(serial_t *obj)
438477
{
439478
#ifdef CONFIG_MBED_ENABLED
440-
if(obj->index == UART_3){
479+
if (obj->index == UART_3) {
441480
log_uart_break_clear(&stdio_uart_log);
442481
return;
443482
}
444483
#endif
445-
446484
PHAL_RUART_ADAPTER pHalRuartAdapter=(PHAL_RUART_ADAPTER)&(obj->hal_uart_adp);
447485
u8 uart_idx = pHalRuartAdapter->UartIndex;
448486
u32 RegValue;
449-
450487
RegValue = HAL_RUART_READ32(uart_idx, RUART_LINE_CTL_REG_OFF);
451488
RegValue &= ~(BIT_UART_LCR_BREAK_CTRL);
452489
HAL_RUART_WRITE32(uart_idx, RUART_LINE_CTL_REG_OFF, RegValue);

0 commit comments

Comments
 (0)