wdt_example.c File Reference


Detailed Description

WDT example application for AVR32 UC3.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file wdt_example.c.

#include <avr32/io.h>
#include "board.h"
#include "compiler.h"
#include "gpio.h"
#include "wdt4.h"
#include "power_clocks_lib.h"
#include "cycle_counter.h"

Go to the source code of this file.

Defines

#define WDT_CTRL_STEP_US   1000000
#define WDT_MAX_VALUE_US   4000000
#define WDT_MIN_VALUE_US   1000000

Functions

void led_task ()
 Led Task to scroll led before reset.
int main (void)
void wdt_scheduler (void)
 Watchdog scheduler.

Variables

volatile U32 current_wdt_value = WDT_MIN_VALUE_US
wdt_opt_t opt
volatile U8 step_led_task = 0


Define Documentation

#define WDT_CTRL_STEP_US   1000000

Definition at line 97 of file wdt_example.c.

Referenced by wdt_scheduler().

#define WDT_MAX_VALUE_US   4000000

Definition at line 95 of file wdt_example.c.

Referenced by wdt_scheduler().

#define WDT_MIN_VALUE_US   1000000

Definition at line 93 of file wdt_example.c.

Referenced by wdt_scheduler().


Function Documentation

void led_task (  ) 

Led Task to scroll led before reset.

Definition at line 117 of file wdt_example.c.

References step_led_task.

Referenced by main().

00118 {
00119   switch(step_led_task)
00120   {
00121     case 0:
00122       gpio_clr_gpio_pin(LED1_GPIO);
00123       gpio_set_gpio_pin(LED2_GPIO);
00124       gpio_set_gpio_pin(LED3_GPIO);
00125       step_led_task=1;
00126       cpu_delay_ms(300,FOSC0);
00127       break;
00128     case 1:
00129       gpio_set_gpio_pin(LED1_GPIO);
00130       gpio_clr_gpio_pin(LED2_GPIO);
00131       gpio_set_gpio_pin(LED3_GPIO);
00132       step_led_task=2;
00133       cpu_delay_ms(300,FOSC0);
00134       break;
00135     case 2:
00136       gpio_set_gpio_pin(LED1_GPIO);
00137       gpio_set_gpio_pin(LED2_GPIO);
00138       gpio_clr_gpio_pin(LED3_GPIO);
00139       step_led_task=0;
00140       cpu_delay_ms(300,FOSC0);
00141       break;
00142     default :
00143       gpio_clr_gpio_pin(LED1_GPIO);
00144       gpio_set_gpio_pin(LED2_GPIO);
00145       gpio_set_gpio_pin(LED3_GPIO);
00146       step_led_task=1;
00147       cpu_delay_ms(300,FOSC0);
00148       break;
00149   }
00150 }

int main ( void   ) 

Definition at line 195 of file wdt_example.c.

References led_task(), and wdt_scheduler().

00196 {
00197   // Switch main clock to external oscillator 0 (crystal).
00198   pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);
00199   
00200   // Call Watchdog scheduler
00201   wdt_scheduler();
00202   
00203   while(1)
00204   {
00205     // Launch led task
00206     led_task();
00207   }
00208 
00209 }

void wdt_scheduler ( void   ) 

Watchdog scheduler.

Definition at line 154 of file wdt_example.c.

References current_wdt_value, wdt_opt_t::us_timeout_period, WDT_CTRL_STEP_US, wdt_enable(), WDT_MAX_VALUE_US, WDT_MIN_VALUE_US, and wdt_reenable().

Referenced by main().

00155 {  
00156   // If Reset Cause is due to a Watchdog reset just relaunch Watchdog and turn
00157   // LED0 to 4 on to let user know that a new wdt reset has occured.
00158   if(AVR32_PM.RCAUSE.wdt) {
00159       wdt_reenable();
00160       gpio_clr_gpio_pin(LED0_GPIO);       
00161       gpio_clr_gpio_pin(LED1_GPIO);
00162       gpio_clr_gpio_pin(LED2_GPIO);
00163       gpio_clr_gpio_pin(LED3_GPIO);
00164       cpu_delay_ms(300,FOSC0);
00165   // If Reset Cause is due to a Power On reset, enable Watchdog with default value
00166   }else if (AVR32_PM.RCAUSE.por) {     
00167       current_wdt_value = WDT_MIN_VALUE_US ;//WDT_MIN_VALUE;
00168       // Save current value in GPLP register
00169       pcl_write_gplp(0,current_wdt_value);
00170       opt.us_timeout_period = current_wdt_value;
00171       wdt_enable(&opt);
00172   // If Reset Cause is due to an External reset, increment current_wdt_value
00173   }else if (AVR32_PM.RCAUSE.ext) {  
00174       // Reload current value stored in GPLP register
00175       current_wdt_value = pcl_read_gplp(0);
00176       current_wdt_value += WDT_CTRL_STEP_US; //WDT_CTRL_STEP;
00177       if (current_wdt_value >=  WDT_MAX_VALUE_US) current_wdt_value = WDT_MIN_VALUE_US;
00178       opt.us_timeout_period = current_wdt_value;
00179       wdt_enable(&opt);
00180       // Save new value in GPLP register
00181       pcl_write_gplp(0,current_wdt_value);
00182   // Else relaunch Watchdog and toggle GPIO to let user know that a new reset has occured
00183   }else{
00184       current_wdt_value = WDT_MIN_VALUE_US; //WDT_MIN_VALUE
00185       // Save start value of watchdog in GPLP register
00186       pcl_write_gplp(0,current_wdt_value);
00187       opt.us_timeout_period = current_wdt_value;
00188       wdt_enable(&opt);
00189   }
00190 }


Variable Documentation

volatile U32 current_wdt_value = WDT_MIN_VALUE_US

Definition at line 102 of file wdt_example.c.

Referenced by wdt_scheduler().

Initial value:

 {
          .dar = FALSE,     
          .mode = WDT_BASIC_MODE,    
          .sfv = FALSE,     
          .fcd = FALSE,     
          .cssel = WDT_CLOCK_SOURCE_SELECT_RCSYS,       
          .us_timeout_period = WDT_MIN_VALUE_US  
}

Definition at line 106 of file wdt_example.c.

volatile U8 step_led_task = 0

Definition at line 104 of file wdt_example.c.

Referenced by led_task().


Generated on Thu Dec 17 20:00:30 2009 for AVR32 - Watchdog Driver by  doxygen 1.5.5