Skip to content

Commit 011dbff

Browse files
committed
Fixing coding style
Fix Details: HAL API for loguart is different that UART. Initially we didnt have support for loguart in the mbed api. These changes have been made to support the loguart from the mbed api by using the correct HAL api calls
1 parent b89ef1f commit 011dbff

File tree

1 file changed

+34
-69
lines changed
  • targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A

1 file changed

+34
-69
lines changed

targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/serial_api.c

Lines changed: 34 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
103103
return;
104104
}
105105
#ifdef CONFIG_MBED_ENABLED
106-
else if(uart_idx == UART_3){
106+
else if (uart_idx == UART_3) {
107107
obj->index = UART_3;
108108
goto init_stdio;
109109
}
@@ -162,11 +162,11 @@ void serial_free(serial_t *obj)
162162
{
163163
PHAL_RUART_ADAPTER pHalRuartAdapter;
164164
#ifdef CONFIG_GDMA_EN
165-
u8 uart_idx;
165+
u8 uart_idx;
166166
PUART_DMA_CONFIG pHalRuartDmaCfg;
167167
#endif
168168
#ifdef CONFIG_MBED_ENABLED
169-
if(obj->index == UART_3){
169+
if (obj->index == UART_3) {
170170
log_uart_free(&stdio_uart_log);
171171
return;
172172
}
@@ -193,7 +193,7 @@ void serial_free(serial_t *obj)
193193
void serial_baud(serial_t *obj, int baudrate)
194194
{
195195
#ifdef CONFIG_MBED_ENABLED
196-
if(obj->index == UART_3){
196+
if (obj->index == UART_3) {
197197
return;
198198
}
199199
#endif
@@ -208,7 +208,7 @@ void serial_baud(serial_t *obj, int baudrate)
208208
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits)
209209
{
210210
#ifdef CONFIG_MBED_ENABLED
211-
if(obj->index == UART_3){
211+
if (obj->index == UART_3) {
212212
log_uart_format(&stdio_uart_log, data_bits, parity, stop_bits);
213213
return;
214214
}
@@ -260,8 +260,7 @@ static void SerialTxDoneCallBack(VOID *pAdapter)
260260
pHalRuartAdapter->Interrupts &= ~RUART_IER_ETBEI;
261261
HalRuartSetIMRRtl8195a (pHalRuartAdapter);
262262

263-
if (irq_handler[uart_idx] != NULL)
264-
{
263+
if (irq_handler[uart_idx] != NULL) {
265264
irq_handler[uart_idx](serial_irq_ids[uart_idx], TxIrq);
266265
}
267266
}
@@ -271,8 +270,7 @@ static void SerialRxDoneCallBack(VOID *pAdapter)
271270
PHAL_RUART_ADAPTER pHalRuartAdapter = pAdapter;
272271
u8 uart_idx = pHalRuartAdapter->UartIndex;
273272

274-
if (irq_handler[uart_idx] != NULL)
275-
{
273+
if (irq_handler[uart_idx] != NULL) {
276274
irq_handler[uart_idx](serial_irq_ids[uart_idx], RxIrq);
277275
}
278276
}
@@ -281,15 +279,13 @@ static void SerialRxDoneCallBack(VOID *pAdapter)
281279
#ifdef CONFIG_MBED_ENABLED
282280
static void serial_loguart_irq_handler(uint32_t id, LOG_UART_INT_ID event)
283281
{
284-
if(event == IIR_RX_RDY || event == IIR_CHAR_TIMEOUT)
282+
if (event == IIR_RX_RDY || event == IIR_CHAR_TIMEOUT)
285283
{
286-
if (log_irq_handler){
284+
if (log_irq_handler) {
287285
log_irq_handler(serial_log_irq_ids, RxIrq);
288286
}
289-
}
290-
else if(event == IIR_THR_EMPTY)
291-
{
292-
if (log_irq_handler){
287+
} else if (event == IIR_THR_EMPTY) {
288+
if (log_irq_handler) {
293289
log_irq_handler(serial_log_irq_ids, TxIrq);
294290
}
295291
}
@@ -303,94 +299,67 @@ void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
303299
{
304300

305301
#ifdef CONFIG_MBED_ENABLED
306-
if(obj->index == UART_3)
307-
{
302+
if (obj->index == UART_3) {
308303
log_irq_handler = handler;
309-
serial_log_irq_ids = id;
310-
304+
serial_log_irq_ids = id;
311305
log_uart_irq_handler(&stdio_uart_log, serial_loguart_irq_handler, id);
312306
return;
313307
}
314308
#endif
315-
316-
317309
PHAL_RUART_ADAPTER pHalRuartAdapter;
318310
u8 uart_idx;
319-
320-
pHalRuartAdapter = &(obj->hal_uart_adp);
311+
pHalRuartAdapter = &(obj->hal_uart_adp);
321312
uart_idx = pHalRuartAdapter->UartIndex;
322-
323313
irq_handler[uart_idx] = handler;
324-
serial_irq_ids[uart_idx] = id;
325-
314+
serial_irq_ids[uart_idx] = id;
326315
pHalRuartAdapter->TxTDCallback = SerialTxDoneCallBack;
327316
pHalRuartAdapter->TxTDCbPara = (void*)pHalRuartAdapter;
328317
pHalRuartAdapter->RxDRCallback = SerialRxDoneCallBack;
329318
pHalRuartAdapter->RxDRCbPara = (void*)pHalRuartAdapter;
330319
}
331320

332-
333321
void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
334322
{
335-
336323
#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-
{
324+
if (obj->index == UART_3) {
325+
if (irq == RxIrq) {
326+
log_uart_irq_set(&stdio_uart_log, IIR_RX_RDY, enable);
327+
} else {
345328
log_uart_irq_set(&stdio_uart_log, IIR_THR_EMPTY, enable);
346329
}
347330
return;
348331
}
349332
#endif
350-
351333
PHAL_RUART_ADAPTER pHalRuartAdapter;
352334
PHAL_RUART_OP pHalRuartOp;
353335
u8 uart_idx;
354-
355336
pHalRuartAdapter = &(obj->hal_uart_adp);
356337
pHalRuartOp = &(obj->hal_uart_op);
357338
uart_idx = pHalRuartAdapter->UartIndex;
358-
359339

360-
if (enable)
361-
{
362-
if (irq == RxIrq)
363-
{
340+
if (enable) {
341+
if (irq == RxIrq) {
364342
pHalRuartAdapter->Interrupts |= RUART_IER_ERBI | RUART_IER_ELSI;
365343
serial_irq_en[uart_idx] |= SERIAL_RX_IRQ_EN;
366344
HalRuartSetIMRRtl8195a (pHalRuartAdapter);
367-
}
368-
else
369-
{
345+
} else {
370346
serial_irq_en[uart_idx] |= SERIAL_TX_IRQ_EN;
371347
}
372348

373349
pHalRuartOp->HalRuartRegIrq(pHalRuartAdapter);
374-
375350
//log_uart
376351
pHalRuartOp->HalRuartIntEnable(pHalRuartAdapter);
377-
}
378-
else
379-
{ // disable
380-
if (irq == RxIrq)
381-
{
352+
} else { // disable
353+
if (irq == RxIrq) {
382354
pHalRuartAdapter->Interrupts &= ~(RUART_IER_ERBI | RUART_IER_ELSI);
383355
serial_irq_en[uart_idx] &= ~SERIAL_RX_IRQ_EN;
384-
}
385-
else
386-
{
356+
} else {
387357
pHalRuartAdapter->Interrupts &= ~RUART_IER_ETBEI;
388358
serial_irq_en[uart_idx] &= ~SERIAL_TX_IRQ_EN;
389359
}
390360
HalRuartSetIMRRtl8195a (pHalRuartAdapter);
391361

392-
if (pHalRuartAdapter->Interrupts == 0)
393-
{
362+
if (pHalRuartAdapter->Interrupts == 0) {
394363
InterruptUnRegister(&pHalRuartAdapter->IrqHandle);
395364
InterruptDis(&pHalRuartAdapter->IrqHandle);
396365
}
@@ -404,7 +373,7 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
404373
int serial_getc(serial_t *obj)
405374
{
406375
#ifdef CONFIG_MBED_ENABLED
407-
if(obj->index == UART_3){
376+
if (obj->index == UART_3) {
408377
return log_uart_getc(&stdio_uart_log);
409378
}
410379
#endif
@@ -418,7 +387,7 @@ int serial_getc(serial_t *obj)
418387
void serial_putc(serial_t *obj, int c)
419388
{
420389
#ifdef CONFIG_MBED_ENABLED
421-
if(obj->index == UART_3){
390+
if (obj->index == UART_3) {
422391
log_uart_putc(&stdio_uart_log, (char)c);
423392
return;
424393
}
@@ -439,7 +408,7 @@ void serial_putc(serial_t *obj, int c)
439408
int serial_readable(serial_t *obj)
440409
{
441410
#ifdef CONFIG_MBED_ENABLED
442-
if(obj->index == UART_3){
411+
if (obj->index == UART_3) {
443412
return log_uart_readable(&stdio_uart_log);
444413
}
445414
#endif
@@ -457,16 +426,15 @@ int serial_readable(serial_t *obj)
457426
int serial_writable(serial_t *obj)
458427
{
459428
#ifdef CONFIG_MBED_ENABLED
460-
if(obj->index == UART_3){
429+
if (obj->index == UART_3) {
461430
return log_uart_writable(&stdio_uart_log);
462431
}
463432
#endif
464433

465434
PHAL_RUART_ADAPTER pHalRuartAdapter=(PHAL_RUART_ADAPTER)&(obj->hal_uart_adp);
466435
u8 uart_idx = pHalRuartAdapter->UartIndex;
467436

468-
if (HAL_RUART_READ32(uart_idx, RUART_LINE_STATUS_REG_OFF) &
469-
(RUART_LINE_STATUS_REG_THRE)) {
437+
if (HAL_RUART_READ32(uart_idx, RUART_LINE_STATUS_REG_OFF) & (RUART_LINE_STATUS_REG_THRE)) {
470438
return 1;
471439
} else {
472440
return 0;
@@ -476,7 +444,7 @@ int serial_writable(serial_t *obj)
476444
void serial_clear(serial_t *obj)
477445
{
478446
#ifdef CONFIG_MBED_ENABLED
479-
if(obj->index == UART_3){
447+
if (obj->index == UART_3) {
480448
log_uart_clear(&stdio_uart_log);
481449
return;
482450
}
@@ -491,7 +459,7 @@ void serial_clear(serial_t *obj)
491459
void serial_break_set(serial_t *obj)
492460
{
493461
#ifdef CONFIG_MBED_ENABLED
494-
if(obj->index == UART_3){
462+
if (obj->index == UART_3) {
495463
log_uart_break_set(&stdio_uart_log);
496464
return;
497465
}
@@ -500,7 +468,6 @@ void serial_break_set(serial_t *obj)
500468
PHAL_RUART_ADAPTER pHalRuartAdapter=(PHAL_RUART_ADAPTER)&(obj->hal_uart_adp);
501469
u8 uart_idx = pHalRuartAdapter->UartIndex;
502470
u32 RegValue;
503-
504471
RegValue = HAL_RUART_READ32(uart_idx, RUART_LINE_CTL_REG_OFF);
505472
RegValue |= BIT_UART_LCR_BREAK_CTRL;
506473
HAL_RUART_WRITE32(uart_idx, RUART_LINE_CTL_REG_OFF, RegValue);
@@ -509,16 +476,14 @@ void serial_break_set(serial_t *obj)
509476
void serial_break_clear(serial_t *obj)
510477
{
511478
#ifdef CONFIG_MBED_ENABLED
512-
if(obj->index == UART_3){
479+
if (obj->index == UART_3) {
513480
log_uart_break_clear(&stdio_uart_log);
514481
return;
515482
}
516483
#endif
517-
518484
PHAL_RUART_ADAPTER pHalRuartAdapter=(PHAL_RUART_ADAPTER)&(obj->hal_uart_adp);
519485
u8 uart_idx = pHalRuartAdapter->UartIndex;
520486
u32 RegValue;
521-
522487
RegValue = HAL_RUART_READ32(uart_idx, RUART_LINE_CTL_REG_OFF);
523488
RegValue &= ~(BIT_UART_LCR_BREAK_CTRL);
524489
HAL_RUART_WRITE32(uart_idx, RUART_LINE_CTL_REG_OFF, RegValue);

0 commit comments

Comments
 (0)