Download Rabbit 2000™ Microprocessor User`s Manual

Transcript
SEC_TIMER in memory. SEC_TIMER is updated every second by the periodic interrupt
and may be read or written directly by the user’s programs. Since SEC_TIMER is driven by
the same oscillator as the real time clock there is no relative gain or loss of time between
the two. As part of the standard startup code SEC_TIMER has bits 15-46 of the real time
clock copied to it. SEC_TIMER holds the number of seconds since 12 AM of 1-January1980. SEC_TIMER can accomodate 136 years from 1980 or to the year 2116. Another long
timer MS_TIMER counts milliseconds and can be used in a similar manner. MS_TIMER
wraps around from max count to zero approximately every 6 weeks. The software that
uses the counters measures intervals correctly even if the counter used wraps arround.
unsigned long int read_rtc(void); // read bits 15-46 rtc
void write_rtc(unsigned long int time); // write bits 15-46
// note: bits 0-14 and bit 47 are zeroed
Two utility routines are provided that can be used to convert times between the traditional
format (10-Jan-2000 17:34:12) and the seconds since 1-Jan-1980 format.
// converts time structure to seconds
unsigned long mktime(struct tm *timeptr);
// seconds to structure
unsigned int mktm(struct tm *timeptr, unsigned long time);
The format of the structure used is the following
struct tm {
char tm_sec;
char tm_min;
char tm_hour;
char tm_mday;
char tm_mon;
char tm_year;
char tm_wday;
};
//
//
//
//
//
//
//
seconds 0-59
0-59
0-59
1-31
1-12
00-150 (1900-2050)
0-6 0==sunday
The day of the week is not used to compute the long seconds, but it is generated when
computing from long seconds to the structure. A utility routine setclock.c is available to
set the date and time in the real time clock from the Dynamic C console.
16.4 WatchDog Support Software
A microprocessor system can crash for a variety of reasons. A software bug or an electrical upset are common reasons. When the system crashes the program will typically settle
into an endless loop because parameters that govern looping behavior have been corrupted. Typically the stack becomes corrupted and returns are made to random addresses.
The usual corrective action taken in response to a crash is to reset the microprocessor and
reboot the system. The crash can be detected either because an anomaly is detected by program consistency checking or because a part of the program that should be executing periodically is not executing and the watchdog times out.
142
Rabbit 2000 Microprocessor