Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Implementation of watchdog timer
PostPosted: Thu Mar 31, 2011 2:30 pm 
Offline

Joined: Thu Dec 09, 2010 1:17 pm
Posts: 5
Hi,
I am using SAM3S-EK development board,i want to implement watch dog timer ie., when ever software get hangs controller should get restart.Can anyone tell the procedure to implement WDT.


Top
 Profile  
 
 Post subject: Re: Implementation of watchdog timer
PostPosted: Thu Mar 31, 2011 8:10 pm 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 574
This seems to represent a fairly good example

http://blogold.chinaunix.net/u3/90973/s ... 06152.html


Top
 Profile  
 
 Post subject: Re: Implementation of watchdog timer
PostPosted: Fri Apr 01, 2011 8:12 am 
Offline

Joined: Thu Dec 09, 2010 1:17 pm
Posts: 5
#define ms_to_ticks(t) (((t << 8) / 1000) - 1)
#define ticks_to_ms(t) (((t + 1) * 1000) >> 8)

/* Hardware timeout in seconds */
#define WDT_HW_TIMEOUT 2

/*
* Set the watchdog time interval in 1/256Hz (write-once)
* Counter is 12 bit.
*/
static int wdt_settimeout(unsigned int timeout)
{
unsigned int reg;
wdt_t *wd = (wdt_t *) WDT_BASE;

/* Check if disabled */
if (readl(&wd->mr) & WDT_MR_WDDIS) {
printf("sorry, watchdog is disabled\n");
return -1;
}

/*
* All counting occurs at SLOW_CLOCK / 128 = 256 Hz
*
* Since WDV is a 12-bit counter, the maximum period is
* 4096 / 256 = 16 seconds.
*/

reg = WDT_MR_WDRSTEN /* causes watchdog reset */
| WDT_MR_WDDBGHLT /* disabled in debug mode */
| WDT_MR_WDD(0xfff) /* restart at any time */
| WDT_MR_WDV(timeout); /* timer value */

writel(reg, &wd->mr);

return 0;
}

void hw_watchdog_reset(void)
{
wdt_t *wd = (wdt_t *) WDT_BASE;
writel(WDT_CR_WDRSTT | WDT_CR_KEY, &wd->cr);
}

void hw_watchdog_init(void)
{
/* 16 seconds timer, resets enabled */
at91_wdt_settimeout(ms_to_ticks(WDT_HW_TIMEOUT * 1000));
}

In this code there is "writel" function,where it is defined.Also my doubt is how to use watchdog timer in main application.I am trying like this,

main()
{
WDT_Enable(10sec);
while(1)
{

//end of while
}
}

So, in the above code i am enabling the watchdog for 10sec,if the code didn't reaches to end of while loop with in 10sec then the controller should get restart.But this is not working properly.I want to know what is the exact procedure to implement it.


Top
 Profile  
 
 Post subject: Re: Implementation of watchdog timer
PostPosted: Fri Apr 01, 2011 1:09 pm 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 574
readl and writel are uboot macros to access 32-bit registers, you could read/write to the same registers in a manner consistent with your own development philosophy.

#define writel(value, address) \
(*(volatile unsigned int *)(address)) = (value)
#define readl(address) \
(*(volatile unsigned int *)(address))

I'd write your code for you, but I'd had to charge.

I think there is enough information here, and in the part manual to get this working.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: