[PATCH v2] bsp/beagle: Update console to new Termios device API.

G S Niteesh Babu niteesh.gs at gmail.com
Sun Mar 15 19:44:33 UTC 2020


This patch updates the console to use new Termios device API.
Update #3034
---
 bsps/arm/beagle/console/console-config.c | 66 +++++++++++++++---------
 1 file changed, 41 insertions(+), 25 deletions(-)

diff --git a/bsps/arm/beagle/console/console-config.c b/bsps/arm/beagle/console/console-config.c
index 78af5f6a93..860a44cb00 100644
--- a/bsps/arm/beagle/console/console-config.c
+++ b/bsps/arm/beagle/console/console-config.c
@@ -41,6 +41,8 @@
 #define TX_FIFO_E (1<<5)
 #define RX_FIFO_E (1<<0)
 
+#define UART0 "/dev/ttyS0"
+
 static uint8_t beagle_uart_get_register(uintptr_t addr, uint8_t i)
 {
   uint8_t v;
@@ -65,34 +67,27 @@ static void beagle_uart_set_register(uintptr_t addr, uint8_t i, uint8_t val)
   reg [i] = val;
 }
 
-console_tbl Console_Configuration_Ports [] = {
-    {
-      .sDeviceName = "/dev/ttyS0",
-      .deviceType = SERIAL_NS16550,
-#if CONSOLE_POLLED	/* option to facilitate running the tests */
-      .pDeviceFns = &ns16550_fns_polled,
-#else
-      .pDeviceFns = &ns16550_fns,
-#endif
-      .ulMargin = 16,
-      .ulHysteresis = 8,
-      .pDeviceParams = (void *) CONSOLE_BAUD,
-      .ulCtrlPort1 = BSP_CONSOLE_UART_BASE,
-      .ulDataPort = BSP_CONSOLE_UART_BASE,
-      .ulIntVector = BSP_CONSOLE_UART_IRQ,
-      .getRegister = beagle_uart_get_register,
-      .setRegister = beagle_uart_set_register,
-      .ulClock = UART_CLOCK,  /* 48MHz base clock */
-    },
-};
-
-unsigned long Console_Configuration_Count = 1;
+ns16550_context uart_context;
 
 static int init_needed = 1; // don't rely on bss being 0
 
 static void beagle_console_init(void)
 {
   if(init_needed) {
+    ns16550_context *ctx;
+
+    /*
+   *  Don't rely on BSS being 0
+    */
+    memset(&uart_context, 0, sizeof(uart_context));
+    ctx = &uart_context;
+
+    ctx->port = BSP_CONSOLE_UART_BASE;
+    ctx->get_reg = beagle_uart_get_register;
+    ctx->set_reg = beagle_uart_set_register;
+    ctx->clock = UART_CLOCK;
+    ctx->initial_baud = CONSOLE_BAUD;
+
     const uint32_t div = UART_CLOCK / 16 / CONSOLE_BAUD;
     CONSOLE_SYSC = 2;
     while ((CONSOLE_SYSS & 1) == 0)
@@ -120,6 +115,8 @@ static void beagle_console_init(void)
     CONSOLE_LCR = 0x03;
     CONSOLE_ACR = 0x00;
     init_needed = 0;
+
+    BSP_output_char = uart_write_polled;
   }
 }
 
@@ -127,15 +124,17 @@ static void beagle_console_init(void)
 
 static void uart_write_polled( char c )
 {
-  if(init_needed) beagle_console_init();
-
   while( ( CONSOLE_LSR & TX_FIFO_E ) == 0 )
     ;
   CONSOLE_THR8 = c;
 }
 
 static void _BSP_put_char( char c ) {
-   uart_write_polled( c );
+
+  if ( init_needed ) {
+    beagle_console_init();
+  }
+  uart_write_polled( c );
 }
 
 static int _BSP_get_char(void)
@@ -147,6 +146,23 @@ static int _BSP_get_char(void)
   }
 }
 
+rtems_status_code console_initialize(
+  rtems_device_major_number major,
+  rtems_device_minor_number minor,
+  void *arg
+)
+{
+  rtems_termios_initialize();
+  rtems_termios_device_install(
+    UART0,
+    &ns16550_handler_polled,
+    NULL,
+    &uart_context.base
+  );
+
+  return RTEMS_SUCCESSFUL;
+}
+
 BSP_output_char_function_type BSP_output_char = _BSP_put_char;
 
 BSP_polling_getchar_function_type BSP_poll_char = _BSP_get_char;
-- 
2.17.1



More information about the devel mailing list