[feat] add watchdog
This commit is contained in:
parent
ea852b4dd7
commit
6afed2f349
@ -12,6 +12,7 @@ src/timer.c
|
|||||||
src/dma.c
|
src/dma.c
|
||||||
src/uart.c
|
src/uart.c
|
||||||
src/usb.c
|
src/usb.c
|
||||||
|
src/watchdog.c
|
||||||
)
|
)
|
||||||
|
|
||||||
set(TARGET driver)
|
set(TARGET driver)
|
||||||
|
|||||||
29
driver/inc/reg/watchdog_reg.h
Normal file
29
driver/inc/reg/watchdog_reg.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#ifndef __HARDWARE_WATCHDOG_REG_H__
|
||||||
|
#define __HARDWARE_WATCHDOG_REG_H__
|
||||||
|
|
||||||
|
#define WATCHDOG_TICK_CYCLES_POS (0U)
|
||||||
|
#define WATCHDOG_TICK_CYCLES_MASK (0x1FF << WATCHDOG_TICK_CYCLES_POS)
|
||||||
|
#define WATCHDOG_TICK_ENABLE (1 << 9U)
|
||||||
|
#define WATCHDOG_TICK_RUNNING (1 << 10U)
|
||||||
|
#define WATCHDOG_TICK_COUNT_POS (11U)
|
||||||
|
#define WATCHDOG_TICK_COUNT_MASK (0x1FF << WATCHDOG_TICK_COUNT_POS)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
io_rw_32 ctrl;
|
||||||
|
io_wo_32 load;
|
||||||
|
io_ro_32 reason;
|
||||||
|
io_rw_32 scratch[8];
|
||||||
|
io_rw_32 tick;
|
||||||
|
} watchdog_hw_t;
|
||||||
|
|
||||||
|
#define watchdog_hw ((watchdog_hw_t *const)WATCHDOG_BASE)
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __HARDWARE_WATCHDOG_REG_H__ */
|
||||||
19
driver/inc/watchdog.h
Normal file
19
driver/inc/watchdog.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef __HARDWARE_WATCHDOG_H__
|
||||||
|
#define __HARDWARE_WATCHDOG_H__
|
||||||
|
|
||||||
|
#include "reg.h"
|
||||||
|
#include "watchdog_reg.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void watchdog_start_tick(uint16_t cycles);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __HARDWARE_WATCHDOG_H__ */
|
||||||
6
driver/src/watchdog.c
Normal file
6
driver/src/watchdog.c
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "watchdog.h"
|
||||||
|
|
||||||
|
void watchdog_start_tick(uint16_t cycles)
|
||||||
|
{
|
||||||
|
watchdog_hw->tick = (cycles << WATCHDOG_TICK_CYCLES_POS) | WATCHDOG_TICK_ENABLE;
|
||||||
|
}
|
||||||
@ -56,6 +56,7 @@ void __attribute__((section(".text.boot2_pre"))) boot2_copy_self(void)
|
|||||||
#include "clock.h"
|
#include "clock.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
#include "flash.h"
|
#include "flash.h"
|
||||||
|
#include "watchdog.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
|
|
||||||
@ -224,7 +225,7 @@ int main(void)
|
|||||||
gpio_init(0, GPIO_FUNC_UART | GPIO_PULL_UP | GPIO_DRIVE_4MA); /* UART_TX pin */
|
gpio_init(0, GPIO_FUNC_UART | GPIO_PULL_UP | GPIO_DRIVE_4MA); /* UART_TX pin */
|
||||||
gpio_init(1, GPIO_FUNC_UART | GPIO_PULL_UP | GPIO_SCHMITT | GPIO_PAD_IE | GPIO_PAD_OD); /* UART_RX pin */
|
gpio_init(1, GPIO_FUNC_UART | GPIO_PULL_UP | GPIO_SCHMITT | GPIO_PAD_IE | GPIO_PAD_OD); /* UART_RX pin */
|
||||||
uart_init(UART_ID_0, &uart_cfg);
|
uart_init(UART_ID_0, &uart_cfg);
|
||||||
*(volatile uint32_t *)(WATCHDOG_BASE + 0x2C) = ((1 << 9) | (12 << 0));
|
watchdog_start_tick(12); /* 12MHz / 12 = 1MHz, as 1us */
|
||||||
timer_start();
|
timer_start();
|
||||||
|
|
||||||
gpio_init(2, GPIO_FUNC_NULL | GPIO_PULL_DOWN | GPIO_SCHMITT | GPIO_PAD_IE | GPIO_PAD_OD); /* boot pin */
|
gpio_init(2, GPIO_FUNC_NULL | GPIO_PULL_DOWN | GPIO_SCHMITT | GPIO_PAD_IE | GPIO_PAD_OD); /* boot pin */
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user