risc-v/esp32-c3: Adds timer driver

This commit is contained in:
Sara Souza
2021-03-09 11:16:53 -03:00
committed by Alan Carvalho de Assis
parent d00e97cbca
commit 85a93be5d7
12 changed files with 1671 additions and 0 deletions
+18
View File
@@ -157,6 +157,10 @@ config ESP32C3_UART
bool
default n
config ESP32C3_TIMER
bool
default n
config ESP32C3_WDT
bool
default n
@@ -178,6 +182,20 @@ config ESP32C3_UART1
select ESP32C3_UART
select UART1_SERIALDRIVER
config ESP32C3_TIMER0
bool "54-bit Timer 0 (Group 0 Timer 0)"
default n
select ESP32C3_TIMER
---help---
Enables Timer 0
config ESP32C3_TIMER1
bool "54-bit Timer 0 (Group 1 Timer 0)"
default n
select ESP32C3_TIMER
---help---
Enables Timer 1
config ESP32C3_MWDT0
bool "Main System Watchdog Timer (Group 0)"
default n
+7
View File
@@ -65,3 +65,10 @@ ifeq ($(CONFIG_WATCHDOG),y)
CHIP_CSRCS += esp32c3_wdt_lowerhalf.c
endif
endif
ifeq ($(CONFIG_ESP32C3_TIMER),y)
CHIP_CSRCS += esp32c3_tim.c
ifeq ($(CONFIG_TIMER),y)
CHIP_CSRCS += esp32c3_tim_lowerhalf.c
endif
endif
File diff suppressed because it is too large Load Diff
+138
View File
@@ -0,0 +1,138 @@
/****************************************************************************
* arch/risc-v/src/esp32c3/esp32c3_tim.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_TIM_H
#define __ARCH_RISCV_SRC_ESP32C3_ESP32C3_TIM_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/irq.h>
#include <stdint.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Helpers ******************************************************************/
#define ESP32C3_TIM_START(d) ((d)->ops->start(d))
#define ESP32C3_TIM_STOP(d) ((d)->ops->stop(d))
#define ESP32C3_TIM_CLEAR(d) ((d)->ops->clear(d))
#define ESP32C3_TIM_SETMODE(d, m) ((d)->ops->setmode(d, m))
#define ESP32C3_TIM_CLK_SRC(d, s) ((d)->ops->setclksrc(d, s))
#define ESP32C3_TIM_SETPRE(d, p) ((d)->ops->setpre(d, p))
#define ESP32C3_TIM_GETCTR(d, v) ((d)->ops->getcounter(d, v))
#define ESP32C3_TIM_SETCTR(d, v) ((d)->ops->setcounter(d, v))
#define ESP32C3_TIM_RLD_NOW(d) ((d)->ops->reloadnow(d))
#define ESP32C3_TIM_GETALRVL(d, v) ((d)->ops->getalarmvalue(d, v))
#define ESP32C3_TIM_SETALRVL(d, v) ((d)->ops->setalarmvalue(d, v))
#define ESP32C3_TIM_SETALRM(d, e) ((d)->ops->setalarm(d, e))
#define ESP32C3_TIM_SETARLD(d, e) ((d)->ops->setautoreload(d, e))
#define ESP32C3_TIM_SETISR(d, hnd, arg) ((d)->ops->setisr(d, hnd, arg))
#define ESP32C3_TIM_ENABLEINT(d) ((d)->ops->enableint(d))
#define ESP32C3_TIM_DISABLEINT(d) ((d)->ops->disableint(d))
#define ESP32C3_TIM_ACKINT(d) ((d)->ops->ackint(d))
/****************************************************************************
* Public Types
****************************************************************************/
/* Instances of Timer */
enum esp32c3_tim_inst_e
{
ESP32C3_TIMER0 = 0, /* Timer 0 from Timer Group 0 */
ESP32C3_TIMER1, /* Timer 0 from Timer Group 1 */
};
/* Timer mode */
enum esp32c3_tim_clksrc_e
{
ESP32C3_TIM_APB_CLK,
ESP32C3_TIM_XTAL_CLK,
};
/* Timer mode */
enum esp32c3_tim_mode_e
{
ESP32C3_TIM_MODE_DOWN,
ESP32C3_TIM_MODE_UP,
};
/* ESP32C3 TIM device */
struct esp32c3_tim_dev_s
{
struct esp32c3_tim_ops_s *ops;
};
/* ESP32C3 TIM ops */
/* This is a struct containing the pointers to the timer operations */
struct esp32c3_tim_ops_s
{
/* Timer tasks */
CODE void (*start)(FAR struct esp32c3_tim_dev_s *dev);
CODE void (*stop)(FAR struct esp32c3_tim_dev_s *dev);
CODE void (*clear)(FAR struct esp32c3_tim_dev_s *dev);
/* Timer operations */
CODE void (*setmode)(FAR struct esp32c3_tim_dev_s *dev,
enum esp32c3_tim_mode_e mode);
CODE void (*setclksrc)(FAR struct esp32c3_tim_dev_s *dev,
enum esp32c3_tim_clksrc_e src);
CODE void (*setpre)(FAR struct esp32c3_tim_dev_s *dev, uint16_t pre);
CODE void (*getcounter)(FAR struct esp32c3_tim_dev_s *dev,
uint64_t *value);
CODE void (*setcounter)(FAR struct esp32c3_tim_dev_s *dev, uint64_t value);
CODE void (*reloadnow)(FAR struct esp32c3_tim_dev_s *dev);
CODE void (*getalarmvalue)(FAR struct esp32c3_tim_dev_s *dev,
uint64_t *value);
CODE void (*setalarmvalue)(FAR struct esp32c3_tim_dev_s *dev,
uint64_t value);
CODE void (*setalarm)(FAR struct esp32c3_tim_dev_s *dev, bool enable);
CODE void (*setautoreload)(FAR struct esp32c3_tim_dev_s *dev, bool enable);
/* Timer interrupts */
CODE int (*setisr)(FAR struct esp32c3_tim_dev_s *dev, xcpt_t handler,
FAR void * arg);
CODE void (*enableint)(FAR struct esp32c3_tim_dev_s *dev);
CODE void (*disableint)(FAR struct esp32c3_tim_dev_s *dev);
CODE void (*ackint)(FAR struct esp32c3_tim_dev_s *dev);
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
FAR struct esp32c3_tim_dev_s *esp32c3_tim_init(int timer);
void esp32c3_tim_deinit(FAR struct esp32c3_tim_dev_s *dev);
#endif /* __ARCH_RISCV_SRC_ESP32C3_ESP32C3_TIM_H */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,40 @@
/****************************************************************************
* arch/risc-v/src/esp32c3/esp32c3_tim_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_TIM_LOWERHALF_H
#define __ARCH_RISCV_SRC_ESP32C3_ESP32C3_TIM_LOWERHALF_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: esp32c3_timer_initialize
****************************************************************************/
int esp32c3_timer_initialize(FAR const char *devpath, uint8_t timer);
#endif /* __ARCH_RISCV_SRC_ESP32C3_ESP32C3_TIM_LOWERHALF_H */
@@ -69,6 +69,12 @@
#define TIMG_WDT_RESET_LENGTH_1600_NS 6
#define TIMG_WDT_RESET_LENGTH_3200_NS 7
/* Maximum value in the high 22 bits from timer counters */
#define LOW_32_MASK 0xffffffff
#define LOW_22_MASK 0x3fffff
#define SHIFT_32 32
#define TIMG_T0CONFIG_REG(i) (REG_TIMG_BASE(i) + 0x0000)
/* TIMG_T0_EN : R/W ;bitpos:[31] ;default: 1'h0 ; */
@@ -0,0 +1,48 @@
#
# 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_TIMER0=y
CONFIG_ESP32C3_TIMER1=y
CONFIG_EXAMPLES_TIMER=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=8
CONFIG_NFILE_DESCRIPTORS=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_SCHED_WAITPID=y
CONFIG_START_DAY=29
CONFIG_START_MONTH=11
CONFIG_START_YEAR=2019
CONFIG_SYSTEM_NSH=y
CONFIG_TIMER=y
CONFIG_UART0_SERIAL_CONSOLE=y
CONFIG_USER_ENTRYPOINT="nsh_main"
@@ -42,6 +42,10 @@ ifeq ($(CONFIG_WATCHDOG),y)
CSRCS += esp32c3_wdt.c
endif
ifeq ($(CONFIG_TIMER),y)
CSRCS += esp32c3_timer.c
endif
SCRIPTIN = $(SCRIPTDIR)$(DELIM)esp32c3.template.ld
SCRIPTOUT = $(SCRIPTDIR)$(DELIM)esp32c3_out.ld
@@ -85,5 +85,21 @@ int esp32c3_gpio_init(void);
int board_wdt_init(void);
#endif
/****************************************************************************
* Name: board_tim_init
*
* Description:
* Configure the timer driver.
*
* Returned Value:
* Zero (OK) is returned on success; A negated errno value is returned
* to indicate the nature of any failure.
*
****************************************************************************/
#ifdef CONFIG_TIMER
int board_tim_init(void);
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_RISCV_ESP32C3_ESP32C3_DEVKIT_SRC_ESP32C3_DEVKIT_H */
@@ -107,6 +107,18 @@ int esp32c3_bringup(void)
}
#endif
#ifdef CONFIG_TIMER
/* Configure timer timer */
ret = board_tim_init();
if (ret < 0)
{
syslog(LOG_ERR,
"ERROR: Failed to initialize timer drivers: %d\n",
ret);
}
#endif
/* If we got here then perhaps not all initialization was successful, but
* at least enough succeeded to bring-up NSH with perhaps reduced
* capabilities.
@@ -0,0 +1,83 @@
/****************************************************************************
* boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3_timer.c
*
* 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 <sys/types.h>
#include <debug.h>
#include "esp32c3_tim_lowerhalf.h"
#include "esp32c3_tim.h"
#include "esp32c3-devkit.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_tim_init
*
* Description:
* Configure the timer driver.
*
* Returned Value:
* Zero (OK) is returned on success; A negated errno value is returned
* to indicate the nature of any failure.
*
****************************************************************************/
int board_tim_init(void)
{
int ret = OK;
#ifdef CONFIG_ESP32C3_TIMER0
ret = esp32c3_timer_initialize("/dev/timer0", ESP32C3_TIMER0);
if (ret < 0)
{
syslog(LOG_ERR,
"ERROR: Failed to initialize timer driver: %d\n",
ret);
return ret;
}
#endif /* CONFIG_ESP32C3_TIMER0 */
#ifdef CONFIG_ESP32C3_TIMER1
ret = esp32c3_timer_initialize("/dev/timer1", ESP32C3_TIMER1);
if (ret < 0)
{
syslog(LOG_ERR,
"ERROR: Failed to initialize timer driver: %d\n",
ret);
return ret;
}
#endif /* CONFIG_ESP32C3_TIMER1 */
return ret;
}