You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.4 KiB
93 lines
2.4 KiB
/*
|
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2014-2019. All rights reserved.
|
|
* Description: sample test for gpio function.
|
|
*/
|
|
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include "uapi_wdg.h"
|
|
|
|
#define TEST_WDG_NO 0
|
|
|
|
td_s32 main(td_s32 argc, td_char *argv[])
|
|
{
|
|
td_s32 ret;
|
|
td_u32 loop;
|
|
td_u32 value;
|
|
td_u32 wdgnum;
|
|
|
|
(void)(argc);
|
|
(void)(argv);
|
|
/* Open WDG */
|
|
ret = uapi_wdg_init();
|
|
if (ret != TD_SUCCESS) {
|
|
printf("%s: %d ErrorCode=0x%x\n", __FILE__, __LINE__, ret);
|
|
return ret;
|
|
}
|
|
|
|
ret = uapi_wdg_get_num(&wdgnum);
|
|
if (ret != TD_SUCCESS) {
|
|
printf("%s: %d ErrorCode=0x%x\n", __FILE__, __LINE__, ret);
|
|
goto ERR1;
|
|
}
|
|
printf("max wdg num:%d\n", wdgnum);
|
|
|
|
/* Set WDG TimeOut */
|
|
value = 2000; /* 2000 ms */
|
|
ret = uapi_wdg_set_timeout(TEST_WDG_NO, value);
|
|
if (ret != TD_SUCCESS) {
|
|
printf("%s: %d ErrorCode=0x%x\n", __FILE__, __LINE__, ret);
|
|
goto ERR1;
|
|
}
|
|
|
|
/* Enable WDG */
|
|
ret = uapi_wdg_enable(TEST_WDG_NO);
|
|
if (ret != TD_SUCCESS) {
|
|
printf("%s: %d ErrorCode=0x%x\n", __FILE__, __LINE__, ret);
|
|
goto ERR1;
|
|
}
|
|
|
|
sleep(1);
|
|
for (loop = 0; loop < 5; loop++) { /* for 5 times */
|
|
/* Clear WDG during timeout, can not reset system */
|
|
ret = uapi_wdg_clear(TEST_WDG_NO);
|
|
if (ret != TD_SUCCESS) {
|
|
printf("%s: %d ErrorCode=0x%x\n", __FILE__, __LINE__, ret);
|
|
goto ERR1;
|
|
}
|
|
|
|
printf("Clear wdg Success\n");
|
|
sleep(1);
|
|
}
|
|
|
|
printf("wdg disabled\n");
|
|
|
|
/* Disable WDG, cat not reset system */
|
|
ret = uapi_wdg_disable(TEST_WDG_NO);
|
|
if (ret != TD_SUCCESS) {
|
|
printf("%s: %d ErrorCode=0x%x\n", __FILE__, __LINE__, ret);
|
|
goto ERR1;
|
|
}
|
|
|
|
sleep(5); /* sleep 5 secends */
|
|
printf("\nwdg doesn't reset board,demo passed\n");
|
|
printf("now enable wdg and wait reset boardaaaa\n\n");
|
|
|
|
/* Enable WDG */
|
|
ret = uapi_wdg_enable(TEST_WDG_NO);
|
|
if (ret != TD_SUCCESS) {
|
|
printf("%s: %d ErrorCode=0x%x\n", __FILE__, __LINE__, ret);
|
|
goto ERR1;
|
|
}
|
|
|
|
printf("system reset at onceaa\n");
|
|
/* After timeout, system reset at once */
|
|
sleep(5); /* sleep 5 secends */
|
|
printf("system reset at once\n");
|
|
|
|
ERR1:
|
|
uapi_wdg_deinit();
|
|
printf("run wdg sample failed\n");
|
|
return ret;
|
|
}
|