Definition in file wdt_example.c.
#include <avr32/io.h>
#include "board.h"
#include "compiler.h"
#include "gpio.h"
#include "wdt.h"
#include "pm.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 |
volatile avr32_pm_t * | pm = &AVR32_PM |
volatile U8 | step_led_task = 0 |
#define WDT_CTRL_STEP_US 1000000 |
#define WDT_MAX_VALUE_US 4000000 |
#define WDT_MIN_VALUE_US 1000000 |
void led_task | ( | ) |
Led Task to scroll led before reset.
Definition at line 109 of file wdt_example.c.
References step_led_task.
Referenced by main().
00110 { 00111 switch(step_led_task) 00112 { 00113 case 0: 00114 gpio_clr_gpio_pin(LED1_GPIO); 00115 gpio_set_gpio_pin(LED2_GPIO); 00116 gpio_set_gpio_pin(LED3_GPIO); 00117 step_led_task=1; 00118 cpu_delay_ms(300,FOSC0); 00119 break; 00120 case 1: 00121 gpio_set_gpio_pin(LED1_GPIO); 00122 gpio_clr_gpio_pin(LED2_GPIO); 00123 gpio_set_gpio_pin(LED3_GPIO); 00124 step_led_task=2; 00125 cpu_delay_ms(300,FOSC0); 00126 break; 00127 case 2: 00128 gpio_set_gpio_pin(LED1_GPIO); 00129 gpio_set_gpio_pin(LED2_GPIO); 00130 gpio_clr_gpio_pin(LED3_GPIO); 00131 step_led_task=0; 00132 cpu_delay_ms(300,FOSC0); 00133 break; 00134 default : 00135 gpio_clr_gpio_pin(LED1_GPIO); 00136 gpio_set_gpio_pin(LED2_GPIO); 00137 gpio_set_gpio_pin(LED3_GPIO); 00138 step_led_task=1; 00139 cpu_delay_ms(300,FOSC0); 00140 break; 00141 } 00142 }
int main | ( | void | ) |
Definition at line 185 of file wdt_example.c.
References led_task(), and wdt_scheduler().
00186 { 00187 // Switch main clock to external oscillator 0 (crystal). 00188 pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP); 00189 // Call Watchdog scheduler 00190 wdt_scheduler(); 00191 while(1) 00192 { 00193 // Launch led task 00194 led_task(); 00195 } 00196 }
void wdt_scheduler | ( | void | ) |
Watchdog scheduler.
Definition at line 146 of file wdt_example.c.
References current_wdt_value, pm, WDT_CTRL_STEP_US, wdt_enable(), WDT_MAX_VALUE_US, WDT_MIN_VALUE_US, and wdt_reenable().
Referenced by main().
00147 { 00148 // If Reset Cause is due to a Watchdog reset just relaunch Watchdog and turn 00149 // LED0 to 4 on to let user know that a new wdt reset has occured. 00150 if(pm->RCAUSE.wdt) { 00151 wdt_reenable(); 00152 gpio_clr_gpio_pin(LED0_GPIO); 00153 gpio_clr_gpio_pin(LED1_GPIO); 00154 gpio_clr_gpio_pin(LED2_GPIO); 00155 gpio_clr_gpio_pin(LED3_GPIO); 00156 cpu_delay_ms(300,FOSC0); 00157 // If Reset Cause is due to a Power On reset, enable Watchdog with default value 00158 }else if (pm->RCAUSE.por) { 00159 current_wdt_value = WDT_MIN_VALUE_US ;//WDT_MIN_VALUE; 00160 // Save current value in GPLP register 00161 pm_write_gplp(pm,0,current_wdt_value); 00162 wdt_enable(current_wdt_value); 00163 // If Reset Cause is due to an External reset, increment current_wdt_value 00164 }else if (pm->RCAUSE.ext) { 00165 // Reload current value stored in GPLP register 00166 current_wdt_value = pm_read_gplp(pm,0); 00167 current_wdt_value += WDT_CTRL_STEP_US; //WDT_CTRL_STEP; 00168 if (current_wdt_value >= WDT_MAX_VALUE_US) current_wdt_value = WDT_MIN_VALUE_US; 00169 wdt_enable(current_wdt_value); 00170 // Save new value in GPLP register 00171 pm_write_gplp(pm,0,current_wdt_value); 00172 00173 // Else relaunch Watchdog and toggle GPIO to let user know that a new reset has occured 00174 }else{ 00175 current_wdt_value = WDT_MIN_VALUE_US; //WDT_MIN_VALUE 00176 // Save start value of watchdog in GPLP register 00177 pm_write_gplp(pm,0,current_wdt_value); 00178 wdt_enable(current_wdt_value); 00179 } 00180 }
volatile U32 current_wdt_value = WDT_MIN_VALUE_US |
volatile avr32_pm_t* pm = &AVR32_PM |
volatile U8 step_led_task = 0 |