KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
Watchdog Timer

Driver for using the WDT as a reset or interval timer More...

Files

file  wdt.h
 Watchdog Timer API.
 

Enumerations

enum  WDT_CLK_DIV {
  WDT_CLK_DIV_32 , WDT_CLK_DIV_64 , WDT_CLK_DIV_128 , WDT_CLK_DIV_256 ,
  WDT_CLK_DIV_512 , WDT_CLK_DIV_1024 , WDT_CLK_DIV_2048 , WDT_CLK_DIV_4096
}
 Clock divider settings. More...
 
enum  WDT_RST { WDT_RST_POWER_ON , WDT_RST_MANUAL }
 Reset signal type. More...
 

Functions

void wdt_enable_timer (uint8_t initial_count, uint32_t microsec_period, uint8_t irq_prio, wdt_callback callback, void *user_data)
 Enables the WDT as an interval timer.
 
void wdt_enable_watchdog (uint8_t initial_count, WDT_CLK_DIV clk_config, WDT_RST reset_select)
 Enables the WDT in watchdog mode.
 
uint8_t wdt_get_counter (void)
 Fetches the counter value.
 
void wdt_set_counter (uint8_t value)
 Sets the counter value.
 
void wdt_pet (void)
 Resets the counter value.
 
void wdt_disable (void)
 Disables the WDT.
 
int wdt_is_enabled (void)
 Returns whether the WDT is enabled.
 

Detailed Description

Driver for using the WDT as a reset or interval timer

The watchdog timer (WDT) is a special-purpose timer peripheral integrated within the Dreamcast's SH4 CPU.

Warning
At this time, there are no known emulators which are emulating the WDT, as it was never used in commercial games; however, it works perfectly fine on real hardware.

There are two different modes of operation which are supported:

To start the WDT in watchdog mode, use wdt_enable_watchdog(). To use the WDT as a general-purpose interval timer, use wdt_enable_timer().

The timer can be stopped in either mode by calling wdt_disable().

See also
Real-Time Clock

Enumeration Type Documentation

◆ WDT_CLK_DIV

Clock divider settings.

Denominators used to set the frequency divider for the input clock to the WDT.

Enumerator
WDT_CLK_DIV_32 

Period: 41us.

WDT_CLK_DIV_64 

Period: 82us.

WDT_CLK_DIV_128 

Period: 164us.

WDT_CLK_DIV_256 

Period: 328us.

WDT_CLK_DIV_512 

Period: 656us.

WDT_CLK_DIV_1024 

Period: 1.31ms.

WDT_CLK_DIV_2048 

Period: 2.62ms.

WDT_CLK_DIV_4096 

Period: 5.25ms.

◆ WDT_RST

enum WDT_RST

Reset signal type.

Specifies the kind of reset to be performed when the WDT overflows in watchdog mode.

Enumerator
WDT_RST_POWER_ON 

Power-On Reset.

WDT_RST_MANUAL 

Manual Reset.

Function Documentation

◆ wdt_disable()

void wdt_disable ( void )

Disables the WDT.

Disables the WDT if it was previously enabled, otherwise does nothing.

See also
wdt_enable_timer(), wdt_enable_watchdog()

◆ wdt_enable_timer()

void wdt_enable_timer ( uint8_t initial_count,
uint32_t microsec_period,
uint8_t irq_prio,
wdt_callback callback,
void * user_data )

Enables the WDT as an interval timer.

Stops the WDT if it was previously running and reconfigures it to be used as a generic interval timer, calling the given callback periodically at the requested interval (or as close to it as possible without calling it prematurely).

Note
The internal resolution for each tick of the WDT in this mode is 41us, meaning a requested microsec_period of 100us will result in an actual callback interval of 123us.
Warning
callback is invoked within an interrupt context, meaning that special care should be taken to not perform any logic requiring additional interrupts. Data that is accessed from both within and outside of the callback should be atomic or protected by a lock.
Parameters
initial_countInitial value of the WDT counter (Normally 0).
microsec_periodTimer callback interval in microseconds
irq_prioPriority for the interval timer IRQ (1-15)
callbackUser function to invoke periodically
user_dataArbitrary user-provided data for the callback
See also
wdt_disable()

◆ wdt_enable_watchdog()

void wdt_enable_watchdog ( uint8_t initial_count,
WDT_CLK_DIV clk_config,
WDT_RST reset_select )

Enables the WDT in watchdog mode.

Stops the WDT if it was previously running and reconfigures it to be used as a typical watchdog timer, generating a reset interrupt upon counter overflow. To prevent this from happening, the user should be periodically resetting the counter.

Note
Keep in mind the speed of the WDT. With a range of 41us to 5.2ms, the WDT will overflow before a single frame in a typical game.
Parameters
initial_countInitial value of the WDT counter (Normally 0)
clk_configClock divider to set watchdog period
reset_selectThe type of reset generated upon overflow
See also
wdt_disable()

◆ wdt_get_counter()

uint8_t wdt_get_counter ( void )

Fetches the counter value.

Returns the current 8-bit value of the WDT counter.

Returns
Current counter value
See also
wdt_set_counter()

◆ wdt_is_enabled()

int wdt_is_enabled ( void )

Returns whether the WDT is enabled.

Checks to see whether the WDT has been enabled.

Returns
1 if enabled, 0 if disabled

◆ wdt_pet()

void wdt_pet ( void )

Resets the counter value.

"Petting" or "kicking" the WDT is the same thing as resetting its counter value to 0.

See also
wdt_set_counter()

◆ wdt_set_counter()

void wdt_set_counter ( uint8_t value)

Sets the counter value.

Sets the current 8-bit value of the WDT counter.

Parameters
valueNew value for the counter
See also
wdt_get_counter(), wdt_pet()