49 lines
1.1 KiB
C

#include <stdint.h>
#define UART0_BASE 0x05000000
#define R_WDOG_BASE 0x07020400
#define WDOG_CTRL_KEY (0xA57 << 1)
#define WDOG_CTRL_RESTART (1 << 0)
#define WDOG_CFG_SYS (1 << 0)
#define WDOG_MODE_EN (1 << 0)
struct watchdog {
uint32_t irq_en;
uint32_t irq_sta;
uint32_t res[2];
uint32_t ctrl;
uint32_t cfg;
uint32_t mode;
};
static volatile struct watchdog *const r_wdog = (struct watchdog *) R_WDOG_BASE;
static inline void delay(uint32_t t) {
for (uint32_t i = 0; i < t; ++i) {
asm volatile ("nop");
}
}
static void uart_tx(uint8_t byte) {
*((uint8_t *) UART0_BASE) = byte;
}
static _Noreturn void board_reset(void) {
// NOTE: this seems to be the suggested method for
// h6 board reset according to u-boot
r_wdog->cfg = WDOG_CFG_SYS;
r_wdog->mode = WDOG_MODE_EN;
r_wdog->ctrl = WDOG_CTRL_KEY | WDOG_CTRL_RESTART;
while (1);
}
_Noreturn void kernel_main(uintptr_t dt_phys_addr) {
for (const char *p = "It's alive\r\n"; *p; ++p) {
uart_tx(*p);
delay(1000);
}
board_reset();
}