xtensa/esp32s3: 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:
Gustavo Henrique Nihei
2022-02-22 10:31:36 -03:00
committed by Xiang Xiao
parent 9603b8f67c
commit b49ee3d4ed
8 changed files with 5109 additions and 2 deletions
+31
View File
@@ -306,6 +306,10 @@ config ESP32S3_TIMER
bool
default n
config ESP32S3_WDT
bool
default n
config ESP32S3_UART0
bool "UART 0"
default n
@@ -355,6 +359,33 @@ config ESP32S3_TIMER3
---help---
Enables Timer 3
config ESP32S3_MWDT0
bool "Main System Watchdog Timer (Group 0)"
default n
select ESP32S3_WDT
---help---
Includes MWDT0. This watchdog timer is part of the Group 0
timer submodule.
config ESP32S3_MWDT1
bool "Main System Watchdog Timer (Group 1)"
default n
select ESP32S3_WDT
---help---
Includes MWDT1. This watchdog timer is part of the Group 0
timer submodule.
config ESP32S3_RWDT
bool "RTC Watchdog Timer"
default n
select ESP32S3_WDT
---help---
Includes RWDT. This watchdog timer is from the RTC module.
When it is selected, if the developer sets it to reset on expiration
it will reset Main System and the RTC module. If you don't want
to have the RTC module reset, please, use the Timers' Module WDTs.
They will only reset Main System.
endmenu # ESP32-S3 Peripheral Selection
menu "UART configuration"
+4
View File
@@ -79,3 +79,7 @@ ifeq ($(CONFIG_TIMER),y)
CHIP_CSRCS += esp32s3_tim_lowerhalf.c
endif
endif
ifeq ($(CONFIG_WATCHDOG),y)
CHIP_CSRCS += esp32s3_wdt_lowerhalf.c
endif
File diff suppressed because it is too large Load Diff
+115
View File
@@ -25,10 +25,125 @@
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <nuttx/irq.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Helpers ******************************************************************/
#define ESP32S3_WDT_START(d) ((d)->ops->start(d))
#define ESP32S3_WDT_STOP(d) ((d)->ops->stop(d))
#define ESP32S3_WDT_LOCK(d) ((d)->ops->enablewp(d))
#define ESP32S3_WDT_UNLOCK(d) ((d)->ops->disablewp(d))
#define ESP32S3_MWDT_PRE(d, v) ((d)->ops->pre(d, v))
#define ESP32S3_WDT_STO(d, v, s) ((d)->ops->settimeout(d, v, s))
#define ESP32S3_WDT_FEED(d) ((d)->ops->feed(d))
#define ESP32S3_WDT_STG_CONF(d, s, c) ((d)->ops->stg_conf(d, s, c))
#define ESP32S3_RWDT_CLK(d) ((d)->ops->rtc_clk(d))
#define ESP32S3_WDT_SETISR(d, hnd, arg) ((d)->ops->setisr(d, hnd, arg))
#define ESP32S3_WDT_ENABLEINT(d) ((d)->ops->enableint(d))
#define ESP32S3_WDT_DISABLEINT(d) ((d)->ops->disableint(d))
#define ESP32S3_WDT_ACKINT(d) ((d)->ops->ackint(d))
/****************************************************************************
* Public Types
****************************************************************************/
/* Instances of Watchdog Timer */
enum esp32s3_wdt_inst_e
{
ESP32S3_WDT_MWDT0 = 0, /* Main System Watchdog Timer (MWDT) of Timer Group 0 */
ESP32S3_WDT_MWDT1, /* Main System Watchdog Timer (MWDT) of Timer Group 1 */
ESP32S3_WDT_RWDT /* RTC Watchdog Timer (RWDT) */
};
/* Stages of a Watchdog Timer. A WDT has 4 stages. */
enum esp32s3_wdt_stage_e
{
ESP32S3_WDT_STAGE0 = 0, /* Stage 0 */
ESP32S3_WDT_STAGE1 = 1, /* Stage 1 */
ESP32S3_WDT_STAGE2 = 2, /* Stage 2 */
ESP32S3_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 esp32s3_wdt_stage_action_e
{
ESP32S3_WDT_STAGE_ACTION_OFF = 0, /* Disabled. This stage will have no effects on the system. */
ESP32S3_WDT_STAGE_ACTION_INT = 1, /* Trigger an interrupt when the stage expires. */
ESP32S3_WDT_STAGE_ACTION_RESET_CPU = 2, /* Reset a CPU core when the stage expires. */
ESP32S3_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.
*/
ESP32S3_WDT_STAGE_ACTION_RESET_RTC = 4 /* Reset the main system and the RTC when the stage expires.
* ONLY AVAILABLE FOR RWDT.
*/
};
/* ESP32-S3 WDT device */
struct esp32s3_wdt_dev_s
{
struct esp32s3_wdt_ops_s *ops;
};
/* ESP32-S3 WDT operations
*
* This is a struct containing the pointers to the WDT operations.
*/
struct esp32s3_wdt_ops_s
{
/* WDT tasks */
void (*start)(struct esp32s3_wdt_dev_s *dev);
void (*stop)(struct esp32s3_wdt_dev_s *dev);
/* WDT configuration */
void (*enablewp)(struct esp32s3_wdt_dev_s *dev);
void (*disablewp)(struct esp32s3_wdt_dev_s *dev);
void (*pre)(struct esp32s3_wdt_dev_s *dev, uint16_t value);
int32_t (*settimeout)(struct esp32s3_wdt_dev_s *dev,
uint32_t value,
enum esp32s3_wdt_stage_e stage);
void (*feed)(struct esp32s3_wdt_dev_s *dev);
int32_t (*stg_conf)(struct esp32s3_wdt_dev_s *dev,
enum esp32s3_wdt_stage_e stage,
enum esp32s3_wdt_stage_action_e conf);
uint16_t (*rtc_clk)(struct esp32s3_wdt_dev_s *dev);
/* WDT interrupts */
int32_t (*setisr)(struct esp32s3_wdt_dev_s *dev, xcpt_t handler,
void *arg);
void (*enableint)(struct esp32s3_wdt_dev_s *dev);
void (*disableint)(struct esp32s3_wdt_dev_s *dev);
void (*ackint)(struct esp32s3_wdt_dev_s *dev);
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
struct esp32s3_wdt_dev_s *esp32s3_wdt_init(enum esp32s3_wdt_inst_e wdt_id);
void esp32s3_wdt_early_deinit(void);
void esp32s3_wdt_deinit(struct esp32s3_wdt_dev_s *dev);
bool esp32s3_wdt_is_running(struct esp32s3_wdt_dev_s *dev);
#endif /* __ARCH_XTENSA_SRC_ESP32S3_ESP32S3_WDT_H */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,57 @@
/****************************************************************************
* arch/xtensa/src/esp32s3/esp32s3_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_ESP32S3_ESP32S3_WDT_LOWERHALF_H
#define __ARCH_XTENSA_SRC_ESP32S3_ESP32S3_WDT_LOWERHALF_H
/****************************************************************************
* Included Files
****************************************************************************/
#include "esp32s3_wdt.h"
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: esp32s3_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 esp32s3_wdt_initialize(const char *devpath, enum esp32s3_wdt_inst_e wdt);
#endif /* __ARCH_XTENSA_SRC_ESP32S3_ESP32S3_WDT_LOWERHALF_H */
File diff suppressed because it is too large Load Diff
@@ -31,12 +31,49 @@
* Pre-processor Definitions
****************************************************************************/
/* Offset relative to each watchdog timer instance memory base */
#define RWDT_CONFIG0_OFFSET 0x0090
/* RWDT */
#define RWDT_STAGE0_TIMEOUT_OFFSET 0x0094
#define RWDT_STAGE1_TIMEOUT_OFFSET 0x0098
#define RWDT_STAGE2_TIMEOUT_OFFSET 0x009c
#define RWDT_STAGE3_TIMEOUT_OFFSET 0x00a0
#define RWDT_FEED_OFFSET 0x00a4
#define RWDT_WP_REG 0x00a8
#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
/* 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
/* Possible values for RTC_CNTL_WDT_CPU_RESET_LENGTH
* and RTC_CNTL_WDT_SYS_RESET_LENGTH
*/
#define RTC_WDT_RESET_LENGTH_100_NS 0
#define RTC_WDT_RESET_LENGTH_200_NS 1
#define RTC_WDT_RESET_LENGTH_300_NS 2
#define RTC_WDT_RESET_LENGTH_400_NS 3
#define RTC_WDT_RESET_LENGTH_500_NS 4
#define RTC_WDT_RESET_LENGTH_800_NS 5
#define RTC_WDT_RESET_LENGTH_1600_NS 6
#define RTC_WDT_RESET_LENGTH_3200_NS 7
#define RTC_CNTL_TIME0_REG RTC_CNTL_TIME_LOW0_REG
#define RTC_CNTL_TIME1_REG RTC_CNTL_TIME_HIGH0_REG
/* RTC_CNTL_RTC_OPTIONS0_REG register
* RTC common configure register
*/