background image

Complete Example of Profiling

A-3

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;    /*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 */

}

void EOnCE_LED_init()
{

*((long *)EE_CTRL) &= ~(3<<2);                  /* Toggle EE1 when event1 happens */

}

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 */

}

void EOnCE_stopwatch_timer_stop(unsigned long *clock_ext, unsigned long *clock_val)
{
    WRITE_IOREG(ECNT_CTRL,0); 

/* Disable event counter */

    READ_IOREG(ECNT_VAL,*clock_val); /* Save ECNT_VAL in program variable */
    READ_IOREG(ECNT_EXT,*clock_ext); /* Save ECNT_EXT in program variable */
    *clock_val = (MAX_32_BIT-*clock_val); /* Adjust for countdown */
}

void EOnCE_LED_off()
{
    EOnCE_stopwatch_timer_flag = 0;                 /* Create an EDCA1 event */
}

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 clock_val/CLOCK_SPEED;
            break;
        case EONCE_MILLISECOND: 
            result= clock_ext*MAX_32_BIT/(CLOCK_SPEED/1000) 
                    + clock_val/(CLOCK_SPEED/1000);
            break;
        case EONCE_MICROSECOND: 
            result= clock_ext*MAX_32_BIT/(CLOCK_SPEED/1000000) 
                    + clock_val/(CLOCK_SPEED/1000000);
            break;
        default: result=0;                          /* error condition */
            break;
    }
    return result;
}

Summary of Contents for ONCE SC140

Page 1: ...AN2090 D Rev 0 11 2000 Using the SC140 Enhanced OnCE Stopwatch Timer Application Note by Kim Chyan Gan and Yuval Ronen ...

Page 2: ...ion in which the failure of the Motorola product could create a situation where personal injury or death may occur Should Buyer purchase or use Motorola 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...

Page 3: ...rectly measured Two stopwatch techniques 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 3 Setting Up the Stopwatch Timer Within an Application 3 3 1 Initializing the Sto...

Page 4: ...iv Using the SC140 Enhanced OnCE Stopwatch Timer 7 Conclusion 17 8 References 17 Appendix A Complete Example of Profiling ...

Page 5: ...e 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 Stopwatch Timer Within an App...

Page 6: ...oses 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 operation...

Page 7: ...ister 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...

Page 8: ... EDCA becomes enabled as soon as these values 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 memory buse...

Page 9: ...izing 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...

Page 10: ...d ECNT_EXT registers into program variables This allows putting the stopwatch timer into use again without losing the result of the previous measurement Because ECNT_VAL contains the result of a countdown process the routine converts that result into the actual number of cycles elapsed by subtracting the ECNT_VAL from the value to which it was initialized specifically 4294967295 3 4 Converting Cyc...

Page 11: ...e use of the stopwatch timer using the routines that have been described so far Code 5 Use of Stopwatch Timer Functions long clock_ext clock_val clock_cycle time_sec EOnCE_stopwatch_timer_init Execute once per program execution EOnCE_stopwatch_timer_start Code whose execution time is measured goes here EOnCE_stopwatch_timer_stop clock_ext clock_val time_sec Convert_clock2time clock_ext clock_val E...

Page 12: ... be available in object form only In such cases it is possible to measure execution times by setting up the stopwatch timer within the Metrowerks Code Warrior SC140 debugger This section explains this set up 4 1 Initializing the Stopwatch Timer The technique described in Section 3 triggered the stopwatch timer by detecting a write to the stopwatch timer flag variable When the stopwatch timer is se...

Page 13: ... steps 1 Choose EOnCE EOnCE Configurator EDCA1 2 Click PC in the Bus Selection box 3 Enter the address of the first instruction in the measured code into the Comparator A Hex 32 bits box 4 Click Enable in the Enabled after Event On box Figure 5 on page 10 shows the event detection settings after performing these steps For more detailed information in Enhanced OnCE configuration in Code Warrior too...

Page 14: ...Control on page 5 except this time the configuration is made using the debugger windows 1 Choose EOnCE EOnCE Configurator Counter 2 Click Core Clock in the What to count box 3 Click EDCA1 in the Enable after Even On box 4 Type 0xffffffff in the Event Counter Value Hex 32 bits box 5 Check the box in the left side of Extension Counter Value Hex 32 bits The result of this procedure is shown in Figure...

Page 15: ...on page 12 shows an example of an event counter dialog box after the debugger halt at the breakpoint Because the countdown counter is initialized to maximum value 0xffffffff the difference between maximum value and the value in the Event Counter Value column yields the real SC140 clock counts To convert the values of the real SC140 clock counts to absolute time use the computation described in Sec...

Page 16: ...defined in Equation 2 Eqn 2 In this equation MFI multiplication factor integer MFN multiplication factor numerator MFD multiplication factor denominator and PODF post division factor are defined in the PCTL1 register PDF pre division factor is defined in the PCTL0 register Fext is external input frequency to the chip at the EXTAL pin Fdevice is the operating frequency of the device The range of va...

