mirror of
https://github.com/apache/nuttx.git
synced 2026-05-29 04:19:37 +08:00
risc-v/esp32c3: Support ESP32-C3 RTC driver
This commit is contained in:
committed by
Alan Carvalho de Assis
parent
45672c269d
commit
dbf9c87a42
@@ -151,6 +151,7 @@ config ESP32C3_CPU_FREQ_MHZ
|
|||||||
config ESP32C3_RT_TIMER
|
config ESP32C3_RT_TIMER
|
||||||
bool "Real-time Timer"
|
bool "Real-time Timer"
|
||||||
default n
|
default n
|
||||||
|
select ESP32C3_TIMER0
|
||||||
|
|
||||||
config ESP32C3_DISABLE_STDC_ATOMIC
|
config ESP32C3_DISABLE_STDC_ATOMIC
|
||||||
bool "Disable standard C atomic"
|
bool "Disable standard C atomic"
|
||||||
|
|||||||
@@ -146,6 +146,10 @@ ifeq ($(CONFIG_ARCH_USE_MODULE_TEXT),y)
|
|||||||
CHIP_CSRCS += esp32c3_modtext.c
|
CHIP_CSRCS += esp32c3_modtext.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_RTC_DRIVER),y)
|
||||||
|
CHIP_CSRCS += esp32c3_rtc_lowerhalf.c
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_ESP32C3_WIRELESS),y)
|
ifeq ($(CONFIG_ESP32C3_WIRELESS),y)
|
||||||
WIRELESS_DRV_UNPACK = esp-wireless-drivers-3rdparty
|
WIRELESS_DRV_UNPACK = esp-wireless-drivers-3rdparty
|
||||||
WIRELESS_DRV_ID = 2b53111
|
WIRELESS_DRV_ID = 2b53111
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -30,6 +30,9 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
#include <nuttx/timers/rtc.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <time.h>
|
||||||
#include "hardware/esp32c3_soc.h"
|
#include "hardware/esp32c3_soc.h"
|
||||||
|
|
||||||
#ifndef __ASSEMBLY__
|
#ifndef __ASSEMBLY__
|
||||||
@@ -137,6 +140,31 @@ struct esp32c3_cpu_freq_config_s
|
|||||||
uint32_t freq_mhz; /* CPU clock frequency */
|
uint32_t freq_mhz; /* CPU clock frequency */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef CONFIG_RTC_ALARM
|
||||||
|
|
||||||
|
/* The form of an alarm callback */
|
||||||
|
|
||||||
|
typedef CODE void (*alm_callback_t)(FAR void *arg, unsigned int alarmid);
|
||||||
|
|
||||||
|
enum alm_id_e
|
||||||
|
{
|
||||||
|
RTC_ALARM0 = 0, /* RTC ALARM 0 */
|
||||||
|
RTC_ALARM1 = 1, /* RTC ALARM 1 */
|
||||||
|
RTC_ALARM_LAST,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Structure used to pass parameters to set an alarm */
|
||||||
|
|
||||||
|
struct alm_setalarm_s
|
||||||
|
{
|
||||||
|
int as_id; /* enum alm_id_e */
|
||||||
|
struct timespec as_time; /* Alarm expiration time */
|
||||||
|
alm_callback_t as_cb; /* Callback (if non-NULL) */
|
||||||
|
FAR void *as_arg; /* Argument for callback */
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* CONFIG_RTC_ALARM */
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Function Prototypes
|
* Public Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -444,6 +472,187 @@ void esp32c3_rtc_sleep_set_wakeup_time(uint64_t t);
|
|||||||
|
|
||||||
uint64_t esp32c3_rtc_get_time_us(void);
|
uint64_t esp32c3_rtc_get_time_us(void);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32c3_rtc_set_boot_time
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Set time to RTC register to replace the original boot time.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* time_us - set time in microseconds.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void esp32c3_rtc_set_boot_time(uint64_t time_us);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32c3_rtc_get_boot_time
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Get time of RTC register to indicate the original boot time.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* time_us - get time in microseconds.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
uint64_t esp32c3_rtc_get_boot_time(void);
|
||||||
|
|
||||||
|
#ifdef CONFIG_RTC_DRIVER
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: up_rtc_time
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Get the current time in seconds. This is similar to the standard time()
|
||||||
|
* function. This interface is only required if the low-resolution
|
||||||
|
* RTC/counter hardware implementation selected. It is only used by the
|
||||||
|
* RTOS during initialization to set up the system time when CONFIG_RTC is
|
||||||
|
* set but neither CONFIG_RTC_HIRES nor CONFIG_RTC_DATETIME are set.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* The current time in seconds
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef CONFIG_RTC_HIRES
|
||||||
|
time_t up_rtc_time(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: up_rtc_settime
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Set the RTC to the provided time. All RTC implementations must be
|
||||||
|
* able to set their time based on a standard timespec.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* tp - the time to use
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno on failure
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int up_rtc_settime(FAR const struct timespec *ts);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: up_rtc_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the hardware RTC per the selected configuration.
|
||||||
|
* This function is called once during the OS initialization sequence
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno on failure
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int up_rtc_initialize(void);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: up_rtc_gettime
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Get the current time from the high resolution RTC clock/counter. This
|
||||||
|
* interface is only supported by the high-resolution RTC/counter hardware
|
||||||
|
* implementation. It is used to replace the system timer.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* tp - The location to return the high resolution time value.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno on failure
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_RTC_HIRES
|
||||||
|
int up_rtc_gettime(FAR struct timespec *tp);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_RTC_ALARM
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: up_rtc_setalarm
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Set up an alarm.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* alminfo - Information about the alarm configuration.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno on failure
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int up_rtc_setalarm(FAR struct alm_setalarm_s *alminfo);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: up_rtc_cancelalarm
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Cancel an alaram.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* alarmid - Identifies the alarm to be cancelled
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno on failure
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int up_rtc_cancelalarm(enum alm_id_e alarmid);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: up_rtc_rdalarm
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Query an alarm configured in hardware.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* tp - Location to return the timer match register.
|
||||||
|
* alarmid - Identifies the alarm to be cancelled
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno on failure
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int up_rtc_rdalarm(FAR struct timespec *tp, uint32_t alarmid);
|
||||||
|
|
||||||
|
#endif /* CONFIG_RTC_ALARM */
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: up_rtc_timer_init
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Init RTC timer.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno on failure
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int up_rtc_timer_init(void);
|
||||||
|
|
||||||
|
#endif /* CONFIG_RTC_DRIVER */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,56 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* arch/risc-v/src/esp32c3/esp32c3_rtc_lowerhalf.h
|
||||||
|
*
|
||||||
|
* 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_RISCV_SRC_ESP32C3_ESP32C3_RTC_LOWERHALF_H
|
||||||
|
#define __ARCH_RISCV_SRC_ESP32C3_ESP32C3_RTC_LOWERHALF_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_RTC_DRIVER
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32c3_rtc_driverinit
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Bind the configuration timer to a timer lower half instance and
|
||||||
|
* register the timer drivers at 'devpath'
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned on success; A negated errno value is returned
|
||||||
|
* to indicate the nature of any failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp32c3_rtc_driverinit(void);
|
||||||
|
|
||||||
|
#endif /* CONFIG_RTC_DRIVER */
|
||||||
|
|
||||||
|
#endif /* __ARCH_RISCV_SRC_ESP32C3_ESP32C3_RTC_LOWERHALF_H */
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
#
|
||||||
|
# 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_ARGCAT is not set
|
||||||
|
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
|
||||||
|
# CONFIG_NSH_CMDPARMS is not set
|
||||||
|
CONFIG_ARCH="risc-v"
|
||||||
|
CONFIG_ARCH_BOARD="esp32c3-devkit"
|
||||||
|
CONFIG_ARCH_BOARD_ESP32C3_DEVKIT=y
|
||||||
|
CONFIG_ARCH_CHIP="esp32c3"
|
||||||
|
CONFIG_ARCH_CHIP_ESP32C3=y
|
||||||
|
CONFIG_ARCH_CHIP_ESP32C3WROOM02=y
|
||||||
|
CONFIG_ARCH_INTERRUPTSTACK=1536
|
||||||
|
CONFIG_ARCH_RISCV=y
|
||||||
|
CONFIG_ARCH_STACKDUMP=y
|
||||||
|
CONFIG_BOARD_LOOPSPERMSEC=15000
|
||||||
|
CONFIG_BUILTIN=y
|
||||||
|
CONFIG_DEV_ZERO=y
|
||||||
|
CONFIG_ESP32C3_RT_TIMER=y
|
||||||
|
CONFIG_EXAMPLES_ALARM=y
|
||||||
|
CONFIG_FS_PROCFS=y
|
||||||
|
CONFIG_IDLETHREAD_STACKSIZE=2048
|
||||||
|
CONFIG_INTELHEX_BINARY=y
|
||||||
|
CONFIG_LIBC_PERROR_STDOUT=y
|
||||||
|
CONFIG_LIBC_STRERROR=y
|
||||||
|
CONFIG_MAX_TASKS=16
|
||||||
|
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
|
||||||
|
CONFIG_NSH_ARCHINIT=y
|
||||||
|
CONFIG_NSH_BUILTIN_APPS=y
|
||||||
|
CONFIG_NSH_FILEIOSIZE=512
|
||||||
|
CONFIG_NSH_READLINE=y
|
||||||
|
CONFIG_NSH_STRERROR=y
|
||||||
|
CONFIG_PREALLOC_TIMERS=0
|
||||||
|
CONFIG_RAW_BINARY=y
|
||||||
|
CONFIG_RR_INTERVAL=200
|
||||||
|
CONFIG_RTC=y
|
||||||
|
CONFIG_RTC_ALARM=y
|
||||||
|
CONFIG_RTC_DRIVER=y
|
||||||
|
CONFIG_RTC_NALARMS=2
|
||||||
|
CONFIG_SCHED_WAITPID=y
|
||||||
|
CONFIG_START_DAY=29
|
||||||
|
CONFIG_START_MONTH=11
|
||||||
|
CONFIG_START_YEAR=2019
|
||||||
|
CONFIG_SYSTEM_NSH=y
|
||||||
|
CONFIG_UART0_SERIAL_CONSOLE=y
|
||||||
|
CONFIG_USER_ENTRYPOINT="nsh_main"
|
||||||
@@ -56,6 +56,10 @@
|
|||||||
|
|
||||||
#include "esp32c3_rtc.h"
|
#include "esp32c3_rtc.h"
|
||||||
|
|
||||||
|
#ifdef CONFIG_RTC_DRIVER
|
||||||
|
# include "esp32c3_rtc_lowerhalf.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -328,6 +332,17 @@ int esp32c3_bringup(void)
|
|||||||
}
|
}
|
||||||
#endif /* CONFIG_ESP32C3_ADC */
|
#endif /* CONFIG_ESP32C3_ADC */
|
||||||
|
|
||||||
|
#ifdef CONFIG_RTC_DRIVER
|
||||||
|
/* Instantiate the ESP32-C3 RTC driver */
|
||||||
|
|
||||||
|
ret = esp32c3_rtc_driverinit();
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR,
|
||||||
|
"ERROR: Failed to Instantiate the RTC driver: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* If we got here then perhaps not all initialization was successful, but
|
/* If we got here then perhaps not all initialization was successful, but
|
||||||
* at least enough succeeded to bring-up NSH with perhaps reduced
|
* at least enough succeeded to bring-up NSH with perhaps reduced
|
||||||
* capabilities.
|
* capabilities.
|
||||||
|
|||||||
Reference in New Issue
Block a user