📄 hplwdtp.nc
字号:
module HPLWdtP
{
provides interface StdControl;
provides interface WDT;
//provides command void reset();
//provides command result_t start(int32_t interval);
uses interface Timer<TMilli> as Timer;
//uses interface StdControl;
//uses interface StdControl as TimerControl;
//uses interface StdControl as WDTControl;
}
implementation
{
int32_t increment;
int32_t remaining;
enum
{
WDT_LATENCY = 490,
// note that the HW watchdog is set to expire every 2
// second; to be safe, we should kick it at least
// twice per expiration period
};
//command void StdControl.start()
//如果和interface StdControl的定义不同(即使是返回值类型不同),系统会认为是新定义的start,stop函数,报错如下
//conflicting types for `StdControl.start' 和 previous declaration of `StdControl.start'
command error_t StdControl.start()
{
wdt_enable(WDTO_1S);//see \Cygwin\usr\avr\include\avr\wdt.h @lzm
increment = 0;
remaining = 1;
//call TimerControl.start();
call Timer.startPeriodic(WDT_LATENCY);
//call WDTControl.start();
return SUCCESS;
}
command error_t StdControl.stop()
{
increment = 0;
wdt_disable();
//call WDTControl.stop();
//call TimerControl.stop();
}
event void Timer.fired()
{
if (increment != 0)
{ // Watchdog is active
atomic
{
remaining = remaining - WDT_LATENCY;
}
}
if (remaining > 0) // the time has not yet passed. kick the dog
//call reset();
wdt_reset();
}
// for starters, only one watchdog per node, settable only once
command error_t WDT.start(int32_t interval)
{
if (increment == 0)
{
increment = interval;
remaining = increment;
return SUCCESS;
}
return FAIL;
}
command void WDT.reset()
{
atomic
{
remaining = increment;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -