2 starting the stopwatch timer, Starting the stopwatch timer, 1 event counter control – Motorola ONCE SC140 User Manual

Page 9

Advertising
background image

Setting Up the Stopwatch Timer Within an Application

5

32-bits of the flag variable’s address are used. Thus, EDCA1_MASK is set to 0xffffffff, meaning all
address bits will be compared.

3.2

Starting the Stopwatch Timer

The C code to start the stopwatch timer is shown in Code 2.

Code 2. C Code to Start the Stopwatch Timer

#include “EOnCE_registers.h”

void EOnCE_stopwatch_timer_start()
{
WRITE_IOREG(ECNT_VAL,MAX_32_BIT);

/* Countdown will start at (2**32)-1 */

WRITE_IOREG(ECNT_EXT,0);

/* Extension will count up from zero */

WRITE_IOREG(ECNT_CTRL,0x12c);

/* Counting will be triggered by detection on EDCA1 */

EOnCE_stopwatch_timer_flag = 0;

/* This write to the flag triggers the counter */

}

Before triggering the stopwatch timer, it is necessary to initialize the counter registers. Initializing the
event counter requires set up of the following three 32-bit registers:

Event counter value register (ECNT_VAL)

Extension counter value register (ECNT_EXT)

Event counter control register (ECNT_CTRL)

Once these initializations are complete, the C code triggers the stopwatch timer and cycle counting
commences.

3.2.1

Event Counter Control

This section describes the initialization of the event counter registers. The register, ECNT_CTRL, controls
the behavior of the event counter. The fields of the ECNT_CTRL register are shown in Figure 3.

Figure 3. Event Counter Control Register (ECNT_CTRL)

Table 2 describes the settings of these fields in the stopwatch timer implementation.

Table 2. ECNT_CTRL Settings

Field

Setting

(binary value)

Description

EXT

1

Event counter operates as a 64-bit counter

ECNTEN

0010

The event counter is disabled, and will be enabled when an event is detected
by EDCA1

ECNTWHAT

1100

The counter will advance on each core clock cycle

Advertising