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 8b8a10dc31fec15eb38f8facb45fecca1b618a05 Author: dechao_gong <[email protected]> AuthorDate: Wed Oct 14 18:23:31 2026 +0800 arch/arm/rtl8730e: add watchdog driver support Wire the shared Ameba watchdog driver (ameba_wdg.c) up for RTL8730E (AmebaSmart, Cortex-A32) with a chip header, a board registration table and a wdg defconfig. Exposes the on-chip watchdog at /dev/watchdog0. No common driver change: the only chip-specific data is the register base and the NuttX IRQ number, both in the new ameba_wdg_chip.h. amebasmart carries five watchdog instances, one per core/domain plus an always-on IWDG. This port drives WDG4, matching the vendor HAL wdt_api.c, which selects WDG4_DEV / WDG4_IRQ for CONFIG_ARM_CORE_CA32 (KM4 gets WDG2 instead). As with the other CA32 drivers, the base used is the non-secure register alias (0x41000...) reachable from this core. NuttX IRQ = GIC SPI + 32 on this chip, and WDG4_IRQ is GIC SPI 62 in the CA32 vector table, giving NuttX IRQ 94. The watchdog needs no RCC clock gating call (it is always-on hardware, matching the other Ameba ports) and no RAM-side fwlib source: all WDG_* symbols the driver calls are in the AP ROM, so CONFIG_AMEBA_WDG does not join the libameba_fwlib.a build/link conditions, only the lib_rom.a and rtl8730e_flash_stubs.c ones already shared by every ROM-backed driver. Verified the inlined AMEBA_WDG_BASE and AMEBA_WDG_IRQ constants by disassembling the built image: ameba_wdg_settimeout loads the literal 0x410004c0, and ameba_wdg_initialize's irq_attach/up_enable_irq calls use r0 = 94. Built for all eight rtl8730e_evb configs under both make and CMake; confirmed the wdg config does not build or link libameba_fwlib.a. Assisted-by: Claude <[email protected]> Signed-off-by: dechao_gong <[email protected]> --- arch/arm/include/rtl8730e/irq.h | 1 + arch/arm/src/rtl8730e/CMakeLists.txt | 14 +++++ arch/arm/src/rtl8730e/Make.defs | 6 +- arch/arm/src/rtl8730e/ameba_wdg_chip.h | 73 ++++++++++++++++++++++ .../rtl8730e/rtl8730e_evb/configs/wdg/defconfig | 62 ++++++++++++++++++ boards/arm/rtl8730e/rtl8730e_evb/scripts/Make.defs | 2 +- .../arm/rtl8730e/rtl8730e_evb/src/CMakeLists.txt | 6 ++ boards/arm/rtl8730e/rtl8730e_evb/src/Makefile | 6 +- .../rtl8730e/rtl8730e_evb/src/rtl8730e_bringup.c | 11 ++++ .../arm/rtl8730e/rtl8730e_evb/src/rtl8730e_evb.h | 4 ++ .../src/{rtl8730e_evb.h => rtl8730e_wdg.c} | 72 ++++++++------------- 11 files changed, 207 insertions(+), 50 deletions(-) diff --git a/arch/arm/include/rtl8730e/irq.h b/arch/arm/include/rtl8730e/irq.h index 8e6ea5c0e44..00c639e181e 100644 --- a/arch/arm/include/rtl8730e/irq.h +++ b/arch/arm/include/rtl8730e/irq.h @@ -47,6 +47,7 @@ #define RTL8730E_IRQ_UART0 82 /* GIC SPI 50: UART0 */ #define RTL8730E_IRQ_UART1 83 /* GIC SPI 51: UART1 */ #define RTL8730E_IRQ_UART2 84 /* GIC SPI 52: UART2 */ +#define RTL8730E_IRQ_WDG4 94 /* GIC SPI 62: WDG4 (CA32 watchdog) */ /**************************************************************************** * Public Types diff --git a/arch/arm/src/rtl8730e/CMakeLists.txt b/arch/arm/src/rtl8730e/CMakeLists.txt index 158d4739ecc..61723ef22b6 100644 --- a/arch/arm/src/rtl8730e/CMakeLists.txt +++ b/arch/arm/src/rtl8730e/CMakeLists.txt @@ -117,6 +117,19 @@ if(CONFIG_AMEBA_TIMER) endif() endif() +if(CONFIG_AMEBA_WDG) + list(APPEND SRCS ${AMEBA_COMMON}/ameba_wdg.c) + if(NOT CONFIG_RTL8730E_FLASH_FS + AND NOT CONFIG_AMEBA_GPIO + AND NOT CONFIG_AMEBA_UART + AND NOT CONFIG_AMEBA_I2C + AND NOT CONFIG_AMEBA_SPI + AND NOT CONFIG_AMEBA_PWM + AND NOT CONFIG_AMEBA_TIMER) + list(APPEND SRCS rtl8730e_flash_stubs.c) + endif() +endif() + target_include_directories(arch PRIVATE ${AMEBA_COMMON}) target_sources(arch PRIVATE ${SRCS}) @@ -279,6 +292,7 @@ if(CONFIG_AMEBA_GPIO OR CONFIG_AMEBA_SPI OR CONFIG_AMEBA_PWM OR CONFIG_AMEBA_TIMER + OR CONFIG_AMEBA_WDG OR CONFIG_RTL8730E_FLASH_FS) list(APPEND AMEBA_EXTRA_LIBS ${AMEBA_SOC}/project/${AMEBA_KM_PROJ}/lib/soc/lib_rom.a) diff --git a/arch/arm/src/rtl8730e/Make.defs b/arch/arm/src/rtl8730e/Make.defs index 91ff9434f30..c7d6353dbbd 100644 --- a/arch/arm/src/rtl8730e/Make.defs +++ b/arch/arm/src/rtl8730e/Make.defs @@ -65,7 +65,7 @@ AMEBA_AP_SOC_LIB = $(TOPDIR)/arch/arm/src/common/ameba/ameba-rtos/component/soc/ # rtl8730e_flash_stubs.c supplies the RAM-side symbols that lib_rom.a objects # expect (DiagPrintfNano, irq_enable, Pinmux_Config, etc.). Compile them once # whenever any driver needing ROM is enabled. -ifneq ($(filter y,$(CONFIG_AMEBA_GPIO) $(CONFIG_AMEBA_UART) $(CONFIG_AMEBA_I2C) $(CONFIG_AMEBA_SPI) $(CONFIG_AMEBA_PWM) $(CONFIG_AMEBA_TIMER) $(CONFIG_RTL8730E_FLASH_FS)),) +ifneq ($(filter y,$(CONFIG_AMEBA_GPIO) $(CONFIG_AMEBA_UART) $(CONFIG_AMEBA_I2C) $(CONFIG_AMEBA_SPI) $(CONFIG_AMEBA_PWM) $(CONFIG_AMEBA_TIMER) $(CONFIG_AMEBA_WDG) $(CONFIG_RTL8730E_FLASH_FS)),) CHIP_CSRCS += rtl8730e_flash_stubs.c EXTRA_LIBS += $(AMEBA_AP_SOC_LIB)$(DELIM)lib_rom.a @@ -95,6 +95,10 @@ ifeq ($(CONFIG_AMEBA_TIMER),y) CHIP_CSRCS += ameba_timer.c endif +ifeq ($(CONFIG_AMEBA_WDG),y) +CHIP_CSRCS += ameba_wdg.c +endif + # WiFi (WHC host, CA32 side). ifeq ($(CONFIG_RTL8730E_WIFI),y) CHIP_CSRCS += rtl8730e_wifi_init.c diff --git a/arch/arm/src/rtl8730e/ameba_wdg_chip.h b/arch/arm/src/rtl8730e/ameba_wdg_chip.h new file mode 100644 index 00000000000..935620bb128 --- /dev/null +++ b/arch/arm/src/rtl8730e/ameba_wdg_chip.h @@ -0,0 +1,73 @@ +/**************************************************************************** + * arch/arm/src/rtl8730e/ameba_wdg_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_ARM_SRC_RTL8730E_AMEBA_WDG_CHIP_H +#define __ARCH_ARM_SRC_RTL8730E_AMEBA_WDG_CHIP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <nuttx/irq.h> + +#include <stdint.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Per-chip watchdog wiring for RTL8730E (amebasmart, CA32). The shared + * driver (arch/arm/src/common/ameba/ameba_wdg.c) includes this header to + * learn which watchdog instance to drive and its interrupt line. The + * shared driver is never edited -- it reads only the two macros below. + * + * amebasmart carries five watchdog instances: an always-on IWDG (WDG0) plus + * one "system" WDG per core/domain, each at its own base and with its own + * secure/non-secure alias split: + * + * WDG0 (IWDG) 0x42008400 always-on, LP domain + * WDG1 0x51000400 + * WDG2 0x41000440 KM4 non-secure system watchdog + * WDG3 0x51000480 + * WDG4 0x410004c0 CA32 (AP) non-secure system watchdog + * + * This port runs on the CA32 core, and -- matching the vendor HAL + * wdt_api.c, which selects WDG4_DEV / WDG4_IRQ for CONFIG_ARM_CORE_CA32 + * (KM4 gets WDG2 instead) -- we drive WDG4, the CA32 non-secure system + * watchdog. As with the other CA32 drivers the non-secure register alias + * (0x41xxxxxx) is the one reachable from this core. + * + * BOTH the base address and the interrupt vector are chip-specific. The WDG + * register block, structures, magic keys and the ms-based timeout are the + * same on every current Ameba chip, so they live in the shared driver; only + * the two values below move per chip (verified against the SoC + * hal_platform.h and the CA32 section of ameba_vector_table.h, not guessed). + * + * NuttX IRQ = GIC SPI number + 32 on this chip (see irq.h); WDG4_IRQ is + * GIC SPI 62 in the CA32 enum, giving NuttX IRQ 94. + */ + +#define AMEBA_WDG_BASE 0x410004c0ul +#define AMEBA_WDG_IRQ RTL8730E_IRQ_WDG4 + +#endif /* __ARCH_ARM_SRC_RTL8730E_AMEBA_WDG_CHIP_H */ diff --git a/boards/arm/rtl8730e/rtl8730e_evb/configs/wdg/defconfig b/boards/arm/rtl8730e/rtl8730e_evb/configs/wdg/defconfig new file mode 100644 index 00000000000..fefda78b23b --- /dev/null +++ b/boards/arm/rtl8730e/rtl8730e_evb/configs/wdg/defconfig @@ -0,0 +1,62 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_NSH_DISABLE_MB is not set +# CONFIG_NSH_DISABLE_MH is not set +# CONFIG_NSH_DISABLE_MW is not set +CONFIG_ALARM_ARCH=y +CONFIG_AMEBA_WDG=y +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="rtl8730e_evb" +CONFIG_ARCH_BOARD_RTL8730E_EVB=y +CONFIG_ARCH_CHIP="rtl8730e" +CONFIG_ARCH_CHIP_RTL8730E=y +CONFIG_ARCH_CHIP_RTL8730E_CA32=y +CONFIG_ARCH_INTERRUPTSTACK=2048 +CONFIG_ARCH_LOWVECTORS=y +CONFIG_ARM_PSCI=y +CONFIG_BOARD_LOOPSPERMSEC=393693 +CONFIG_BUILTIN=y +CONFIG_DEBUG_ASSERTIONS=y +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DEFAULT_TASK_STACKSIZE=4096 +CONFIG_EXAMPLES_HELLO=y +CONFIG_EXAMPLES_WATCHDOG=y +CONFIG_EXPERIMENTAL=y +CONFIG_FLASH_SIZE=1048576 +CONFIG_FLASH_START=0x60300000 +CONFIG_FLASH_VSTART=0x60300000 +CONFIG_FS_PROCFS=y +CONFIG_FS_TMPFS=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_IDLETHREAD_STACKSIZE=4096 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_LIBC_MEMFD_ERROR=y +CONFIG_MM_DEFAULT_ALIGNMENT=64 +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_READLINE=y +CONFIG_PRIORITY_INHERITANCE=y +CONFIG_RAM_SIZE=3145728 +CONFIG_RAM_START=0x60400000 +CONFIG_RAM_VSTART=0x60400000 +CONFIG_RAW_BINARY=y +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_HPWORK=y +CONFIG_SCHED_HPWORKPRIORITY=192 +CONFIG_SMP=y +CONFIG_SMP_NCPUS=2 +CONFIG_STACK_COLORATION=y +CONFIG_START_DAY=25 +CONFIG_START_MONTH=4 +CONFIG_START_YEAR=2023 +CONFIG_SYSTEM_NSH=y +CONFIG_USEC_PER_TICK=1000 diff --git a/boards/arm/rtl8730e/rtl8730e_evb/scripts/Make.defs b/boards/arm/rtl8730e/rtl8730e_evb/scripts/Make.defs index 0628ed05829..cd0e93042c0 100644 --- a/boards/arm/rtl8730e/rtl8730e_evb/scripts/Make.defs +++ b/boards/arm/rtl8730e/rtl8730e_evb/scripts/Make.defs @@ -62,7 +62,7 @@ include $(TOPDIR)$(DELIM)arch$(DELIM)arm$(DELIM)src$(DELIM)rtl8730e$(DELIM)ameba # lib_rom.a and the RTK toolchain's libgcc.a are compiled without VFP ABI # flags; suppress the harmless mismatch so the linker does not abort on it # whenever libameba_fwlib.a is in the link (GPIO, WiFi, or flash-FS config). -ifneq ($(filter y,$(CONFIG_AMEBA_GPIO) $(CONFIG_AMEBA_UART) $(CONFIG_AMEBA_I2C) $(CONFIG_AMEBA_SPI) $(CONFIG_AMEBA_PWM) $(CONFIG_AMEBA_TIMER) $(CONFIG_RTL8730E_WIFI) $(CONFIG_RTL8730E_FLASH_FS)),) +ifneq ($(filter y,$(CONFIG_AMEBA_GPIO) $(CONFIG_AMEBA_UART) $(CONFIG_AMEBA_I2C) $(CONFIG_AMEBA_SPI) $(CONFIG_AMEBA_PWM) $(CONFIG_AMEBA_TIMER) $(CONFIG_AMEBA_WDG) $(CONFIG_RTL8730E_WIFI) $(CONFIG_RTL8730E_FLASH_FS)),) LDFLAGS += --no-warn-mismatch endif diff --git a/boards/arm/rtl8730e/rtl8730e_evb/src/CMakeLists.txt b/boards/arm/rtl8730e/rtl8730e_evb/src/CMakeLists.txt index b9459da670c..4eaf77767f5 100644 --- a/boards/arm/rtl8730e/rtl8730e_evb/src/CMakeLists.txt +++ b/boards/arm/rtl8730e/rtl8730e_evb/src/CMakeLists.txt @@ -57,6 +57,12 @@ if(CONFIG_AMEBA_TIMER) PRIVATE ${NUTTX_DIR}/arch/arm/src/common/ameba) endif() +if(CONFIG_AMEBA_WDG) + list(APPEND SRCS rtl8730e_wdg.c) + target_include_directories(board + PRIVATE ${NUTTX_DIR}/arch/arm/src/common/ameba) +endif() + if(CONFIG_LIBC_FDT) target_include_directories(board PRIVATE ${NUTTX_DIR}/libs/libc/fdt/dtc/libfdt) diff --git a/boards/arm/rtl8730e/rtl8730e_evb/src/Makefile b/boards/arm/rtl8730e/rtl8730e_evb/src/Makefile index a65b41f80f6..b6b8cc8cc54 100644 --- a/boards/arm/rtl8730e/rtl8730e_evb/src/Makefile +++ b/boards/arm/rtl8730e/rtl8730e_evb/src/Makefile @@ -34,7 +34,7 @@ ifeq ($(CONFIG_LIBC_FDT),y) CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)fdt$(DELIM)dtc$(DELIM)libfdt endif -ifneq ($(CONFIG_RTL8730E_FLASH_FS)$(CONFIG_AMEBA_GPIO)$(CONFIG_AMEBA_UART)$(CONFIG_AMEBA_I2C)$(CONFIG_AMEBA_SPI)$(CONFIG_AMEBA_PWM)$(CONFIG_AMEBA_TIMER),) +ifneq ($(CONFIG_RTL8730E_FLASH_FS)$(CONFIG_AMEBA_GPIO)$(CONFIG_AMEBA_UART)$(CONFIG_AMEBA_I2C)$(CONFIG_AMEBA_SPI)$(CONFIG_AMEBA_PWM)$(CONFIG_AMEBA_TIMER)$(CONFIG_AMEBA_WDG),) CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)arm$(DELIM)src$(DELIM)common$(DELIM)ameba endif @@ -62,4 +62,8 @@ ifeq ($(CONFIG_AMEBA_TIMER),y) CSRCS += rtl8730e_timer.c endif +ifeq ($(CONFIG_AMEBA_WDG),y) +CSRCS += rtl8730e_wdg.c +endif + include $(TOPDIR)/boards/Board.mk diff --git a/boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_bringup.c b/boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_bringup.c index c5cec54f76c..49d9dac6d74 100644 --- a/boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_bringup.c +++ b/boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_bringup.c @@ -304,6 +304,17 @@ int rtl8730e_bringup(void) } #endif +#ifdef CONFIG_AMEBA_WDG + /* Register the on-chip watchdog at /dev/watchdog0. */ + + ret = rtl8730e_wdg_initialize(); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to initialize watchdog: %d\n", ret); + } +#endif + UNUSED(ret); return OK; } diff --git a/boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_evb.h b/boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_evb.h index fd9ed70a490..28de502f7cc 100644 --- a/boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_evb.h +++ b/boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_evb.h @@ -81,5 +81,9 @@ int rtl8730e_pwm_initialize(void); int rtl8730e_timer_initialize(void); #endif +#ifdef CONFIG_AMEBA_WDG +int rtl8730e_wdg_initialize(void); +#endif + #endif /* __ASSEMBLY__ */ #endif /* __BOARDS_ARM_RTL8730E_RTL8730E_EVB_SRC_RTL8730E_EVB_H */ diff --git a/boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_evb.h b/boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_wdg.c similarity index 55% copy from boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_evb.h copy to boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_wdg.c index fd9ed70a490..72122b9ef05 100644 --- a/boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_evb.h +++ b/boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_wdg.c @@ -1,5 +1,5 @@ /**************************************************************************** - * boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_evb.h + * boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_wdg.c * * SPDX-License-Identifier: Apache-2.0 * @@ -20,66 +20,44 @@ * ****************************************************************************/ -#ifndef __BOARDS_ARM_RTL8730E_RTL8730E_EVB_SRC_RTL8730E_EVB_H -#define __BOARDS_ARM_RTL8730E_RTL8730E_EVB_SRC_RTL8730E_EVB_H - /**************************************************************************** * Included Files ****************************************************************************/ #include <nuttx/config.h> -#include <stdint.h> - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ +#include <syslog.h> +#include <errno.h> -#ifndef __ASSEMBLY__ +#include "ameba_wdg.h" +#include "rtl8730e_evb.h" /**************************************************************************** - * Public Functions Definitions + * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: rtl8730e_bringup + * Name: rtl8730e_wdg_initialize * * Description: - * Bring up board features + * Register the on-chip watchdog at /dev/watchdog0. The WDG has no board + * wiring (it is an internal timer), so this simply defers to the shared + * driver. * ****************************************************************************/ -#if defined(CONFIG_BOARDCTL) || defined(CONFIG_BOARD_LATE_INITIALIZE) -int rtl8730e_bringup(void); -#endif - -#ifdef CONFIG_AMEBA_GPIO -int rtl8730e_gpio_initialize(void); -#endif - -#ifdef CONFIG_AMEBA_UART -int rtl8730e_uart_initialize(void); -#endif - -#ifdef CONFIG_AMEBA_I2C -int rtl8730e_i2c_initialize(void); -#endif - -#ifdef CONFIG_AMEBA_SPI -int rtl8730e_spi_initialize(void); -#endif - -#ifdef CONFIG_AMEBA_PWM -int rtl8730e_pwm_initialize(void); -#endif - -#ifdef CONFIG_AMEBA_TIMER -int rtl8730e_timer_initialize(void); -#endif - -#endif /* __ASSEMBLY__ */ -#endif /* __BOARDS_ARM_RTL8730E_RTL8730E_EVB_SRC_RTL8730E_EVB_H */ +int rtl8730e_wdg_initialize(void) +{ + int ret; + + ret = ameba_wdg_initialize(); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: ameba_wdg_initialize(/dev/watchdog0) failed: %d\n", + ret); + return ret; + } + + return OK; +}
