STC15W408AS library 0.9.0
Watchdog timer

watchdog timer

Watchdog timer functions

#define wdt_init(wdt_scale)
 Init WDT. More...
 
#define wdt_start()   (bit_set(WDT_CONTR, SBIT5))
 Start WDT. More...
 
#define wdt_stop()   (bit_clr(WDT_CONTR, CBIT5))
 Stop WDT. More...
 
#define is_wdt_started()   (test_if_bit_set(WDT_CONTR, SBIT5))
 Get WDT start status. More...
 
#define wdt_clear()   (bit_set(WDT_CONTR, SBIT4))
 clear WDT to prevent restart More...
 
#define is_wdt_flag_on()   (test_if_bit_set(WDT_CONTR, SBIT7))
 Get reset by WDT flag. More...
 
#define wdt_flag_reset()   (bit_clr(WDT_CONTR, CBIT7))
 Reset WDT flag. More...
 
#define wdt_enable_in_idle()   (bit_set(WDT_CONTR, SBIT3))
 Enable WDT in MCU idle mode. More...
 
#define wdt_disable_in_idle()   (bit_clr(WDT_CONTR, CBIT3))
 Disable WDT in MCU idle mode. More...
 

Detailed Description

Functions and data structures related WDT

WDT - Watchdog timer is purposed for reset MCU on program hang up.

First step is init with scale. Scale determine WDT overflow time. Init WDT assume it not started. Separate wdt_start() / wdt_stop routines is used for explicitly start and stop WDT.

After wdt_start() call wdt_clear should be periodically called to restart WDT.

If wdt_clear() not called before WDT overflow MCU reset occurs.

If restart reason is WDT overflow then is_wdt_flag_on() return true. wdt_flag_reset() could be called to clear wdt_flag.

By default WDT is disabled in idle mode. wdt_enable_in_idle() change this.

WDT timings biased by MCU frequency change (frequency divider).

Author
Michael Golovanov

Macro Definition Documentation

◆ is_wdt_flag_on

#define is_wdt_flag_on ( )    (test_if_bit_set(WDT_CONTR, SBIT7))

Get reset by WDT flag.

WDT reset flag set after restart caused by WDT

Returns
bool true if MCU reset caused by WDT and false otherwise

◆ is_wdt_started

#define is_wdt_started ( )    (test_if_bit_set(WDT_CONTR, SBIT5))

Get WDT start status.

Call is_wdt_started after wdt_init call

Returns
bool - true if WDT started and false if not

◆ wdt_clear

#define wdt_clear ( )    (bit_set(WDT_CONTR, SBIT4))

clear WDT to prevent restart

Call wdt_clear after wdt_start call to prevent WDT reset MCU

◆ wdt_disable_in_idle

#define wdt_disable_in_idle ( )    (bit_clr(WDT_CONTR, CBIT3))

Disable WDT in MCU idle mode.

By default WDT in idle mode is disabled.

◆ wdt_enable_in_idle

#define wdt_enable_in_idle ( )    (bit_set(WDT_CONTR, SBIT3))

Enable WDT in MCU idle mode.

By default WDT in idle mode is disabled.

◆ wdt_flag_reset

#define wdt_flag_reset ( )    (bit_clr(WDT_CONTR, CBIT7))

Reset WDT flag.

Reset WDT flag to false.

◆ wdt_init

#define wdt_init (   wdt_scale)
Value:
{ \
WDT_CONTR = 0; \
WDT_CONTR |= (wdt_scale & 0x07); \
}

Init WDT.

WDT overflow time = (12 * wdt_scale * 32768) / MainFosc

Parameters
wdt_scaleuint8_t WDT timer scale in range 0..7

◆ wdt_start

#define wdt_start ( )    (bit_set(WDT_CONTR, SBIT5))

Start WDT.

Call wdt_start after wdt_init call

◆ wdt_stop

#define wdt_stop ( )    (bit_clr(WDT_CONTR, CBIT5))

Stop WDT.

Call wdt_stop after wdt_init and wdt_start call