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

Function wdt_task

bsp/ht32/ht32f52352/applications/test.c:669–732  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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