Setting Up the Stopwatch Timer Within an Application 3
3Setting Up the Stopwatch Timer Within an Application
This section describes the operations necessary to initialize, start, and stop the stopwatch timer within an
application. The sequence of operations is shown in Figure1. Additionally, this section presents the
conversion of cycles to actual time and puts all the application cod e t ogether. Finally, this section explains
how to adapt the stopwatch timer code to other SC140-based devices.
Figure 1. Sequence of Operations

3.1 Initializing the Stopwatch Timer

The C code to set up the stopwatch timer is shown in Code1.
Code 1. Event Detector Setup Code
/*
* Header file contains definitions of EOnCE memory-mapped register addresses,
* and definition of the WRITE_IOREG() macro.
*/
#include “EOnCE_registers.h”
static volatile long EOnCE_stopwatch_timer_flag; /*Global dummby variable*/
void EOnCE_stopwatch_timer_init()
{WRITE_IOREG(EDCA1_REFA,(long)&EOnCE_stopwatch_timer_flag);
/* Address to snoop for on XABA */
WRITE_IOREG(EDCA1_REFB,(long)&EOnCE_stopwatch_timer_flag);
/* Address to snoop for on XABB */
WRITE_IOREG(EDCA1_MASK,MAX_32_BIT);
/* No masking is performed in address comparison */
WRITE_IOREG(EDCA1_CTRL,0x3f06);
/* Detect writes on both XABA and XABB */
}
The header file EOnCE_registers.h contains the macro definitions, such as EDCA1_MASK, which
provides each of the Enhanced OnCE memory-mapped registers corresponding memory address.
This header file also defines the C macros: READ_IOREG() and WRITE_IOREG(). These macros
simplify the read and write operations on m emory-mapped registers.
Sequence Instructions
to be Timed
Initialize Stopwatch
Enable Stopwatch
Disable Stopwatch