Page 17: ...include EOnCE_registers h void PLL_setup_300MHz asm move l 80030003 PCTL0 asm move l 00010000 PCTL1 To set up the SC140 for operation at 300 MHz the registers PCTL0 and PCTL1 should be set to the values 0x80030003 and 0x00010000 respectively These settings are explained in Table 3 Table 3 Settings of PCTL0 and PCTL1 Field Setting binary value Description PCTL0 PEN 1 PLL enabled The internal clocks...

Page 18: ...able as described in Section 3 Setting Up the Stopwatch Timer Within an Application on page 3 The verification process is based on measuring a specified time period while also creating an external behavior turning on and off an LED that can be measured independently by a wall clock that is an independent stopwatch such as an oscilloscope 6 1 Using the LED on the SDP The implementation described in...

Page 19: ... an EDCA1 event 6 2 Testing the Stopwatch Timer The program depicted in Code 9 on page 16 sets up the stopwatch timer and then measures the time it takes to execute two loops whose duration is built into the program The measured code sequences are constructed to take 10 seconds and 7 5 seconds respectively These durations are constructed by having the code sample the Enhanced OnCE counter and loop...

Page 20: ...rt Event 1 happens counter LED on do READ_IOREG ECNT_VAL clock_cycle Read bit 31 0 counter value clock_cycle MAX_32_BIT clock_cycle Minus max value due to count down while clock_cycle cycle_req EOnCE_stopwatch_timer_stop clock_ext clock_val Stop timer return bit 63 0 counter value EOnCE_LED_off LED off time_sec Convert_clock2time clock_ext clock_val EONCE_SECOND printf duration u sec n time_sec cy...

Page 21: ...imer within the Metrowerks Code Warrier debugger In addition examples were provided in this application note to demonstrate setting up the SC140 Phase Lock Loop and software control of the LED available on the Software Development Platform 8 References 1 StarCore SC140 DSP Core Reference Manual order number MNSC140CORE D Motorola Inc 2000 2 StarCore 140 Software Development Platform Hardware Refer...

Page 22: ...18 Using the SC140 Enhanced OnCE Stopwatch Timer ...

Page 23: ...COND 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 void EOnCE_stopwatch_timer_start void EOnCE_stopwatch_timer_stop unsigned long clock_ext unsigned long clock_val void EOnCE_LED_init void EOnCE_LED_off unsigned long Convert_clock2time unsigned l...

Page 24: ...EDCA 1 Reference Value B define EDCA2_REFB REG_BASE_ADDRESS 0x88 EOnCE EDCA 2 Reference Value B define EDCA3_REFB REG_BASE_ADDRESS 0x8c EOnCE EDCA 3 Reference Value B define EDCA4_REFB REG_BASE_ADDRESS 0x90 EOnCE EDCA 4 Reference Value B define EDCA5_REFB REG_BASE_ADDRESS 0x94 EOnCE EDCA 5 Reference Value B define EDCA0_MASK REG_BASE_ADDRESS 0xc0 EOnCE EDCA 0 Mask Register define EDCA1_MASK REG_BA...

Page 25: ..._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 void EOnCE_stopwatch_timer_stop unsigned long clock_ext unsigned long clock_val WRITE_IOREG ECNT_CTRL 0 Disable event counter READ_IOREG ECNT_VAL clock_val Save ECNT_VAL in program variable READ_IOR...

Page 26: ...test_r_l 11 11232 3256 3463 16354 6929 13451 31455 6034 19039 21655 2132 Word16 test_wind 240 2621 2623 2627 2634 2644 2656 2671 2689 2710 2734 2760 2789 2821 2855 2893 2933 2975 3021 3069 3120 3173 3229 3288 3350 3414 3481 3550 3622 3697 3774 3853 3936 4021 4108 4198 4290 4385 4482 4582 4684 4788 4895 5004 5116 5230 5346 5464 5585 5708 5833 5960 6090 6221 6355 6491 6629 6769 6910 7054 7200 7348 7...

Page 27: ... x Word16 m Word16 r_h Word16 r_l const Word16 wind Word16 i j norm Word16 y L_WINDOW Word32 sum Word16 overfl overfl_shft for i 0 i L_WINDOW i y i mult_r x i wind i overfl_shft 0 do overfl 0 sum 0L for i 0 i L_WINDOW i sum L_mac sum y i y i if L_sub sum MAX_32 0L overfl_shft add overfl_shft 4 overfl 1 for i 0 i L_WINDOW i y i shr y i 2 while overfl 0 sum L_add sum 1L norm norm_l sum sum L_shl sum...

Page 28: ...A 6 Using the SC140 Enhanced OnCE Stopwatch Timer ...

Reviews: