2021-02-26 13:15:40 -03:00
|
|
|
/****************************************************************************
|
2024-01-04 14:20:50 +03:00
|
|
|
* arch/risc-v/src/esp32c3-legacy/esp32c3_tim.h
|
2021-02-26 13:15:40 -03:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2024-01-04 14:20:50 +03:00
|
|
|
#ifndef __ARCH_RISCV_SRC_ESP32C3_LEGACY_ESP32C3_TIM_H
|
|
|
|
#define __ARCH_RISCV_SRC_ESP32C3_LEGACY_ESP32C3_TIM_H
|
2021-02-26 13:15:40 -03:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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))
|
2021-04-22 17:28:20 -03:00
|
|
|
#define ESP32C3_TIM_CHECKINT(d) ((d)->ops->checkint(d))
|
2021-02-26 13:15:40 -03:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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 */
|
2021-07-08 16:37:55 -03:00
|
|
|
ESP32C3_SYSTIM, /* SYSTIMER 1 */
|
2021-02-26 13:15:40 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
/* 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,
|
|
|
|
};
|
|
|
|
|
2021-04-28 10:20:22 -03:00
|
|
|
/* ESP32-C3 TIM device */
|
2021-02-26 13:15:40 -03:00
|
|
|
|
|
|
|
struct esp32c3_tim_dev_s
|
|
|
|
{
|
|
|
|
struct esp32c3_tim_ops_s *ops;
|
|
|
|
};
|
|
|
|
|
2021-04-28 10:20:22 -03:00
|
|
|
/* ESP32-C3 TIM ops */
|
2021-02-26 13:15:40 -03:00
|
|
|
|
|
|
|
/* This is a struct containing the pointers to the timer operations */
|
|
|
|
|
|
|
|
struct esp32c3_tim_ops_s
|
|
|
|
{
|
|
|
|
/* Timer tasks */
|
|
|
|
|
2021-09-21 16:49:05 -03:00
|
|
|
void (*start)(struct esp32c3_tim_dev_s *dev);
|
|
|
|
void (*stop)(struct esp32c3_tim_dev_s *dev);
|
|
|
|
void (*clear)(struct esp32c3_tim_dev_s *dev);
|
2021-02-26 13:15:40 -03:00
|
|
|
|
|
|
|
/* Timer operations */
|
|
|
|
|
2021-09-21 16:49:05 -03:00
|
|
|
void (*setmode)(struct esp32c3_tim_dev_s *dev,
|
2021-02-26 13:15:40 -03:00
|
|
|
enum esp32c3_tim_mode_e mode);
|
2021-09-21 16:49:05 -03:00
|
|
|
void (*setclksrc)(struct esp32c3_tim_dev_s *dev,
|
2021-02-26 13:15:40 -03:00
|
|
|
enum esp32c3_tim_clksrc_e src);
|
2021-09-21 16:49:05 -03:00
|
|
|
void (*setpre)(struct esp32c3_tim_dev_s *dev, uint16_t pre);
|
|
|
|
void (*getcounter)(struct esp32c3_tim_dev_s *dev,
|
2021-02-26 13:15:40 -03:00
|
|
|
uint64_t *value);
|
2021-09-21 16:49:05 -03:00
|
|
|
void (*setcounter)(struct esp32c3_tim_dev_s *dev, uint64_t value);
|
|
|
|
void (*reloadnow)(struct esp32c3_tim_dev_s *dev);
|
|
|
|
void (*getalarmvalue)(struct esp32c3_tim_dev_s *dev,
|
2021-02-26 13:15:40 -03:00
|
|
|
uint64_t *value);
|
2021-09-21 16:49:05 -03:00
|
|
|
void (*setalarmvalue)(struct esp32c3_tim_dev_s *dev,
|
2021-02-26 13:15:40 -03:00
|
|
|
uint64_t value);
|
2021-09-21 16:49:05 -03:00
|
|
|
void (*setalarm)(struct esp32c3_tim_dev_s *dev, bool enable);
|
|
|
|
void (*setautoreload)(struct esp32c3_tim_dev_s *dev, bool enable);
|
2021-02-26 13:15:40 -03:00
|
|
|
|
|
|
|
/* Timer interrupts */
|
|
|
|
|
2021-09-21 16:49:05 -03:00
|
|
|
int (*setisr)(struct esp32c3_tim_dev_s *dev, xcpt_t handler,
|
2021-09-21 16:48:15 -03:00
|
|
|
void * arg);
|
2021-09-21 16:49:05 -03:00
|
|
|
void (*enableint)(struct esp32c3_tim_dev_s *dev);
|
|
|
|
void (*disableint)(struct esp32c3_tim_dev_s *dev);
|
|
|
|
void (*ackint)(struct esp32c3_tim_dev_s *dev);
|
|
|
|
int (*checkint)(struct esp32c3_tim_dev_s *dev);
|
2021-02-26 13:15:40 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-09-21 16:48:15 -03:00
|
|
|
struct esp32c3_tim_dev_s *esp32c3_tim_init(int timer);
|
|
|
|
void esp32c3_tim_deinit(struct esp32c3_tim_dev_s *dev);
|
2021-02-26 13:15:40 -03:00
|
|
|
|
2024-01-04 14:20:50 +03:00
|
|
|
#endif /* __ARCH_RISCV_SRC_ESP32C3_LEGACY_ESP32C3_TIM_H */
|