[rtems commit] bsp/tms570: Fix console receive interrupts

Sebastian Huber sebh at rtems.org
Thu Feb 1 06:57:03 UTC 2024


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

Author:    Adrien Chardon <adrien at reflexaerospace.com>
Date:      Wed Jan 24 18:01:52 2024 +0100

bsp/tms570: Fix console receive interrupts

`tms570_sci_interrupt_handler()` is called when an RX interrupt fires. It checks
in the register `FLR`, the `RXRDY` bit (Receiver ready flag - indicate that the
SCIRD contains new data). If it is set, it calls
`tms570_sci_read_received_chars()`.

`tms570_sci_read_received_chars()` checks the register `RD` against 0. If it is
non zero, it returns 1 to indicate that one byte was read.

In the old behavior, if it is zero, the function returns 0 to indicate that no
data was read.

The new behavior is to not silently drop 0x00 bytes. Ignoring 0x00 bytes is fine
when working with printable text (which, I assume, is how this driver was
tested), but as soon as the UART is used in non canonical (raw) mode, with
potentially 0x00 bytes, these bytes will be silently dropped, causing issues in
the data/protocol layer above.

Update #4982.

---

 bsps/arm/tms570/console/tms570-sci.c | 45 ++++++++----------------------------
 1 file changed, 9 insertions(+), 36 deletions(-)

diff --git a/bsps/arm/tms570/console/tms570-sci.c b/bsps/arm/tms570/console/tms570-sci.c
index b945855986..63f8e7c8ee 100644
--- a/bsps/arm/tms570/console/tms570-sci.c
+++ b/bsps/arm/tms570/console/tms570-sci.c
@@ -49,8 +49,6 @@
 #include <bsp/fatal.h>
 #include <bsp/irq.h>
 
-#define TMS570_SCI_BUFFER_SIZE 1
-
 /**
  * @brief Table including all serial drivers
  *
@@ -171,33 +169,6 @@ rtems_device_driver console_initialize(
   return RTEMS_SUCCESSFUL;
 }
 
-/**
- * @brief Reads chars from HW
- *
- * Reads chars from HW peripheral specified in driver context.
- * TMS570 does not have HW buffer for serial line so this function can
- * return only 0 or 1 char
- *
- * @param[in] ctx context of the driver
- * @param[out] buf read data buffer
- * @param[in] N size of buffer
- * @retval x Number of read chars from peripherals
- */
-static int tms570_sci_read_received_chars(
-  tms570_sci_context * ctx,
-  char * buf,
-  int N)
-{
-  if ( N < 1 ) {
-    return 0;
-  }
-  if ( ctx->regs->RD != 0 ) {
-     buf[0] = ctx->regs->RD;
-    return 1;
-  }
-  return 0;
-}
-
 /**
  * @brief Enables RX interrupt
  *
@@ -351,23 +322,25 @@ static void tms570_sci_interrupt_handler(void * arg)
 {
   rtems_termios_tty *tty = arg;
   tms570_sci_context *ctx = rtems_termios_get_device_context(tty);
-  char buf[TMS570_SCI_BUFFER_SIZE];
-  size_t n;
 
   /*
    * Check if we have received something.
    */
    if ( (ctx->regs->FLR & TMS570_SCI_FLR_RXRDY ) == TMS570_SCI_FLR_RXRDY ) {
-      n = tms570_sci_read_received_chars(ctx, buf, TMS570_SCI_BUFFER_SIZE);
-      if ( n > 0 ) {
-        /* Hand the data over to the Termios infrastructure */
-        rtems_termios_enqueue_raw_characters(tty, buf, n);
-      }
+      char buf[1];
+
+      /* Read the received byte */
+      buf[0] = ctx->regs->RD & 0x000000FF;
+
+      /* Hand the data over to the Termios infrastructure */
+      rtems_termios_enqueue_raw_characters(tty, buf, 1);
     }
   /*
    * Check if we have something transmitted.
    */
   if ( (ctx->regs->FLR & TMS570_SCI_FLR_TXRDY ) == TMS570_SCI_FLR_TXRDY ) {
+    size_t n;
+
     n = tms570_sci_transmitted_chars(ctx);
     if ( n > 0 ) {
       /*



More information about the vc mailing list