KallistiOS git master
Independent SDK for the Sega Dreamcast
|
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. | |
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.
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().
enum WDT_CLK_DIV |
Clock divider settings.
Denominators used to set the frequency divider for the input clock to the WDT.
enum WDT_RST |
void wdt_disable | ( | void | ) |
Disables the WDT.
Disables the WDT if it was previously enabled, otherwise does nothing.
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).
microsec_period
of 100us will result in an actual callback interval of 123us.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.initial_count | Initial value of the WDT counter (Normally 0). |
microsec_period | Timer callback interval in microseconds |
irq_prio | Priority for the interval timer IRQ (1-15) |
callback | User function to invoke periodically |
user_data | Arbitrary user-provided data for the callback |
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.
initial_count | Initial value of the WDT counter (Normally 0) |
clk_config | Clock divider to set watchdog period |
reset_select | The type of reset generated upon overflow |
uint8_t wdt_get_counter | ( | void | ) |
Fetches the counter value.
Returns the current 8-bit value of the WDT counter.
int wdt_is_enabled | ( | void | ) |
Returns whether the WDT is enabled.
Checks to see whether the WDT has been enabled.
void wdt_pet | ( | void | ) |
Resets the counter value.
"Petting" or "kicking" the WDT is the same thing as resetting its counter value to 0.
void wdt_set_counter | ( | uint8_t | value | ) |
Sets the counter value.
Sets the current 8-bit value of the WDT counter.
value | New value for the counter |