[bsp][pico] add drv_wdt (#7614)

This commit is contained in:
Shicheng Chu 2023-06-06 10:03:16 +08:00 committed by GitHub
parent 26ac806521
commit ff8064c02e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 112 additions and 0 deletions

View File

@ -19,6 +19,9 @@ if GetDepend('BSP_USING_SOFT_SPI'):
if GetDepend('BSP_USING_ADC'):
src += ['drv_adc.c']
if GetDepend('BSP_USING_WDT'):
src += ['drv_wdt.c']
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
Return('group')

View File

@ -0,0 +1,77 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-06-05 Chushicheng the first version
*/
#include "drv_wdt.h"
#include <hardware/watchdog.h>
#define DBG_TAG "drv.wdt"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
static struct pico_wdt pico_wdt_obj;
static rt_err_t wdt_init(rt_watchdog_t *wdt)
{
return RT_EOK;
}
static rt_err_t wdt_control(rt_watchdog_t *wdt, int cmd, void *arg)
{
static rt_uint32_t delay_ms;
switch (cmd)
{
/* feed the watchdog */
case RT_DEVICE_CTRL_WDT_KEEPALIVE:
watchdog_update();
break;
/* set watchdog timeout */
case RT_DEVICE_CTRL_WDT_SET_TIMEOUT:
delay_ms = *((rt_uint32_t*)arg) * 1000;
watchdog_reboot(0, RT_NULL, delay_ms);
break;
case RT_DEVICE_CTRL_WDT_GET_TIMEOUT:
(*((rt_uint32_t*)arg)) = watchdog_get_count();
break;
case RT_DEVICE_CTRL_WDT_START:
watchdog_enable(delay_ms, 1);
pico_wdt_obj.is_start = 1;
break;
default:
LOG_W("This command is not supported.");
return -RT_ERROR;
}
return RT_EOK;
}
static const struct rt_watchdog_ops ops =
{
.init = wdt_init,
.control = wdt_control,
};
int rt_hw_wdt_init(void)
{
int result = RT_EOK;
pico_wdt_obj.watchdog.ops = &ops;
/* register wdt device */
if (rt_hw_watchdog_register(&pico_wdt_obj.watchdog, "wdt", RT_DEVICE_FLAG_DEACTIVATE, RT_NULL) == RT_EOK)
{
LOG_D("wdt init success");
}
else
{
LOG_E("wdt register failed");
result = -RT_ERROR;
}
return result;
}
INIT_BOARD_EXPORT(rt_hw_wdt_init);

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-06-05 Chushicheng the first version
*/
#ifndef DRV_WDT_H
#define DRV_WDT_H
#include <rtdevice.h>
/* pico wdt driver class */
struct pico_wdt
{
rt_watchdog_t watchdog;
rt_uint16_t is_start;
};
int rt_hw_wdt_init(void);
#endif /* DRV_WDT_H */

View File

@ -114,6 +114,11 @@ menu "On-chip Peripheral Drivers"
bool "Enable ADC2 (GP28)"
default n
endif
config BSP_USING_WDT
bool "Enable WDT"
select RT_USING_WDT
default n
endmenu
endmenu

View File

@ -12,6 +12,7 @@ pico-sdk/src/rp2_common/pico_multicore/multicore.c
pico-sdk/src/rp2_common/pico_stdlib/stdlib.c
pico-sdk/src/rp2_common/hardware_gpio/gpio.c
pico-sdk/src/rp2_common/hardware_adc/adc.c
pico-sdk/src/rp2_common/hardware_watchdog/watchdog.c
pico-sdk/src/rp2_common/hardware_claim/claim.c
pico-sdk/src/rp2_common/hardware_sync/sync.c
pico-sdk/src/rp2_common/pico_platform/platform.c
@ -67,6 +68,7 @@ path = [
cwd + '/pico-sdk/src/common/pico_stdlib/include',
cwd + '/pico-sdk/src/rp2_common/hardware_gpio/include',
cwd + '/pico-sdk/src/rp2_common/hardware_adc/include',
cwd + '/pico-sdk/src/rp2_common/hardware_watchdog/include',
cwd + '/pico-sdk/src/common/pico_base/include',
cwd + '/pico-sdk/src/boards/include',
cwd + '/pico-sdk/src/rp2_common/pico_platform/include',