[rtems commit] libchip/ns16550: Allow user calculate baud divisor

Christian Mauderer christianm at rtems.org
Sun Feb 16 18:26:30 UTC 2020


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

Author:    G S Niteesh <gsnb.gn at gmail.com>
Date:      Mon Feb 10 01:09:43 2020 +0530

libchip/ns16550: Allow user calculate baud divisor

This patch will allow the user to pass a function to calculate
the baud divisor.
This will allow for more flexibility, since for some BSPs
like raspberrypi, the calculation of baud divisor is different
from what is in the current driver.

---

 bsps/include/libchip/ns16550.h           | 9 +++++++--
 bsps/shared/dev/serial/ns16550-context.c | 2 ++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/bsps/include/libchip/ns16550.h b/bsps/include/libchip/ns16550.h
index f053c87..b45331a 100644
--- a/bsps/include/libchip/ns16550.h
+++ b/bsps/include/libchip/ns16550.h
@@ -60,7 +60,11 @@ typedef uint8_t (*ns16550_get_reg)(uintptr_t port, uint8_t reg);
 
 typedef void (*ns16550_set_reg)(uintptr_t port, uint8_t reg, uint8_t value);
 
-typedef struct {
+typedef struct ns16550_context ns16550_context;
+
+typedef uint32_t (*ns16550_calculate_baud_divisor)(ns16550_context *ctx, uint32_t baud);
+
+struct ns16550_context{
   rtems_termios_device_context base;
   ns16550_get_reg get_reg;
   ns16550_set_reg set_reg;
@@ -78,7 +82,8 @@ typedef struct {
   size_t out_current;
   const char *out_buf;
   rtems_termios_tty *tty;
-} ns16550_context;
+  ns16550_calculate_baud_divisor calculate_baud_divisor;
+};
 
 extern const rtems_termios_device_handler ns16550_handler_interrupt;
 extern const rtems_termios_device_handler ns16550_handler_polled;
diff --git a/bsps/shared/dev/serial/ns16550-context.c b/bsps/shared/dev/serial/ns16550-context.c
index ce55b83..dbf6c64 100644
--- a/bsps/shared/dev/serial/ns16550-context.c
+++ b/bsps/shared/dev/serial/ns16550-context.c
@@ -112,6 +112,8 @@ static uint32_t NS16550_GetBaudDivisor(ns16550_context *ctx, uint32_t baud)
       NS16550_FRACTIONAL_DIVIDER,
       fractionalDivider
     );
+  } else if (ctx->calculate_baud_divisor != NULL) {
+    baudDivisor = ctx->calculate_baud_divisor(ctx, baud);
   }
 
   return baudDivisor;



More information about the vc mailing list