Motorola ONCE SC140 Application Note

Enhanced once stopwatch timer

Advertisement

Quick Links

Using the SC140 Enhanced OnCE
Stopwatch Timer
Application Note
by
Kim-Chyan Gan
and Yuval Ronen
AN2090/D
Rev. 0, 11/2000

Advertisement

Table of Contents
loading

Summary of Contents for Motorola ONCE SC140

  • Page 1 Using the SC140 Enhanced OnCE ™ Stopwatch Timer Application Note Kim-Chyan Gan and Yuval Ronen AN2090/D Rev. 0, 11/2000...
  • Page 2 “Typicals” must be validated for each customer application by customer’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 support 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.
  • Page 3: Table Of Contents

    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 minimizes CPU load, enabling more applications to fit into a single chip. In selecting a processor for a system, it is important to understand and compare the speed of execution of different processors.
  • Page 4 Conclusion ............17 References .
  • Page 5: Introduction

    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 DSP’s Enhanced On-Chip Emulation (OnCE) module.
  • Page 6: Sc140 Enhanced Once Stopwatch Timer Capabilities

    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. Features The Enhanced OnCE stopwatch timer provides the following features: •...
  • Page 7: Setting Up The Stopwatch Timer Within An Application

    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 cycles to actual time and puts all the application code together. Finally, this section explains how to adapt the stopwatch timer code to other SC140-based devices.
  • Page 8 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.
  • Page 9: Starting The Stopwatch Timer

    32-bits of the flag variable’s address are used. Thus, EDCA1_MASK is set to 0xffffffff, meaning all address bits will be compared. 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”...
  • Page 10: Stopping The Stopwatch Timer

    3.2.2 Counter Registers ECNT_VAL is a countdown counter, and ECNT_EXT is a countup counter. ECNT_VAL is decremented on each occurrence of an event, as specified in the control register. ECNT_EXT is incremented each time there is an underflow in ECNT_VAL. For maximum cycle counting capacity, the stopwatch timer implementation initializes ECNT_VAL to the largest possible value which is 4294967295, or 0xffffffff.
  • Page 11: Putting It All Together

    Code 4. C Code for Clock-Cycle-to-Time Conversion typedef enum { EONCE_SECOND, EONCE_MILLISECOND, EONCE_MICROSECOND } tunit; unsigned long Convert_clock2time(unsigned long clock_ext, unsigned long clock_val, short option) unsigned long result; switch(option) case EONCE_SECOND: result= clock_ext*MAX_32_BIT/CLOCK_SPEED + clock_val/CLOCK_SPEED; break; case EONCE_MILLISECOND: result= clock_ext*MAX_32_BIT/(CLOCK_SPEED/1000) + clock_val/(CLOCK_SPEED/1000);...
  • Page 12: Adapting Stopwatch Timer Code To Other Sc140 Devices

    Adapting Stopwatch Timer Code to Other SC140 Devices The stopwatch timer implementation controls the Enhanced OnCE by writing to its memory-mapped registers. The addresses of these registers are determined in the memory map of the device in which the SC140 core is embedded. The offset between the base address of the memory-mapped peripherals and the addresses of the Enhanced OnCE registers is the same across SC140-based devices.
  • Page 13 Figure 4. Finding the Starting Address in the Debugger After finding the starting address, the event detector can be setup. The procedures are outlined in these steps: 1. Choose EOnCE > EOnCE Configurator > EDCA1. 2. Click PC in the “Bus Selection” box. 3.
  • Page 14 4.1.2 Setting Up the Event Counter The event counter is configured to the same mode as described in Section 3.2.1, “Event Counter Control,” on page -5, except this time the configuration is made using the debugger windows: 1. Choose EOnCE > EOnCE Configurator > Counter. 2.
  • Page 15: Stopping The Stopwatch Timer

    Figure 6. Event Counter Settings Stopping the Stopwatch Timer Stopping the stopwatch timer is achieved by halting execution of the application at a breakpoint. Set up the breakpoint at the point in the application at which timing should stop to achieve the desired affect. After the breakpoint is in place, the debugger can be instructed to run the application.
  • Page 16: Setting Up The System Clock Speed

    Figure 7. Event Counter Dialog Box When Debugger Halts at Breakpoint Setting Up the System Clock Speed Every SC140-based device contains a Phase Lock Loop (PLL) block, which controls the operating frequency of the device. The frequency of the device is governed by the frequency control bits in the PLL control register, as defined in Equation 2.
  • Page 17: Setting Up The Pll In Software

    Figure 8. Programming Model of PCTL0 Figure 9. Programming Model of PCTL1 Setting Up the PLL in Software The clock frequency of the SC140 can be set up either in software or in hardware. This section describes how to set the SC140 in the Software Development Platform (SDP) to operate at 300 MHz using these two alternatives.
  • Page 18: Setting Up The Pll In Hardware

    With these configurations, the Fchip is calculated as expressed in Equation 3. Fchip The PLL should be configured so that the resulting PLL output frequency is in the range specified in the device’s technical data sheet. Setting Up the PLL in Hardware During the assertion of hardware reset, the value of all the PLL hardware configurations pins are sampled into the clock control registers (PCTL0 and PCTL1).
  • Page 19: Testing The Stopwatch Timer

    In EE_CTRL, the EE1DEF field is set to 00, which signifies output signal when detected by EDCA1. The remaining fields in EE_CTRL are irrelevant because they are not used. Code 7 shows the setup code for EE control registers. Code 7. EOnCE_LED_init() void EOnCE_LED_init() *((long *)EE_CTRL) &= ~(3<<2);...
  • Page 20 #include <stdio.h> #include "EOnCE_stopwatch.h" #ifdef COMPILER_BETA_1_BUG extern long ECNT_VAL; #else #include "EOnCE_registers.h" #endif void PLL_setup_300MHz() asm("move.l #$80030003,PCTL0"); asm("move.l #$00010000,PCTL1"); void main(){ unsigned long clock_ext,clock_val,clock_cycle,cycle_req; unsigned long time_sec; extern unsigned long CLOCK_SPEED; PLL_setup_300MHz(); EOnCE_stopwatch_timer_init(); EOnCE_LED_init(); cycle_req = CLOCK_SPEED*10; EOnCE_stopwatch_timer_start(); do { READ_IOREG(ECNT_VAL,clock_cycle);...
  • Page 21 [1] StarCore SC140 DSP Core Reference Manual (order number MNSC140CORE/D), Motorola Inc., 2000. [2] StarCore 140 Software Development Platform, Hardware Reference Manual (order number SC140SDPRM/D), Motorola Inc., 1999. [3] Code Warrior Targeting StarCore (Beta 1.0 Release), Metrowerks Corp., 1993. Conclusion...
  • Page 22 Using the SC140 Enhanced OnCE Stopwatch Timer...
  • Page 23 Appendix A Complete Example of Profiling A complete example of profiling using the Enhanced OnCE stopwatch timer in the SC140 platform is presented in this appendix. typedef enum { EONCE_SECOND, EONCE_MILLISECOND, EONCE_MICROSECOND } tunit; #define READ_IOREG(reg,val) val = *((volatile long *)reg) #define WRITE_IOREG(reg,val) *((volatile long *)reg) = val #define MAX_32_BIT 0xffffffff void EOnCE_stopwatch_timer_init();...
  • Page 24 EOnCE registers */ #define EXCP_TABLE 0x7000 #define REG_BASE_ADDRESS 0x00effe00 #ifdef COMPILER_BETA_1_BUG long EE_CTRL long EDCA1_CTRL long EDCA1_REFA long EDCA1_REFB long EDCA1_MASK long ECNT_CTRL long ECNT_VAL long ECNT_EXT #else #define EMCR #define ERCV #define ETRSMT0 #define ETRSMT1 #define EE_CTRL #define PC_EX #define EDCA0_CTRL #define...
  • Page 25 Code A-3. EOnCE_stopwatch.c * Header file contains definitions of EOnCE memory-mapped register addresses, * and definition of the WRITE_IOREG() macro. #include "EOnCE_registers.h" #include "EOnCE_stopwatch.h" unsigned long CLOCK_SPEED = 300000000; static volatile long EOnCE_stopwatch_timer_flag; void EOnCE_stopwatch_timer_init() WRITE_IOREG(EDCA1_REFA,(long)&EOnCE_stopwatch_timer_flag); WRITE_IOREG(EDCA1_REFB,(long)&EOnCE_stopwatch_timer_flag); WRITE_IOREG(EDCA1_MASK,MAX_32_BIT); WRITE_IOREG(EDCA1_CTRL,0x3f06); void EOnCE_LED_init() *((long *)EE_CTRL) &= ~(3<<2);...
  • Page 26 #include "EOnCE_stopwatch.h" #include <prototype.h> #include <stdio.h> #define L_WINDOW 240 # define SIGN_32 (1U << 31U) Word16 Autocorr (Word16 x[], Word16 m, Word16 r_h[], Word16 r_l[], const Word16 wind[]); void L_Extract (Word32, Word16 *, Word16 *); Word16 test_x[240] = -116, -179, -258, -128, 321, 714, 757, 640, 648, 867, 840, 1181, 1071, 786, 760, 617, 803, 697, 559, 64, 164, 492, 437, 413, 167, -170, -75, 97, 27, 546, 618, 103, 51, 371, 104, -410, -387, -178, -151, -180, -213, -295, -430, -369, -268, -407, -387, -171, -217,...
  • Page 27 asm("move.l #$00010000,PCTL1"); int main(void) int rc = 0; unsigned long clock_ext, clock_val,time_us; PLL_setup_300MHz(); EOnCE_stopwatch_timer_init(); EOnCE_LED_init(); EOnCE_stopwatch_timer_start(); if (Autocorr(test_x, test_m, test_r_h, test_r_l, test_wind) != ref_result) { rc = 1; EOnCE_stopwatch_timer_stop(&clock_ext, &clock_val); EOnCE_LED_off(); time_us=Convert_clock2time(clock_ext, clock_val,EONCE_MICROSECOND); printf("time consumed by function is %d us\n", time_us); return rc;...
  • Page 28 Using the SC140 Enhanced OnCE Stopwatch Timer...

Table of Contents