#How to use the Watchdog

<div class="text-success lead">
This article illustrates how to use the watchdog on Aria G25 and Arietta G25
</div>

##AT91bootstrap (boot.bin) configuration

By default the watchdog is disabled at boot time by AT91Bootstrap. To enable it you have to recompile
AT91Bootstrap after have disabled this flag:
 
	[ ] Disable Watchdog   

To know how to compile AT91Bootstrap follow the tutorials on [this link](/compile_at91bootstrap).

To change the default flag value use the <b>make menuconfig</b> command.

##Defconfig configuration (Linux Kernel)

This is the Kernel flag to enable inside the Kernel configuration.

	Device Drivers  --->
	  [*] Watchdog Timer Support  --->
		<*>   AT91SAM9X / AT91CAP9 watchdog

To know how to change the kernel configuration and compile it to generate 
the bootable zImage follow this tutorials [this link](/tutorials).

##Device tree configuration (Linux Kernel)

Add to board <b>xxxx.dts</b> these lines inside the <b>apb</b> section: 

	ahb {
		apb {

			...
	<b>
			watchdog@fffffe40 {
				compatible = "atmel,at91sam9260-wdt";
				reg = <0xfffffe40 0x10>;
				timeout-sec = <30>;
				status = "okay";
			};
	</b>
			...
		};
	};	

Setting the parameter <b>timeout-sec</b> as you like.

To know how to compile the Device Tree file follow the tutorials on how to
cross compile the Linux Kernel on [this link](/tutorials).

##Using the watchdog

If everything is going well you will see this message on the debug port during the bootstrap:

	at91sam9_wdt: enabled (heartbeat=30 sec, nowayout=0)

or from the command line:

	root@arietta:~# dmesg | grep "wdt"
	[    5.375000] at91sam9_wdt: enabled (heartbeat=30 sec, nowayout=0)

a device node called <b>/dev/watchdog</b> exists on the rootfs:

	root@arietta:~# ls /dev/watchdog
	/dev/watchdog

Now simply try the watchdog by typing and wait 30 sec doing nothing...

	# echo "hello" > /dev/watchdog
	watchdog watchdog0: watchdog did not stop!

After 30 secs the board will restart.

	at91sam9_wdt: I will reset your machine !

Writing something on <b>/dev/watchdog</b> you have armed the watchdog timer and after
the first write you have to write on it before 30 sec to avoid the restart.

More info about the watchdog under Linux is available on this link:

* [Watchdog Kernel documentatiom](https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/plain/Documentation/watchdog/)
* [Watchdog programming examples](https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/plain/Documentation/watchdog/src/)

