1587 views|0 replies

6555

Posts

0

Resources
The OP
 

CC2541 Bluetooth Watchdog Mode [Copy link]


Watchdog is a way for CPU to recover itself when software runs away. Watchdog is divided into hard watchdog and soft watchdog. Hard watchdog is realized by special watchdog hardware circuit. There are many watchdog chips, such as DS1232, which has power supply voltage monitoring function in addition to watchdog function. Soft watchdog is the watchdog function realized by software. Now many CPUs have built-in soft watchdog. It is difficult to say whether hard watchdog or soft watchdog is better. If soft watchdog is enough, try to use soft watchdog to simplify the design. Watchdog is just a timer! When the software cannot set the watchdog timer (WDT) within the selected time interval, WDT resets the system. Watchdog can be used in harsh working environment or environment with high reliability requirements such as electrical noise, power failure or electrostatic discharge. If the system does not need to apply watchdog, WDT can be configured as interval timer, and interruption will be generated when the time interval is reached. The features of WDT are as follows:
4 selectable time intervals Watchdog
mode Timer mode Generate interrupt request in timer mode The CC2541 watchdog timer (WDT) can be configured as watchdog mode or ordinary interval timer. WDT includes a 15-bit timer/counter whose frequency is determined by a 32.768KHz crystal oscillator. The user cannot view the counter value. Watchdog mode



Sample program: WDT is in watchdog mode, the time interval is 1s, and the watchdog is fed regularly. If the watchdog is not fed, the system will reset continuously, and the LED light will turn on and off every 1s. There is no need for the delay program in line 87, because the watchdog time interval is set to 1s, and the LED is on for exactly 1s.

Copy code
1 /******************************************************************************
2 *File name: WDT.c
3 *Author: Chen Zhao
4 *Time: 2015-06-01
5 *Version: 1.0
6 *Description: Watchdog program
7 **************************************************************************/
8 #include
9
10 #define LED1 P1_0
11
12 /**********************************************************************************
13 *Function name: Delay1ms
14 *Function: Delay 1ms
15 *Entry parameter: uiDelay, delay parameter, the larger the value, the longer the delay
16 *Exit parameter: None
17 **************************************************************************/
18 void Delay1ms(unsigned int uiDelay)
19 {
20 unsigned int i,j;
21 for(i = 0; i < uiDelay; i++)
22 {
23 for(j = 0;j < 1322; j++);
24 }
25 }
26
27 /****************************************************************
28 *Function name: InitClock
29 *Function: system clock initialization
30 *Entry parameter: None
31 *Exit parameter: None
32 *****************************************************************/
33 void InitClock(void)
34 {
35 CLKCONCMD &= ~(1 << 6); //Select 32MHz crystal
36 while(CLKCONSTA & (1 << 6)); //Wait for the clock to stabilize
37 CLKCONCMD &= ~0x47; //Both the system clock and the timer clock are 32M
38 }
39
40 /******************************************************************************
41 *Function name: InitLED
42 *Function: LED lamp initialization
43 *Entry parameter: None
44 *Exit parameter: None
45 ******************************************************************************/
46 void InitLED(void)
47 {
48 P1SEL &= ~0x01; //P1.0 is set as a general I/O port
49 P1DIR |= 0x01; //P1.0 is set as output
50 }
51
52 /**************************************************************************************
53 *Function name: Init_Watchdog
54 *Function: Watchdog initialization
55 *Entry parameter: None
56 *Exit parameter: None
57 ******************************************************************************/
58 void Init_Watchdog(void)
59 {
60 WDCTL = 0x00; //Open IDLE to set the watchdog
61 WDCTL |= 0x08; //Timer interval selection, one second interval, set to watchdog mode
62 }
63
64 /**************************************************************************
65 *Function name: FeetDog
66 *Function: Feed the dog, clear the counter
67 *Entry parameter: None
68 *Exit parameter: None
69 **************************************************************************/
70 void FeetDog(void)
71 {
72 WDCTL = 0xa0; //Clear timer.
83 InitLED(); //LED initialization 84 LED1 = 0; //Turn off LED1 85 Delay1ms(1000); 86 LED1
= 1;
// Turn
on LED1 87 //Delay1ms (1000); 88 Init_Watchdog(); //Watchdog initialization 89 90 while ( 1 ) 91 { 92 FeetDog(); //Dog feeding program 93 //Comment out the sub-function, the system keeps resetting, and LED1 flashes 94 } 95 } Use privileges for more operations



















This post is from Wireless Connectivity
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list