[rtems commit] bsp/riscv: Fix format and warnings

Sebastian Huber sebh at rtems.org
Thu Nov 14 10:49:23 UTC 2019


Module:    rtems
Branch:    master
Commit:    ae5546704d15fa87a111760d777e95321143c199
Changeset: http://git.rtems.org/rtems/commit/?id=ae5546704d15fa87a111760d777e95321143c199

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Nov 14 11:20:41 2019 +0100

bsp/riscv: Fix format and warnings

Update #3785.

---

 bsps/riscv/riscv/console/console-config.c | 22 +++++++-------
 bsps/riscv/riscv/console/fe310-uart.c     | 50 +++++++++++--------------------
 2 files changed, 27 insertions(+), 45 deletions(-)

diff --git a/bsps/riscv/riscv/console/console-config.c b/bsps/riscv/riscv/console/console-config.c
index 0e82624..ec64df2 100644
--- a/bsps/riscv/riscv/console/console-config.c
+++ b/bsps/riscv/riscv/console/console-config.c
@@ -30,7 +30,7 @@
 
 #if RISCV_ENABLE_FRDME310ARTY_SUPPORT != 0
 #include <bsp/fe310-uart.h>
-fe310_uart_context driver_context;
+fe310_uart_context fe310_uart_instance;
 #endif
 
 #if RISCV_ENABLE_HTIF_SUPPORT != 0
@@ -217,12 +217,11 @@ static void riscv_console_probe(void)
 
 #if RISCV_ENABLE_FRDME310ARTY_SUPPORT != 0
     if (RISCV_CONSOLE_IS_COMPATIBLE(compat, compat_len, "sifive,uart0")) {
-      fe310_uart_context *ctx ;
+      fe310_uart_context *ctx;
 
-      ctx=&driver_context;
-      ctx->regs = (uintptr_t) riscv_fdt_get_address(fdt, node);
-      if (ctx->regs == 0)
-      {
+      ctx = &fe310_uart_instance;
+      ctx->regs = riscv_fdt_get_address(fdt, node);
+      if (ctx->regs == NULL) {
         bsp_fatal(RISCV_FATAL_NO_NS16550_REG_IN_DEVICE_TREE);
       }
 
@@ -268,7 +267,8 @@ rtems_status_code console_initialize(
 #endif
 
 #if RISCV_ENABLE_FRDME310ARTY_SUPPORT != 0
-  char path[] = "/dev/ttyS0";
+  fe310_uart_context *ctx;
+  char fe310_path[] = "/dev/ttyS0";
 #endif
 
   rtems_termios_initialize();
@@ -303,19 +303,17 @@ rtems_status_code console_initialize(
 #endif
 
 #if RISCV_ENABLE_FRDME310ARTY_SUPPORT != 0
-  fe310_uart_context * ctx = &driver_context;
-
+  ctx = &fe310_uart_instance;
   rtems_termios_device_install(
-    path,
+    fe310_path,
     &fe310_uart_handler,
     NULL,
     &ctx->base
   );
 
   if (&ctx->base == riscv_console.context) {
-    link(path, CONSOLE_DEVICE_NAME);
+    link(fe310_path, CONSOLE_DEVICE_NAME);
   }
-
 #endif
 
   return RTEMS_SUCCESSFUL;
diff --git a/bsps/riscv/riscv/console/fe310-uart.c b/bsps/riscv/riscv/console/fe310-uart.c
index a8e87f4..4ae62d7 100644
--- a/bsps/riscv/riscv/console/fe310-uart.c
+++ b/bsps/riscv/riscv/console/fe310-uart.c
@@ -31,24 +31,18 @@
 
 #include <assert.h>
 
-static void irq_handler(void *arg)
-{
-	/*TODO*/
-}
-
 int fe310_uart_read(rtems_termios_device_context *base)
 {
-	fe310_uart_context * ctx = (fe310_uart_context*) base;
-	  size_t i;
+  fe310_uart_context * ctx = (fe310_uart_context*) base;
 
-	  if (((ctx->regs->rxdata) & TXRXREADY) != 0) {
-	    return -1;
-	  } else {
-	    return ctx->regs->rxdata;
-	}
+  if ((ctx->regs->rxdata & TXRXREADY) != 0) {
+    return -1;
+  } else {
+    return ctx->regs->rxdata;
+  }
 }
 
-static ssize_t fe310_uart_write (
+static void fe310_uart_write (
   rtems_termios_device_context  *base,
   const char                    *buf,
   size_t                        n
@@ -57,32 +51,22 @@ static ssize_t fe310_uart_write (
   fe310_uart_context * ctx = (fe310_uart_context*) base;
   size_t i;
 
-  rtems_status_code sc;
-
-  (ctx->regs)->div = riscv_get_core_frequency()/ 115200 - 1;
-  (ctx->regs)->txctrl |= 1;
-  (ctx->regs)->rxctrl |= 1;
+  ctx->regs->div = riscv_get_core_frequency() / 115200 - 1;
+  ctx->regs->txctrl |= 1;
+  ctx->regs->rxctrl |= 1;
 
   for (i = 0; i < n; ++i) {
-    while (((ctx->regs->txdata) & TXRXREADY) != 0) {
-        ;
+    while ((ctx->regs->txdata & TXRXREADY) != 0) {
+      /* Wait */
     }
+
     ctx->regs->txdata = buf[i];
   }
-  return n;
 }
 
-void fe310_console_putchar(rtems_termios_device_context * context,char c)
-{
-	fe310_uart_write ( context, &c,1);
-}
-
-void console_context_init(
-  rtems_termios_device_context *base,
-  int device_tree_node
-)
+void fe310_console_putchar(rtems_termios_device_context *context, char c)
 {
-	/*TODO*/
+  fe310_uart_write(context, &c, 1);
 }
 
 static bool fe310_uart_first_open (
@@ -97,14 +81,14 @@ static bool fe310_uart_first_open (
 
   /* Configure GPIO to be UART */
 
-  sc = rtems_termios_set_initial_baud (tty, B115200);
+  sc = rtems_termios_set_initial_baud(tty, B115200);
   if ( sc != RTEMS_SUCCESSFUL ) {
     return false;
   }
 
   /* Set up a baud rate and enable tx and rx */
   ctx = (fe310_uart_context *) base;
-  (ctx->regs)->div = riscv_get_core_frequency()/ 115200 - 1;
+  (ctx->regs)->div = riscv_get_core_frequency() / 115200 - 1;
   (ctx->regs)->txctrl |= 1;
   (ctx->regs)->rxctrl |= 1;
   return true;



More information about the vc mailing list