add raspi3-64 wdt driver

This commit is contained in:
bigmagic 2020-03-01 11:50:22 +08:00
parent 972f28476c
commit d5f8397009
5 changed files with 58 additions and 37 deletions

View File

@ -114,4 +114,26 @@ int rt_hw_wdt_init(void)
} }
INIT_DEVICE_EXPORT(rt_hw_wdt_init); INIT_DEVICE_EXPORT(rt_hw_wdt_init);
/**
* Reboot
*/
int reboot(void)
{
unsigned int r;
rt_kprintf("reboot system...\n");
rt_thread_mdelay(100);
// trigger a restart by instructing the GPU to boot from partition 0
r = PM_RSTS; r &= ~0xfffffaaa;
PM_RSTS = PM_PASSWORD | r; // boot from partition 0
PM_WDOG = PM_PASSWORD | 10;
PM_RSTC = PM_PASSWORD | PM_RSTC_WRCFG_FULL_RESET;
while (1);
return 0;
}
MSH_CMD_EXPORT(reboot,reboot system...);
#endif /*BSP_USING_WDT */ #endif /*BSP_USING_WDT */

View File

@ -164,7 +164,7 @@ CONFIG_RT_MMCSD_THREAD_PREORITY=22
CONFIG_RT_MMCSD_MAX_PARTITION=16 CONFIG_RT_MMCSD_MAX_PARTITION=16
CONFIG_RT_SDIO_DEBUG=y CONFIG_RT_SDIO_DEBUG=y
# CONFIG_RT_USING_SPI is not set # CONFIG_RT_USING_SPI is not set
# CONFIG_RT_USING_WDT is not set CONFIG_RT_USING_WDT=y
# CONFIG_RT_USING_AUDIO is not set # CONFIG_RT_USING_AUDIO is not set
# CONFIG_RT_USING_SENSOR is not set # CONFIG_RT_USING_SENSOR is not set
# CONFIG_RT_USING_TOUCH is not set # CONFIG_RT_USING_TOUCH is not set
@ -470,7 +470,7 @@ CONFIG_RT_USING_SYSTIMER1=y
CONFIG_RT_USING_SYSTIMER3=y CONFIG_RT_USING_SYSTIMER3=y
# CONFIG_BSP_USING_I2C is not set # CONFIG_BSP_USING_I2C is not set
# CONFIG_BSP_USING_SPI is not set # CONFIG_BSP_USING_SPI is not set
# CONFIG_BSP_USING_WDT is not set CONFIG_BSP_USING_WDT=y
# CONFIG_BSP_USING_RTC is not set # CONFIG_BSP_USING_RTC is not set
CONFIG_BSP_USING_SDIO=y CONFIG_BSP_USING_SDIO=y
CONFIG_BSP_USING_SDIO0=y CONFIG_BSP_USING_SDIO0=y

View File

