[PATCH v1 1/1] bsps/shared: Allow setting baud rate for zynq uart

Jan Sommer jan.sommer at dlr.de
Mon Feb 22 15:43:37 UTC 2021


---
 bsps/shared/dev/serial/zynq-uart.c | 42 +++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/bsps/shared/dev/serial/zynq-uart.c b/bsps/shared/dev/serial/zynq-uart.c
index 8f17d3ca65..124f9e032d 100644
--- a/bsps/shared/dev/serial/zynq-uart.c
+++ b/bsps/shared/dev/serial/zynq-uart.c
@@ -144,14 +144,50 @@ static bool zynq_uart_set_attributes(
 {
   zynq_uart_context *ctx = (zynq_uart_context *) context;
   volatile zynq_uart *regs = ctx->regs;
+  int32_t baud;
   uint32_t brgr = 0;
   uint32_t bauddiv = 0;
   uint32_t mode = 0;
   int rc;
 
-  rc = zynq_cal_baud_rate(115200, &brgr, &bauddiv, regs->mode);
-  if (rc != 0)
-    return rc;
+  /* 
+   * Determine the baud rate
+   */
+  switch (term->c_ospeed) {
+    case B0:      baud = 0;      break;
+    case B50:     baud = 50;     break;
+    case B75:     baud = 75;     break;
+    case B110:    baud = 110;    break;
+    case B134:    baud = 134;    break;
+    case B150:    baud = 150;    break;
+    case B200:    baud = 200;    break;
+    case B300:    baud = 300;    break;
+    case B600:    baud = 600;    break;
+    case B1200:   baud = 1200;   break;
+    case B1800:   baud = 1800;   break;
+    case B2400:   baud = 2400;   break;
+    case B4800:   baud = 4800;   break;
+    case B9600:   baud = 9600;   break;
+    case B19200:  baud = 19200;  break;
+    case B38400:  baud = 38400;  break;
+    case B57600:  baud = 57600;  break;
+    case B115200: baud = 115200; break;
+    case B230400: baud = 230400; break;
+    case B460800: baud = 460800; break;
+    case B921600: baud = 921600; break;
+    default: baud = -1; break;
+  }
+
+  if (baud < 0) {
+	errno = EINVAL;
+	return -1;
+  }
+
+  if (baud > 0) {
+    rc = zynq_cal_baud_rate(baud, &brgr, &bauddiv, regs->mode);
+    if (rc != 0)
+      return rc;
+  }
 
   /*
    * Configure the mode register
-- 
2.17.1



More information about the devel mailing list