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 98 of file wdt_example.c.

Referenced by wdt_scheduler().

#define WDT_MAX_VALUE_US   4000000

Definition at line 96 of file wdt_example.c.

Referenced by wdt_scheduler().

#define WDT_MIN_VALUE_US   1000000

Definition at line 94 of file wdt_example.c.

Referenced by wdt_scheduler().


Function Documentation

void led_task (  ) 

Led Task to scroll led before reset.

Definition at line 116 of file wdt_example.c.

References step_led_task.

Referenced by main().

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

int main ( void   ) 

Definition at line 194 of file wdt_example.c.

References led_task(), and wdt_scheduler().

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

void wdt_scheduler ( void   ) 

Watchdog scheduler.

Definition at line 153 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().

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


Variable Documentation

volatile U32 current_wdt_value = WDT_MIN_VALUE_US

Definition at line 101 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 105 of file wdt_example.c.

volatile U8 step_led_task = 0

Definition at line 103 of file wdt_example.c.

Referenced by led_task().


Generated on Fri Feb 19 02:27:58 2010 for AVR32 - Watchdog Driver by  doxygen 1.5.5