From 2b8b67a993e2126e74c082b5e119f559b441e53b Mon Sep 17 00:00:00 2001 From: Avi Weiss Date: Fri, 24 Apr 2026 15:47:55 +0200 Subject: [PATCH] bsp/arm/tms570: apply RTEMS clang format to sci.c --- bsps/arm/tms570/console/tms570-sci.c | 151 ++++++++++++++------------- 1 file changed, 76 insertions(+), 75 deletions(-) diff --git a/bsps/arm/tms570/console/tms570-sci.c b/bsps/arm/tms570/console/tms570-sci.c index e1474d9c3d..d33d9c10d6 100644 --- a/bsps/arm/tms570/console/tms570-sci.c +++ b/bsps/arm/tms570/console/tms570-sci.c @@ -41,13 +41,16 @@ */ #include + #include -#include -#include + #include +#include + #include #include #include +#include /** * @brief Table including all serial drivers @@ -56,7 +59,7 @@ */ tms570_sci_context driver_context_table[] = { { - .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("TMS570 SCI1"), + .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER( "TMS570 SCI1" ), .device_name = "/dev/console", /* TMS570 UART peripheral use subset of LIN registers which are equivalent * to SCI ones @@ -65,14 +68,14 @@ tms570_sci_context driver_context_table[] = { .irq = TMS570_IRQ_SCI_LEVEL_0, }, { - .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("TMS570 SCI2"), + .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER( "TMS570 SCI2" ), .device_name = "/dev/ttyS1", .regs = &TMS570_SCI, .irq = TMS570_IRQ_SCI2_LEVEL_0, } }; -void tms570_sci_initialize(tms570_sci_context *ctx) +void tms570_sci_initialize( tms570_sci_context *ctx ) { uint32_t rx_pin = 1 << 1; uint32_t tx_pin = 1 << 2; @@ -121,9 +124,9 @@ void tms570_sci_initialize(tms570_sci_context *ctx) * @retval RTEMS_SUCCESSFUL Initialization completed */ rtems_device_driver console_initialize( - rtems_device_major_number major, - rtems_device_minor_number minor, - void *arg + rtems_device_major_number major, + rtems_device_minor_number minor, + void *arg ) { (void) major; @@ -145,13 +148,11 @@ rtems_device_driver console_initialize( /* Initialize each device */ for ( - minor = 0; - minor < RTEMS_ARRAY_SIZE(driver_context_table); - ++minor + minor = 0; minor < RTEMS_ARRAY_SIZE( driver_context_table ); ++minor ) { - tms570_sci_context *ctx = &driver_context_table[minor]; + tms570_sci_context *ctx = &driver_context_table[ minor ]; - tms570_sci_initialize(ctx); + tms570_sci_initialize( ctx ); /* * Install this device in the file system and Termios. In order @@ -166,7 +167,7 @@ rtems_device_driver console_initialize( &ctx->base ); if ( sc != RTEMS_SUCCESSFUL ) { - bsp_fatal(BSP_FATAL_CONSOLE_NO_DEV); + bsp_fatal( BSP_FATAL_CONSOLE_NO_DEV ); } } return RTEMS_SUCCESSFUL; @@ -181,7 +182,7 @@ rtems_device_driver console_initialize( * @param[in] ctx context of the driver * @retval Void */ -static void tms570_sci_enable_interrupts(tms570_sci_context * ctx) +static void tms570_sci_enable_interrupts( tms570_sci_context *ctx ) { ctx->regs->SETINT = TMS570_SCI_SETINT_SET_RX_INT; } @@ -195,7 +196,7 @@ static void tms570_sci_enable_interrupts(tms570_sci_context * ctx) * @param[in] ctx context of the driver * @retval Void */ -static void tms570_sci_disable_interrupts(tms570_sci_context * ctx) +static void tms570_sci_disable_interrupts( tms570_sci_context *ctx ) { ctx->regs->CLEARINT = TMS570_SCI_CLEARINT_CLR_RX_INT; } @@ -211,7 +212,7 @@ static void tms570_sci_disable_interrupts(tms570_sci_context * ctx) * @param[in] ctx context of the driver * @retval x */ -static int tms570_sci_transmitted_chars(tms570_sci_context * ctx) +static int tms570_sci_transmitted_chars( tms570_sci_context *ctx ) { int ret; @@ -234,14 +235,14 @@ static int tms570_sci_transmitted_chars(tms570_sci_context * ctx) */ bool tms570_sci_set_attributes( rtems_termios_device_context *base, - const struct termios *t + const struct termios *t ) { - tms570_sci_context *ctx = (tms570_sci_context *) base; + tms570_sci_context *ctx = (tms570_sci_context *) base; rtems_interrupt_lock_context lock_context; - int32_t bauddiv; - int32_t baudrate; - uint32_t flr_tx_ready = TMS570_SCI_FLR_TX_EMPTY; + int32_t bauddiv; + int32_t baudrate; + uint32_t flr_tx_ready = TMS570_SCI_FLR_TX_EMPTY; /* * Test for TMS570_SCI_FLR_TXRDY is not necessary * because both SCITD and SCITXSHF has to be empty @@ -250,9 +251,9 @@ bool tms570_sci_set_attributes( */ /* Baud rate */ - baudrate = rtems_termios_baud_to_number(cfgetospeed(t)); + baudrate = rtems_termios_baud_to_number( cfgetospeed( t ) ); - rtems_termios_device_lock_acquire(base, &lock_context); + rtems_termios_device_lock_acquire( base, &lock_context ); while ( (ctx->regs->GCR1 & TMS570_SCI_GCR1_TXENA) && (ctx->regs->FLR & flr_tx_ready) != flr_tx_ready) { @@ -263,23 +264,24 @@ bool tms570_sci_set_attributes( */ rtems_interval tw; - rtems_termios_device_lock_release(base, &lock_context); + rtems_termios_device_lock_release( base, &lock_context ); tw = rtems_clock_get_ticks_per_second(); tw = tw * 5 / baudrate + 1; rtems_task_wake_after( tw ); - rtems_termios_device_lock_acquire(base, &lock_context); + rtems_termios_device_lock_acquire( base, &lock_context ); } - ctx->regs->GCR1 &= ~( TMS570_SCI_GCR1_SWnRST | TMS570_SCI_GCR1_TXENA | - TMS570_SCI_GCR1_RXENA ); + ctx->regs->GCR1 &= ~( + TMS570_SCI_GCR1_SWnRST | TMS570_SCI_GCR1_TXENA | TMS570_SCI_GCR1_RXENA + ); - ctx->regs->GCR1 &= ~TMS570_SCI_GCR1_STOP; /*one stop bit*/ - ctx->regs->FORMAT = TMS570_SCI_FORMAT_CHAR(0x7); + ctx->regs->GCR1 &= ~TMS570_SCI_GCR1_STOP; /*one stop bit*/ + ctx->regs->FORMAT = TMS570_SCI_FORMAT_CHAR( 0x7 ); - switch ( t->c_cflag & ( PARENB|PARODD ) ) { - case ( PARENB|PARODD ): + switch ( t->c_cflag & ( PARENB | PARODD ) ) { + case ( PARENB | PARODD ): /* Odd parity */ ctx->regs->GCR1 &= ~TMS570_SCI_GCR1_PARITY; ctx->regs->GCR1 |= TMS570_SCI_GCR1_PARITY_ENA; @@ -300,13 +302,13 @@ bool tms570_sci_set_attributes( /* Apply baudrate to the hardware */ baudrate *= 16; - bauddiv = (TMS570_VCLK_HZ + baudrate / 2) / baudrate; - ctx->regs->BRS = bauddiv? bauddiv - 1: 0; + bauddiv = ( TMS570_VCLK_HZ + baudrate / 2 ) / baudrate; + ctx->regs->BRS = bauddiv ? bauddiv - 1 : 0; ctx->regs->GCR1 |= TMS570_SCI_GCR1_SWnRST | TMS570_SCI_GCR1_TXENA | TMS570_SCI_GCR1_RXENA; - rtems_termios_device_lock_release(base, &lock_context); + rtems_termios_device_lock_release( base, &lock_context ); return true; } @@ -321,10 +323,10 @@ bool tms570_sci_set_attributes( * @param[in] arg rtems_termios_tty * @retval Void */ -static void tms570_sci_interrupt_handler(void * arg) +static void tms570_sci_interrupt_handler( void *arg ) { - rtems_termios_tty *tty = arg; - tms570_sci_context *ctx = rtems_termios_get_device_context(tty); + rtems_termios_tty *tty = arg; + tms570_sci_context *ctx = rtems_termios_get_device_context( tty ); /* * Check if we have received something. @@ -341,17 +343,17 @@ static void tms570_sci_interrupt_handler(void * arg) /* * Check if we have something transmitted. */ - if ( (ctx->regs->FLR & TMS570_SCI_FLR_TXRDY ) == TMS570_SCI_FLR_TXRDY ) { + if ( ( ctx->regs->FLR & TMS570_SCI_FLR_TXRDY ) == TMS570_SCI_FLR_TXRDY ) { size_t n; - n = tms570_sci_transmitted_chars(ctx); + n = tms570_sci_transmitted_chars( ctx ); if ( n > 0 ) { /* * Notify Termios that we have transmitted some characters. It * will call now the interrupt write function if more characters * are ready for transmission. */ - rtems_termios_dequeue_characters(tty, n); + rtems_termios_dequeue_characters( tty, n ); } } } @@ -370,8 +372,8 @@ static void tms570_sci_interrupt_handler(void * arg) */ static void tms570_sci_interrupt_write( rtems_termios_device_context *base, - const char *buf, - size_t len + const char *buf, + size_t len ) { tms570_sci_context *ctx = (tms570_sci_context *) base; @@ -382,11 +384,10 @@ static void tms570_sci_interrupt_write( /* character written - raise count*/ ctx->tx_chars_in_hw = 1; /* Enable TX interrupt (interrupt is edge-triggered) */ - ctx->regs->SETINT = (1<<8); - + ctx->regs->SETINT = ( 1 << 8 ); } else { /* No more to send, disable TX interrupts */ - ctx->regs->CLEARINT = (1<<8); + ctx->regs->CLEARINT = ( 1 << 8 ); /* Tell close that we sent everything */ } } @@ -404,20 +405,20 @@ static void tms570_sci_interrupt_write( */ static void tms570_sci_poll_write( rtems_termios_device_context *base, - const char *buf, - size_t n + const char *buf, + size_t n ) { tms570_sci_context *ctx = (tms570_sci_context *) base; - size_t i; + size_t i; /* Write */ for ( i = 0; i < n; ++i ) { - while ( (ctx->regs->FLR & TMS570_SCI_FLR_TX_EMPTY ) == 0) { + while ( ( ctx->regs->FLR & TMS570_SCI_FLR_TX_EMPTY ) == 0 ) { ; } - ctx->regs->TD = buf[i]; + ctx->regs->TD = buf[ i ]; } } @@ -430,9 +431,7 @@ static void tms570_sci_poll_write( * @retval 0 No character to read * @retval x Character ready to read */ -static int TMS570_sci_can_read_char( - tms570_sci_context * ctx -) +static int TMS570_sci_can_read_char( tms570_sci_context *ctx ) { return ctx->regs->FLR & TMS570_SCI_FLR_RXRDY; } @@ -445,9 +444,7 @@ static int TMS570_sci_can_read_char( * @param[in] ctx context of the driver * @retval x Character */ -static char TMS570_sci_read_char( - tms570_sci_context * ctx -) +static char TMS570_sci_read_char( tms570_sci_context *ctx ) { return ctx->regs->RD; } @@ -461,13 +458,13 @@ static char TMS570_sci_read_char( * @retval -1 No character to be read * @retval x Read character */ -static int tms570_sci_poll_read(rtems_termios_device_context *base) +static int tms570_sci_poll_read( rtems_termios_device_context *base ) { tms570_sci_context *ctx = (tms570_sci_context *) base; /* Check if a character is available */ - if ( TMS570_sci_can_read_char(ctx) ) { - return TMS570_sci_read_char(ctx); + if ( TMS570_sci_can_read_char( ctx ) ) { + return TMS570_sci_read_char( ctx ); } else { return -1; } @@ -498,8 +495,8 @@ static bool tms570_sci_poll_first_open( bool ok; - rtems_termios_set_best_baud(term, TMS570_SCI_BAUD_RATE); - ok = tms570_sci_set_attributes(ctx, term); + rtems_termios_set_best_baud( term, TMS570_SCI_BAUD_RATE ); + ok = tms570_sci_set_attributes( ctx, term ); if ( !ok ) { return false; } @@ -526,10 +523,10 @@ static bool tms570_sci_interrupt_first_open( ) { tms570_sci_context *ctx = (tms570_sci_context *) base; - rtems_status_code sc; - bool ret; + rtems_status_code sc; + bool ret; - ret = tms570_sci_poll_first_open(tty, base, term, args); + ret = tms570_sci_poll_first_open( tty, base, term, args ); if ( ret == false ) { return false; } @@ -544,7 +541,7 @@ static bool tms570_sci_interrupt_first_open( if ( sc != RTEMS_SUCCESSFUL ) { return false; } - tms570_sci_enable_interrupts(ctx); + tms570_sci_enable_interrupts( ctx ); return true; } @@ -587,15 +584,15 @@ static void tms570_sci_interrupt_last_close( rtems_libio_open_close_args_t *args ) { - tms570_sci_context *ctx = (tms570_sci_context *) base; + tms570_sci_context *ctx = (tms570_sci_context *) base; rtems_interrupt_lock_context lock_context; - rtems_interval tw; - int32_t baudrate; + rtems_interval tw; + int32_t baudrate; /* Turn off RX interrupts */ - rtems_termios_device_lock_acquire(base, &lock_context); - tms570_sci_disable_interrupts(ctx); - rtems_termios_device_lock_release(base, &lock_context); + rtems_termios_device_lock_acquire( base, &lock_context ); + tms570_sci_disable_interrupts( ctx ); + rtems_termios_device_lock_release( base, &lock_context ); tw = rtems_clock_get_ticks_per_second(); baudrate = rtems_termios_baud_to_number(cfgetospeed(&tty->termios)); @@ -605,9 +602,13 @@ static void tms570_sci_interrupt_last_close( } /* uninstall ISR */ - rtems_interrupt_handler_remove(ctx->irq, tms570_sci_interrupt_handler, tty); + rtems_interrupt_handler_remove( + ctx->irq, + tms570_sci_interrupt_handler, + tty + ); - tms570_sci_poll_last_close(tty, base, args); + tms570_sci_poll_last_close( tty, base, args ); } /** @@ -631,7 +632,7 @@ const rtems_termios_device_handler tms570_sci_handler_polled = { * Encapsulates interrupt driven driver functions. * Use of this table is determited by defining TMS570_USE_INTERRUPTS */ -const rtems_termios_device_handler tms570_sci_handler_interrupt = { +const rtems_termios_device_handler tms570_sci_handler_interrupt = { .first_open = tms570_sci_interrupt_first_open, .last_close = tms570_sci_interrupt_last_close, .poll_read = NULL,