first commit
This commit is contained in:
5
application/samples/peripheral/watchdog/CMakeLists.txt
Executable file
5
application/samples/peripheral/watchdog/CMakeLists.txt
Executable file
@ -0,0 +1,5 @@
|
||||
#===============================================================================
|
||||
# @brief cmake file
|
||||
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
#===============================================================================
|
||||
set(SOURCES "${SOURCES}" "${CMAKE_CURRENT_SOURCE_DIR}/watchdog_demo.c" PARENT_SCOPE)
|
15
application/samples/peripheral/watchdog/Kconfig
Executable file
15
application/samples/peripheral/watchdog/Kconfig
Executable file
@ -0,0 +1,15 @@
|
||||
#===============================================================================
|
||||
# @brief Kconfig file.
|
||||
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
#===============================================================================
|
||||
config WDT_TIMEOUT_SAMPLE
|
||||
bool
|
||||
prompt "Choose watchdog kick timeout."
|
||||
depends on SAMPLE_SUPPORT_WDT
|
||||
default n
|
||||
|
||||
config WDT_KICK_SAMPLE
|
||||
bool
|
||||
prompt "Choose watchdog kick normally."
|
||||
depends on SAMPLE_SUPPORT_WDT
|
||||
default n
|
11
application/samples/peripheral/watchdog/watchdog.code-workspace
Executable file
11
application/samples/peripheral/watchdog/watchdog.code-workspace
Executable file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "../../../../"
|
||||
}
|
||||
],
|
||||
"settings": {
|
||||
"debug.onTaskErrors": "debugAnyway",
|
||||
"workspace.samplePath": "./samples/peripheral/watchdog"
|
||||
}
|
||||
}
|
69
application/samples/peripheral/watchdog/watchdog_demo.c
Executable file
69
application/samples/peripheral/watchdog/watchdog_demo.c
Executable file
@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
*
|
||||
* Description: WDT Sample Source. \n
|
||||
*
|
||||
* History: \n
|
||||
* 2023-06-29, Create file. \n
|
||||
*/
|
||||
#include "pinctrl.h"
|
||||
#include "watchdog.h"
|
||||
#include "soc_osal.h"
|
||||
#include "app_init.h"
|
||||
|
||||
#define TIME_OUT 2
|
||||
#define WDT_MODE 1
|
||||
#define TEST_PARAM_KICK_TIME 10
|
||||
#define WDT_TASK_DURATION_MS 500
|
||||
|
||||
#define WDT_TASK_PRIO 24
|
||||
#define WDT_TASK_STACK_SIZE 0x1000
|
||||
|
||||
static errcode_t watchdog_callback(uintptr_t param)
|
||||
{
|
||||
UNUSED(param);
|
||||
osal_printk("watchdog kick timeout!\r\n");
|
||||
return ERRCODE_SUCC;
|
||||
}
|
||||
|
||||
static void *watchdog_task(const char *arg)
|
||||
{
|
||||
UNUSED(arg);
|
||||
|
||||
errcode_t ret = uapi_watchdog_init(TIME_OUT);
|
||||
if (ret == ERRCODE_INVALID_PARAM) {
|
||||
osal_printk("param is error, timeout is %d.\r\n", TIME_OUT);
|
||||
return NULL;
|
||||
}
|
||||
(void)uapi_watchdog_enable((wdt_mode_t)WDT_MODE);
|
||||
(void)uapi_register_watchdog_callback(watchdog_callback);
|
||||
osal_printk("init watchdog\r\n");
|
||||
#if defined(CONFIG_WDT_TIMEOUT_SAMPLE)
|
||||
while (1) {};
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_WDT_KICK_SAMPLE)
|
||||
while (1) {
|
||||
osal_msleep(WDT_TASK_DURATION_MS);
|
||||
(void)uapi_watchdog_kick();
|
||||
osal_printk("kick success\r\n");
|
||||
}
|
||||
#endif
|
||||
(void)uapi_watchdog_deinit();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void watchdog_entry(void)
|
||||
{
|
||||
osal_task *task_handle = NULL;
|
||||
osal_kthread_lock();
|
||||
task_handle = osal_kthread_create((osal_kthread_handler)watchdog_task, 0, "WatchdogTask", WDT_TASK_STACK_SIZE);
|
||||
if (task_handle != NULL) {
|
||||
osal_kthread_set_priority(task_handle, WDT_TASK_PRIO);
|
||||
osal_kfree(task_handle);
|
||||
}
|
||||
osal_kthread_unlock();
|
||||
}
|
||||
|
||||
/* Run the watchdog_entry. */
|
||||
app_run(watchdog_entry);
|
Reference in New Issue
Block a user