@ -8,30 +8,14 @@
* 2019-07-29 zdzn first version * 2019-07-29 zdzn first version
*/ */
#include "drv_wdt.h" #include "drv_wdt.h"
#include "raspi.h"
#ifdef BSP_USING_WDT #ifdef BSP_USING_WDT
#define PM_RSTC 0x1c
#define PM_RSTS 0x20
#define PM_WDOG 0x24
#define PM_PASSWORD 0x5a000000
#define PM_WDOG_TIME_SET 0x000fffff
#define PM_RSTC_WRCFG_CLR 0xffffffcf
#define PM_RSTS_HADWRH_SET 0x00000040
#define PM_RSTC_WRCFG_SET 0x00000030
#define PM_RSTC_WRCFG_FULL_RESET 0x00000020
#define PM_RSTC_RESET 0x00000102
#define PM_RSTS_PARTITION_CLR 0xfffffaaa
#define SECS_TO_WDOG_TICKS(x) ((x) << 16) #define SECS_TO_WDOG_TICKS(x) ((x) << 16)
#define WDOG_TICKS_TO_SECS(x) ((x) >> 16) #define WDOG_TICKS_TO_SECS(x) ((x) >> 16)
static struct raspi_wdt_driver bcm_wdt = static struct raspi_wdt_driver bcm_wdt;
{
.base = PER_BASE,
};
void raspi_watchdog_init(rt_uint32_t time_init) void raspi_watchdog_init(rt_uint32_t time_init)
{ {
@ -41,21 +25,14 @@ void raspi_watchdog_init(rt_uint32_t time_init)
void raspi_watchdog_start() void raspi_watchdog_start()
{ {
volatile rt_uint32_t cur; volatile rt_uint32_t cur;
bcm283x_peri_write(bcm_wdt.base + PM_WDOG, PM_PASSWORD PM_WDOG = PM_PASSWORD | (SECS_TO_WDOG_TICKS(bcm_wdt.timeout) & PM_WDOG_TIME_SET);
| (SECS_TO_WDOG_TICKS(bcm_wdt.timeout) & PM_WDOG_TIME_SET)); cur = PM_RSTC;
bcm283x_peri_write(bcm_wdt.base + PM_WDOG, PM_PASSWORD PM_RSTC = PM_PASSWORD | (cur & PM_RSTC_WRCFG_CLR) | PM_RSTC_WRCFG_FULL_RESET;
| (SECS_TO_WDOG_TICKS(bcm_wdt.timeout) & PM_WDOG_TIME_SET));
cur = bcm283x_peri_read(bcm_wdt.base + PM_RSTC);
bcm283x_peri_write(bcm_wdt.base + PM_RSTC, PM_PASSWORD
| (cur & PM_RSTC_WRCFG_CLR) | PM_RSTC_WRCFG_FULL_RESET);
} }
void raspi_watchdog_stop() void raspi_watchdog_stop()
{ {
bcm283x_peri_write(bcm_wdt.base + PM_RSTC, PM_PASSWORD | PM_RSTC_RESET); PM_RSTC = PM_PASSWORD | PM_RSTC_RESET;
} }
void raspi_watchdog_clr() void raspi_watchdog_clr()
@ -63,7 +40,7 @@ void raspi_watchdog_clr()
bcm_wdt.timeout = 0; bcm_wdt.timeout = 0;
} }
void raspi_watchdog_set_timeout( rt_uint32_t timeout_us) void raspi_watchdog_set_timeout(rt_uint32_t timeout_us)
{ {
bcm_wdt.timeout = timeout_us; bcm_wdt.timeout = timeout_us;
} }
@ -75,7 +52,7 @@ rt_uint64_t raspi_watchdog_get_timeout()
rt_uint64_t raspi_watchdog_get_timeleft() rt_uint64_t raspi_watchdog_get_timeleft()
{ {
rt_uint32_t ret = bcm283x_peri_read(bcm_wdt.base + PM_WDOG); rt_uint32_t ret = PM_WDOG;
return WDOG_TICKS_TO_SECS(ret & PM_WDOG_TIME_SET); return WDOG_TICKS_TO_SECS(ret & PM_WDOG_TIME_SET);
} }
@ -136,5 +113,28 @@ int rt_hw_wdt_init(void)
rt_hw_watchdog_register(&raspi_wdg, "wdg", 0, RT_NULL); rt_hw_watchdog_register(&raspi_wdg, "wdg", 0, RT_NULL);
return RT_EOK; return RT_EOK;
} }
INIT_DEVICE_EXPORT(rt_hw_wdt_init); INIT_DEVICE_EXPORT(rt_hw_wdt_init);
/**
* Reboot
*/
int reboot(void)
{
unsigned int r;
rt_kprintf("reboot system...\n");
rt_thread_mdelay(100);
// trigger a restart by instructing the GPU to boot from partition 0
r = PM_RSTS; r &= ~0xfffffaaa;
PM_RSTS = PM_PASSWORD | r; // boot from partition 0
PM_WDOG = PM_PASSWORD | 10;
PM_RSTC = PM_PASSWORD | PM_RSTC_WRCFG_FULL_RESET;
while (1);
return 0;
}
MSH_CMD_EXPORT(reboot,reboot system...);
#endif /*BSP_USING_WDT */ #endif /*BSP_USING_WDT */

View File

@ -11,16 +11,13 @@
#ifndef __DRV_WDT_H__ #ifndef __DRV_WDT_H__
#define __DRV_WDT_H__ #define __DRV_WDT_H__
#include <rtdef.h>
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h> #include <rtdevice.h>
#include <drivers/watchdog.h>
#include "bcm283x.h" #include "board.h"
struct raspi_wdt_driver struct raspi_wdt_driver
{ {
volatile rt_uint32_t base;
rt_uint32_t timeout; rt_uint32_t timeout;
}; };

View File

@ -110,6 +110,7 @@
#define RT_MMCSD_THREAD_PREORITY 22 #define RT_MMCSD_THREAD_PREORITY 22
#define RT_MMCSD_MAX_PARTITION 16 #define RT_MMCSD_MAX_PARTITION 16
#define RT_SDIO_DEBUG #define RT_SDIO_DEBUG
#define RT_USING_WDT
/* Using USB */ /* Using USB */
@ -197,6 +198,7 @@
#define BSP_USING_SYSTIMER #define BSP_USING_SYSTIMER
#define RT_USING_SYSTIMER1 #define RT_USING_SYSTIMER1
#define RT_USING_SYSTIMER3 #define RT_USING_SYSTIMER3
#define BSP_USING_WDT
#define BSP_USING_SDIO #define BSP_USING_SDIO
#define BSP_USING_SDIO0 #define BSP_USING_SDIO0