xtensa/esp32-s2: Adds support to the timer driver

Only one more support for ESP32-S2 chip.
This commit is contained in:
Sara Souza
2021-08-23 09:15:49 -03:00
committed by Gustavo Henrique Nihei
parent afc0e2f0f4
commit 8081228556
9 changed files with 1986 additions and 171 deletions
+6
View File
@@ -75,3 +75,9 @@ ifeq ($(CONFIG_ESP32S2_UART),y)
CMN_CSRCS += esp32s2_serial.c
endif
ifeq ($(CONFIG_ESP32S2_TIMER),y)
CHIP_CSRCS += esp32s2_tim.c
ifeq ($(CONFIG_TIMER),y)
CHIP_CSRCS += esp32s2_tim_lowerhalf.c
endif
endif
File diff suppressed because it is too large Load Diff
+138
View File
@@ -0,0 +1,138 @@
/****************************************************************************
* arch/xtensa/src/esp32s2/esp32s2_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_XTENSA_SRC_ESP32S2_ESP32S2_TIM_H
#define __ARCH_XTENSA_SRC_ESP32S2_ESP32S2_TIM_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <nuttx/irq.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Helpers ******************************************************************/
#define ESP32S2_TIM_START(d) ((d)->ops->start(d))
#define ESP32S2_TIM_STOP(d) ((d)->ops->stop(d))
#define ESP32S2_TIM_CLEAR(d) ((d)->ops->clear(d))
#define ESP32S2_TIM_SETMODE(d, m) ((d)->ops->setmode(d, m))
#define ESP32S2_TIM_SETPRE(d, p) ((d)->ops->setpre(d, p))
#define ESP32S2_TIM_GETCTR(d, v) ((d)->ops->getcounter(d, v))
#define ESP32S2_TIM_CLK_SRC(d, s) ((d)->ops->setclksrc(d, s))
#define ESP32S2_TIM_SETCTR(d, v) ((d)->ops->setcounter(d, v))
#define ESP32S2_TIM_RLD_NOW(d) ((d)->ops->reloadnow(d))
#define ESP32S2_TIM_GETALRVL(d, v) ((d)->ops->getalarmvalue(d, v))
#define ESP32S2_TIM_SETALRVL(d, v) ((d)->ops->setalarmvalue(d, v))
#define ESP32S2_TIM_SETALRM(d, e) ((d)->ops->setalarm(d, e))
#define ESP32S2_TIM_SETARLD(d, e) ((d)->ops->setautoreload(d, e))
#define ESP32S2_TIM_SETISR(d, hnd, arg) ((d)->ops->setisr(d, hnd, arg))
#define ESP32S2_TIM_ENABLEINT(d) ((d)->ops->enableint(d))
#define ESP32S2_TIM_DISABLEINT(d) ((d)->ops->disableint(d))
#define ESP32S2_TIM_ACKINT(d) ((d)->ops->ackint(d))
#define ESP32S2_TIM_CHECKINT(d) ((d)->ops->checkint(d))
#define TIMER0 0
#define TIMER1 1
#define TIMER2 2
#define TIMER3 3
/****************************************************************************
* Public Types
****************************************************************************/
/* Timer mode */
enum esp32s2_tim_mode_e
{
ESP32S2_TIM_MODE_DOWN,
ESP32S2_TIM_MODE_UP,
};
/* Timer mode */
enum esp32s2_tim_clksrc_e
{
ESP32S2_TIM_APB_CLK,
ESP32S2_TIM_XTAL_CLK,
};
/* ESP32-S2 TIM device */
struct esp32s2_tim_dev_s
{
struct esp32s2_tim_ops_s *ops;
};
/* ESP32-S2 TIM ops */
/* This is a struct containing the pointers to the timer operations */
struct esp32s2_tim_ops_s
{
/* Timer tasks */
CODE void (*start)(FAR struct esp32s2_tim_dev_s *dev);
CODE void (*stop)(FAR struct esp32s2_tim_dev_s *dev);
CODE void (*clear)(FAR struct esp32s2_tim_dev_s *dev);
/* Timer operations */
CODE void (*setmode)(FAR struct esp32s2_tim_dev_s *dev,
enum esp32s2_tim_mode_e mode);
CODE void (*setpre)(FAR struct esp32s2_tim_dev_s *dev, uint16_t pre);
CODE void (*getcounter)(FAR struct esp32s2_tim_dev_s *dev,
uint64_t *value);
CODE void (*setclksrc)(FAR struct esp32s2_tim_dev_s *dev,
enum esp32s2_tim_clksrc_e src);
CODE void (*setcounter)(FAR struct esp32s2_tim_dev_s *dev, uint64_t value);
CODE void (*reloadnow)(FAR struct esp32s2_tim_dev_s *dev);
CODE void (*getalarmvalue)(FAR struct esp32s2_tim_dev_s *dev,
uint64_t *value);
CODE void (*setalarmvalue)(FAR struct esp32s2_tim_dev_s *dev,
uint64_t value);
CODE void (*setalarm)(FAR struct esp32s2_tim_dev_s *dev, bool enable);
CODE void (*setautoreload)(FAR struct esp32s2_tim_dev_s *dev, bool enable);
/* Timer interrupts */
CODE int (*setisr)(FAR struct esp32s2_tim_dev_s *dev, xcpt_t handler,
FAR void * arg);
CODE void (*enableint)(FAR struct esp32s2_tim_dev_s *dev);
CODE void (*disableint)(FAR struct esp32s2_tim_dev_s *dev);
CODE void (*ackint)(FAR struct esp32s2_tim_dev_s *dev);
CODE int (*checkint)(FAR struct esp32s2_tim_dev_s *dev);
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
FAR struct esp32s2_tim_dev_s *esp32s2_tim_init(int timer);
void esp32s2_tim_deinit(FAR struct esp32s2_tim_dev_s *dev);
#endif /* __ARCH_XTENSA_SRC_ESP32S2_ESP32S2_TIM_H */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,42 @@
/****************************************************************************
* arch/xtensa/src/esp32s2/esp32s2_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_XTENSA_SRC_ESP32S2_ESP32S2_TIM_LOWERHALF_H
#define __ARCH_XTENSA_SRC_ESP32S2_ESP32S2_TIM_LOWERHALF_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <esp32s2_tim.h>
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: esp32s2_timer_initialize
****************************************************************************/
int esp32s2_timer_initialize(FAR const char *devpath, uint8_t timer);
#endif /* __ARCH_XTENSA_SRC_ESP32S2_ESP32S2_TIM_LOWERHALF_H */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,56 @@
#
# 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_ARCH_LEDS is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
# CONFIG_NSH_CMDPARMS is not set
CONFIG_ARCH="xtensa"
CONFIG_ARCH_BOARD="esp32s2-saola-1"
CONFIG_ARCH_BOARD_ESP32S2_SAOLA_1=y
CONFIG_ARCH_CHIP="esp32s2"
CONFIG_ARCH_CHIP_ESP32S2=y
CONFIG_ARCH_CHIP_ESP32S2WROVER=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARCH_XTENSA=y
CONFIG_BOARD_LOOPSPERMSEC=16717
CONFIG_BUILTIN=y
CONFIG_DEV_GPIO=y
CONFIG_ESP32S2_DATA_CACHE_0KB=y
CONFIG_ESP32S2_GPIO_IRQ=y
CONFIG_ESP32S2_TIMER0=y
CONFIG_ESP32S2_TIMER1=y
CONFIG_ESP32S2_TIMER2=y
CONFIG_ESP32S2_TIMER3=y
CONFIG_ESP32S2_UART0=y
CONFIG_EXAMPLES_TIMER=y
CONFIG_EXAMPLES_TIMER_GPOUT=y
CONFIG_FS_PROCFS=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_IDLETHREAD_STACKSIZE=3072
CONFIG_INTELHEX_BINARY=y
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_RAM_SIZE=114688
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_START_DAY=6
CONFIG_START_MONTH=12
CONFIG_START_YEAR=2011
CONFIG_SYSTEM_NSH=y
CONFIG_TIMER=y
CONFIG_TIMER_ARCH=y
CONFIG_UART0_SERIAL_CONSOLE=y
CONFIG_USER_ENTRYPOINT="nsh_main"
@@ -39,6 +39,13 @@
#define BUTTON_BOOT 0
/* TIMERS */
#define TIMER0 0
#define TIMER1 1
#define TIMER2 2
#define TIMER3 3
/****************************************************************************
* Public Types
****************************************************************************/
@@ -46,6 +46,10 @@
# include <nuttx/input/buttons.h>
#endif
#ifdef CONFIG_TIMER
# include "esp32s2_tim_lowerhalf.h"
#endif
#include "esp32s2-saola-1.h"
/****************************************************************************
@@ -100,6 +104,56 @@ int esp32s2_bringup(void)
}
#endif
/* Register the timer drivers */
#ifdef CONFIG_TIMER
#ifdef CONFIG_ESP32S2_TIMER0
ret = esp32s2_timer_initialize("/dev/timer0", TIMER0);
if (ret < 0)
{
syslog(LOG_ERR,
"ERROR: Failed to initialize timer driver: %d\n",
ret);
return ret;
}
#endif
#ifdef CONFIG_ESP32S2_TIMER1
ret = esp32s2_timer_initialize("/dev/timer1", TIMER1);
if (ret < 0)
{
syslog(LOG_ERR,
"ERROR: Failed to initialize timer driver: %d\n",
ret);
return ret;
}
#endif
#ifdef CONFIG_ESP32S2_TIMER2
ret = esp32s2_timer_initialize("/dev/timer2", TIMER2);
if (ret < 0)
{
syslog(LOG_ERR,
"ERROR: Failed to initialize timer driver: %d\n",
ret);
return ret;
}
#endif
#ifdef CONFIG_ESP32S2_TIMER3
ret = esp32s2_timer_initialize("/dev/timer3", TIMER3);
if (ret < 0)
{
syslog(LOG_ERR,
"ERROR: Failed to initialize timer driver: %d\n",
ret);
return ret;
}
#endif
#endif /* CONFIG_TIMER */
/* If we got here then perhaps not all initialization was successful, but
* at least enough succeeded to bring-up NSH with perhaps reduced
* capabilities.