This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit f927781275594d5bc6fc3baf286f2086aa71c3ad
Author: Saravanan Sekar <[email protected]>
AuthorDate: Sat Oct 31 18:32:15 2026 +0530

    arch/rh850: add the RH850/U2C chip.
    
    Add the RH850/U2C chip (R7F702600) on CPU0, with the interrupt
    controllers, OSTM0 as the system timer (ticked or tickless), the RLIN311
    UART as console and the software system reset.
    
    Co-authored-by: Parthiban Nallathambi <[email protected]>
    Signed-off-by: Saravanan Sekar <[email protected]>
    Signed-off-by: Parthiban Nallathambi <[email protected]>
---
 arch/rh850/Kconfig                        |  45 +++++
 arch/rh850/include/u2c/chip.h             |  37 ++++
 arch/rh850/include/u2c/irq.h              |  49 +++++
 arch/rh850/src/u2c/CMakeLists.txt         |  26 +++
 arch/rh850/src/u2c/Make.defs              |  30 +++
 arch/rh850/src/u2c/chip.h                 |  34 ++++
 arch/rh850/src/u2c/hardware/u2c_intc.h    |  48 +++++
 arch/rh850/src/u2c/hardware/u2c_ostm.h    |  47 +++++
 arch/rh850/src/u2c/hardware/u2c_rlin3.h   |  62 ++++++
 arch/rh850/src/u2c/hardware/u2c_sysctrl.h |  62 ++++++
 arch/rh850/src/u2c/u2c_clockconfig.c      |  97 +++++++++
 arch/rh850/src/u2c/u2c_irq.c              | 193 ++++++++++++++++++
 arch/rh850/src/u2c/u2c_lowputc.c          | 138 +++++++++++++
 arch/rh850/src/u2c/u2c_ostm.c             | 221 ++++++++++++++++++++
 arch/rh850/src/u2c/u2c_serial.c           | 325 ++++++++++++++++++++++++++++++
 arch/rh850/src/u2c/u2c_systemreset.c      |  56 +++++
 16 files changed, 1470 insertions(+)

diff --git a/arch/rh850/Kconfig b/arch/rh850/Kconfig
index bdb201f78d1..4f22b4dfb8d 100644
--- a/arch/rh850/Kconfig
+++ b/arch/rh850/Kconfig
@@ -6,6 +6,25 @@
 if ARCH_RH850
 comment "RH850 Options"
 
+choice
+       prompt "RH850 chip selection"
+       default ARCH_CHIP_R7F702600
+
+config ARCH_CHIP_R7F702600
+       bool "R7F702600 (RH850/U2C8)"
+       select ARCH_CHIP_U2C
+       ---help---
+               Renesas RH850/U2C8 microcontroller, CPU0 (G4KH core).
+
+endchoice
+
+config ARCH_CHIP_U2C
+       bool
+       select ARCH_RH850_G4KH
+       select ALARM_ARCH
+       select ONESHOT
+       select ONESHOT_COUNT
+
 config ARCH_RH850_G4KH
        bool
        select ARCH_HAVE_FPU
@@ -14,5 +33,31 @@ config ARCH_RH850_G4KH
 
 config ARCH_CHIP
        string
+       default "u2c"           if ARCH_CHIP_U2C
+
+config RH850_CLK_HSB_FREQUENCY
+       int "CLKC_HSB frequency (Hz)"
+       default 20000000
+       ---help---
+               Frequency of CLKC_HSB, the clock of RLIN3 and OSTM (QEMU 
rh850-u2c
+               machine property clk-hsb, default 20 MHz).
+
+menu "RH850 Peripheral Selection"
+
+config RH850_RLIN311
+       bool "RLIN311 (UART0)"
+       default y
+       select UART0_SERIALDRIVER
+       ---help---
+               RLIN3 unit 11 in UART mode, UART0 (QEMU serial0).
+
+config RH850_OSTM0_PRIORITY
+       int "OSTM0 interrupt priority (0 highest, 15 lowest)"
+       default 1
+       range 0 15
+       ---help---
+               EIP of the system timer interrupt (OSTM0, channel 63).
+
+endmenu
 
 endif # ARCH_RH850
