
#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(); /* Setup to event d etector 1 for a ny write to
dummy va riable. Setup EOn CE eve nt count er
to count if even t 1 happe ns */
EOnCE_LED_init(); /* Setup LE D to tog gle in de tectio n of
event 1 */
cycle_req = CLOCK_SPEED*10; /* Calculat e total clock cyc les re quired
by 10 se c */
EOnCE_stopwatch_timer_start(); /* Event 1 happens, counter & LED on */
do {
READ_IOREG(ECNT_VAL,clock_cycle); /* Read bit 31-0 co unter val ue */
clock_cycle = MAX_32_BIT - clock_cycle;/* Minus ma x value due to co unt do wn */
} while (clock_cycle <= cycle_req);
EOnCE_stopwatch_timer_stop(&clock_ext, &clock_val); / * Stop t imer, ret urn bi t 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);
cycle_req = CLOCK_SPEED*7.5; /* Calculate total c lock cycl es req uired
by 7.5 s ec */
EOnCE_stopwatch_timer_start(); /* Event 1 h appens, counter & LED o n */
do {
READ_IOREG(ECNT_VAL,clock_cycle); /* Read bit 31-0 co unter val ue */
clock_cycle = MAX_32_BIT - clock_cycle;/* Minus ma x value due to co unt do wn */
} while (clock_cycle <= cycle_req);
EOnCE_stopwatch_timer_stop(&clock_ext, &clock_val); / * Stop t imer, ret urn bi t 63-0
counter value */
EOnCE_LED_off(); /* LED off */
time_sec = Convert_clock2time(clock_ext, clock_val, EONCE_MILLISECOND);
printf("duration = %u ms\n", time_sec);
return;
}