mirror of
https://github.com/apache/nuttx.git
synced 2026-08-27 20:30:38 +00:00
arch/arm/rtl8720f: add RTC driver support
Wire the shared Ameba RTC driver (arch/arm/src/common/ameba/ameba_rtc.c) into RTL8720F. The driver is chip-agnostic and reads only per-chip macros from ameba_rtc_chip.h; RTL8720F differs from amebadplus only in the RTC interrupt vector (RTL8720F_IRQ_RTC, vector 33). The APBPeriph_RTC masks and RTC_BASE_YEAR (1900) are identical across all current Ameba chips. - ameba_rtc_chip.h: per-chip RTC IRQ / clock masks / base year - Make.defs, ameba_board.mk: compile ameba_rtc.c and the fwlib RAM RTC source when CONFIG_AMEBA_RTC=y - board: rtl8720f_rtc.c registers /dev/rtc0 from bringup - configs/rtc: examples/alarm profile Signed-off-by: dechao_gong <dechao_gong@realsil.com.cn> Assisted-by: Claude <noreply@anthropic.com>
This commit is contained in:
parent
2b65c77adb
commit
01041d2b1a
11 changed files with 276 additions and 2 deletions
|
|
@ -43,6 +43,8 @@ Supported in this NuttX port:
|
|||
the SDK fwlib timer register layer
|
||||
* ADC channels exposed as an ``/dev/adc0`` character device, driven directly
|
||||
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
|
||||
|
||||
Buttons and LEDs
|
||||
================
|
||||
|
|
@ -161,6 +163,20 @@ example::
|
|||
|
||||
nsh> adc -n 1 # one sweep of /dev/adc0
|
||||
|
||||
rtc
|
||||
---
|
||||
|
||||
Minimal NSH with the on-chip RTC driver and the ``alarm`` example enabled
|
||||
(no Wi-Fi). The RTC is registered at ``/dev/rtc0`` from the board bring-up
|
||||
(``boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_rtc.c``); it has no board
|
||||
wiring (it is an internal clock). The hardware stores year + day-of-year, so
|
||||
the shared driver bridges to a full calendar. Read and set the clock with the
|
||||
NSH ``date`` command, and arm a one-shot wakeup with the example::
|
||||
|
||||
nsh> date # read /dev/rtc0
|
||||
nsh> date -s "Jun 16 12:00:00 2026" # set the RTC
|
||||
nsh> alarm 10 # fire an alarm in 10 seconds
|
||||
|
||||
nsh
|
||||
---
|
||||
|
||||
|
|
|
|||
|
|
@ -70,6 +70,10 @@ if(CONFIG_AMEBA_ADC)
|
|||
list(APPEND SRCS ${AMEBA_COMMON}/ameba_adc.c)
|
||||
endif()
|
||||
|
||||
if(CONFIG_AMEBA_RTC)
|
||||
list(APPEND SRCS ${AMEBA_COMMON}/ameba_rtc.c)
|
||||
endif()
|
||||
|
||||
target_include_directories(arch PRIVATE ${AMEBA_COMMON})
|
||||
target_sources(arch PRIVATE ${SRCS})
|
||||
|
||||
|
|
@ -156,6 +160,13 @@ if(CONFIG_AMEBA_ADC)
|
|||
list(APPEND AMEBA_FWLIB_SRCS ${AMEBA_SOC}/fwlib/ram_common/ameba_adc.c)
|
||||
endif()
|
||||
|
||||
# RTC register layer. The RTC driver (arch/.../common/ameba/ameba_rtc.c) calls
|
||||
# the fwlib RTC API; the data tables and helpers it indexes live in this RAM
|
||||
# source and must be compiled in (mirrors the make build's ameba_board.mk).
|
||||
if(CONFIG_AMEBA_RTC)
|
||||
list(APPEND AMEBA_FWLIB_SRCS ${AMEBA_SOC}/fwlib/ram_common/ameba_rtc.c)
|
||||
endif()
|
||||
|
||||
# Silence a couple of warnings the vendored SDK sources trip under NuttX's
|
||||
# warning set, scoped to this fwlib compile only (never relaxing NuttX's own):
|
||||
# -Wno-int-conversion: the SDK passes NULL to irq_register()'s u32 "Data"
|
||||
|
|
|
|||
|
|
@ -80,6 +80,10 @@ ifeq ($(CONFIG_AMEBA_ADC),y)
|
|||
CHIP_CSRCS += ameba_adc.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_AMEBA_RTC),y)
|
||||
CHIP_CSRCS += ameba_rtc.c
|
||||
endif
|
||||
|
||||
############################################################################
|
||||
# Realtek RTL8720F SDK integration
|
||||
#
|
||||
|
|
|
|||
|
|
@ -161,6 +161,15 @@ ifeq ($(CONFIG_AMEBA_ADC),y)
|
|||
AMEBA_FWLIB_SRCS += $(AMEBA_SOC)/fwlib/ram_common/ameba_adc.c
|
||||
endif
|
||||
|
||||
# RTC register layer. The whole fwlib RTC API the RTC driver
|
||||
# (arch/.../common/ameba/ameba_rtc.c) calls -- RTC_Init/StructInit,
|
||||
# RTC_SetTime/GetTime and RTC_SetAlarm/GetAlarm/AlarmStructInit/AlarmCmd/
|
||||
# AlarmClear -- is compiled from this RAM source (the _LONG_CALL_ prototypes
|
||||
# resolve here, not to ROM) and must be linked in.
|
||||
ifeq ($(CONFIG_AMEBA_RTC),y)
|
||||
AMEBA_FWLIB_SRCS += $(AMEBA_SOC)/fwlib/ram_common/ameba_rtc.c
|
||||
endif
|
||||
|
||||
# -Wno-int-conversion: the vendored SDK passes NULL to irq_register()'s u32
|
||||
# "Data" (interrupt context) argument in many places -- an intentional
|
||||
# NULL-as-context idiom. Silence -Wint-conversion for the SDK fwlib sources
|
||||
|
|
|
|||
85
arch/arm/src/rtl8720f/ameba_rtc_chip.h
Normal file
85
arch/arm/src/rtl8720f/ameba_rtc_chip.h
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/****************************************************************************
|
||||
* arch/arm/src/rtl8720f/ameba_rtc_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_RTL8720F_AMEBA_RTC_CHIP_H
|
||||
#define __ARCH_ARM_SRC_RTL8720F_AMEBA_RTC_CHIP_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Per-chip RTC wiring for RTL8720F. The shared driver
|
||||
* (arch/arm/src/common/ameba/ameba_rtc.c) includes this header to learn the
|
||||
* RTC interrupt line, the peripheral-clock masks and the calendar base year.
|
||||
* 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
|
||||
* macros below, and it drives the RTC through the SDK fwlib API, which takes
|
||||
* no register base (it selects the secure/non-secure alias internally), so
|
||||
* no register address appears here at all.
|
||||
*
|
||||
* The RTC register model, structures and constants (year + day-of-year time,
|
||||
* RTC_Format_BIN, the alarm mask values, RTC_BASE_YEAR = 1900) are identical
|
||||
* on every current Ameba chip (verified against amebadplus/amebalite/
|
||||
* amebasmart/amebagreen2/RTL8720F fwlib ameba_rtc.h), so they live in the
|
||||
* shared driver. The one thing that genuinely differs per chip is the RTC
|
||||
* interrupt vector, so only that is abstracted here:
|
||||
*
|
||||
* chip RTC_IRQ vector (SDK ameba_vector_table.h)
|
||||
* ----------- -----------------------------------------
|
||||
* amebadplus 46
|
||||
* amebalite 53
|
||||
* amebasmart 12
|
||||
* amebagreen2 41
|
||||
* RTL8720F 33 (this header: RTL8720F_IRQ_RTC)
|
||||
*
|
||||
* A new chip only edits this header: AMEBA_RTC_IRQ carries the NuttX IRQ
|
||||
* number of its RTC line -- see the ADC/PWM chip headers for the same
|
||||
* data-driven, never-computed pattern.
|
||||
*/
|
||||
|
||||
#define AMEBA_RTC_IRQ RTL8720F_IRQ_RTC
|
||||
|
||||
/* APBPeriph_RTC (function) and APBPeriph_RTC_CLOCK masks, from the SDK
|
||||
* sysreg_aon.h: bit group selector (3 << 30) plus the RTC enable bit
|
||||
* (1 << 3). Both are equal on this chip. The driver gates the RTC clock
|
||||
* with these before the first fwlib call.
|
||||
*/
|
||||
|
||||
#define AMEBA_RTC_APBPERIPH (((uint32_t)3 << 30) | ((uint32_t)1 << 3))
|
||||
#define AMEBA_RTC_APBPERIPH_CLK (((uint32_t)3 << 30) | ((uint32_t)1 << 3))
|
||||
|
||||
/* Calendar base year the fwlib RTC uses for RTC_TimeTypeDef.RTC_Year
|
||||
* (RTC_BASE_YEAR); the hardware stores year + day-of-year, not month/day.
|
||||
*/
|
||||
|
||||
#define AMEBA_RTC_BASE_YEAR 1900
|
||||
|
||||
#endif /* __ARCH_ARM_SRC_RTL8720F_AMEBA_RTC_CHIP_H */
|
||||
51
boards/arm/rtl8720f/rtl8720f_evb/configs/rtc/defconfig
Normal file
51
boards/arm/rtl8720f/rtl8720f_evb/configs/rtc/defconfig
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#
|
||||
# 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_DEBUG_WARN is not set
|
||||
CONFIG_AMEBA_RTC=y
|
||||
CONFIG_ARCH="arm"
|
||||
CONFIG_ARCH_BOARD="rtl8720f_evb"
|
||||
CONFIG_ARCH_BOARD_RTL8720F_EVB=y
|
||||
CONFIG_ARCH_CHIP="rtl8720f"
|
||||
CONFIG_ARCH_CHIP_RTL8720F=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_ALARM=y
|
||||
CONFIG_EXAMPLES_HELLO=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=262144
|
||||
CONFIG_RAM_START=0x30008000
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_RTC_ALARM=y
|
||||
CONFIG_SCHED_HPWORK=y
|
||||
CONFIG_SCHED_HPWORKPRIORITY=192
|
||||
CONFIG_SCHED_LPWORK=y
|
||||
CONFIG_STACK_COLORATION=y
|
||||
CONFIG_START_DAY=16
|
||||
CONFIG_START_MONTH=6
|
||||
CONFIG_START_YEAR=2026
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_SYSTEM_NSH_STACKSIZE=2500
|
||||
CONFIG_TIMER=y
|
||||
CONFIG_TIMER_ARCH=y
|
||||
CONFIG_USEC_PER_TICK=1000
|
||||
|
|
@ -46,6 +46,10 @@ if(CONFIG_AMEBA_ADC)
|
|||
list(APPEND SRCS rtl8720f_adc.c)
|
||||
endif()
|
||||
|
||||
if(CONFIG_AMEBA_RTC)
|
||||
list(APPEND SRCS rtl8720f_rtc.c)
|
||||
endif()
|
||||
|
||||
target_sources(board PRIVATE ${SRCS})
|
||||
|
||||
if(CONFIG_AMEBA_GPIO
|
||||
|
|
@ -53,7 +57,8 @@ if(CONFIG_AMEBA_GPIO
|
|||
OR CONFIG_AMEBA_I2C
|
||||
OR CONFIG_AMEBA_SPI
|
||||
OR CONFIG_AMEBA_PWM
|
||||
OR CONFIG_AMEBA_ADC)
|
||||
OR CONFIG_AMEBA_ADC
|
||||
OR CONFIG_AMEBA_RTC)
|
||||
# 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
|
||||
|
|
|
|||
|
|
@ -48,10 +48,14 @@ ifeq ($(CONFIG_AMEBA_ADC),y)
|
|||
CSRCS += rtl8720f_adc.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_AMEBA_RTC),y)
|
||||
CSRCS += rtl8720f_rtc.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),)
|
||||
ifneq ($(CONFIG_AMEBA_GPIO)$(CONFIG_AMEBA_UART)$(CONFIG_AMEBA_I2C)$(CONFIG_AMEBA_SPI)$(CONFIG_AMEBA_PWM)$(CONFIG_AMEBA_ADC)$(CONFIG_AMEBA_RTC),)
|
||||
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)arm$(DELIM)src$(DELIM)common$(DELIM)ameba
|
||||
endif
|
||||
|
||||
|
|
|
|||
|
|
@ -180,6 +180,16 @@ int rtl8720f_bringup(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_AMEBA_RTC
|
||||
/* Register the board's RTC at /dev/rtc0. */
|
||||
|
||||
ret = rtl8720f_rtc_initialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: rtl8720f_rtc_initialize failed: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Install the inter-core HW IPC-semaphore RTOS hooks LAST -- after all the
|
||||
* flash / WHC bring-up above, and just before this (board_late_initialize)
|
||||
* path returns and nx_start() hands off to the init task.
|
||||
|
|
|
|||
66
boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_rtc.c
Normal file
66
boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_rtc.c
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/****************************************************************************
|
||||
* boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_rtc.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_rtc.h"
|
||||
#include "rtl8720f_rtl8720f_evb.h"
|
||||
|
||||
#ifdef CONFIG_AMEBA_RTC
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rtl8720f_rtc_initialize
|
||||
*
|
||||
* Description:
|
||||
* Bring up the on-chip RTC and register it at /dev/rtc0. The RTC has no
|
||||
* board wiring (it is an internal clock), so this simply defers to the
|
||||
* shared driver.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int rtl8720f_rtc_initialize(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = ameba_rtc_initialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR,
|
||||
"ERROR: ameba_rtc_initialize(/dev/rtc0) failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_AMEBA_RTC */
|
||||
|
|
@ -91,6 +91,19 @@ int rtl8720f_pwm_initialize(void);
|
|||
int rtl8720f_adc_initialize(void);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_AMEBA_RTC
|
||||
/****************************************************************************
|
||||
* Name: rtl8720f_rtc_initialize
|
||||
*
|
||||
* Description:
|
||||
* Register the board's RTC at /dev/rtc0
|
||||
* (boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_rtc.c).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int rtl8720f_rtc_initialize(void);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_RTL8720F_WIFI
|
||||
/****************************************************************************
|
||||
* Name: rtl8720f_wifi_initialize
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue