[新版中科蓝讯AB32VG1 RISC-V开发板] - 9:WDT
本帖最后由 MianQi 于 2021-9-17 16:37 编辑<p>参考例程 - https://docs.qq.com/doc/DTVVWWXpLRVl6cER2?_t=1626260921919(第八例)</p>
<p>首先,在项目中的“RT-Thread设置”中的“硬件”目录下,打开看门狗定时器:</p>
<p></p>
<p>不做其他任何工作,生成的主程序代码是这样:</p>
<pre>
<code class="language-cpp">#include <rtthread.h>
#include "board.h"
int main(void)
{
uint8_t pin = rt_pin_get("PE.1");
rt_pin_mode(pin, PIN_MODE_OUTPUT);
rt_kprintf("Hello, world\n");
while (1)
{
rt_pin_write(pin, PIN_LOW);
rt_thread_mdelay(500);
rt_pin_write(pin, PIN_HIGH);
rt_thread_mdelay(500);
}
}
</code></pre>
<p> </p>
<p>在上述主程序中加入两段代码,其一:</p>
<pre>
<code class="language-cpp">rt_device_t watchdog = rt_device_find("wdt");
rt_uint32_t timeout = 4; //设定看门狗2048ms后溢出
rt_device_control(watchdog, RT_DEVICE_CTRL_WDT_SET_TIMEOUT, &timeout);
rt_device_control(watchdog, RT_DEVICE_CTRL_WDT_START, RT_NULL);
</code></pre>
<p>加在"while(1)"之前。</p>
<p> </p>
<p>其二:</p>
<pre>
<code class="language-cpp">rt_device_control(watchdog, RT_DEVICE_CTRL_WDT_KEEPALIVE, NULL);
rt_kprintf("feed dog\n");
</code></pre>
<p>加在"while(1)"里边。</p>
本帖最后由 MianQi 于 2021-9-17 17:19 编辑
<p>对教程做的内容补充是,要想看到WDT的效果,需要将这一句:</p>
<pre>
<code class="language-cpp">rt_device_control(watchdog, RT_DEVICE_CTRL_WDT_KEEPALIVE, NULL);</code></pre>
<p>在注释和取消注释之间做一切换,分别观察效果。</p>
<p> </p>
<p>这是加上注释的效果:</p>
<p><iframe allowfullscreen="true" frameborder="0" height="450" src="//player.bilibili.com/player.html?bvid=1Vv411A7tu&page=1" style="background:#eee;margin-bottom:10px;" width="700"></iframe></p>
<p><br />
<iframe allowfullscreen="true" frameborder="0" height="450" src="//player.bilibili.com/player.html?bvid=1pP4y1h7V1&page=1" style="background:#eee;margin-bottom:10px;" width="700"></iframe><br />
</p>
<p>这是取消注释的效果:</p>
<p><iframe allowfullscreen="true" frameborder="0" height="450" src="//player.bilibili.com/player.html?bvid=1Xv411w7Pu&page=1" style="background:#eee;margin-bottom:10px;" width="700"></iframe><br />
</p>
<p><iframe allowfullscreen="true" frameborder="0" height="450" src="//player.bilibili.com/player.html?bvid=1QL411x74m&page=1" style="background:#eee;margin-bottom:10px;" width="700"></iframe><br />
</p>
<p> </p>
<p>谢谢分享,看来坑不少。。。</p>
freebsder 发表于 2021-9-17 18:07
谢谢分享,看来坑不少。。。
<p>就迄今为止的情况来看,AB32VG1只是开了个头,距离成为“RISC-V 时代的 Arduino”还有较长的路要走。</p>
页:
[1]