Software Timer
Élan™SC520 Microcontroller User’s Manual 18-3
For example, here is some example code that can be used to maintain a system timebase:
typedef unsigned long int DWORD; // an unsigned 32-bit value
typedef unsigned short int WORD: // an unsigned 16-bit value
static volatile WORD* SWTMRMILLI = 0xA0000200; // volatile is essential
static volatile WORD* SWTMRMICRO = 0xA0000202; // volatile is essential
static DWORD ticks; // the number of 1-ms ticks since system boot
// that have passed since system reset
static DWORD mics; // A running microsecond value
DWORD sys_ticks()
{
ticks += *SWTMRMILLI;
mics = *SWTMRMICRO + (ticks * 1000);
return ticks;
}
DWORD sys_mics()
{
ticks += *SWTMRMILLI;
mics = *SWTMRMICRO + (ticks * 1000);
return mics;
}
This is all the code necessary to maintain both a 32-bit microsecond and a 32-bit millisecond
timebase for an operating system or other timing needs.
18.4.1 Configuration Information
The software timer counter elements (millisecond and microsecond counts) are read-only.
The software timer is always free-running, and it does not have any input or output (external
pin or interrupt). The software timer can be configured to maintain an accurate time for
either a 33.000-MHz or a 33.333-MHz crystal.
18.5 INITIALIZATION
At system reset, the software timer begins counting up from zero.
The software timer must be initialized for operation with either 33.000 MHz or 33.333 MHz,
depending on the crystal being used in the system. This is configured with the XTAL_FREQ
bit in Software Timer Configuration (SWTMRCFG) register (MMCR offset C64h).