diff --git a/arch/rh850/include/u2c/chip.h b/arch/rh850/include/u2c/chip.h
new file mode 100644
index 00000000000..c2292ccb35a
--- /dev/null
+++ b/arch/rh850/include/u2c/chip.h
@@ -0,0 +1,37 @@
+/****************************************************************************
+ * arch/rh850/include/u2c/chip.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_RH850_INCLUDE_U2C_CHIP_H
+#define __ARCH_RH850_INCLUDE_U2C_CHIP_H
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* RH850/U2C8 (R7F702600), CPU0 (G4KH) memory map */
+
+#define RH850_CODEFLASH_BASE    0x00000000
+#define RH850_CODEFLASH_SIZE    (8 * 1024 * 1024)
+#define RH850_LRAM_BASE         0xfdc00000
+#define RH850_LRAM_SIZE         (128 * 1024)
+
+#endif /* __ARCH_RH850_INCLUDE_U2C_CHIP_H */
diff --git a/arch/rh850/include/u2c/irq.h b/arch/rh850/include/u2c/irq.h
new file mode 100644
index 00000000000..6bb70f0e899
--- /dev/null
+++ b/arch/rh850/include/u2c/irq.h
@@ -0,0 +1,49 @@
+/****************************************************************************
+ * arch/rh850/include/u2c/irq.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/* This file should never be included directly but, rather,
+ * only indirectly through nuttx/irq.h
+ */
+
+#ifndef __ARCH_RH850_INCLUDE_U2C_IRQ_H
+#define __ARCH_RH850_INCLUDE_U2C_IRQ_H
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* IRQ numbers are the EIINT channel numbers of the U2C8 INTC */
+
+#define NR_IRQS                 630
+
+/* OSTM0 TINT */
+
+#define RH850_IRQ_OSTM0         63
+
+/* RLIN311 channels */
+
+#define RH850_IRQ_RLIN311_LIN   493
+#define RH850_IRQ_RLIN311_TX    494     /* UR0 */
+#define RH850_IRQ_RLIN311_RX    495     /* UR1 */
+#define RH850_IRQ_RLIN311_ERR   496     /* UR2 */
+
+#endif /* __ARCH_RH850_INCLUDE_U2C_IRQ_H */
diff --git a/arch/rh850/src/u2c/CMakeLists.txt 
b/arch/rh850/src/u2c/CMakeLists.txt
new file mode 100644
index 00000000000..da475985d10
--- /dev/null
+++ b/arch/rh850/src/u2c/CMakeLists.txt
@@ -0,0 +1,26 @@
+# 
##############################################################################
+# arch/rh850/src/u2c/CMakeLists.txt
+#
+# 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.
+#
+# 
##############################################################################
+
+set(SRCS u2c_clockconfig.c u2c_irq.c u2c_lowputc.c u2c_ostm.c u2c_serial.c
+         u2c_systemreset.c)
+
+target_sources(arch PRIVATE ${SRCS})
diff --git a/arch/rh850/src/u2c/Make.defs b/arch/rh850/src/u2c/Make.defs
new file mode 100644
index 00000000000..8352c2b0462
--- /dev/null
+++ b/arch/rh850/src/u2c/Make.defs
@@ -0,0 +1,30 @@
+############################################################################
+# arch/rh850/src/u2c/Make.defs
+#
+# 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.
+#
+############################################################################
+
+include common/Make.defs
+
+CHIP_CSRCS += u2c_clockconfig.c
+CHIP_CSRCS += u2c_irq.c
+CHIP_CSRCS += u2c_lowputc.c
+CHIP_CSRCS += u2c_ostm.c
+CHIP_CSRCS += u2c_serial.c
+CHIP_CSRCS += u2c_systemreset.c
diff --git a/arch/rh850/src/u2c/chip.h b/arch/rh850/src/u2c/chip.h
new file mode 100644
index 00000000000..ead329a4817
--- /dev/null
+++ b/arch/rh850/src/u2c/chip.h
@@ -0,0 +1,34 @@
+/****************************************************************************
+ * arch/rh850/src/u2c/chip.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_RH850_SRC_U2C_CHIP_H
+#define __ARCH_RH850_SRC_U2C_CHIP_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <arch/u2c/chip.h>
+
+#endif /* __ARCH_RH850_SRC_U2C_CHIP_H */
diff --git a/arch/rh850/src/u2c/hardware/u2c_intc.h 
b/arch/rh850/src/u2c/hardware/u2c_intc.h
new file mode 100644
index 00000000000..aeeb509335c
--- /dev/null
+++ b/arch/rh850/src/u2c/hardware/u2c_intc.h
@@ -0,0 +1,48 @@
+/****************************************************************************
+ * arch/rh850/src/u2c/hardware/u2c_intc.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_RH850_SRC_U2C_HARDWARE_U2C_INTC_H
+#define __ARCH_RH850_SRC_U2C_HARDWARE_U2C_INTC_H
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* EIC registers: channels 0-31 in INTC1 of CPU0, the others in INTC2.  The
+ * EIC of channel n is at base + 2 * n.
+ */
+
+#define U2C_INTC1_BASE          0xfffc4000
+#define U2C_INTC2_BASE          0xfff80000
+#define U2C_INTC1_CHANNELS      32
+
+/* EIC low byte */
+
+#define U2C_EIC_EIMK            (1 << 7)    /* Interrupt masked */
+#define U2C_EIC_EITB            (1 << 6)    /* Table reference method */
+#define U2C_EIC_EIP_MASK        0x0f        /* Priority, 0 is the highest */
+
+/* EIC high byte */
+
+#define U2C_EIC_HI_EIRF         (1 << 4)    /* Interrupt request flag */
+
+#endif /* __ARCH_RH850_SRC_U2C_HARDWARE_U2C_INTC_H */
diff --git a/arch/rh850/src/u2c/hardware/u2c_ostm.h 
b/arch/rh850/src/u2c/hardware/u2c_ostm.h
new file mode 100644
index 00000000000..b5c17abf874
--- /dev/null
+++ b/arch/rh850/src/u2c/hardware/u2c_ostm.h
@@ -0,0 +1,47 @@
+/****************************************************************************
+ * arch/rh850/src/u2c/hardware/u2c_ostm.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_RH850_SRC_U2C_HARDWARE_U2C_OSTM_H
+#define __ARCH_RH850_SRC_U2C_HARDWARE_U2C_OSTM_H
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define U2C_OSTM0_BASE          0xffbf0000
+
+/* Register offsets */
+
+#define OSTM_CMP_OFFSET         0x00        /* 32-bit */
+#define OSTM_CNT_OFFSET         0x04        /* 32-bit */
+#define OSTM_TS_OFFSET          0x14        /* 8-bit */
+#define OSTM_TT_OFFSET          0x18        /* 8-bit */
+#define OSTM_CTL_OFFSET         0x20        /* 8-bit */
+
+/* Register bits */
+
+#define OSTM_TS_START           (1 << 0)
+#define OSTM_TT_STOP            (1 << 0)
+#define OSTM_CTL_MD1            (1 << 1)    /* Free-run compare mode */
+#define OSTM_CTL_IE             (1 << 7)    /* TINT enabled */
+
+#endif /* __ARCH_RH850_SRC_U2C_HARDWARE_U2C_OSTM_H */
diff --git a/arch/rh850/src/u2c/hardware/u2c_rlin3.h 
b/arch/rh850/src/u2c/hardware/u2c_rlin3.h
new file mode 100644
index 00000000000..8b26994d11b
--- /dev/null
+++ b/arch/rh850/src/u2c/hardware/u2c_rlin3.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+ * arch/rh850/src/u2c/hardware/u2c_rlin3.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_RH850_SRC_U2C_HARDWARE_U2C_RLIN3_H
+#define __ARCH_RH850_SRC_U2C_HARDWARE_U2C_RLIN3_H
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* RLIN3 unit base addresses */
+
+#define U2C_RLIN311_BASE        0xff89bb00
+
+/* RLIN3 register offsets, 8-bit unless noted */
+
+#define RLIN3_LWBR_OFFSET       0x01
+#define RLIN3_LBRP01_OFFSET     0x02        /* 16-bit */
+#define RLIN3_LMD_OFFSET        0x08
+#define RLIN3_LBFC_OFFSET       0x09
+#define RLIN3_LEDE_OFFSET       0x0d
+#define RLIN3_LCUC_OFFSET       0x0e
+#define RLIN3_LMST_OFFSET       0x11
+#define RLIN3_LST_OFFSET        0x12
+#define RLIN3_LUOER_OFFSET      0x20
+#define RLIN3_LUOR1_OFFSET      0x21
+#define RLIN3_LUTDR_OFFSET      0x24        /* 16-bit */
+#define RLIN3_LURDR_OFFSET      0x26        /* 16-bit */
+
+/* Register bits */
+
+#define RLIN3_LMD_UART          0x01        /* UART mode */
+#define RLIN3_LCUC_OM0          (1 << 0)    /* Leave LIN reset mode */
+#define RLIN3_LMST_OMM0         (1 << 0)    /* Not in LIN reset mode */
+#define RLIN3_LST_UTS           (1 << 4)    /* Transmission in progress */
+#define RLIN3_LUOER_UTOE        (1 << 0)    /* Transmission enable */
+#define RLIN3_LUOER_UROE        (1 << 1)    /* Reception enable */
+
+/* LWBR.NSPB = 0: 16 samples per bit, prescaler 1/1 */
+
+#define RLIN3_SAMPLES           16
+
+#endif /* __ARCH_RH850_SRC_U2C_HARDWARE_U2C_RLIN3_H */
diff --git a/arch/rh850/src/u2c/hardware/u2c_sysctrl.h 
b/arch/rh850/src/u2c/hardware/u2c_sysctrl.h
new file mode 100644
index 00000000000..a632f4e3da2
--- /dev/null
+++ b/arch/rh850/src/u2c/hardware/u2c_sysctrl.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+ * arch/rh850/src/u2c/hardware/u2c_sysctrl.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_RH850_SRC_U2C_HARDWARE_U2C_SYSCTRL_H
+#define __ARCH_RH850_SRC_U2C_HARDWARE_U2C_SYSCTRL_H
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Clock controller */
+
+#define U2C_CKS_RLINC           0xff980140  /* CLK_RLIN3 source selection */
+#define U2C_CKS_RLINS           0xff980148  /* CLK_RLIN3 source status */
+#define U2C_CLKKCPROT1          0xff980700  /* Clock register write protection 
*/
+
+#define U2C_CKS_RLIN_HSB        1           /* CLK_RLIN3 from CLKC_HSB */
+#define U2C_CKS_RLIN_MASK       0x7
+
+/* Reset controller: module reset status, software system reset */
+
+#define U2C_SWMRESS_RLIN3       0xff980964
+#define U2C_SWMRESS_OSTM        0xff980a84
+#define U2C_RESKCPROT0          0xff980f00  /* Reset register write protection 
*/
+#define U2C_SWSRESA             0xff98840c  /* Software system reset */
+
+#define U2C_SWSRESA_TRIGGER     (1 << 0)    /* Generate a System Reset 2 */
+
+/* Standby controller: module stop */
+
+#define U2C_MSR_RLIN3           0xff981060
+#define U2C_MSR_OSTM            0xff981180
+#define U2C_MSRKCPROT           0xff981710  /* MSR write protection */
+
+#define U2C_MSR_RLIN311         (1 << 11)
+#define U2C_MSR_OSTM0           (1 << 0)
+
+/* Write protection keys */
+
+#define U2C_KCPROT_ENABLE       0xa5a5a501
+#define U2C_KCPROT_DISABLE      0xa5a5a500
+
+#endif /* __ARCH_RH850_SRC_U2C_HARDWARE_U2C_SYSCTRL_H */
diff --git a/arch/rh850/src/u2c/u2c_clockconfig.c 
b/arch/rh850/src/u2c/u2c_clockconfig.c
new file mode 100644
index 00000000000..362dc3c0050
--- /dev/null
+++ b/arch/rh850/src/u2c/u2c_clockconfig.c
@@ -0,0 +1,97 @@
+/****************************************************************************
+ * arch/rh850/src/u2c/u2c_clockconfig.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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+
+#include "rh850_internal.h"
+#include "hardware/u2c_sysctrl.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: u2c_module_release
+ *
+ * Description:
+ *   Wait for the end of the module reset, then clear its module stop bit.
+ *
+ ****************************************************************************/
+
+static void u2c_module_release(uintptr_t swmress, uintptr_t msr,
+                               uint32_t bit)
+{
+  while ((getreg32(swmress) & bit) != 0)
+    {
+    }
+
+  putreg32(U2C_KCPROT_ENABLE, U2C_MSRKCPROT);
+  putreg32(getreg32(msr) & ~bit, msr);
+  while ((getreg32(msr) & bit) != 0)
+    {
+    }
+
+  putreg32(U2C_KCPROT_DISABLE, U2C_MSRKCPROT);
+  while (getreg32(U2C_MSRKCPROT) != 0)
+    {
+    }
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rh850_clockconfig
+ *
+ * Description:
+ *   Clock and standby setup of the modules in use.  PLL and CPU clock keep
+ *   their reset settings.
+ *
+ ****************************************************************************/
+
+void rh850_clockconfig(void)
+{
+#ifdef CONFIG_RH850_RLIN311
+  /* CLK_RLIN3 from CLKC_HSB, then RLIN311 out of module stop */
+
+  putreg32(U2C_KCPROT_ENABLE, U2C_CLKKCPROT1);
+  putreg32(U2C_CKS_RLIN_HSB, U2C_CKS_RLINC);
+  while ((getreg32(U2C_CKS_RLINS) & U2C_CKS_RLIN_MASK) != U2C_CKS_RLIN_HSB)
+    {
+    }
+
+  putreg32(U2C_KCPROT_DISABLE, U2C_CLKKCPROT1);
+
+  u2c_module_release(U2C_SWMRESS_RLIN3, U2C_MSR_RLIN3, U2C_MSR_RLIN311);
+#endif
+
+  /* OSTM0, the system timer */
+
+  u2c_module_release(U2C_SWMRESS_OSTM, U2C_MSR_OSTM, U2C_MSR_OSTM0);
+}
diff --git a/arch/rh850/src/u2c/u2c_irq.c b/arch/rh850/src/u2c/u2c_irq.c
new file mode 100644
index 00000000000..bbdc1d8b728
--- /dev/null
+++ b/arch/rh850/src/u2c/u2c_irq.c
@@ -0,0 +1,193 @@
+/****************************************************************************
+ * arch/rh850/src/u2c/u2c_irq.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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <errno.h>
+#include <stdint.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/irq.h>
+
+#include "rh850_internal.h"
+#include "hardware/u2c_intc.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/* The low and high EIC bytes are written separately so that EIRF is never
+ * written by mask or priority changes.
+ */
+
+static uintptr_t u2c_eic(int irq)
+{
+  return (irq < U2C_INTC1_CHANNELS ? U2C_INTC1_BASE : U2C_INTC2_BASE) +
+         2 * irq;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_irqinitialize
+ *
+ * Description:
+ *   Mask all channels, direct vector method (EITB = 0) at the lowest
+ *   priority, no register bank, then enable EI level interrupts.
+ *
+ ****************************************************************************/
+
+void up_irqinitialize(void)
+{
+  int irq;
+
+  up_irq_save();
+
+  for (irq = 0; irq < NR_IRQS; irq++)
+    {
+      putreg8(U2C_EIC_EIMK | U2C_EIC_EIP_MASK, u2c_eic(irq));
+    }
+
+  __asm__ __volatile__("ldsr r0, 15, 2" : : : "memory");   /* RBCR0 = 0 */
+
+#ifdef CONFIG_STACK_COLORATION
+  rh850_stack_color(g_intstackalloc, CONFIG_ARCH_INTERRUPTSTACK & ~3);
+#endif
+
+#ifndef CONFIG_SUPPRESS_INTERRUPTS
+  up_irq_enable();
+#endif
+}
+
+/****************************************************************************
+ * Name: up_enable_irq
+ ****************************************************************************/
+
+void up_enable_irq(int irq)
+{
+  uintptr_t eic;
+
+  if (irq >= 0 && irq < NR_IRQS)
+    {
+      eic = u2c_eic(irq);
+      putreg8(getreg8(eic) & ~U2C_EIC_EIMK, eic);
+    }
+}
+
+/****************************************************************************
+ * Name: up_disable_irq
+ *
+ * Description:
+ *   Mask a channel; a pending request flag stays set.
+ *
+ ****************************************************************************/
+
+void up_disable_irq(int irq)
+{
+  uintptr_t eic;
+
+  if (irq >= 0 && irq < NR_IRQS)
+    {
+      eic = u2c_eic(irq);
+      putreg8(getreg8(eic) | U2C_EIC_EIMK, eic);
+    }
+}
+
+#ifdef CONFIG_ARCH_IRQPRIO
+/****************************************************************************
+ * Name: up_prioritize_irq
+ *
+ * Description:
+ *   Set the priority (EIP 0-15, 0 is the highest) of a channel.
+ *
+ ****************************************************************************/
+
+int up_prioritize_irq(int irq, int priority)
+{
+  return u2c_irq_setpriority(irq, priority);
+}
+#endif
+
+/****************************************************************************
+ * Name: u2c_irq_setpriority
+ *
+ * Description:
+ *   Set EIP (0-15, 0 is the highest) with the direct vector method.
+ *
+ ****************************************************************************/
+
+int u2c_irq_setpriority(int irq, int priority)
+{
+  uintptr_t eic;
+  uint8_t regval;
+
+  if (irq < 0 || irq >= NR_IRQS || priority < 0 ||
+      priority > U2C_EIC_EIP_MASK)
+    {
+      return -EINVAL;
+    }
+
+  eic    = u2c_eic(irq);
+  regval = getreg8(eic) & ~(U2C_EIC_EITB | U2C_EIC_EIP_MASK);
+  putreg8(regval | priority, eic);
+  return OK;
+}
+
+/****************************************************************************
+ * Name: u2c_irq_raise
+ *
+ * Description:
+ *   Set the request flag of a channel by software.
+ *
+ ****************************************************************************/
+
+void u2c_irq_raise(int irq)
+{
+  putreg8(U2C_EIC_HI_EIRF, u2c_eic(irq) + 1);
+}
+
+/****************************************************************************
+ * Name: u2c_irq_pending
+ *
+ * Description:
+ *   Return and clear the request flag of a channel.
+ *
+ ****************************************************************************/
+
+bool u2c_irq_pending(int irq)
+{
+  uintptr_t eic = u2c_eic(irq) + 1;
+
+  if ((getreg8(eic) & U2C_EIC_HI_EIRF) != 0)
+    {
+      putreg8(0, eic);
+      return true;
+    }
+
+  return false;
+}
diff --git a/arch/rh850/src/u2c/u2c_lowputc.c b/arch/rh850/src/u2c/u2c_lowputc.c
new file mode 100644
index 00000000000..d1ca7f4ae41
--- /dev/null
+++ b/arch/rh850/src/u2c/u2c_lowputc.c
@@ -0,0 +1,138 @@
+/****************************************************************************
+ * arch/rh850/src/u2c/u2c_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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/irq.h>
+
+#include "rh850_internal.h"
+#include "hardware/u2c_rlin3.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifdef CONFIG_RH850_RLIN311
+#  define CONSOLE_BASE  U2C_RLIN311_BASE
+#  define CONSOLE_BAUD  CONFIG_UART0_BAUD
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: u2c_rlin3_setup
+ *
+ * Description:
+ *   RLIN3 UART mode, 8N1, LSB first, no error detection.  The unit clock
+ *   and module stop are set up by rh850_clockconfig().
+ *
+ ****************************************************************************/
+
+void u2c_rlin3_setup(uintptr_t base, uint32_t baud)
+{
+  uint32_t samples = RLIN3_SAMPLES * baud;
+
+  putreg8(0, base + RLIN3_LCUC_OFFSET);
+  while ((getreg8(base + RLIN3_LMST_OFFSET) & RLIN3_LMST_OMM0) != 0)
+    {
+    }
+
+  /* LBRP01 = round(clock / (16 x baud)) - 1 */
+
+  putreg8(0, base + RLIN3_LWBR_OFFSET);
+  putreg16((CONFIG_RH850_CLK_HSB_FREQUENCY + samples / 2) / samples - 1,
+           base + RLIN3_LBRP01_OFFSET);
+  putreg8(RLIN3_LMD_UART, base + RLIN3_LMD_OFFSET);
+  putreg8(0, base + RLIN3_LBFC_OFFSET);
+  putreg8(0, base + RLIN3_LEDE_OFFSET);
+  putreg8(0, base + RLIN3_LUOR1_OFFSET);
+
+  putreg8(RLIN3_LCUC_OM0, base + RLIN3_LCUC_OFFSET);
+  while ((getreg8(base + RLIN3_LMST_OFFSET) & RLIN3_LMST_OMM0) == 0)
+    {
+    }
+
+  putreg8(RLIN3_LUOER_UTOE | RLIN3_LUOER_UROE, base + RLIN3_LUOER_OFFSET);
+}
+
+/****************************************************************************
+ * Name: u2c_rlin3_putc
+ *
+ * Description:
+ *   Send one character and wait for the end of the transmission.
+ *
+ ****************************************************************************/
+
+void u2c_rlin3_putc(uintptr_t base, int ch)
+{
+  putreg8((uint8_t)ch, base + RLIN3_LUTDR_OFFSET);
+  while ((getreg8(base + RLIN3_LST_OFFSET) & RLIN3_LST_UTS) != 0)
+    {
+    }
+}
+
+/****************************************************************************
+ * Name: rh850_lowputc
+ ****************************************************************************/
+
+void rh850_lowputc(int ch)
+{
+#ifdef CONSOLE_BASE
+  u2c_rlin3_putc(CONSOLE_BASE, ch);
+#endif
+}
+
+/****************************************************************************
+ * Name: rh850_lowsetup
+ *
+ * Description:
+ *   Console setup, after rh850_clockconfig().
+ *
+ ****************************************************************************/
+
+void rh850_lowsetup(void)
+{
+#ifdef CONSOLE_BASE
+  u2c_rlin3_setup(CONSOLE_BASE, CONSOLE_BAUD);
+#endif
+}
+
+/****************************************************************************
+ * Name: up_putc
+ ****************************************************************************/
+
+void up_putc(int ch)
+{
+  irqstate_t flags = up_irq_save();
+
+  rh850_lowputc(ch);
+  up_irq_restore(flags);
+}
diff --git a/arch/rh850/src/u2c/u2c_ostm.c b/arch/rh850/src/u2c/u2c_ostm.c
new file mode 100644
index 00000000000..ec7d69ddf9c
--- /dev/null
+++ b/arch/rh850/src/u2c/u2c_ostm.c
@@ -0,0 +1,221 @@
+/****************************************************************************
+ * arch/rh850/src/u2c/u2c_ostm.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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/irq.h>
+#include <nuttx/timers/arch_alarm.h>
+#include <nuttx/timers/oneshot.h>
+
+#include "rh850_internal.h"
+#include "hardware/u2c_ostm.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* The 32-bit counter is extended in software; a delay below half the
+ * counter range keeps at least one counter read per wrap.
+ */
+
+#define OSTM_MAX_DELAY      0x7fffffff
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct u2c_ostm_s
+{
+  struct oneshot_lowerhalf_s lower;
+  uintptr_t base;
+  uint64_t  high;     /* Counter bits 63-32 */
+  uint32_t  last;     /* Last counter value read */
+  bool      armed;    /* A compare match is expected */
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static clkcnt_t u2c_ostm_current(FAR struct oneshot_lowerhalf_s *lower);
+static void u2c_ostm_start(FAR struct oneshot_lowerhalf_s *lower,
+                           clkcnt_t delay);
+static void u2c_ostm_start_absolute(FAR struct oneshot_lowerhalf_s *lower,
+                                    clkcnt_t cnt);
+static void u2c_ostm_cancel(FAR struct oneshot_lowerhalf_s *lower);
+static clkcnt_t u2c_ostm_max_delay(FAR struct oneshot_lowerhalf_s *lower);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct oneshot_operations_s g_u2c_ostm_ops =
+{
+  .current        = u2c_ostm_current,
+  .start          = u2c_ostm_start,
+  .start_absolute = u2c_ostm_start_absolute,
+  .cancel         = u2c_ostm_cancel,
+  .max_delay      = u2c_ostm_max_delay,
+};
+
+static struct u2c_ostm_s g_u2c_ostm0 =
+{
+  .lower.ops = &g_u2c_ostm_ops,
+  .base      = U2C_OSTM0_BASE,
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/* Called with interrupts disabled */
+
+static uint64_t u2c_ostm_count(FAR struct u2c_ostm_s *priv)
+{
+  uint32_t cnt = getreg32(priv->base + OSTM_CNT_OFFSET);
+
+  if (cnt < priv->last)
+    {
+      priv->high += (uint64_t)1 << 32;
+    }
+
+  priv->last = cnt;
+  return priv->high | cnt;
+}
+
+static clkcnt_t u2c_ostm_current(FAR struct oneshot_lowerhalf_s *lower)
+{
+  FAR struct u2c_ostm_s *priv = (FAR struct u2c_ostm_s *)lower;
+  irqstate_t flags;
+  uint64_t cnt;
+
+  flags = up_irq_save();
+  cnt = u2c_ostm_count(priv);
+  up_irq_restore(flags);
+  return cnt;
+}
+
+/* A CMP that the counter has already passed waits a whole wrap: a deadline
+ * reached by the time CMP is written raises the request in the INTC.
+ */
+
+static void u2c_ostm_start_absolute(FAR struct oneshot_lowerhalf_s *lower,
+                                    clkcnt_t expected)
+{
+  FAR struct u2c_ostm_s *priv = (FAR struct u2c_ostm_s *)lower;
+  irqstate_t flags;
+  uint64_t now;
+
+  flags = up_irq_save();
+
+  now = u2c_ostm_count(priv);
+  if (expected > now + OSTM_MAX_DELAY)
+    {
+      expected = now + OSTM_MAX_DELAY;
+    }
+
+  priv->armed = true;
+  putreg32((uint32_t)expected, priv->base + OSTM_CMP_OFFSET);
+  getreg32(priv->base + OSTM_CMP_OFFSET);
+
+  if (u2c_ostm_count(priv) >= expected)
+    {
+      u2c_irq_raise(RH850_IRQ_OSTM0);
+    }
+
+  up_irq_restore(flags);
+}
+
+static void u2c_ostm_start(FAR struct oneshot_lowerhalf_s *lower,
+                           clkcnt_t delay)
+{
+  u2c_ostm_start_absolute(lower, u2c_ostm_current(lower) + delay);
+}
+
+static void u2c_ostm_cancel(FAR struct oneshot_lowerhalf_s *lower)
+{
+  FAR struct u2c_ostm_s *priv = (FAR struct u2c_ostm_s *)lower;
+  irqstate_t flags;
+
+  flags = up_irq_save();
+  priv->armed = false;
+  u2c_irq_pending(RH850_IRQ_OSTM0);
+  up_irq_restore(flags);
+}
+
+static clkcnt_t u2c_ostm_max_delay(FAR struct oneshot_lowerhalf_s *lower)
+{
+  return OSTM_MAX_DELAY;
+}
+
+static int u2c_ostm_interrupt(int irq, FAR void *context, FAR void *arg)
+{
+  FAR struct u2c_ostm_s *priv = arg;
+
+  if (priv->armed)
+    {
+      priv->armed = false;
+      oneshot_process_callback(&priv->lower);
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_timer_initialize
+ *
+ * Description:
+ *   OSTM0 in free-run compare mode as the oneshot timer of arch_alarm.  The
+ *   module stop of OSTM0 is released by rh850_clockconfig().
+ *
+ ****************************************************************************/
+
+void up_timer_initialize(void)
+{
+  FAR struct u2c_ostm_s *priv = &g_u2c_ostm0;
+
+  putreg8(OSTM_TT_STOP, priv->base + OSTM_TT_OFFSET);
+  putreg32(UINT32_MAX, priv->base + OSTM_CMP_OFFSET);
+  putreg8(OSTM_CTL_IE | OSTM_CTL_MD1, priv->base + OSTM_CTL_OFFSET);
+  putreg8(OSTM_TS_START, priv->base + OSTM_TS_OFFSET);
+
+  oneshot_count_init(&priv->lower, CONFIG_RH850_CLK_HSB_FREQUENCY);
+
+  u2c_irq_pending(RH850_IRQ_OSTM0);
+  u2c_irq_setpriority(RH850_IRQ_OSTM0, CONFIG_RH850_OSTM0_PRIORITY);
+  irq_attach(RH850_IRQ_OSTM0, u2c_ostm_interrupt, priv);
+  up_enable_irq(RH850_IRQ_OSTM0);
+
+  up_alarm_set_lowerhalf(&priv->lower);
+}
diff --git a/arch/rh850/src/u2c/u2c_serial.c b/arch/rh850/src/u2c/u2c_serial.c
new file mode 100644
index 00000000000..5b62cb1d1c3
--- /dev/null
+++ b/arch/rh850/src/u2c/u2c_serial.c
@@ -0,0 +1,325 @@
+/****************************************************************************
+ * arch/rh850/src/u2c/u2c_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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <errno.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/irq.h>
+#include <nuttx/serial/serial.h>
+
+#include "rh850_internal.h"
+#include "hardware/u2c_rlin3.h"
+
+#ifdef USE_SERIALDRIVER
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#if defined(CONFIG_RH850_RLIN311) && defined(CONFIG_UART0_SERIAL_CONSOLE)
+#  define HAVE_SERIAL_CONSOLE 1
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct u2c_uart_s
+{
+  uintptr_t base;     /* RLIN3 unit base address */
+  uint32_t  baud;     /* Baud rate */
+  int       txirq;    /* UR0, one request per transmitted byte */
+  int       rxirq;    /* UR1, reception complete */
+  bool      txbusy;   /* A byte was written, its UR0 not taken yet */
+  bool      rxpend;   /* A received byte waits in LURDR */
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  u2c_setup(FAR struct uart_dev_s *dev);
+static void u2c_shutdown(FAR struct uart_dev_s *dev);
+static int  u2c_attach(FAR struct uart_dev_s *dev);
+static void u2c_detach(FAR struct uart_dev_s *dev);
+static int  u2c_tx_interrupt(int irq, FAR void *context, FAR void *arg);
+static int  u2c_rx_interrupt(int irq, FAR void *context, FAR void *arg);
+static int  u2c_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+static int  u2c_receive(FAR struct uart_dev_s *dev,
+                        FAR unsigned int *status);
+static void u2c_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool u2c_rxavailable(FAR struct uart_dev_s *dev);
+static void u2c_send(FAR struct uart_dev_s *dev, int ch);
+static void u2c_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool u2c_txready(FAR struct uart_dev_s *dev);
+static bool u2c_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_u2c_uart_ops =
+{
+  .setup          = u2c_setup,
+  .shutdown       = u2c_shutdown,
+  .attach         = u2c_attach,
+  .detach         = u2c_detach,
+  .ioctl          = u2c_ioctl,
+  .receive        = u2c_receive,
+  .rxint          = u2c_rxint,
+  .rxavailable    = u2c_rxavailable,
+#ifdef CONFIG_SERIAL_IFLOWCONTROL
+  .rxflowcontrol  = NULL,
+#endif
+  .send           = u2c_send,
+  .txint          = u2c_txint,
+  .txready        = u2c_txready,
+  .txempty        = u2c_txempty,
+};
+
+#ifdef CONFIG_RH850_RLIN311
+static char g_rlin311rxbuffer[CONFIG_UART0_RXBUFSIZE];
+static char g_rlin311txbuffer[CONFIG_UART0_TXBUFSIZE];
+
+static struct u2c_uart_s g_rlin311priv =
+{
+  .base  = U2C_RLIN311_BASE,
+  .baud  = CONFIG_UART0_BAUD,
+  .txirq = RH850_IRQ_RLIN311_TX,
+  .rxirq = RH850_IRQ_RLIN311_RX,
+};
+
+static uart_dev_t g_rlin311port =
+{
+#ifdef HAVE_SERIAL_CONSOLE
+  .isconsole = true,
+#endif
+  .recv      =
+  {
+    .size    = CONFIG_UART0_RXBUFSIZE,
+    .buffer  = g_rlin311rxbuffer,
+  },
+  .xmit      =
+  {
+    .size    = CONFIG_UART0_TXBUFSIZE,
+    .buffer  = g_rlin311txbuffer,
+  },
+  .ops       = &g_u2c_uart_ops,
+  .priv      = &g_rlin311priv,
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int u2c_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct u2c_uart_s *priv = dev->priv;
+
+  /* The console is set up by rh850_lowsetup() */
+
+  if (!dev->isconsole)
+    {
+      u2c_rlin3_setup(priv->base, priv->baud);
+    }
+
+  return OK;
+}
+
+static void u2c_shutdown(FAR struct uart_dev_s *dev)
+{
+  FAR struct u2c_uart_s *priv = dev->priv;
+
+  up_disable_irq(priv->txirq);
+  up_disable_irq(priv->rxirq);
+}
+
+static int u2c_attach(FAR struct uart_dev_s *dev)
+{
+  FAR struct u2c_uart_s *priv = dev->priv;
+  int ret;
+
+  /* up_putc() output before this point left a UR0 request */
+
+  u2c_irq_pending(priv->txirq);
+  ret = irq_attach(priv->txirq, u2c_tx_interrupt, dev);
+  if (ret == OK)
+    {
+      ret = irq_attach(priv->rxirq, u2c_rx_interrupt, dev);
+    }
+
+  return ret;
+}
+
+static void u2c_detach(FAR struct uart_dev_s *dev)
+{
+  FAR struct u2c_uart_s *priv = dev->priv;
+
+  up_disable_irq(priv->txirq);
+  up_disable_irq(priv->rxirq);
+  irq_detach(priv->txirq);
+  irq_detach(priv->rxirq);
+}
+
+/* UR0 for the last byte written: the next byte may go */
+
+static int u2c_tx_interrupt(int irq, FAR void *context, FAR void *arg)
+{
+  FAR struct uart_dev_s *dev = arg;
+  FAR struct u2c_uart_s *priv = dev->priv;
+
+  priv->txbusy = false;
+  uart_xmitchars(dev);
+  return OK;
+}
+
+/* Accepting the edge request cleared EIRF: the byte is noted in rxpend */
+
+static int u2c_rx_interrupt(int irq, FAR void *context, FAR void *arg)
+{
+  FAR struct uart_dev_s *dev = arg;
+  FAR struct u2c_uart_s *priv = dev->priv;
+
+  priv->rxpend = true;
+  uart_recvchars(dev);
+  return OK;
+}
+
+static int u2c_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  return -ENOTTY;
+}
+
+static int u2c_receive(FAR struct uart_dev_s *dev, FAR unsigned int *status)
+{
+  FAR struct u2c_uart_s *priv = dev->priv;
+
+  priv->rxpend = false;
+  *status = 0;
+  return getreg16(priv->base + RLIN3_LURDR_OFFSET) & 0xff;
+}
+
+static void u2c_rxint(FAR struct uart_dev_s *dev, bool enable)
+{
+  FAR struct u2c_uart_s *priv = dev->priv;
+
+  if (enable)
+    {
+      up_enable_irq(priv->rxirq);
+    }
+  else
+    {
+      up_disable_irq(priv->rxirq);
+    }
+}
+
+/* A byte that arrived after the request was accepted sets EIRF again */
+
+static bool u2c_rxavailable(FAR struct uart_dev_s *dev)
+{
+  FAR struct u2c_uart_s *priv = dev->priv;
+
+  if (u2c_irq_pending(priv->rxirq))
+    {
+      priv->rxpend = true;
+    }
+
+  return priv->rxpend;
+}
+
+static void u2c_send(FAR struct uart_dev_s *dev, int ch)
+{
+  FAR struct u2c_uart_s *priv = dev->priv;
+
+  priv->txbusy = true;
+  putreg8((uint8_t)ch, priv->base + RLIN3_LUTDR_OFFSET);
+}
+
+/* One byte per UR0 request.  With no byte in flight no request will
+ * come, so enabling starts the first byte.
+ */
+
+static void u2c_txint(FAR struct uart_dev_s *dev, bool enable)
+{
+  FAR struct u2c_uart_s *priv = dev->priv;
+  irqstate_t flags;
+
+  flags = enter_critical_section();
+  if (enable)
+    {
+      up_enable_irq(priv->txirq);
+      if (!priv->txbusy)
+        {
+          uart_xmitchars(dev);
+        }
+    }
+  else
+    {
+      up_disable_irq(priv->txirq);
+    }
+
+  leave_critical_section(flags);
+}
+
+static bool u2c_txready(FAR struct uart_dev_s *dev)
+{
+  FAR struct u2c_uart_s *priv = dev->priv;
+
+  return !priv->txbusy &&
+         (getreg8(priv->base + RLIN3_LST_OFFSET) & RLIN3_LST_UTS) == 0;
+}
+
+static bool u2c_txempty(FAR struct uart_dev_s *dev)
+{
+  FAR struct u2c_uart_s *priv = dev->priv;
+
+  return (getreg8(priv->base + RLIN3_LST_OFFSET) & RLIN3_LST_UTS) == 0;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rh850_serialinit
+ ****************************************************************************/
+
+void rh850_serialinit(void)
+{
+#ifdef CONFIG_RH850_RLIN311
+#ifdef HAVE_SERIAL_CONSOLE
+  uart_register("/dev/console", &g_rlin311port);
+#endif
+  uart_register("/dev/ttyS0", &g_rlin311port);
+#endif
+}
+
+#endif /* USE_SERIALDRIVER */
diff --git a/arch/rh850/src/u2c/u2c_systemreset.c 
b/arch/rh850/src/u2c/u2c_systemreset.c
new file mode 100644
index 00000000000..f9e1fbc5933
--- /dev/null
+++ b/arch/rh850/src/u2c/u2c_systemreset.c
@@ -0,0 +1,56 @@
+/****************************************************************************
+ * arch/rh850/src/u2c/u2c_systemreset.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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <nuttx/arch.h>
+
+#include "rh850_internal.h"
+#include "hardware/u2c_sysctrl.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_systemreset
+ *
+ * Description:
+ *   Software system reset (System Reset 2) through SWSRESA, which needs the
+ *   RESKCPROT0 key.
+ *
+ ****************************************************************************/
+
+void up_systemreset(void)
+{
+  up_irq_save();
+  putreg32(U2C_KCPROT_ENABLE, U2C_RESKCPROT0);
+  putreg32(U2C_SWSRESA_TRIGGER, U2C_SWSRESA);
+
+  for (; ; )
+    {
+    }
+}

Reply via email to