Motorola ONCE SC140 User Manual

Using the SC140 Enhanced OnCE
Stopwatch Timer
Application Note
Kim-Chyan Gan
AN2090/D
Rev. 0, 11/2000
by
OnCE is a trademark of Motorola, Inc. This document contains information on a new product. Specifications and information herein are subject to change
without notice.
Motorola reserves the right to make changes without further notice to any products herein. Motorola makes no warranty, representation or guarantee regarding the suitability of its products for any pa rticular purpose, nor does Motorola assume any liability arising out of the application or use of any product or circuit, and specifically disclaims any and all liability, including without limitation consequential or incidental damages. “Typical” parameters which may be provided in Motorola data sheets and/or specifications can and do vary in different applications and actual performance may vary ov er time. All operating parameters, including “Typicals” must be validated for each customer application by cust omer’s technical experts. Motorola does not convey any license under its patent rights nor the rights of others. Motorola products are not designed, intended, or authorized for use as components in systems intended for surgical implant into the body, or other applications intended to suppor t life, or for any other application in which the failure of the Motorola product could create a situation where personal injury or death may occur. Should Buyer purchase or use Moto rola products for any such unintended or unauthorized application, Buyer shall indemnify and hold Motorola and its officers, employees, subsidiaries, affiliates, and distributors harmless against all claims, costs, damages, and expenses, and reasonable attorney fees arising out of, directly or indirectly, any claim of personal injury or death associated with such unintended or unauthorized use, even if such claim alleges that Motorola was negligent regarding the design or manufacture of the part.
Motorola and are registered trademarks of Motorola, Inc. Motorola, Inc. is an Equal Opportunity/Affirmative Action Employer. All other tradenames, trademarks, and registered trademarks are the property of their respective owners.
How to reach us: USA/EUROPE/Locations Not Listed: Motorola Literature Distribution; P.O. Box 5405, Denver, Colorado, 80217
1-303-675-2140 or 1-800-441-2447 JAPAN: Motorola Japan, Ltd.; SPS, Technical Information Center, 3-20-1, Minami-Azabu, Minato-ku,
Tokyo 106-8573 Japan. 81-3-3440-3569 ASIA/PACIFIC: Motorola Semiconductors H.K. Ltd., Silicon Harbour Centre, 2 Dai King Street,
Tai Po Industrial Estate, Tai Po, N.T., Hong Kong. 852-26668334
Customer Focus Center: 1-800-521-6274
HOME PAGE: http://motorola.com/s emi co ndu ct ors
© Copyright Motorola, Inc., 2000

Abstract and Contents

In software application development on embedded devices, optimization is critical. Optimized code provides not only faster processing speed but also lower power consumption and longer battery life. Optimized code also mini miz es CPU load, enabling more applications to f it in to a single chip. In s el ect ing a processor for a system, it is important to understand and compare the speed of execution of different processors. All of these applications may require a stopwatch as a criterion for measurement. This application note presents the stopwatch timer application developed on the Software Development Platform (SDP). The stopwatch timer is implemented using the Enhanced OnCE non-intrusive to SC14 0 operation , therefor e, timing can be correctly me asured. Two sto pwatch techn iques, with and without source code modification, are presented. This application note also explains how to port stopwatch applications to other SC140 based devices.
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 SC140 Enhanced OnCE Stopwatch Timer Capabilities . . . . . . . . . . . . . . . . . . . 2
2.1 Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.2 Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.3 Implementation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
resource, which is
3 Setting Up the Stopwatch Timer Within an Application . . . . . . . . . . . . . . . . . . . 3
3.1 Initializing the Stopwatch Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3.2 Starting the Stopwatch Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.3 Stopping the Stopwatch Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.4 Converting Cycles to Actual Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.5 Putting it All Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.6 Adapting Stopwatch Timer Code to Other SC140 Devices . . . . . . . . . . . . . . . . . . . . . . . . 8
4 Setting Up the Stopwatch Timer Within the Debugger . . . . . . . . . . . . . . . . . . . . 8
4.1 Initializing the Stopwatch Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.2 Stopping the Stopwatch Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5 Setting Up the System Clock Speed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5.1 Setting Up the PLL in Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5.2 Setting Up the PLL in Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
6 Verifying Correct Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
6.1 Using the LED on the SDP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
6.2 Testing the Stopwatch Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Abstract and Contents iii
7 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
8 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Appendix A
Complete Example of Profiling
iv Using the SC140 Enhanced OnCE Stopwatch Timer

1 Introduction

