mirror of
https://github.com/apache/nuttx.git
synced 2026-10-17 11:08:57 +00:00
arch/arm/rtl8721f: add watchdog driver support
Wire the RTL8721F (amebagreen2) into the shared Ameba watchdog driver (arch/arm/src/common/ameba/ameba_wdg.c), registered as /dev/watchdog0. Only the per-chip base address and IRQ differ, so this adds a small ameba_wdg_chip.h (WDG2 non-secure system watchdog at 0x4080AD80, CPU0_NS_WDG IRQ 69, verified against the SoC hal_platform.h and ameba_vector_table.h) plus the Make.defs/CMakeLists build hooks, the board bring-up registration, and a wdg defconfig. The shared driver is unchanged. Assisted-by: Claude <noreply@anthropic.com> Signed-off-by: dechao_gong <dechao_gong@realsil.com.cn>
This commit is contained in:
parent
ceea742239
commit
15678acf6f
10 changed files with 243 additions and 2 deletions
|
|
@ -46,6 +46,8 @@ Supported in this NuttX port:
|
|||
on the SDK fwlib register layer
|
||||
* On-chip RTC exposed as a ``/dev/rtc0`` date/time character device with
|
||||
alarm support, driven directly on the SDK fwlib register layer
|
||||
* On-chip watchdog exposed as a ``/dev/watchdog0`` character device, driven
|
||||
directly on the SDK fwlib register layer
|
||||
|
||||
Buttons and LEDs
|
||||
================
|
||||
|
|
@ -180,6 +182,17 @@ NSH ``date`` command, and arm a one-shot wakeup with the example::
|
|||
nsh> date -s "Jun 16 12:00:00 2026" # set the RTC
|
||||
nsh> alarm 10 # fire an alarm in 10 seconds
|
||||
|
||||
wdg
|
||||
---
|
||||
|
||||
Minimal NSH with the on-chip watchdog driver and the ``wdog`` example
|
||||
enabled (no Wi-Fi). The watchdog is registered at ``/dev/watchdog0`` from the
|
||||
board bring-up (``boards/arm/rtl8721f/rtl8721f_evb/src/rtl8721f_wdg.c``); it
|
||||
has no board wiring (it is an internal timer). Exercise it with the example,
|
||||
which opens the device, sets a timeout, and pings it::
|
||||
|
||||
nsh> wdog # run the watchdog example
|
||||
|
||||
nsh
|
||||
---
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,10 @@ if(CONFIG_AMEBA_RTC)
|
|||
list(APPEND SRCS ${AMEBA_COMMON}/ameba_rtc.c)
|
||||
endif()
|
||||
|
||||
if(CONFIG_AMEBA_WDG)
|
||||
list(APPEND SRCS ${AMEBA_COMMON}/ameba_wdg.c)
|
||||
endif()
|
||||
|
||||
target_include_directories(arch PRIVATE ${AMEBA_COMMON})
|
||||
target_sources(arch PRIVATE ${SRCS})
|
||||
|
||||
|
|
|
|||
|
|
@ -84,6 +84,10 @@ ifeq ($(CONFIG_AMEBA_RTC),y)
|
|||
CHIP_CSRCS += ameba_rtc.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_AMEBA_WDG),y)
|
||||
CHIP_CSRCS += ameba_wdg.c
|
||||
endif
|
||||
|
||||
############################################################################
|
||||
# Realtek RTL8721F SDK integration
|
||||
#
|
||||
|
|
|
|||
75
arch/arm/src/rtl8721f/ameba_wdg_chip.h
Normal file
75
arch/arm/src/rtl8721f/ameba_wdg_chip.h
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/****************************************************************************
|
||||
* arch/arm/src/rtl8721f/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_RTL8721F_AMEBA_WDG_CHIP_H
|
||||
#define __ARCH_ARM_SRC_RTL8721F_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 RTL8721F (amebagreen2). 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. A port to
|
||||
* another Ameba chip supplies a same-named header on the chip include path;
|
||||
* the shared driver is never edited -- it reads only the two macros below.
|
||||
*
|
||||
* The Ameba SoCs carry several watchdog instances (an always-on IWDG plus
|
||||
* one "system" WDG per CPU, each with a secure and a non-secure alias).
|
||||
* This NuttX port runs on the CPU0 core, and -- matching the vendor HAL
|
||||
* wdt_api.c, which selects the CPU's non-secure system WDG device / IRQ --
|
||||
* we drive that non-secure system watchdog. As with the I2C/SPI drivers
|
||||
* the non-secure register alias (0x40xxxxxx) is the one actually reachable
|
||||
* from this core, so that is the base used here.
|
||||
*
|
||||
* 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 each SoC's
|
||||
* hal_platform.h and ameba_vector_table.h):
|
||||
*
|
||||
* chip non-secure system WDG base NuttX IRQ
|
||||
* ----------- ----------------------------------- ---------------------
|
||||
* amebadplus WDG2_REG_BASE 0x41008D80 KM4_NS_WDG_IRQ = 65
|
||||
* amebagreen2 WDG2_REG_BASE 0x4080AD80 CPU0_NS_WDG_IRQ = 69
|
||||
* RTL8720F WDG2_REG_BASE 0x40801D80 KM4TZ_NS_WDG_IRQ = 52
|
||||
*
|
||||
* A new chip only edits this header: AMEBA_WDG_BASE is the register base of
|
||||
* its non-secure system WDG (cast to the fwlib WDG_TypeDef * by the shared
|
||||
* driver) and AMEBA_WDG_IRQ carries the NuttX IRQ number of that WDG's
|
||||
* early-interrupt line -- see the ADC/RTC chip headers for the same
|
||||
* data-driven, never-computed pattern.
|
||||
*/
|
||||
|
||||
#define AMEBA_WDG_BASE 0x4080ad80ul
|
||||
#define AMEBA_WDG_IRQ RTL8721F_IRQ_CPU0_NS_WDG
|
||||
|
||||
#endif /* __ARCH_ARM_SRC_RTL8721F_AMEBA_WDG_CHIP_H */
|
||||
46
boards/arm/rtl8721f/rtl8721f_evb/configs/wdg/defconfig
Normal file
46
boards/arm/rtl8721f/rtl8721f_evb/configs/wdg/defconfig
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#
|
||||
# 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_AMEBA_WDG=y
|
||||
CONFIG_ARCH="arm"
|
||||
CONFIG_ARCH_BOARD="rtl8721f_evb"
|
||||
CONFIG_ARCH_BOARD_RTL8721F_EVB=y
|
||||
CONFIG_ARCH_CHIP="rtl8721f"
|
||||
CONFIG_ARCH_CHIP_RTL8721F=y
|
||||
CONFIG_ARCH_INTERRUPTSTACK=2048
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_ARMV8M_SYSTICK=y
|
||||
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_FS_PROCFS=y
|
||||
CONFIG_FS_TMPFS=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=4096
|
||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||
CONFIG_LIBC_MEMFD_ERROR=y
|
||||
CONFIG_MM_DEFAULT_ALIGNMENT=32
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_FILEIOSIZE=512
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_PREALLOC_TIMERS=4
|
||||
CONFIG_RAM_SIZE=401408
|
||||
CONFIG_RAM_START=0x20006000
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_SCHED_HPWORK=y
|
||||
CONFIG_SCHED_HPWORKPRIORITY=192
|
||||
CONFIG_SCHED_LPWORK=y
|
||||
CONFIG_STACK_COLORATION=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_SYSTEM_NSH_STACKSIZE=2500
|
||||
CONFIG_TIMER=y
|
||||
CONFIG_TIMER_ARCH=y
|
||||
CONFIG_USEC_PER_TICK=1000
|
||||
|
|
@ -50,6 +50,10 @@ if(CONFIG_AMEBA_RTC)
|
|||
list(APPEND SRCS rtl8721f_rtc.c)
|
||||
endif()
|
||||
|
||||
if(CONFIG_AMEBA_WDG)
|
||||
list(APPEND SRCS rtl8721f_wdg.c)
|
||||
endif()
|
||||
|
||||
target_sources(board PRIVATE ${SRCS})
|
||||
|
||||
if(CONFIG_AMEBA_GPIO
|
||||
|
|
@ -58,7 +62,8 @@ if(CONFIG_AMEBA_GPIO
|
|||
OR CONFIG_AMEBA_SPI
|
||||
OR CONFIG_AMEBA_PWM
|
||||
OR CONFIG_AMEBA_ADC
|
||||
OR CONFIG_AMEBA_RTC)
|
||||
OR CONFIG_AMEBA_RTC
|
||||
OR CONFIG_AMEBA_WDG)
|
||||
# The board pin tables pull in the shared drivers' public headers from
|
||||
# arch/arm/src/common/ameba/, not on the default board include path.
|
||||
target_include_directories(board
|
||||
|
|
|
|||
|
|
@ -52,10 +52,14 @@ ifeq ($(CONFIG_AMEBA_RTC),y)
|
|||
CSRCS += rtl8721f_rtc.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_AMEBA_WDG),y)
|
||||
CSRCS += rtl8721f_wdg.c
|
||||
endif
|
||||
|
||||
# The board pin tables pull in the shared drivers' public headers from
|
||||
# arch/arm/src/common/ameba/, which is not on the default board include path.
|
||||
|
||||
ifneq ($(CONFIG_AMEBA_GPIO)$(CONFIG_AMEBA_UART)$(CONFIG_AMEBA_I2C)$(CONFIG_AMEBA_SPI)$(CONFIG_AMEBA_PWM)$(CONFIG_AMEBA_ADC)$(CONFIG_AMEBA_RTC),)
|
||||
ifneq ($(CONFIG_AMEBA_GPIO)$(CONFIG_AMEBA_UART)$(CONFIG_AMEBA_I2C)$(CONFIG_AMEBA_SPI)$(CONFIG_AMEBA_PWM)$(CONFIG_AMEBA_ADC)$(CONFIG_AMEBA_RTC)$(CONFIG_AMEBA_WDG),)
|
||||
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)arm$(DELIM)src$(DELIM)common$(DELIM)ameba
|
||||
endif
|
||||
|
||||
|
|
|
|||
|
|
@ -204,6 +204,16 @@ int rtl8721f_bringup(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_AMEBA_WDG
|
||||
/* Register the board's watchdog at /dev/watchdog0. */
|
||||
|
||||
ret = rtl8721f_wdg_initialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: rtl8721f_wdg_initialize failed: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
IPC_patch_function(rtos_critical_enter, rtos_critical_exit,
|
||||
AMEBA_RTOS_CRITICAL_SEMA);
|
||||
IPC_SEMDelayStub(rtos_time_delay_ms);
|
||||
|
|
|
|||
|
|
@ -173,6 +173,19 @@ int rtl8721f_adc_initialize(void);
|
|||
int rtl8721f_rtc_initialize(void);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_AMEBA_WDG
|
||||
/****************************************************************************
|
||||
* Name: rtl8721f_wdg_initialize
|
||||
*
|
||||
* Description:
|
||||
* Register the board's watchdog at /dev/watchdog0
|
||||
* (boards/arm/rtl8721f/rtl8721f_evb/src/rtl8721f_wdg.c).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int rtl8721f_wdg_initialize(void);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_RTL8721F_FLASH_FS
|
||||
/****************************************************************************
|
||||
* Name: ameba_flash_fs_initialize
|
||||
|
|
|
|||
67
boards/arm/rtl8721f/rtl8721f_evb/src/rtl8721f_wdg.c
Normal file
67
boards/arm/rtl8721f/rtl8721f_evb/src/rtl8721f_wdg.c
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/****************************************************************************
|
||||
* boards/arm/rtl8721f/rtl8721f_evb/src/rtl8721f_wdg.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 <syslog.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "ameba_wdg.h"
|
||||
#include "rtl8721f_rtl8721f_evb.h"
|
||||
|
||||
#ifdef CONFIG_AMEBA_WDG
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rtl8721f_wdg_initialize
|
||||
*
|
||||
* Description:
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int rtl8721f_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;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_AMEBA_WDG */
|
||||
Loading…
Add table
Add a link
Reference in a new issue