mirror of
https://github.com/apache/nuttx.git
synced 2026-06-07 09:18:00 +08:00
xtensa/esp32s2: Add support for Main System Watchdog Timers
Support for RTC Watchdog Timer is currently in place, but not yet functional due to not yet implemented RTC driver. Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
This commit is contained in:
committed by
Alan Carvalho de Assis
parent
01517b2ebe
commit
140dc248db
@@ -195,10 +195,6 @@ config ESP32S2_RUN_IRAM
|
||||
|
||||
menu "ESP32-S2 Peripheral Selection"
|
||||
|
||||
config ESP32S2_UART
|
||||
bool
|
||||
default n
|
||||
|
||||
config ESP32S2_UART
|
||||
bool
|
||||
default n
|
||||
|
||||
@@ -23,7 +23,7 @@ include chip/Bootloader.mk
|
||||
# The start-up, "head", file. May be either a .S or a .c file.
|
||||
|
||||
HEAD_ASRC = xtensa_vectors.S xtensa_window_vector.S xtensa_windowspill.S
|
||||
HEAD_ASRC += xtensa_int_handlers.S xtensa_user_handler.S
|
||||
HEAD_ASRC += xtensa_int_handlers.S xtensa_user_handler.S
|
||||
HEAD_CSRC = esp32s2_start.c esp32s2_wdt.c
|
||||
|
||||
# Common XTENSA files (arch/xtensa/src/common)
|
||||
@@ -88,6 +88,10 @@ CHIP_CSRCS += esp32s2_tim_lowerhalf.c
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_WATCHDOG),y)
|
||||
CHIP_CSRCS += esp32s2_wdt_lowerhalf.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ESP32S2_FREERUN),y)
|
||||
CHIP_CSRCS += esp32s2_freerun.c
|
||||
endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -25,10 +25,125 @@
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Helpers ******************************************************************/
|
||||
|
||||
#define ESP32S2_WDT_START(d) ((d)->ops->start(d))
|
||||
#define ESP32S2_WDT_STOP(d) ((d)->ops->stop(d))
|
||||
#define ESP32S2_WDT_LOCK(d) ((d)->ops->enablewp(d))
|
||||
#define ESP32S2_WDT_UNLOCK(d) ((d)->ops->disablewp(d))
|
||||
#define ESP32S2_MWDT_PRE(d, v) ((d)->ops->pre(d, v))
|
||||
#define ESP32S2_WDT_STO(d, v, s) ((d)->ops->settimeout(d, v, s))
|
||||
#define ESP32S2_WDT_FEED(d) ((d)->ops->feed(d))
|
||||
#define ESP32S2_WDT_STG_CONF(d, s, c) ((d)->ops->stg_conf(d, s, c))
|
||||
#define ESP32S2_RWDT_CLK(d) ((d)->ops->rtc_clk(d))
|
||||
#define ESP32S2_WDT_SETISR(d, hnd, arg) ((d)->ops->setisr(d, hnd, arg))
|
||||
#define ESP32S2_WDT_ENABLEINT(d) ((d)->ops->enableint(d))
|
||||
#define ESP32S2_WDT_DISABLEINT(d) ((d)->ops->disableint(d))
|
||||
#define ESP32S2_WDT_ACKINT(d) ((d)->ops->ackint(d))
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* Instances of Watchdog Timer */
|
||||
|
||||
enum esp32s2_wdt_inst_e
|
||||
{
|
||||
ESP32S2_WDT_MWDT0 = 0, /* Main System Watchdog Timer (MWDT) of Timer Group 0 */
|
||||
ESP32S2_WDT_MWDT1, /* Main System Watchdog Timer (MWDT) of Timer Group 1 */
|
||||
ESP32S2_WDT_RWDT /* RTC Watchdog Timer (RWDT) */
|
||||
};
|
||||
|
||||
/* Stages of a Watchdog Timer. A WDT has 4 stages. */
|
||||
|
||||
enum esp32s2_wdt_stage_e
|
||||
{
|
||||
ESP32S2_WDT_STAGE0 = 0, /* Stage 0 */
|
||||
ESP32S2_WDT_STAGE1 = 1, /* Stage 1 */
|
||||
ESP32S2_WDT_STAGE2 = 2, /* Stage 2 */
|
||||
ESP32S2_WDT_STAGE3 = 3 /* Stage 3 */
|
||||
};
|
||||
|
||||
/**
|
||||
* Behavior of the WDT stage if it times out.
|
||||
*
|
||||
* @note These enum values should be compatible with the
|
||||
* corresponding register field values.
|
||||
*/
|
||||
|
||||
enum esp32s2_wdt_stage_action_e
|
||||
{
|
||||
ESP32S2_WDT_STAGE_ACTION_OFF = 0, /* Disabled. This stage will have no effects on the system. */
|
||||
ESP32S2_WDT_STAGE_ACTION_INT = 1, /* Trigger an interrupt when the stage expires. */
|
||||
ESP32S2_WDT_STAGE_ACTION_RESET_CPU = 2, /* Reset a CPU core when the stage expires. */
|
||||
ESP32S2_WDT_STAGE_ACTION_RESET_SYSTEM = 3, /* Reset the main system when the stage expires.
|
||||
* This includes the CPU and all peripherals.
|
||||
* The RTC is an exception and will not be reset.
|
||||
*/
|
||||
ESP32S2_WDT_STAGE_ACTION_RESET_RTC = 4 /* Reset the main system and the RTC when the stage expires.
|
||||
* ONLY AVAILABLE FOR RWDT.
|
||||
*/
|
||||
};
|
||||
|
||||
/* ESP32-S2 WDT device */
|
||||
|
||||
struct esp32s2_wdt_dev_s
|
||||
{
|
||||
struct esp32s2_wdt_ops_s *ops;
|
||||
};
|
||||
|
||||
/* ESP32-S2 WDT operations
|
||||
*
|
||||
* This is a struct containing the pointers to the WDT operations.
|
||||
*/
|
||||
|
||||
struct esp32s2_wdt_ops_s
|
||||
{
|
||||
/* WDT tasks */
|
||||
|
||||
void (*start)(struct esp32s2_wdt_dev_s *dev);
|
||||
void (*stop)(struct esp32s2_wdt_dev_s *dev);
|
||||
|
||||
/* WDT configuration */
|
||||
|
||||
void (*enablewp)(struct esp32s2_wdt_dev_s *dev);
|
||||
void (*disablewp)(struct esp32s2_wdt_dev_s *dev);
|
||||
void (*pre)(struct esp32s2_wdt_dev_s *dev, uint16_t value);
|
||||
int32_t (*settimeout)(struct esp32s2_wdt_dev_s *dev,
|
||||
uint32_t value,
|
||||
enum esp32s2_wdt_stage_e stage);
|
||||
void (*feed)(struct esp32s2_wdt_dev_s *dev);
|
||||
int32_t (*stg_conf)(struct esp32s2_wdt_dev_s *dev,
|
||||
enum esp32s2_wdt_stage_e stage,
|
||||
enum esp32s2_wdt_stage_action_e conf);
|
||||
uint16_t (*rtc_clk)(struct esp32s2_wdt_dev_s *dev);
|
||||
|
||||
/* WDT interrupts */
|
||||
|
||||
int32_t (*setisr)(struct esp32s2_wdt_dev_s *dev, xcpt_t handler,
|
||||
void *arg);
|
||||
void (*enableint)(struct esp32s2_wdt_dev_s *dev);
|
||||
void (*disableint)(struct esp32s2_wdt_dev_s *dev);
|
||||
void (*ackint)(struct esp32s2_wdt_dev_s *dev);
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
struct esp32s2_wdt_dev_s *esp32s2_wdt_init(enum esp32s2_wdt_inst_e wdt_id);
|
||||
void esp32s2_wdt_early_deinit(void);
|
||||
void esp32s2_wdt_deinit(struct esp32s2_wdt_dev_s *dev);
|
||||
bool esp32s2_wdt_is_running(struct esp32s2_wdt_dev_s *dev);
|
||||
|
||||
#endif /* __ARCH_XTENSA_SRC_ESP32S2_ESP32S2_WDT_H */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,57 @@
|
||||
/****************************************************************************
|
||||
* arch/xtensa/src/esp32s2/esp32s2_wdt_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_WDT_LOWERHALF_H
|
||||
#define __ARCH_XTENSA_SRC_ESP32S2_ESP32S2_WDT_LOWERHALF_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include "esp32s2_wdt.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32s2_wdt_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the watchdog timer. The watchdog timer is initialized
|
||||
* and registered as 'devpath'.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devpath - The full path to the watchdog.
|
||||
* wdt - WDT instance to be initialized.
|
||||
*
|
||||
* Returned Values:
|
||||
* Zero (OK) is returned on success; a negated errno value is returned on
|
||||
* any failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp32s2_wdt_initialize(const char *devpath, enum esp32s2_wdt_inst_e wdt);
|
||||
|
||||
#endif /* __ARCH_XTENSA_SRC_ESP32S2_ESP32S2_WDT_LOWERHALF_H */
|
||||
@@ -31,11 +31,32 @@
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Offset relative to each watchdog timer instance memory base */
|
||||
|
||||
#define RWDT_CONFIG0_OFFSET 0x0094
|
||||
|
||||
/* RWDT */
|
||||
|
||||
#define RWDT_STAGE0_TIMEOUT_OFFSET 0x0098
|
||||
#define RWDT_STAGE1_TIMEOUT_OFFSET 0x009c
|
||||
#define RWDT_STAGE2_TIMEOUT_OFFSET 0x00a0
|
||||
#define RWDT_STAGE3_TIMEOUT_OFFSET 0x00a4
|
||||
#define RWDT_FEED_OFFSET 0x00a8
|
||||
#define RWDT_WP_REG 0x00ac
|
||||
#define RWDT_INT_ENA_REG_OFFSET 0x0040
|
||||
#define RWDT_INT_CLR_REG_OFFSET 0x004c
|
||||
|
||||
/* The value that needs to be written to RTC_CNTL_WDT_WKEY to
|
||||
* write-enable the wdt registers
|
||||
*/
|
||||
|
||||
#define RTC_CNTL_WDT_WKEY_VALUE 0x50d83aa1
|
||||
#define RTC_CNTL_WDT_WKEY_VALUE 0x50d83aa1
|
||||
|
||||
/* The value that needs to be written to RTC_CNTL_SWD_WPROTECT_REG
|
||||
* to write-enable the wdt registers
|
||||
*/
|
||||
|
||||
#define RTC_CNTL_SWD_WKEY_VALUE 0x8f1d312a
|
||||
|
||||
#define DPORT_CPUPERIOD_SEL_80 0
|
||||
#define DPORT_CPUPERIOD_SEL_160 1
|
||||
|
||||
@@ -31,7 +31,29 @@
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define SHIFT_32 32
|
||||
/* Offset relative to each watchdog timer instance memory base */
|
||||
|
||||
#define MWDT_CONFIG0_OFFSET 0x0048
|
||||
|
||||
/* MWDT */
|
||||
|
||||
#define MWDT_CLK_PRESCALE_OFFSET 0x004c
|
||||
#define MWDT_STAGE0_TIMEOUT_OFFSET 0x0050
|
||||
#define MWDT_STAGE1_TIMEOUT_OFFSET 0x0054
|
||||
#define MWDT_STAGE2_TIMEOUT_OFFSET 0x0058
|
||||
#define MWDT_STAGE3_TIMEOUT_OFFSET 0x005c
|
||||
#define MWDT_FEED_OFFSET 0x0060
|
||||
#define MWDT_WP_REG 0x0064
|
||||
#define MWDT_INT_ENA_REG_OFFSET 0x0098
|
||||
#define MWDT_INT_CLR_REG_OFFSET 0x00a0
|
||||
|
||||
/* The value that needs to be written to TIMG_WDT_WKEY to
|
||||
* write-enable the WDT registers.
|
||||
*/
|
||||
|
||||
#define TIMG_WDT_WKEY_VALUE 0x50d83aa1
|
||||
|
||||
#define SHIFT_32 32
|
||||
|
||||
/* TIMG_T0CONFIG_REG(i) register
|
||||
* Timer 0 configuration register
|
||||
|
||||
Reference in New Issue
Block a user