ZigBee Learning Path (11): Watchdog

Source: Internet
Author: User
Tags xms

I. Preface

Today, we want to learn through experiments and understand the use of the watchdog, the watchdog is to prevent the program to fly, through constant feeding to the dog, so that the watchdog can continue to monitor the running state of the program, when the program runs fly, can promptly pull back the program.

Two. Principle and analysis

The watchdog timer (WDT) is used as a recovery method in cases where the CPU may be subject to a software disruption. WDT must reset the system when the software is not able to clear WDT during the selected time interval. The watchdog can be used for applications that are affected by electrical noise, power failure, electrostatic discharge, or require a high reliability environment. If a watchdog function is not required for an application, the watchdog timer can be configured as an interval timer, which can be used to generate interrupts at selected intervals. This is what we learn about the watchdog, we first configure the WDT registers, the WDT registers are as follows:

The experiment selected is the watchdog mode, time interval 1 seconds to detect once, clear bit also to configure, equivalent to feed the dog.

Three. Procedures

#include <ioCC2530.h>

#define UINT unsigned int

#define UCHAR unsigned char

#define LED1 p1_0//P1_0 Connection LED1

#define LED2 p1_1//p1_1 Connection LED2

#define LED3 p1_4//p1_4 Connection LED3

function declaration void led_io_init (void); void Watchdog_init (void); void Feetdog (void); void delayms (UINT XMS);

/********************* function Name: Main function Description: Watchdog test (observe experimental phenomenon by commenting out "feed dog function") input parameter: None output parameter: None return value: None ****************/

void Main (void)

{

Led_io_init (); LED IO Initialization

Watchdog_init (); Watchdog initialization

while (1)

{

led1=~led1;

delayms (1000); With the comment test, you can see that the LCD1 flashes at a time interval of less than 1s, indicating that the system is continuously reset//

Feetdog (); To prevent the program from running and flying

} }

/*************** function Name: led_io_init function Description: led_io initialization function input parameter: None output parameter: None return value: None *********/

void Led_io_init (void)

{

P1dir=0xff;

led1=0; Light LED1.

led2=0; Light LED2, indicating function

Led3=1; Light LED3, indicating function

}

/************************ function Name: watchdog_init function Description: Watchdog initialization function input parameter: None output parameter: None return value: None ********** ***************/

void Watchdog_init (void)

{

Wdctl = 0x00; This is necessary, open idle to set the watchdog

Wdctl |= 0x08; Time interval One second, watchdog mode

}

/************************ function Name: Feetdog function Description: Hello dog function input parameter: None output parameter: None return value: None ******************** ****/

void Feetdog (void) {wdctl = 0xa0; Wdctl = 0x50; }

/*************************** function Name: delayms function Description: Millisecond delay input parameter: XMS: Delay time, such as I=XMS that is, delay I/2 milliseconds output parameter: None return value: No NE ***********************/

void delayms (UINT XMS)

{

UINT I,j;

for (i=xms;i>0;i--)

for (j=587;j>0;j--);

}

Four. Summary

Through the above program, we can see that the main program has been executing feetdog () This function, that is, always feeding the dog, so that the watchdog does not reset, if not feeding the dog this function, the watchdog will bite people, that is, let the program constantly reset, from the beginning to execute, watchdog in the actual project application, is still very common, I hope you understand a lot.

ZigBee Learning Path (11): Watchdog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.