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 afb5f3ed2d93c593edced598d028acb5dd813b7e Author: dechao_gong <[email protected]> AuthorDate: Wed Oct 14 17:14:50 2026 +0800 arch/arm/rtl8730e: add general-purpose timer driver support Wire the shared Ameba timer driver (ameba_timer.c) up for RTL8730E (AmebaSmart, Cortex-A32) with a chip header, a board registration table and a timer defconfig. Exposes TIM2 at /dev/timer0 and TIM3 at /dev/timer1, both 32-bit LP basic timers at 32.768 kHz, so a tick is ~30.5 us and one timeout reaches ~36 hours. No common driver change: everything chip-specific sits in the new ameba_timer_chip.h -- register bases, APBPeriph masks, input clock and IRQ numbers, all read out of the SoC hal_platform.h, sysreg_lsys.h and the CA32 section of ameba_vector_table.h. TIM0 and TIM1 are deliberately not exposed, both being claimed by vendor code this port keeps working: the ROM uses TIM0 as the system timer behind DelayUs()/SYSTIMER_*, and the vendor HAL uses TIM1 as its application (us_ticker.c APP_TIM_ID) and UART-timeout (serial_api.c UART_TIMER_ID) timer. The amebadplus port starts its bank at TIM1 because only TIM0 is reserved there. The amebasmart timer block sits in RCC group 2 with the per-timer bit at 16 + n, unlike the SPI (group 1) and I2C (group 0) blocks on this same chip. ram_common/ameba_tim.c supplies the part of the RTIM API the AP ROM lacks, so it joins the fwlib archive for CONFIG_AMEBA_TIMER as it already does for CONFIG_AMEBA_PWM. While bringing this driver up under CMake, also fixes a pre-existing defect in the chip's CMakeLists.txt: the libameba_fwlib.a build block was gated on CONFIG_RTL8730E_FLASH_FS or CONFIG_RTL8730E_WIFI, so a config that enables only a peripheral driver never set AMEBA_FWLIB_SRCS and never ran ameba_build_lib at all. The link step below does list those drivers, so such a config linked whatever libameba_fwlib.a a previous config had left in the board tree -- or an archive without the members it needs -- and failed with undefined fwlib symbols (I2C_*, SSI_*, RTIM_*). The make side has no such outer gate. This widens the build condition to the drivers whose SDK support code is not in lib_rom.a, matching AMEBA_FWLIB_SRCS in ameba_board.mk, and keeps the IPC sources behind FLASH_FS/WIFI where they belong. It also makes the archive step remove the old archive before repacking it, since it lives in the board source tree and is shared by every build directory, so "ar crs" alone left members from a previously built config in place (the make PREBUILD already does this "rm -f" for the same reason). Before the CMake fix: cmake builds of the i2c, spi, pwm and timer configs all failed to link. After: all seven rtl8730e_evb configs build under both make and CMake, and the archive holds exactly the members its config selects. Assisted-by: Claude <[email protected]> Signed-off-by: dechao_gong <[email protected]> --- arch/arm/include/rtl8730e/irq.h | 2 + arch/arm/src/rtl8730e/CMakeLists.txt | 55 ++++++++-- arch/arm/src/rtl8730e/Make.defs | 8 +- arch/arm/src/rtl8730e/ameba_board.mk | 7 +- arch/arm/src/rtl8730e/ameba_timer_chip.h | 122 +++++++++++++++++++++ .../rtl8730e/rtl8730e_evb/configs/timer/defconfig | 63 +++++++++++ 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_timer.c} | 76 ++++++------- 12 files changed, 301 insertions(+), 61 deletions(-) diff --git a/arch/arm/include/rtl8730e/irq.h b/arch/arm/include/rtl8730e/irq.h index 1426d7bebe1..8e6ea5c0e44 100644 --- a/arch/arm/include/rtl8730e/irq.h +++ b/arch/arm/include/rtl8730e/irq.h @@ -41,6 +41,8 @@ * Numbers taken from SDK ameba_vector_table.h (CA32 section). */ +#define RTL8730E_IRQ_TIMER2 34 /* GIC SPI 2: TIM2 (LP basic timer) */ +#define RTL8730E_IRQ_TIMER3 35 /* GIC SPI 3: TIM3 (LP basic timer) */ #define RTL8730E_IRQ_IPC_AP 56 /* GIC SPI 24: CA32 AP-IPC (WHC WiFi) */ #define RTL8730E_IRQ_UART0 82 /* GIC SPI 50: UART0 */ #define RTL8730E_IRQ_UART1 83 /* GIC SPI 51: UART1 */ diff --git a/arch/arm/src/rtl8730e/CMakeLists.txt b/arch/arm/src/rtl8730e/CMakeLists.txt index fa1dea6d596..158d4739ecc 100644 --- a/arch/arm/src/rtl8730e/CMakeLists.txt +++ b/arch/arm/src/rtl8730e/CMakeLists.txt @@ -105,6 +105,18 @@ if(CONFIG_AMEBA_PWM) endif() endif() +if(CONFIG_AMEBA_TIMER) + list(APPEND SRCS ${AMEBA_COMMON}/ameba_timer.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) + list(APPEND SRCS rtl8730e_flash_stubs.c) + endif() +endif() + target_include_directories(arch PRIVATE ${AMEBA_COMMON}) target_sources(arch PRIVATE ${SRCS}) @@ -155,8 +167,13 @@ function(ameba_build_lib lib obj_subdir srcs_var inc_var out_target) COMMENT "CC (ameba ${obj_subdir}) ${_base}.o") list(APPEND _objs ${_obj}) endforeach() + # Remove the archive before repacking it: it lives in the board source tree + # and is shared by every build directory, so "ar crs" alone would leave + # members from a previously built config behind (the make PREBUILD does the + # same "rm -f" for this reason). add_custom_command( OUTPUT ${lib} + COMMAND ${CMAKE_COMMAND} -E rm -f ${lib} COMMAND ${CMAKE_AR} crs ${lib} ${_objs} DEPENDS ${_objs} COMMENT "AR ${lib}") @@ -168,20 +185,34 @@ function(ameba_build_lib lib obj_subdir srcs_var inc_var out_target) endfunction() # ---------------------------------------------------------------------------- -# libameba_fwlib.a -- minimal fwlib subset needed by flash MTD + IPC (and the -# WiFi IPC path). Built from SDK source with the amebasmart CA32 include set. -# Linked only when FLASH_FS is enabled (mirrors ameba_board.mk). +# libameba_fwlib.a -- minimal fwlib subset needed by the drivers whose SDK +# support code is not in lib_rom.a. Built from SDK source with the amebasmart +# CA32 include set. The set of sources and the conditions selecting them mirror +# AMEBA_FWLIB_SRCS in ameba_board.mk one for one, and so must the conditions +# below: a config that links the archive (see AMEBA_EXTRA_LIBS) but does not +# build it here links a stale archive left in the board tree by a previous +# config, and fails on undefined fwlib symbols. # ---------------------------------------------------------------------------- set(AMEBA_FWLIB_A ${AMEBA_PREBUILT_LIBS}/libameba_fwlib.a) -if(CONFIG_RTL8730E_FLASH_FS OR CONFIG_RTL8730E_WIFI) +if(CONFIG_RTL8730E_FLASH_FS + OR CONFIG_RTL8730E_WIFI + OR CONFIG_AMEBA_UART + OR CONFIG_AMEBA_I2C + OR CONFIG_AMEBA_SPI + OR CONFIG_AMEBA_PWM + OR CONFIG_AMEBA_TIMER) set(AMEBA_FWLIB_SRCS - ${AMEBA_SOC}/fwlib/ram_common/ameba_arch.c - ${AMEBA_SOC}/swlib/log.c - ${AMEBA_SOC}/swlib/sscanf_minimal.c - ${AMEBA_SOC}/fwlib/ram_common/ameba_ipc_api.c - ${AMEBA_SOC}/fwlib/ram_common/ameba_ipc_ram.c) + ${AMEBA_SOC}/fwlib/ram_common/ameba_arch.c ${AMEBA_SOC}/swlib/log.c + ${AMEBA_SOC}/swlib/sscanf_minimal.c) + + # IPC layer is needed by both WiFi (WHC) and Flash FS (write-lock protocol). + # Include it once regardless of which feature(s) are enabled. + if(CONFIG_RTL8730E_FLASH_FS OR CONFIG_RTL8730E_WIFI) + list(APPEND AMEBA_FWLIB_SRCS ${AMEBA_SOC}/fwlib/ram_common/ameba_ipc_api.c + ${AMEBA_SOC}/fwlib/ram_common/ameba_ipc_ram.c) + endif() if(CONFIG_RTL8730E_FLASH_FS) list(APPEND AMEBA_FWLIB_SRCS @@ -203,7 +234,7 @@ if(CONFIG_RTL8730E_FLASH_FS OR CONFIG_RTL8730E_WIFI) endif() # The AP ROM carries only part of the RTIM API; the rest lives here. - if(CONFIG_AMEBA_PWM) + if(CONFIG_AMEBA_PWM OR CONFIG_AMEBA_TIMER) list(APPEND AMEBA_FWLIB_SRCS ${AMEBA_SOC}/fwlib/ram_common/ameba_tim.c) endif() @@ -247,6 +278,7 @@ if(CONFIG_AMEBA_GPIO OR CONFIG_AMEBA_I2C OR CONFIG_AMEBA_SPI OR CONFIG_AMEBA_PWM + OR CONFIG_AMEBA_TIMER OR CONFIG_RTL8730E_FLASH_FS) list(APPEND AMEBA_EXTRA_LIBS ${AMEBA_SOC}/project/${AMEBA_KM_PROJ}/lib/soc/lib_rom.a) @@ -257,7 +289,8 @@ if(CONFIG_RTL8730E_FLASH_FS OR CONFIG_AMEBA_UART OR CONFIG_AMEBA_I2C OR CONFIG_AMEBA_SPI - OR CONFIG_AMEBA_PWM) + OR CONFIG_AMEBA_PWM + OR CONFIG_AMEBA_TIMER) list(APPEND AMEBA_EXTRA_LIBS ${AMEBA_FWLIB_A}) endif() diff --git a/arch/arm/src/rtl8730e/Make.defs b/arch/arm/src/rtl8730e/Make.defs index e8863ae630e..91ff9434f30 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_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_RTL8730E_FLASH_FS)),) CHIP_CSRCS += rtl8730e_flash_stubs.c EXTRA_LIBS += $(AMEBA_AP_SOC_LIB)$(DELIM)lib_rom.a @@ -91,6 +91,10 @@ ifeq ($(CONFIG_AMEBA_PWM),y) CHIP_CSRCS += ameba_pwm.c endif +ifeq ($(CONFIG_AMEBA_TIMER),y) +CHIP_CSRCS += ameba_timer.c +endif + # WiFi (WHC host, CA32 side). ifeq ($(CONFIG_RTL8730E_WIFI),y) CHIP_CSRCS += rtl8730e_wifi_init.c @@ -121,7 +125,7 @@ endif # fwlib archive is needed whenever any driver uses RAM-side SDK tables # (flash MTD, UART, I2C, ...). Link it once for all such configs. -ifneq ($(filter y,$(CONFIG_RTL8730E_FLASH_FS) $(CONFIG_AMEBA_UART) $(CONFIG_AMEBA_I2C) $(CONFIG_AMEBA_SPI) $(CONFIG_AMEBA_PWM)),) +ifneq ($(filter y,$(CONFIG_RTL8730E_FLASH_FS) $(CONFIG_AMEBA_UART) $(CONFIG_AMEBA_I2C) $(CONFIG_AMEBA_SPI) $(CONFIG_AMEBA_PWM) $(CONFIG_AMEBA_TIMER)),) # Prebuilt staging area (within the board tree, gitignored). AMEBA_PREBUILT = $(BOARD_DIR)$(DELIM)prebuilt diff --git a/arch/arm/src/rtl8730e/ameba_board.mk b/arch/arm/src/rtl8730e/ameba_board.mk index 36e8fc270a9..dcd4b0fbcdd 100644 --- a/arch/arm/src/rtl8730e/ameba_board.mk +++ b/arch/arm/src/rtl8730e/ameba_board.mk @@ -90,9 +90,10 @@ endif # The AP ROM carries only part of the RTIM API (Cmd/TimeBaseInit/INT*); # RTIM_PrescalerConfig/ChangePeriod/CCStructInit/CCxInit/CCRxSet/CCxCmd, -# which the PWM driver needs, live in ram_common/ameba_tim.c, so that file -# must be compiled into libameba_fwlib.a whenever PWM is enabled. -ifeq ($(CONFIG_AMEBA_PWM),y) +# which the PWM driver needs, plus the TIMx_irq/APBPeriph_TIMx tables, live +# in ram_common/ameba_tim.c, so that file must be compiled into +# libameba_fwlib.a whenever PWM or the general-purpose timers are enabled. +ifneq ($(filter y,$(CONFIG_AMEBA_PWM) $(CONFIG_AMEBA_TIMER)),) AMEBA_FWLIB_SRCS += $(AMEBA_SOC)/fwlib/ram_common/ameba_tim.c endif diff --git a/arch/arm/src/rtl8730e/ameba_timer_chip.h b/arch/arm/src/rtl8730e/ameba_timer_chip.h new file mode 100644 index 00000000000..c75eb87b33e --- /dev/null +++ b/arch/arm/src/rtl8730e/ameba_timer_chip.h @@ -0,0 +1,122 @@ +/**************************************************************************** + * arch/arm/src/rtl8730e/ameba_timer_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_TIMER_CHIP_H +#define __ARCH_ARM_SRC_RTL8730E_AMEBA_TIMER_CHIP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <nuttx/irq.h> + +#include <stdint.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Per-chip general-purpose timer wiring for RTL8730E (amebasmart, CA32). + * The shared driver (arch/arm/src/common/ameba/ameba_timer.c) includes this + * header to learn which timer instances it may expose and, for each one, its + * register base, input clock, RCC clock masks and interrupt line. The + * shared driver is never edited: it reads only the macros below and the + * instance table, computing the period from clkfreq with one formula. + * + * amebasmart carries fourteen timers (TIM0..TIM13) sharing the one RTIM + * register layout and fwlib API, grouped by the SoC as follows (see the + * APBPeriph_TIMx comment in sysreg_lsys.h): TIM0..TIM7 are the 32-bit LP + * "basic" timers, TIM8 is the PWM timer, TIM9 the input-pulse timer and + * TIM10..TIM13 the HP basic timers. Values below were read out of the SoC + * hal_platform.h, sysreg_lsys.h and the CA32 section of + * ameba_vector_table.h, not guessed. + * + * This port exposes two of the fourteen, both from the 32-bit LP basic bank + * so a single lower-half serves them uniformly: + * + * instance timer base clock RCC gate NuttX IRQ + * -------- ------ ---------- --------- ------------ ------------- + * 0 TIM2 0x4200b400 32.768 kHz APBPeriph_TIM2 IRQ_TIMER2 + * 1 TIM3 0x4200b600 32.768 kHz APBPeriph_TIM3 IRQ_TIMER3 + * + * The LP basic timers are clocked from the 32.768 kHz LS clock (the vendor + * us_ticker.c states GTIMER_CLK_HZ = 32768 for this bank): ~30.5 us per + * tick, and a full 32-bit auto-reload -- "TIM_Period is 16bits for TIM8-9, + * and 32bits for TIM0-TIM7" per the fwlib RTIM_TimeBaseInitTypeDef comment + * -- gives ~36 h in one shot, covering the whole microsecond timer API + * range. That is why this bank is exposed rather than TIM8..TIM13: TIM8/ + * TIM9 are only 16-bit (max ~1.638 ms at 40 MHz) and are already claimed by + * the PWM and input-capture blocks, TIM8 being what CONFIG_AMEBA_PWM drives. + * + * TIM0 and TIM1 are deliberately NOT exposed, both being claimed by vendor + * code this port keeps working: + * + * - TIM0 is the always-on system timer. The vendor ameba_delay.h says + * "TIM0 is used as systimer, so TIM0 can not be used for other purpose", + * and DelayUs/DelayMs/SYSTIMER_* all rely on it. + * - TIM1 is the mbed-HAL application timer (us_ticker.c APP_TIM_ID = 1) + * and doubles as the serial_api.c receive timeout timer (UART_TIMER_ID + * = 1, "TIM1"). + * + * So the basic bank is exposed starting at TIM2, unlike the amebadplus port + * which starts at TIM1 because only TIM0 is reserved there. + */ + +/* RCC "function" and "clock" masks. Note the group selector: the amebasmart + * timer block is group 2 (bit30 = 2) with the per-timer bit at 16 + n, so + * TIM2 is bit18 and TIM3 is bit19 (APBPeriph_TIM2 / APBPeriph_TIM3 and their + * _CLOCK twins, which are equal on this chip). The SPI block here is group + * 1 and the I2C block group 0, so each peripheral -- not just each chip -- + * must supply its own values. They are written out here rather than pulled + * from <sysreg_lsys.h> to keep the vendor headers out of the NuttX include + * world (same rule as the PWM chip header). + */ + +#define AMEBA_TIMER_TIM2_MASK (((uint32_t)2 << 30) | ((uint32_t)1 << 18)) +#define AMEBA_TIMER_TIM3_MASK (((uint32_t)2 << 30) | ((uint32_t)1 << 19)) + +/* Number of timer instances this chip exposes and the data table that + * describes each one. The shared driver defines struct + * ameba_timer_config_s and instantiates this table; each row is + * { base, periph, clk, clkfreq, irq, idx }. + * + * The bases are the non-secure LP_APB aliases (TIMER2_REG_BASE / + * TIMER3_REG_BASE); the secure aliases at 0x5200b400 / 0x5200b600 must not + * be used from the non-secure world. + */ + +#define AMEBA_TIMER_NINSTANCES 2 + +#define AMEBA_TIMER_CONFIG_TABLE \ +{ \ + { \ + 0x4200b400ul, AMEBA_TIMER_TIM2_MASK, AMEBA_TIMER_TIM2_MASK, \ + 32768ul, RTL8730E_IRQ_TIMER2, 2 \ + }, \ + { \ + 0x4200b600ul, AMEBA_TIMER_TIM3_MASK, AMEBA_TIMER_TIM3_MASK, \ + 32768ul, RTL8730E_IRQ_TIMER3, 3 \ + }, \ +} + +#endif /* __ARCH_ARM_SRC_RTL8730E_AMEBA_TIMER_CHIP_H */ diff --git a/boards/arm/rtl8730e/rtl8730e_evb/configs/timer/defconfig b/boards/arm/rtl8730e/rtl8730e_evb/configs/timer/defconfig new file mode 100644 index 00000000000..ac3d055fbbf --- /dev/null +++ b/boards/arm/rtl8730e/rtl8730e_evb/configs/timer/defconfig @@ -0,0 +1,63 @@ +# +# 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_TIMER=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_TIMER=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_PREALLOC_TIMERS=4 +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 f3baef4087e..0628ed05829 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_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_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 3f2c574da01..b9459da670c 100644 --- a/boards/arm/rtl8730e/rtl8730e_evb/src/CMakeLists.txt +++ b/boards/arm/rtl8730e/rtl8730e_evb/src/CMakeLists.txt @@ -51,6 +51,12 @@ if(CONFIG_AMEBA_PWM) PRIVATE ${NUTTX_DIR}/arch/arm/src/common/ameba) endif() +if(CONFIG_AMEBA_TIMER) + list(APPEND SRCS rtl8730e_timer.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 a8a9c5786bc..a65b41f80f6 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),) +ifneq ($(CONFIG_RTL8730E_FLASH_FS)$(CONFIG_AMEBA_GPIO)$(CONFIG_AMEBA_UART)$(CONFIG_AMEBA_I2C)$(CONFIG_AMEBA_SPI)$(CONFIG_AMEBA_PWM)$(CONFIG_AMEBA_TIMER),) CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)arm$(DELIM)src$(DELIM)common$(DELIM)ameba endif @@ -58,4 +58,8 @@ ifeq ($(CONFIG_AMEBA_PWM),y) CSRCS += rtl8730e_pwm.c endif +ifeq ($(CONFIG_AMEBA_TIMER),y) +CSRCS += rtl8730e_timer.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 c5bcd65625d..c5cec54f76c 100644 --- a/boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_bringup.c +++ b/boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_bringup.c @@ -293,6 +293,17 @@ int rtl8730e_bringup(void) } #endif +#ifdef CONFIG_AMEBA_TIMER + /* Register the board's general-purpose timers at /dev/timerN. */ + + ret = rtl8730e_timer_initialize(); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to initialize timers: %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 73355c802cd..fd9ed70a490 100644 --- a/boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_evb.h +++ b/boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_evb.h @@ -77,5 +77,9 @@ int rtl8730e_spi_initialize(void); 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 */ diff --git a/boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_evb.h b/boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_timer.c similarity index 56% copy from boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_evb.h copy to boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_timer.c index 73355c802cd..bea674713b0 100644 --- a/boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_evb.h +++ b/boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_timer.c @@ -1,5 +1,5 @@ /**************************************************************************** - * boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_evb.h + * boards/arm/rtl8730e/rtl8730e_evb/src/rtl8730e_timer.c * * SPDX-License-Identifier: Apache-2.0 * @@ -20,62 +20,52 @@ * ****************************************************************************/ -#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> -#ifndef __ASSEMBLY__ +#include "ameba_timer.h" +#include "rtl8730e_evb.h" /**************************************************************************** - * Public Functions Definitions + * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: rtl8730e_bringup + * Name: rtl8730e_timer_initialize * * Description: - * Bring up board features + * Register the board's general-purpose timers. Both timers are internal + * (no board wiring), so this just binds the two exposed instances to their + * device nodes: /dev/timer0 is TIM2 and /dev/timer1 is TIM3, both 32-bit + * LP basic timers at 32.768 kHz. TIM0 is reserved by the ROM as the + * system timer backing DelayUs/SYSTIMER_*, and TIM1 by the vendor HAL as + * its application and UART-timeout timer, so neither is exposed. A + * failure on either is logged but does not abort the other. * ****************************************************************************/ -#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 - -#endif /* __ASSEMBLY__ */ -#endif /* __BOARDS_ARM_RTL8730E_RTL8730E_EVB_SRC_RTL8730E_EVB_H */ +int rtl8730e_timer_initialize(void) +{ + int ret; + + ret = ameba_timer_initialize("/dev/timer0", 0); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: ameba_timer_initialize(/dev/timer0) failed: %d\n", ret); + } + + ret = ameba_timer_initialize("/dev/timer1", 1); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: ameba_timer_initialize(/dev/timer1) failed: %d\n", ret); + } + + return ret; +}
