/AVR32_software_reset.c Secret
Created
May 26, 2013 08:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Some register definitions | |
#ifndef WDTCTRL | |
#define WDTCTRL (*((unsigned long*)0xFFFF0D30)) | |
#endif // WDTCTRL defined | |
#ifndef WDTCLR | |
#define WDTCLR (*((unsigned long*)0xFFFF0D34)) | |
#endif // WDTCLR defined | |
void myAvr32SoftwareReset(void) | |
{ | |
//In AVR32, WDT module is clocked from internam 115KHz RC oscillator. | |
//We use PSEL field in WDTCTRL register to set a timeout period of 2^(PSEL+1) / 115000 seconds. | |
//In the code below we set a timeout period of 65536/115000 = 0.567 seconds | |
//Let's configure Watchdog as... | |
// WDTCTRL.KEY = [0x55, 0xAA] | |
// WDTCTRL.PSEL = 15 (timeout period to 2^16 / 115000 => 65536/115000 seconds => 0.567 seconds | |
// WDTCTRL.EN = 1 (enable WDT) | |
WDTCTRL = 0x55000F01; | |
WDTCTRL = 0xAA000F01; | |
//Endless loop until watchdog overflow. | |
while(1) {} | |
} | |
//And later, in your main function... | |
int main(void) | |
{ | |
// ... Variable declarations ... | |
//Reset watchdog. | |
WDTCLR = 0x0000000f; //Any value is valid. | |
//Disable watchdog by setting EN field to '0' | |
WDTCTRL = 0x55000F00; | |
WDTCTRL = 0xAA000F00; | |
// ... continue with your program code ... | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment