Watch Dog
1. Check Watchdog ResourcesUse the ls command to view the number of watchdog nodes in the system:
ls /dev/watchdog*If you are reading this document for the first time, please refer to《Getting Started Guide/Development Environment Preparation/Easy-EAI Compilation Environment Preparation and Update》, and deploy the compilation environment according to the relevant operations.
Execute the run script in the Ubuntu system on the PC to enter the EASY-EAI compilation environment, as follows:
cd ~/develop_environment
./run.shFirst, in the background terminal of the virtual machine, execute the following commands to create a directory for managing peripheral singleton source code:
cd /opt
mkdir -p EASY-EAI-Nano-TB/demoFirst, download the relevant singleton program from 【Baidu Netdisk】:
Link: https://pan.baidu.com/s/1Br608Hiff2Xs65PzWO_qWQ?pwd=1234
Extraction Code: 1234First, download the relevant singleton program from 【Baidu Netdisk】:Link: https://pan.baidu.com/s/1Br608Hiff2Xs65PzWO_qWQ?pwd=1234
For example, download the singleton program to: This PC\D:\BaiduNetdisk (no fixed rules; users can choose freely), as shown in the figure below.
Then copy the downloaded singleton program to the file system of the virtual machine, as shown in the figure below.
📷📷
Finally, enter the corresponding example directory and execute the compilation command, as follows:
cd EASY-EAI-Nano-TB/demo/05_watchDog
./build.shNote:
- Since the dependent libraries are deployed on the board, the
/mntmount must be maintained during the cross-compilation process.
Access the background of the board via serial port debugging or SSH debugging,and navigate to the deployment location of the example, as follows:
cd /userdataThe command to run the example is as follows:
./05_watchDog2.4 Execution EffectThe execution effect is as follows 【Warning!!! Running the demo will restart the system; please operate with caution】.
If you do not want to restart the system, you can stop the watchdog process with the key combination 【Ctrl+C】 midway.
3. C Language Usage ExampleA C language usage example for the watchdog is provided in 05_watchDog/test-watchDog/main.c for users' coding reference. The following code demonstrates the basic operation process of the watchdog timer:
void ctrl_c_handler()
{
int ret = wdt_close();
if(ret < 0){
printf("\n看门狗关闭失败!!!\n");
}else if(ret == 0){
printf("\n看门狗关闭成功!!!\n");
}
exit(0);
}
int main()
{
int timeout = 30;
int ret = wdt_open(timeout);
if(ret < 0){
printf("看门狗使能失败!!!\n");
return -1;
}
printf("看门狗使能成功,实际溢出时间:%d(秒)\n", ret);
// 捕捉ctrl+c信号
signal(SIGINT, ctrl_c_handler);
int feedTimes = 0;
while (1)
{
sleep(3);
if(5 < feedTimes){
printf("不再喂狗\n");
continue;
}
if(0 == wdt_feeddog()){
feedTimes++;
printf("喂狗成功!!!\n");
}else{
printf("喂狗失败!!!\n");
}
}
return 0;
}





Comments