A stopwatch timer is an apparatus for measuring the exact duration of an event. Measuring time during execution of code on a Digital Signal Processor (DSP) is useful to identify opportunities for code optimization, to understand system loading, and to compare execution speeds of different processors.
This application note presents techniques to implement a stopwatch timer on the StarCore, SC140, using
the built-in features of the DSPs Enhanced On-Chip Emulation (OnCE) module. Although many devices with embedded DSPs provide application-specific timer blocks, these timers
cannot be used for debugging purposes without interference from the application itself. The ability to use the Enhanced OnCE as a stopwatch timer allows for non-intrusive timing capabilities and is available on any system that integrates the SC140 core.
Two techniques to set up the stopwatch timer are described in this application note:
1. Setting up the stopwatch timer using the SC140 code within an application.
1
2. Setting up the stopwatch timer using the Metrowerks Code Warrior debugger
The examples given in this application note describe the use of the stopwatch timer in the StarCore, SC140s Software Development Platform (SDP). Minor configuration changes are needed to apply the techniques to other SC140-based devices. The necessary modifications are also described in this application note.
This document is organized to present these techniques as follows: Section 2, SC140 Enhanced OnCE Stopwatch Timer Capabilities, describes the specific capabilities of the stopwatch timer for the SC140 Enhanced OnCE. Section 3, Setting Up the Sto pwatch Tim er Within an Application, describes instrumenting the SC1 40 application code to u se the stopwatch timer. Section 4, Setting Up the Stopwatch Timer Within t he Debug ger, pre sen ts th e set up o f the stopwat ch ti mer wit hin th e Met rowerks Code Warrior debugger.
.
Supporting information is included in the remainder of the document. Section 5, Setting Up the System Clock Speed, describes how to set the clock rate of the SC140 in the SDP by configuring the PLL in hardware and software applications. Section 6, Verifying Correct Setup, describes techniques to verify that the system is set up co rr ectly and that the measuremen ts are reasonable. The Se cti on 7, “Conclusion,” provides a summary of this document. Section 8, “References,” lists additional documentation to help the reader and Appendix A, Complete Example of Profiling,” provides a complete profile using the Enhanced OnCE stopwatch timer in the SC140.
1. At the time this application note was written, the release of Metrowerks Code Warrior is Beta v.1.0. All the figures related to screen capture of Code Warrior tools may vary in future versions.
Introduction 1
2 SC140 Enhanced OnCE Stopwatch Timer
Capabilities
This section presents the features of the Enhanced OnCE stopwatch timer and the resources required for implementation. The capabilities of the implementation of the stopwatch timer are also explained.

2.1 Features

The Enhanced OnCE stopwatch timer provides the following features:
A 64-bit counter , incrementing on each DSP clock cycle. The co unter is less suscepti ble to overflow with 64-bit precision.
The stopwatch timer can be used repeatedly during the execution of an application.
Conversion between clo ck cycle s and abs olu te time, based on th e operat ing cl ock fre quency of the DSP, is described in Section 3.4, Converting Cycles to Actual Time, on page -6.

2.2 Resources

The Enhanced OnCE stopwatch timer requires use of these resources:
One Enhanced OnCE event detector (of the six available on each DSP)
The Enhanced OnCE event counter
Program memory of 724 bytes
Because the Enhanced OnCE supports only one event counter, the stopwatch timer cannot be used if the event counter is required for other debugging purposes (such as; the set up of a debugger breakpoint that requires counting occurrences of events).

2.3 Implementation

The stopwatch timer implementation allocates a variable in memory which serves as the target for memory write operations. The Enhanced OnCE event detector is set up to detect writes to this flag variable. When setting up of an Enhanced OnCE event detector to detect memory access operations, it is necessary to specify which of the two data memory buses should be “snooped”. Because the selection of the bus to be used is performed dynamically, the event detector is set up to snoop both buses (XABA or XABB). Upon detecting the write to the flag variable, the event detector enables the Enhanced OnCE event counter, which starts counting down.
The Enhanced OnCE event counter can be configured as either a 64-bit counter or a 32-bit counter. Configuring the cou nte r to use 64-bits el i mi nat es the danger of counte r o v er fl ow, at a negligible extra c ost .
To stop the stopwatch timer, an appropriate value is written into the Enhanced OnCE memory-mapped event counter cont rol regi ster. When this oper ation is completed, the cy cle countd own halts. At this poi nt it is possible to read out the values of the Enhanced OnCE event counter registers, and translate them into elapsed number of cycles, or elapsed absolute time.
2 Using the SC140 Enhanced OnCE Stopwatch Timer
3 Setting 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 Figure 1. Additionally, this section presents the conversion of cyc les t o ac tual time and puts all t he application cod e t oge the r. Finally, this sect ion explains how to adapt the stopwatch timer code to other SC140-based devices.
Initialize Stopwatch
Enable Stopwatch
Sequence Instructions
to be Timed
Disable Stopwatch
Figure 1. Sequence of Operations

