To start the countdown of the Watch Dog Timer, write 1 to the START bit of the control register.
To reset and reload the counter, write
any data to any of the period registers. (The value has no meaning.)
(Reference) Embedded Peripherals IP User Guide
https://www.intel.com/content/dam/www/programmable/us/en/pdfs/literature/ug/ug_embedded_ip.pdf
(See the section 23.3.4, Configuring the Timer as a Watchdog Timer.)
The following is sample code.
#include <stdio.h>
#include <unistd.h>
#include "system.h"
#include "altera_avalon_timer.h"
#include "altera_avalon_timer_regs.h"
#include "altera_avalon_pio_regs.h"
// If you want to use timer as WDT, sys_clk_timer feature should not be used in bsp-editor.
// Please Select - 1: kick wdt in app / 0: No kick wdt in app(Will be reset)
#define WDT_KICK (0)
#define LED_BLINK_PERIOD_MS (250)
static int boot_count = 1; //if 0, it will be assigned to bss. so initial value is 1, in this case it will assign to rwdata.
int main() {
printf("Hello from Nios II!\n");
printf("Boot Count = 0x%x \n", boot_count++);
//Start WDT
IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_0_BASE, ALTERA_AVALON_TIMER_CONTROL_START_MSK);
while(1){
IOWR_ALTERA_AVALON_PIO_ DATA(LED_PIO_BASE, 0xFF);
usleep(1000 * LED_BLINK_PERIOD_MS);
IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0x00);
usleep(1000 * LED_BLINK_ PERIOD_MS);
#if WDT_KICK
//Write Dummy Value to restart a timer
IOWR_ALTERA_AVALON_TIMER_PERIODL(TIMER_0_BASE, 0xff);
#endif
}
return 0;
}
--------------------
Category: IP (Other)
Tools:-
Devices:-