Copilot commented on code in PR #19500:
URL: https://github.com/apache/nuttx/pull/19500#discussion_r3625968849
##########
boards/Kconfig:
##########
@@ -1050,6 +1050,15 @@ config ARCH_BOARD_LAUNCHXL_TMS57004
TI Hercules TMS570LS04x/03x LaunchPad Evaluation Kit (LAUNCHXL-
TMS57004) featuring the Hercules TMS570LS0432PZ chip.
+config ARCH_BOARD_RM57L843_LAUNCHXL2
+ bool "TI Hercules RM57L LaunchXL2"
+ depends on ARCH_CHIP_RM57L843
+ select ARCH_HAVE_LEDS
+ select ARCH_HAVE_BUTTONS
Review Comment:
ARCH_HAVE_BUTTONS is selected for this board, but there is no button
implementation in boards/arm/rm57/rm57l843-launchxl2 (no
board_button_initialize/board_buttons). This makes CONFIG_ARCH_BUTTONS appear
supported when it will fail to link or behave incorrectly.
##########
boards/arm/rm57/rm57l843-launchxl2/src/rm57_autoleds.c:
##########
@@ -0,0 +1,110 @@
+/****************************************************************************
+ * boards/arm/rm57/rm57l843-launchxl2/src/rm57_autoleds.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/* LEDs
+ *
+ * The LAUNCHXL2-RM57L has two user LEDs, labeled B6 and B7 on the board
+ * silkscreen, driven by GIOB[6] and GIOB[7] (see rm57l843-launchxl2.h).
+ * This LED is not used by the board port unless CONFIG_ARCH_LEDS is
+ * defined. In that case, the usage by the board port is defined in
+ * include/board.h and this file. Both LEDs are driven together to encode
+ * OS-related events as follows:
+ *
+ * ------------------- ----------------------- ------
+ * SYMBOL Meaning LEDs
+ * ------------------- ----------------------- ------
+ * LED_STARTED NuttX has been started OFF
+ * LED_HEAPALLOCATE Heap has been allocated OFF
+ * LED_IRQSENABLED Interrupts enabled OFF
+ * LED_STACKCREATED Idle stack created ON
+ * LED_INIRQ In an interrupt N/C
+ * LED_SIGNAL In a signal handler N/C
+ * LED_ASSERTION An assertion failed N/C
+ * LED_PANIC The system has crashed FLASH
+ *
+ * Thus if the LEDs are statically on, NuttX has successfully booted and
+ * is, apparently, running normally. If the LEDs are flashing at
+ * approximately 2Hz, then a fatal error has been detected and the system
+ * has halted.
+ */
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <nuttx/debug.h>
+
+#include <nuttx/board.h>
+#include <arch/board/board.h>
+
+#include "rm57_gio.h"
+#include "rm57l843-launchxl2.h"
+
+#ifdef CONFIG_ARCH_LEDS
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_autoled_initialize
+ ****************************************************************************/
+
+void board_autoled_initialize(void)
+{
+ /* Configure LED GIOs for output */
+
+ rm57_configgio(GIO_LED_B6);
+ rm57_configgio(GIO_LED_B7);
+}
+
+/****************************************************************************
+ * Name: board_autoled_on
+ ****************************************************************************/
+
+void board_autoled_on(int led)
+{
+ if (led == 1 || led == 3)
Review Comment:
Use the LED_* event macros (from include/board.h) instead of magic numbers
for OS LED events. This avoids accidental mismatch if the mapping changes and
makes the code self-documenting.
##########
boards/arm/rm57/rm57l843-launchxl2/src/rm57_autoleds.c:
##########
@@ -0,0 +1,110 @@
+/****************************************************************************
+ * boards/arm/rm57/rm57l843-launchxl2/src/rm57_autoleds.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/* LEDs
+ *
+ * The LAUNCHXL2-RM57L has two user LEDs, labeled B6 and B7 on the board
+ * silkscreen, driven by GIOB[6] and GIOB[7] (see rm57l843-launchxl2.h).
+ * This LED is not used by the board port unless CONFIG_ARCH_LEDS is
+ * defined. In that case, the usage by the board port is defined in
+ * include/board.h and this file. Both LEDs are driven together to encode
+ * OS-related events as follows:
+ *
+ * ------------------- ----------------------- ------
+ * SYMBOL Meaning LEDs
+ * ------------------- ----------------------- ------
+ * LED_STARTED NuttX has been started OFF
+ * LED_HEAPALLOCATE Heap has been allocated OFF
+ * LED_IRQSENABLED Interrupts enabled OFF
+ * LED_STACKCREATED Idle stack created ON
+ * LED_INIRQ In an interrupt N/C
+ * LED_SIGNAL In a signal handler N/C
+ * LED_ASSERTION An assertion failed N/C
+ * LED_PANIC The system has crashed FLASH
+ *
+ * Thus if the LEDs are statically on, NuttX has successfully booted and
+ * is, apparently, running normally. If the LEDs are flashing at
+ * approximately 2Hz, then a fatal error has been detected and the system
+ * has halted.
+ */
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <nuttx/debug.h>
+
+#include <nuttx/board.h>
+#include <arch/board/board.h>
+
+#include "rm57_gio.h"
+#include "rm57l843-launchxl2.h"
+
+#ifdef CONFIG_ARCH_LEDS
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_autoled_initialize
+ ****************************************************************************/
+
+void board_autoled_initialize(void)
+{
+ /* Configure LED GIOs for output */
+
+ rm57_configgio(GIO_LED_B6);
+ rm57_configgio(GIO_LED_B7);
+}
+
+/****************************************************************************
+ * Name: board_autoled_on
+ ****************************************************************************/
+
+void board_autoled_on(int led)
+{
+ if (led == 1 || led == 3)
+ {
+ rm57_giowrite(GIO_LED_B6, true); /* High illuminates */
+ rm57_giowrite(GIO_LED_B7, true);
+ }
+}
+
+/****************************************************************************
+ * Name: board_autoled_off
+ ****************************************************************************/
+
+void board_autoled_off(int led)
+{
+ if (led == 3)
Review Comment:
Use the LED_* event macros (from include/board.h) instead of magic numbers
for OS LED events. This avoids accidental mismatch if the mapping changes and
makes the code self-documenting.
##########
boards/arm/rm57/rm57l843-launchxl2/src/rm57_autoleds.c:
##########
@@ -0,0 +1,110 @@
+/****************************************************************************
+ * boards/arm/rm57/rm57l843-launchxl2/src/rm57_autoleds.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/* LEDs
+ *
+ * The LAUNCHXL2-RM57L has two user LEDs, labeled B6 and B7 on the board
+ * silkscreen, driven by GIOB[6] and GIOB[7] (see rm57l843-launchxl2.h).
+ * This LED is not used by the board port unless CONFIG_ARCH_LEDS is
Review Comment:
Minor grammar: the board has two LEDs (B6 and B7), but the comment says
"This LED is not used". Pluralizing avoids confusion when reading the auto-LED
behavior description.
##########
arch/arm/src/rm57/rm57_lowputc.c:
##########
@@ -0,0 +1,278 @@
+/****************************************************************************
+ * arch/arm/src/rm57/rm57_lowputc.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/* Adapted from tms570_lowputc.c, using RM57's SCI register layout
+ * (hardware/rm57_sci.h). Only SCI1 is currently supported.
+ */
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <assert.h>
+#include <errno.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/arch.h>
+#include <arch/board/board.h>
+#include <nuttx/spinlock.h>
+
+#include "arm_internal.h"
+#include "hardware/rm57_sci.h"
+#include "rm57_lowputc.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Select SCI parameters for the selected console */
+
+#if defined(CONFIG_SCI1_SERIAL_CONSOLE) && defined(CONFIG_RM57_SCI1)
+# define RM57_CONSOLE_BASE RM57_SCI1_BASE
+# define RM57_CONSOLE_BAUD CONFIG_SCI1_BAUD
+# define RM57_CONSOLE_BITS 8
+# define RM57_CONSOLE_PARITY 0
+# define RM57_CONSOLE_2STOP CONFIG_SCI1_2STOP
+# define HAVE_SERIAL_CONSOLE 1
+#else
+# error "No CONFIG_SCIn_SERIAL_CONSOLE Setting"
+# undef HAVE_SERIAL_CONSOLE
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static spinlock_t g_rm57_lowputc_lock = SP_UNLOCKED;
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef HAVE_SERIAL_CONSOLE
+static const struct sci_config_s g_console_config =
+{
+ .baud = RM57_CONSOLE_BAUD,
+ .parity = RM57_CONSOLE_PARITY,
+ .bits = RM57_CONSOLE_BITS,
+ .stopbits2 = RM57_CONSOLE_2STOP,
+};
+#endif /* HAVE_SERIAL_CONSOLE */
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rm57_sci_initialize
+ *
+ * Description:
+ * Perform one-time initialization of an SCI module: bring it out of
+ * reset and configure its RX/TX pins.
+ *
+ ****************************************************************************/
+
+static void rm57_sci_initialize(uint32_t base)
+{
+ /* Bring the SCI out of reset */
+
+ putreg32(0x0, base + RM57_SCI_GCR0_OFFSET);
+ putreg32(SCI_GCR0_RESET, base + RM57_SCI_GCR0_OFFSET);
+
+ /* Pin Function Register: RX is receive pin, TX is transmit pin */
+
+ putreg32(SCI_PIO_RX | SCI_PIO_TX, base + RM57_SCI_PIO0_OFFSET);
+
+ /* Pin Direction Register: general purpose inputs (irrelevant, TX/RX
+ * function bits above take priority)
+ */
+
+ putreg32(0, base + RM57_SCI_PIO1_OFFSET);
+
+ /* Pin Open Drain Output Enable Register: disabled */
+
+ putreg32(0, base + RM57_SCI_PIO6_OFFSET);
+
+ /* Pin Pullup/Pulldown Disable Register: pull control enabled */
+
+ putreg32(0, base + RM57_SCI_PIO7_OFFSET);
+
+ /* Pin Pullup/Pulldown Selection Register: pulled up */
+
+ putreg32(SCI_PIO_RX | SCI_PIO_TX, base + RM57_SCI_PIO8_OFFSET);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: arm_lowputc
+ *
+ * Description:
+ * Output one byte on the serial console
+ *
+ ****************************************************************************/
+
+void arm_lowputc(char ch)
+{
+#ifdef HAVE_SERIAL_CONSOLE
+ irqstate_t flags;
+
+ /* Wait for the transmitter to be available */
+
+ flags = spin_lock_irqsave(&g_rm57_lowputc_lock);
+
+ while ((getreg32(RM57_CONSOLE_BASE + RM57_SCI_FLR_OFFSET) &
+ SCI_INT_TX) == 0)
+ {
+ }
Review Comment:
arm_lowputc() polls the SCI FLR register but masks with SCI_INT_TX. The
TX-ready flag in FLR has a dedicated name (SCI_FLR_TXRDY) which matches the
tms570 implementation; using the FLR constant makes the intent clearer and
avoids accidental reuse if the values ever diverge.
##########
arch/arm/src/rm57/rm57_serial.c:
##########
@@ -0,0 +1,688 @@
+/****************************************************************************
+ * arch/arm/src/rm57/rm57_serial.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/* Adapted from tms570_serial.c, using RM57's SCI register layout. Only
+ * SCI1/LIN1 is currently supported.
+ */
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <string.h>
+#include <assert.h>
+#include <errno.h>
+#include <nuttx/debug.h>
+
+#ifdef CONFIG_SERIAL_TERMIOS
+# include <termios.h>
+#endif
+
+#include <nuttx/irq.h>
+#include <nuttx/arch.h>
+#include <nuttx/fs/ioctl.h>
+#include <nuttx/serial/serial.h>
+
+#include <arch/board/board.h>
+
+#include "arm_internal.h"
+#include "hardware/rm57_sci.h"
+#include "rm57_lowputc.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifdef USE_SERIALDRIVER
+
+/* Which SCI will be tty0/console? */
+
+#if defined(CONFIG_SCI1_SERIAL_CONSOLE) && defined(CONFIG_RM57_SCI1)
+# define CONSOLE_DEV g_sci1port /* SCI1 is console */
+# define TTYS0_DEV g_sci1port /* SCI1 is ttyS0 */
+#else
+# undef CONSOLE_DEV /* No console */
+# if defined(CONFIG_RM57_SCI1)
+# define TTYS0_DEV g_sci1port /* SCI1 is ttyS0 */
+# endif
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct rm57_dev_s
+{
+ const uint32_t scibase; /* Base address of SCI registers */
+ struct sci_config_s config; /* SCI configuration */
+ uint8_t irq; /* IRQ associated with this SCI */
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int rm57_setup(struct uart_dev_s *dev);
+static void rm57_shutdown(struct uart_dev_s *dev);
+static int rm57_attach(struct uart_dev_s *dev);
+static void rm57_detach(struct uart_dev_s *dev);
+static int rm57_interrupt(int irq, void *context, void *arg);
+static int rm57_ioctl(struct file *filep, int cmd, unsigned long arg);
+static int rm57_receive(struct uart_dev_s *dev, unsigned int *status);
+static void rm57_rxint(struct uart_dev_s *dev, bool enable);
+static bool rm57_rxavailable(struct uart_dev_s *dev);
+static void rm57_send(struct uart_dev_s *dev, int ch);
+static void rm57_txint(struct uart_dev_s *dev, bool enable);
+static bool rm57_txready(struct uart_dev_s *dev);
+static bool rm57_txempty(struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_sci_ops =
+{
+ .setup = rm57_setup,
+ .shutdown = rm57_shutdown,
+ .attach = rm57_attach,
+ .detach = rm57_detach,
+ .ioctl = rm57_ioctl,
+ .receive = rm57_receive,
+ .rxint = rm57_rxint,
+ .rxavailable = rm57_rxavailable,
+#ifdef CONFIG_SERIAL_IFLOWCONTROL
+ .rxflowcontrol = NULL,
+#endif
+ .send = rm57_send,
+ .txint = rm57_txint,
+ .txready = rm57_txready,
+ .txempty = rm57_txempty,
+};
+
+/* I/O buffers */
+
+#ifdef CONFIG_RM57_SCI1
+static char g_sci1rxbuffer[CONFIG_SCI1_RXBUFSIZE];
+static char g_sci1txbuffer[CONFIG_SCI1_TXBUFSIZE];
+#endif
+
+/* This describes the state of the SCI1 port. */
+
+#ifdef CONFIG_RM57_SCI1
+static struct rm57_dev_s g_sci1priv =
+{
+ .scibase = RM57_SCI1_BASE,
+ .config =
+ {
+ .baud = CONFIG_SCI1_BAUD,
+ .parity = 0,
+ .bits = 8,
+ .stopbits2 = CONFIG_SCI1_2STOP,
+ },
+ .irq = RM57_REQ_LIN1HIGH,
+};
+
+static uart_dev_t g_sci1port =
+{
+ .recv =
+ {
+ .size = CONFIG_SCI1_RXBUFSIZE,
+ .buffer = g_sci1rxbuffer,
+ },
+ .xmit =
+ {
+ .size = CONFIG_SCI1_TXBUFSIZE,
+ .buffer = g_sci1txbuffer,
+ },
+ .ops = &g_sci_ops,
+ .priv = &g_sci1priv,
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rm57_serialin
+ ****************************************************************************/
+
+static inline uint32_t rm57_serialin(struct rm57_dev_s *priv, int offset)
+{
+ return getreg32(priv->scibase + offset);
+}
+
+/****************************************************************************
+ * Name: rm57_serialout
+ ****************************************************************************/
+
+static inline void rm57_serialout(struct rm57_dev_s *priv, int offset,
+ uint32_t value)
+{
+ putreg32(value, priv->scibase + offset);
+}
+
+/****************************************************************************
+ * Name: rm57_restoresciint
+ ****************************************************************************/
+
+static inline void rm57_restoresciint(struct rm57_dev_s *priv,
+ uint32_t ints)
+{
+ rm57_serialout(priv, RM57_SCI_SETINT_OFFSET, ints);
+}
+
+/****************************************************************************
+ * Name: rm57_disableallints
+ ****************************************************************************/
+
+static void rm57_disableallints(struct rm57_dev_s *priv, uint32_t *ints)
+{
+ irqstate_t flags;
+
+ /* The following must be atomic */
+
+ flags = enter_critical_section();
+ if (ints)
+ {
+ *ints = rm57_serialin(priv, RM57_SCI_SETINT_OFFSET);
+ }
+
+ rm57_serialout(priv, RM57_SCI_CLEARINT_OFFSET, SCI_INT_ALLINTS);
+ leave_critical_section(flags);
+}
+
+/****************************************************************************
+ * Name: rm57_setup
+ *
+ * Description:
+ * Configure the SCI baud, bits, parity, etc. This method is called the
+ * first time that the serial port is opened.
+ *
+ ****************************************************************************/
+
+static int rm57_setup(struct uart_dev_s *dev)
+{
+#ifndef CONFIG_SUPPRESS_SCI_CONFIG
+ struct rm57_dev_s *priv = (struct rm57_dev_s *)dev->priv;
+
+ return rm57_sci_configure(priv->scibase, &priv->config);
+#else
+ return OK;
+#endif
+}
+
+/****************************************************************************
+ * Name: rm57_shutdown
+ *
+ * Description:
+ * Disable the SCI. This method is called when the serial
+ * port is closed
+ *
+ ****************************************************************************/
+
+static void rm57_shutdown(struct uart_dev_s *dev)
+{
+ struct rm57_dev_s *priv = (struct rm57_dev_s *)dev->priv;
+
+ rm57_serialout(priv, RM57_SCI_GCR1_OFFSET, 0);
+ rm57_disableallints(priv, NULL);
+}
+
+/****************************************************************************
+ * Name: rm57_attach
+ *
+ * Description:
+ * Configure the SCI to operate in interrupt driven mode. This method
+ * is called when the serial port is opened, normally just after the
+ * setup() method is called.
+ *
+ ****************************************************************************/
+
+static int rm57_attach(struct uart_dev_s *dev)
+{
+ struct rm57_dev_s *priv = (struct rm57_dev_s *)dev->priv;
+ int ret;
+
+ ret = irq_attach(priv->irq, rm57_interrupt, dev);
+ if (ret == OK)
+ {
+ up_enable_irq(priv->irq);
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: rm57_detach
+ *
+ * Description:
+ * Detach SCI interrupts. This method is called when the serial port
+ * is closed normally, just before the shutdown method is called.
+ *
+ ****************************************************************************/
+
+static void rm57_detach(struct uart_dev_s *dev)
+{
+ struct rm57_dev_s *priv = (struct rm57_dev_s *)dev->priv;
+ up_disable_irq(priv->irq);
+ irq_detach(priv->irq);
+}
+
+/****************************************************************************
+ * Name: rm57_interrupt
+ *
+ * Description:
+ * This is the common SCI interrupt handler.
+ *
+ ****************************************************************************/
+
+static int rm57_interrupt(int irq, void *context, void *arg)
+{
+ struct uart_dev_s *dev = (struct uart_dev_s *)arg;
+ struct rm57_dev_s *priv;
+ uint32_t intvec;
+
+ DEBUGASSERT(dev != NULL && dev->priv != NULL);
+ priv = (struct rm57_dev_s *)dev->priv;
+
+ for (; ; )
+ {
+ /* Reading INTVECT0 clears the corresponding INTFLAG bit for most
+ * interrupt sources.
+ */
+
+ intvec = rm57_serialin(priv, RM57_SCI_INTVECT0_OFFSET) &
+ SCI_INTVECT_MASK;
+
+ switch (intvec)
+ {
+ case SCI_INTVECT_NONE: /* No interrupt */
+ return OK;
+
+ case SCI_INTVECT_WAKEUP: /* Wake-up interrupt (ignored) */
+ break;
+
+ /* SCI errors: ignored for now, since break-detect interrupt
+ * is never enabled
+ */
+
+ case SCI_INTVECT_PE:
+ case SCI_INTVECT_FE:
+ case SCI_INTVECT_OE:
+ case SCI_INTVECT_BRKDT:
+ case SCI_INTVECT_BE:
+ break;
+
+ case SCI_INTVECT_RX: /* Receive interrupt */
+ uart_recvchars(dev);
+ break;
+
+ case SCI_INTVECT_TX: /* Transmit interrupt */
+ uart_xmitchars(dev);
+ break;
+
+ /* LIN mode only. These should never occur in SCI mode */
+
+ case SCI_INTVECT_ISFE:
+ case SCI_INTVECT_ID:
+ case SCI_INTVECT_PBE:
+ case SCI_INTVECT_CE:
+ case SCI_INTVECT_NRE:
+ case SCI_INTVECT_TOAWUS:
+ case SCI_INTVECT_TOA3WUS:
+ case SCI_INTVECT_TIMEOUT:
+ default:
+ DEBUGPANIC();
+ }
+ }
+
+ return OK;
+}
+
+/****************************************************************************
+ * Name: rm57_ioctl
+ *
+ * Description:
+ * All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int rm57_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#if defined(CONFIG_SERIAL_TERMIOS) || defined(CONFIG_SERIAL_TIOCSERGSTRUCT)
+ struct inode *inode = filep->f_inode;
+ struct uart_dev_s *dev = inode->i_private;
+#endif
+ int ret = OK;
+
+ switch (cmd)
+ {
+#ifdef CONFIG_SERIAL_TIOCSERGSTRUCT
+ case TIOCSERGSTRUCT:
+ {
+ struct rm57_dev_s *user = (struct rm57_dev_s *)arg;
+ if (!user)
+ {
+ ret = -EINVAL;
+ }
+ else
+ {
+ memcpy(user, dev, sizeof(struct rm57_dev_s));
Review Comment:
TIOCSERGSTRUCT is copying from the uart_dev_s object into a rm57_dev_s
buffer (memcpy(user, dev, ...)), which copies the wrong structure layout and
returns garbage. It should copy the private rm57_dev_s data (dev->priv) instead.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]