MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / wdt_task

Function wdt_task

bsp/ht32/ht32f12366/applications/test.c:668–731  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

666}
667
668static int wdt_task(int argc, char *argv[])
669{
670 rt_err_t ret = -RT_ERROR;
671 rt_uint16_t wdt_time = 5;
672 char dev_name[] = "wdt";
673 if(argc == 2)
674 {
675 if(rt_strcmp(argv[1],"start") == 0)
676 {
677 /* Find wdt devices */
678 wdt_dev = rt_device_find(dev_name);
679 if(wdt_dev == RT_NULL)
680 {
681 rt_kprintf("No corresponding equipment found.\n");
682 return -1;
683 }
684 /* Configuring the Watchdog */
685 ret = rt_device_control(wdt_dev, RT_DEVICE_CTRL_WDT_SET_TIMEOUT, &wdt_time);
686 if(ret != RT_EOK)
687 {
688 rt_kprintf("wdt configuration failed.\n");
689 return -1;
690 }
691 /* Start the Watchdog */
692 ret = rt_device_control(wdt_dev, RT_DEVICE_CTRL_WDT_START, RT_NULL);
693 if(ret != RT_EOK)
694 {
695 rt_kprintf("wdt start failed.\n");
696 return -1;
697 }
698 /* Setting up idle threads */
699 rt_thread_idle_sethook(wdt_test);
700 rt_kprintf("Watchdog started successfully.\n");
701 }
702 else if(rt_strcmp(argv[1],"stop") == 0)
703 {
704 /* Verify device handle */
705 if(wdt_dev == RT_NULL)
706 {
707 rt_kprintf("Device handle does not exist.\n");
708 return -1;
709 }
710 /* Stop the Watchdog */
711 ret = rt_device_control(wdt_dev, RT_DEVICE_CTRL_WDT_STOP, RT_NULL);
712 if(ret != RT_EOK)
713 {
714 rt_kprintf("wdt start failed.\n");
715 return -1;
716 }
717 /* Hook function to delete idle threads */
718 rt_thread_idle_delhook(wdt_test);
719 rt_kprintf("Watchdog has stopped.\n");
720 }
721 }
722 else
723 {
724 rt_kprintf("Necessary parameters are missing.\n");
725 rt_kprintf("You can use the following commands.\n");

Callers

nothing calls this directly

Calls 6

rt_strcmpFunction · 0.85
rt_device_findFunction · 0.85
rt_kprintfFunction · 0.85
rt_device_controlFunction · 0.85
rt_thread_idle_sethookFunction · 0.85
rt_thread_idle_delhookFunction · 0.85

Tested by

no test coverage detected