[rtems commit] dev/sc16is752: Add RS485 mode variants

Sebastian Huber sebh at rtems.org
Fri Jun 14 05:36:25 UTC 2019


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Jun 14 07:35:21 2019 +0200

dev/sc16is752: Add RS485 mode variants

---

 cpukit/dev/serial/sc16is752-regs.h    |  3 +++
 cpukit/dev/serial/sc16is752.c         | 20 ++++++++++++++++----
 cpukit/include/dev/serial/sc16is752.h | 13 ++++++++++++-
 3 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/cpukit/dev/serial/sc16is752-regs.h b/cpukit/dev/serial/sc16is752-regs.h
index b07e489..b74f5aa 100644
--- a/cpukit/dev/serial/sc16is752-regs.h
+++ b/cpukit/dev/serial/sc16is752-regs.h
@@ -68,6 +68,8 @@ extern "C" {
 #define SC16IS752_EFCR_RS485_ENABLE (1u << 0)
 #define SC16IS752_EFCR_RX_DISABLE (1u << 1)
 #define SC16IS752_EFCR_TX_DISABLE (1u << 2)
+#define SC16IS752_EFCR_RTSCON (1u << 4)
+#define SC16IS752_EFCR_RTSINVER (1u << 5)
 
 /* IER */
 #define SC16IS752_IER_RHR (1u << 0)
@@ -91,6 +93,7 @@ extern "C" {
 #define SC16IS752_LCR_2_STOP_BIT (1u << 2)
 #define SC16IS752_LCR_SET_PARITY (1u << 3)
 #define SC16IS752_LCR_EVEN_PARITY (1u << 4)
+#define SC16IS752_LCR_BREAK (1u << 5)
 #define SC16IS752_LCR_ENABLE_DIVISOR (1u << 7)
 
 /* LSR */
diff --git a/cpukit/dev/serial/sc16is752.c b/cpukit/dev/serial/sc16is752.c
index a58b87b..5384563 100644
--- a/cpukit/dev/serial/sc16is752.c
+++ b/cpukit/dev/serial/sc16is752.c
@@ -212,6 +212,7 @@ static bool sc16is752_first_open(
 {
   bool ok;
   uint8_t fcr;
+  uint8_t efcr;
 
   (void)args;
   sc16is752_context *ctx = (sc16is752_context *)base;
@@ -223,12 +224,23 @@ static bool sc16is752_first_open(
     return ok;
   }
 
-  if (ctx->mode == SC16IS752_MODE_RS485) {
-    ctx->efcr = SC16IS752_EFCR_RS485_ENABLE;
-  } else {
-    ctx->efcr = 0;
+  efcr = 0;
+
+  switch (ctx->mode) {
+    case SC16IS752_MODE_RS485_RTS_INV:
+      efcr |= SC16IS752_EFCR_RTSINVER;
+      /* Fall through */
+    case SC16IS752_MODE_RS485_RTS:
+      efcr |= SC16IS752_EFCR_RTSCON;
+      /* Fall through */
+    case SC16IS752_MODE_RS485:
+      efcr |= SC16IS752_EFCR_RS485_ENABLE;
+      break;
+    default:
+      break;
   }
 
+  ctx->efcr = efcr;
   write_reg(ctx, SC16IS752_FCR, &ctx->efcr, 1);
 
   fcr = SC16IS752_FCR_FIFO_EN
diff --git a/cpukit/include/dev/serial/sc16is752.h b/cpukit/include/dev/serial/sc16is752.h
index 67c2e00..ea8ba70 100644
--- a/cpukit/include/dev/serial/sc16is752.h
+++ b/cpukit/include/dev/serial/sc16is752.h
@@ -31,7 +31,18 @@ extern "C" {
 
 typedef enum {
   SC16IS752_MODE_RS232,
-  SC16IS752_MODE_RS485
+
+  /* Enable RS485 mode */
+  SC16IS752_MODE_RS485,
+
+  /* Enable RS485 mode, enable the transmitter to control the #RTS pin */
+  SC16IS752_MODE_RS485_RTS,
+
+  /*
+   * Enable RS485 mode, enable the transmitter to control the #RTS pin, invert
+   * RTS signal (#RTS = 1 during transmission and #RTS = 0 during reception)
+   */
+  SC16IS752_MODE_RS485_RTS_INV
 } sc16is752_mode;
 
 typedef struct sc16is752_context sc16is752_context;



More information about the vc mailing list