mirror of
https://github.com/apache/nuttx.git
synced 2026-03-23 14:05:12 +08:00
arch/risc-v/k210: Add Watchdog Timer (WDT) driver support.
Add WDT driver for K210 with support for both WDT0 and WDT1 peripherals. This includes: - Add k210_wdt.c and k210_wdt.h driver files with interrupt-based watchdog timer functionality - Add hardware register definitions in k210_wdt.h - Add K210_WDT, K210_WDT0, K210_WDT1 Kconfig options - Add memory map definitions for WDT0 (0x50400000) and WDT1 (0x50410000) - Reorder WDT IRQ definitions (IRQ 21, 22) before UART0 (IRQ 33) in irq.h - Add WDT initialization in board bringup for maix-bit Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
@@ -22,6 +22,20 @@ The driver supports querying clock frequencies for:
|
|||||||
CPU frequency can be configured at build time using the ``K210_CPU_FREQ``
|
CPU frequency can be configured at build time using the ``K210_CPU_FREQ``
|
||||||
Kconfig option (default: 400 MHz, range: 40-600 MHz).
|
Kconfig option (default: 400 MHz, range: 40-600 MHz).
|
||||||
|
|
||||||
|
Watchdog Timers
|
||||||
|
===============
|
||||||
|
|
||||||
|
The K210 has two independent watchdog timers (WDT0 and WDT1) for system
|
||||||
|
reliability. Both are accessible as character drivers via the standard
|
||||||
|
NuttX watchdog interface.
|
||||||
|
|
||||||
|
* **WDT0**: Base address ``0x50400000``, IRQ 21
|
||||||
|
* **WDT1**: Base address ``0x50410000``, IRQ 22
|
||||||
|
* **Timeout range**: Programmable based on 16-bit counter
|
||||||
|
|
||||||
|
Enable via Kconfig: ``CONFIG_K210_WDT`` (automatically selects
|
||||||
|
``CONFIG_WATCHDOG``). Devices are ``/dev/watchdog0`` and ``/dev/watchdog1``.
|
||||||
|
|
||||||
Supported Boards
|
Supported Boards
|
||||||
================
|
================
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,8 @@
|
|||||||
#ifdef CONFIG_K210_WITH_QEMU
|
#ifdef CONFIG_K210_WITH_QEMU
|
||||||
#define K210_IRQ_UART0 (RISCV_IRQ_MEXT + 4)
|
#define K210_IRQ_UART0 (RISCV_IRQ_MEXT + 4)
|
||||||
#else
|
#else
|
||||||
|
#define K210_IRQ_WDT0 (RISCV_IRQ_MEXT + 21)
|
||||||
|
#define K210_IRQ_WDT1 (RISCV_IRQ_MEXT + 22)
|
||||||
#define K210_IRQ_UART0 (RISCV_IRQ_MEXT + 33)
|
#define K210_IRQ_UART0 (RISCV_IRQ_MEXT + 33)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -32,4 +32,8 @@ if(CONFIG_BUILD_PROTECTED)
|
|||||||
list(APPEND SRCS k210_userspace.c)
|
list(APPEND SRCS k210_userspace.c)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(CONFIG_K210_WDT)
|
||||||
|
list(APPEND SRCS k210_wdt.c)
|
||||||
|
endif()
|
||||||
|
|
||||||
target_sources(arch PRIVATE ${SRCS})
|
target_sources(arch PRIVATE ${SRCS})
|
||||||
|
|||||||
@@ -25,6 +25,20 @@ config K210_UART0
|
|||||||
select ARCH_HAVE_SERIAL_TERMIOS
|
select ARCH_HAVE_SERIAL_TERMIOS
|
||||||
select K210_UART
|
select K210_UART
|
||||||
|
|
||||||
|
config K210_WDT
|
||||||
|
bool
|
||||||
|
select WATCHDOG
|
||||||
|
|
||||||
|
config K210_WDT0
|
||||||
|
bool "WDT0"
|
||||||
|
default n
|
||||||
|
select K210_WDT
|
||||||
|
|
||||||
|
config K210_WDT1
|
||||||
|
bool "WDT1"
|
||||||
|
default n
|
||||||
|
select K210_WDT
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
config K210_CPU_FREQ
|
config K210_CPU_FREQ
|
||||||
|
|||||||
@@ -35,3 +35,7 @@ CHIP_CSRCS += k210_start.c k210_timerisr.c k210_gpiohs.c k210_sysctl.c
|
|||||||
ifeq ($(CONFIG_BUILD_PROTECTED),y)
|
ifeq ($(CONFIG_BUILD_PROTECTED),y)
|
||||||
CHIP_CSRCS += k210_userspace.c
|
CHIP_CSRCS += k210_userspace.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_K210_WDT),y)
|
||||||
|
CHIP_CSRCS += k210_wdt.c
|
||||||
|
endif
|
||||||
|
|||||||
@@ -40,6 +40,9 @@
|
|||||||
#define K210_GPIOHS_BASE 0x38001000
|
#define K210_GPIOHS_BASE 0x38001000
|
||||||
#define K210_FPIOA_BASE 0x502B0000
|
#define K210_FPIOA_BASE 0x502B0000
|
||||||
|
|
||||||
|
#define K210_WDT0_BASE 0x50400000
|
||||||
|
#define K210_WDT1_BASE 0x50410000
|
||||||
|
|
||||||
#define K210_SYSCTL_BASE 0x50440000
|
#define K210_SYSCTL_BASE 0x50440000
|
||||||
|
|
||||||
#endif /* __ARCH_RISCV_SRC_K210_HARDWARE_K210_MEMORYMAP_H */
|
#endif /* __ARCH_RISCV_SRC_K210_HARDWARE_K210_MEMORYMAP_H */
|
||||||
|
|||||||
54
arch/risc-v/src/k210/hardware/k210_wdt.h
Normal file
54
arch/risc-v/src/k210/hardware/k210_wdt.h
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* arch/risc-v/src/k210/hardware/k210_wdt.h
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* 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_K210_HARDWARE_K210_WDT_H
|
||||||
|
#define __ARCH_RISCV_SRC_K210_HARDWARE_K210_WDT_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#define K210_WDT_CR_OFFSET 0x0000
|
||||||
|
#define K210_WDT_TORR_OFFSET 0x0004
|
||||||
|
#define K210_WDT_CCVR_OFFSET 0x0008
|
||||||
|
#define K210_WDT_CRR_OFFSET 0x000c
|
||||||
|
#define K210_WDT_STAT_OFFSET 0x0010
|
||||||
|
#define K210_WDT_EOI_OFFSET 0x0014
|
||||||
|
#define K210_WDT_PROT_LEVEL_OFFSET 0x001c
|
||||||
|
|
||||||
|
#define K210_WDT_CR(base) ((base) + K210_WDT_CR_OFFSET)
|
||||||
|
#define K210_WDT_TORR(base) ((base) + K210_WDT_TORR_OFFSET)
|
||||||
|
#define K210_WDT_CCVR(base) ((base) + K210_WDT_CCVR_OFFSET)
|
||||||
|
#define K210_WDT_CRR(base) ((base) + K210_WDT_CRR_OFFSET)
|
||||||
|
#define K210_WDT_STAT(base) ((base) + K210_WDT_STAT_OFFSET)
|
||||||
|
#define K210_WDT_EOI(base) ((base) + K210_WDT_EOI_OFFSET)
|
||||||
|
|
||||||
|
#define K210_WDT_CR_ENABLE 0x00000001u
|
||||||
|
#define K210_WDT_CR_RMOD_MASK 0x00000002u
|
||||||
|
#define K210_WDT_CR_RMOD_RESET 0x00000000u
|
||||||
|
#define K210_WDT_CR_RMOD_INTERRUPT 0x00000002u
|
||||||
|
|
||||||
|
#define K210_WDT_TORR_TOP(n) (((n) << 4) | ((n) << 0))
|
||||||
|
|
||||||
|
#define K210_WDT_CRR_RESTART 0x00000076u
|
||||||
|
|
||||||
|
#endif /* __ARCH_RISCV_SRC_K210_HARDWARE_K210_WDT_H */
|
||||||
516
arch/risc-v/src/k210/k210_wdt.c
Normal file
516
arch/risc-v/src/k210/k210_wdt.c
Normal file
File diff suppressed because it is too large
Load Diff
60
arch/risc-v/src/k210/k210_wdt.h
Normal file
60
arch/risc-v/src/k210/k210_wdt.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* arch/risc-v/src/k210/k210_wdt.h
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* 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_K210_K210_WDT_H
|
||||||
|
#define __ARCH_RISCV_SRC_K210_K210_WDT_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
K210_WDT_DEVICE0 = 0,
|
||||||
|
K210_WDT_DEVICE1,
|
||||||
|
K210_WDT_DEVICE_MAX
|
||||||
|
} k210_wdt_id_t;
|
||||||
|
|
||||||
|
#ifndef __ASSEMBLY__
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int k210_wdt_initialize(const char *devpath, k210_wdt_id_t id);
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __ASSEMBLY__ */
|
||||||
|
#endif /* __ARCH_RISCV_SRC_K210_K210_WDT_H */
|
||||||
@@ -35,6 +35,7 @@
|
|||||||
#include <nuttx/fs/fs.h>
|
#include <nuttx/fs/fs.h>
|
||||||
|
|
||||||
#include "k210.h"
|
#include "k210.h"
|
||||||
|
#include "k210_wdt.h"
|
||||||
#include "maix-bit.h"
|
#include "maix-bit.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -68,5 +69,27 @@ int k210_bringup(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_K210_WDT0
|
||||||
|
ret = k210_wdt_initialize(CONFIG_WATCHDOG_DEVPATH, K210_WDT_DEVICE0);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_WARNING, "WARNING: Failed to initialize WDT0: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_K210_WDT1
|
||||||
|
ret = k210_wdt_initialize(
|
||||||
|
#ifdef CONFIG_K210_WDT0
|
||||||
|
"/dev/watchdog1",
|
||||||
|
#else
|
||||||
|
CONFIG_WATCHDOG_DEVPATH,
|
||||||
|
#endif
|
||||||
|
K210_WDT_DEVICE1);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_WARNING, "WARNING: Failed to initialize WDT1: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user