3.1 Initializing the Stopwatch Timer

The C code to set up the stopwatch timer is shown in Code 1.
Code 1. Event Detector Setup Code
/* * Header file contains defin itions of EOnCE memor y-mapped register add resses, * and definition of the WRIT E_IOREG() macro. */ #include “EOnCE_registers.h”
static volatile long EOnCE_s topwatch_timer_flag; /*Global du mmby variable*/ void EOnCE_stopwatch_timer_i nit()
{
WRITE_IOREG(EDCA1_REFA,(long )&EOnCE_stopwatch_tim er_flag); WRITE_IOREG(EDCA1_REFB,(long )&EOnCE_stopwatch_tim er_flag); WRITE_IOREG(EDCA1_MASK,MAX_3 2_BIT); WRITE_IOREG(EDCA1_CTRL,0x3f0 6);
}
/* Address to snoop for on X ABA */ /* Address to snoop for on X ABB */ /* No masking is performed i n address comparison */ /* Detect writes on both XAB A 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 memory-mapped registers.

Setting Up the Stopwatch Timer Within an Application 3

Initializing the stopwatch timer consists of setting up the Address Event Detection Channel (EDCA). The role of EDCA in the stopwatch timer implementation is to trigger the commencement of the cycle countdown. The Enhanced OnCE supports six EDCAs. The implementation presented in this application note uses EDCA1, though this choice is arbitrary.
Set up of the EDCA requires initializing the following four registers:
The 32-bit EDCA reference value register A (EDCA1_REFA).
The 32-bit EDCA reference value register B (EDCA1_REFB).
The 32-bit EDCA mask register (EDCA1_MASK).
The 16-bit EDCA control register (EDCA1_CTRL).
3.1.1 Event Detecto r Control
The register, EDCA1_CTRL, c ontrols the beha vior of the EDCA. The fields of the EDCA1_ CTRL regist er are shown in Figure 2.
Figure 2. EDCA Control Register (EDCA1_CTRL)
Table 1 describes the settings of these fields in the stopwatch timer implementation.
Table 1. EDCA_CTRL Settings
Field
EDCAEN 1111 This channel is enabled CS 11 Trigger event if address matches either comparator A or comparator B CBCS 00 An address match is detected when sampled bus value equals value in
CACS 00 An address match is detected when sampled bus value equals value in
ATS 01 Detect write access only BS 10 The sampled buses are XABA and XABB
Setting
(binary value)
Description
EDCA_REFB
EDCA_REFA
The EDCA becomes enabled as soon as th ese val ues are written into the control register. The EDCA stays enabled for the duration of the program execution to enable repeated use of the stopwatch timer.
3.1.2 Address Comparison Setup
The purpose of the address comparison in the EDCA is to detect writes to the stopwatch timer flag variable. Because writes may take place on either of the two data m emory buses, both registers, EDCA1_REFA and EDCA1_REFB, are set up to contain the address of the stopwatch timer flag variable.
The register EDCA1_MASK allows masking of address bits when comparing the sampled address with those in the EDCA1_REFA and EDCA1_REFB registers. In the implementat ion of the sto pwatch timer all
4 Using the SC140 Enhanced OnCE Stopwatch Timer
32-bits of the flag variables address are used. Thus, EDCA1_MASK is se t 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_s tart()
{ WRITE_IOREG(ECNT_VAL,MAX _32_BIT); /* Countdown will start at ( 2**32)-1 */ WRITE_IOREG(ECNT_EXT,0); /* Extension will count up f rom zero */ WRITE_IOREG(ECNT_CTRL,0x 12c);
EOnCE_stopwatch_timer_fl ag = 0; }
Before triggering the stopwatch ti mer, it is necessary to initialize the counter registers. Ini tializing 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)
/* Counting will be triggere d by detection on EDC A1 */ /* This write to the flag tr iggers the counter */
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 desc ribes the i niti aliza tion o f the even t count er re gist ers. The re giste r, ECNT_C TRL, contr ols 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
EXT 1 Event counter operates as a 64-bit counter ECNTEN 0010 The event counter is disab led, and will b e enabled whe n an event is detected
Setting
(binary value)
Description
by EDCA1
ECNTWHAT 1100 The counter will advance on each core clock cycle
Setting Up the Stopwatch Timer Within an Application 5
Loading...
+ 19 hidden pages