Beispiel #1
0
int main( int argc, char **argv )
{    
    if( find_option( argc, argv, "-h" ) >= 0 )
    {
        printf( "Options:\n" );
        printf( "-h to see this help\n" );
        printf( "-n <int> to set the number of particles\n" );
        printf( "-o <filename> to specify the output file name\n" );
        return 0;
    }
    
    int n = read_int( argc, argv, "-n", 1000 );

    char *savename = read_string( argc, argv, "-o", NULL );
    
    FILE *fsave = savename ? fopen( savename, "w" ) : NULL;
    particle_t *particles = (particle_t*) malloc( n * sizeof(particle_t) );
    set_size( n );
    init_particles( n, particles );
    
    //
    //  simulate a number of time steps
    //
    double simulation_time = read_timer( );
    run_simulation(particles, n, fsave);
    simulation_time = read_timer( ) - simulation_time;
    
    printf( "n = %d, simulation time = %g seconds\n", n, simulation_time );
    
    free( particles );
    if( fsave )
        fclose( fsave );
    
    return 0;
}
Beispiel #2
0
int main(int argc, char *argv[]) {
    int N = VECTOR_LENGTH;
    int num_tasks = 4;
    double elapsed; /* for timing */
    if (argc < 3) {
        fprintf(stderr, "Usage: sum [<N(%d)>] [<#tasks(%d)>]\n", N,num_tasks);
        fprintf(stderr, "\t Example: ./sum %d %d\n", N,num_tasks);
    } else {
    	N = atoi(argv[1]);
    	num_tasks = atoi(argv[2]);
    }

    REAL *A = (REAL*)malloc(sizeof(REAL)*N);

    srand48((1 << 12));
    init(A, N);
    /* example run */
    elapsed = read_timer();
    REAL result = sum(N, A);
    elapsed = (read_timer() - elapsed);

    /* more runs */

    /* you should add the call to each function and time the execution */
    printf("======================================================================================================\n");
    printf("\tSum %d numbers with %d tasks\n", N, num_tasks);
    printf("------------------------------------------------------------------------------------------------------\n");
    printf("Performance:\t\tRuntime (ms)\t MFLOPS \n");
    printf("------------------------------------------------------------------------------------------------------\n");
    printf("Sum:\t\t\t%4f\t%4f\n", elapsed * 1.0e3, 2*N / (1.0e6 * elapsed));
    free(A);
    return 0;
}
Beispiel #3
0
/* read command line, initialize, and create threads */
int main(int argc, char *argv[]) {
  int i, j;
  long l; /* use long in case of a 64-bit system */
  pthread_attr_t attr;
  pthread_t workerid[MAXWORKERS];

  /* set global thread attributes */
  pthread_attr_init(&attr);
  pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);

  /* initialize mutex and condition variable */
  pthread_mutex_init(&updatelock, NULL);
  pthread_mutex_init(&baglock, NULL);
  pthread_cond_init(&finished, NULL);

  final_num_workers = 0;
  final_min = 1000;

  current_row = 0;

  /* read command line args if any */
  size = (argc > 1)? atoi(argv[1]) : MAXSIZE;
  numWorkers = (argc > 2)? atoi(argv[2]) : MAXWORKERS;
  if (size > MAXSIZE) size = MAXSIZE;
  if (numWorkers > MAXWORKERS) numWorkers = MAXWORKERS;
  
  /* initialize random seed */
  srand ( time(NULL) );

  /* initialize the matrix */
  for (i = 0; i < size; i++) {
	  for (j = 0; j < size; j++) {
      matrix[i][j] = rand()%99;
	  }
  }

  /* print the matrix */
#ifdef DEBUG
  for (i = 0; i < size; i++) {
	  printf("[ ");
	  for (j = 0; j < size; j++) {
	    printf(" %d", matrix[i][j]);
	  }
	  printf(" ]\n");
  }
#endif

  /* do the parallel work: create the workers */
  start_time = read_timer();
  for (l = 0; l < numWorkers; l++)
    pthread_create(&workerid[l], &attr, Worker, (void *) l);

  pthread_cond_wait(&finished, &updatelock);
  
  end_time = read_timer();
  
  print_result();

  pthread_exit(NULL);
}
Beispiel #4
0
int main(int argc, char **argv) {
  std::string interleaving;
  if (argc > 1) {
      interleaving = argv[1];
  } else {
      interleaving = "";
  }

  for( int n = 1000; n <= 10000000; n *= 10 ) {

    std::vector<Point*> S;
    for( int i = 0; i < n; i++ ) {
      S.push_back( new Point );
      S.back()->index = i;
      S.back()->x = drand48();
      S.back()->y = drand48();
    }

    double stime = read_timer();

    DelaunayProblem *problem = new DelaunayProblem(&S, 0, n);

    Framework::solve(problem, interleaving);

    printf("%d time %f\n", n, read_timer()-stime);
    delete problem;
  }
}
Beispiel #5
0
//
//  benchmarking program
//
int main( int argc, char **argv )
{    
    if( find_option( argc, argv, "-h" ) >= 0 )
    {
        printf( "Options:\n" );
        printf( "-h to see this help\n" );
        printf( "-n <int> to set the number of particles\n" );
        printf( "-o <filename> to specify the output file name\n" );
        return 0;
    }
    
    int n = read_int( argc, argv, "-n", 1000 );

    char *savename = read_string( argc, argv, "-o", NULL );
    
    FILE *fsave = savename ? fopen( savename, "w" ) : NULL;
    particle_t *particles = (particle_t*) malloc( n * sizeof(particle_t) );
    set_size( n );
    init_particles( n, particles );
    
    //
    //  simulate a number of time steps
    //
    double simulation_time = read_timer( );
    for( int step = 0; step < NSTEPS; step++ )
    {
        //
        //  compute forces
        //
        for( int i = 0; i < n; i++ )
        {
            particles[i].ax = particles[i].ay = 0;
            for (int j = 0; j < n; j++ )
                apply_force( particles[i], particles[j] );
        }
        
        //
        //  move particles
        //
        for( int i = 0; i < n; i++ ) 
            move( particles[i] );
        
        //
        //  save if necessary
        //
        if( fsave && (step%SAVEFREQ) == 0 )
            save( fsave, n, particles );
    }
    simulation_time = read_timer( ) - simulation_time;
    
    printf( "n = %d, simulation time = %g seconds\n", n, simulation_time );
    
    free( particles );
    if( fsave )
        fclose( fsave );
    
    return 0;
}
// For benchmark purposes, makes a clean copy of array to sort 
// before calling sequential quicksort
void do_seq_quicksort() {
    int *arr_cpy = malloc(sizeof (array));
    memcpy(arr_cpy, array, sizeof (array));
    double start = read_timer();
    sequential_quicksort(arr_cpy, 0, size);
    double end = read_timer();
    printf("Sequential quicksort time: %f\n", (end - start));
    free(arr_cpy);
}
Beispiel #7
0
void __udelay(unsigned long usec)
{
    unsigned long long target;

    read_timer();

    target = timer.ticks + usecs_to_ticks(usec);

    while (timer.ticks < target)
        read_timer();
}
Beispiel #8
0
int main( int argc, char **argv ) {

  initCommunication( &argc, &argv );
  
  // make up a simple test
  int size = read_int( argc, argv, "-s", 8 );
  int r = read_int( argc, argv, "-r", 2 );
  int P;
  MPI_Comm_size( MPI_COMM_WORLD, &P );
  initSizes( P, r, size );
  if( getRank() == 0 ) {
    if( P > (1<<r) )
      printf("Need more recursive steps for this many processors\n");
    if( P > (size/(1<<r))*(size/(1<<r)+1)/2)
      printf("Need a bigger matrix/fewer recursive steps for this many processors\n");
    printf("-s %d -r %d -n %d\n", size, r, P);
  }
  int sizeSq = getSizeSq(r,P);
  int sizeTri = getSizeTri(r,P);
  double *X = (double*) malloc( sizeSq*sizeof(double) );
  srand48(getRank());
  fill(X,sizeSq);
  double *A = (double*) malloc( sizeTri*sizeof(double) );
  if( getRank() == 0 )
    printf("Generating a symmetric positive definite test matrix\n");
  initTimers();
  MPI_Barrier( MPI_COMM_WORLD );
  double st2 = read_timer();
  syrk( A, X, size, P, r, 0. );
  MPI_Barrier( MPI_COMM_WORLD );
  double et2 = read_timer();
  if( getRank() == 0 )
    printf("Generation time: %f\n", et2-st2);
  initTimers();
  free(X);
  for( int i = 0; i < sizeTri; i++ )
    A[i] = -A[i];

  if( getRank() == 0 )
    printf("Starting benchmark\n");
  MPI_Barrier( MPI_COMM_WORLD );
  double startTime = read_timer();
  chol( A, size, P, r );
  MPI_Barrier( MPI_COMM_WORLD );
  double endTime = read_timer();
  
  if( getRank() == 0 )
    printf("Time: %f Gflop/s %f\n", endTime-startTime, size*1.*size*size/3./(endTime-startTime)/1.e9);

  free(A);
  printCounters(size);
  MPI_Finalize();
}
Beispiel #9
0
/* delay x useconds */
void __udelay(unsigned long usec)
{
	long tmo = USEC_TO_COUNT(usec);
	ulong now, last = read_timer();

	while (tmo > 0) {
		now = read_timer();
		if (now > last)	/* normal (non rollover) */
			tmo -= now - last;
		else		/* rollover */
			tmo -= TIMER_LOAD_VAL - last + now;
		last = now;
	}
}
Beispiel #10
0
/*
 * Reset the timer
 */
void reset_timer_count(void)
{
	/* capure current decrementer value time */
	gd->lastinc = read_timer();
	/* start "advancing" time stamp from 0 */
	gd->tbl = 0;
}
Beispiel #11
0
int dotcpwatch (int argc, char** argv, void *p)
{
    if(argc < 2)
    {
        tprintf ("TCP Watch Dog timer %d/%d seconds\n",
        	read_timer (&TcpWatchTimer)/1000,
        		dur_timer(&TcpWatchTimer)/1000);

        return 0;
    }

    stop_timer (&TcpWatchTimer);	/* in case it's already running */

	/* what to call on timeout */
    TcpWatchTimer.func = (void (*)(void*))dowatchtick;

    TcpWatchTimer.arg = NULLCHAR;	/* dummy value */

	/* set timer duration */
    set_timer (&TcpWatchTimer, (uint32)atoi (argv[1])*1000);

    start_timer (&TcpWatchTimer);	/* and fire it up */

    return 0;
}
// Starts multithreaded quicksort
void do_parallel_quicksort() {
    range array_range = {0, size - 1};
    /* set global thread attributes */
    pthread_t worker;
    pthread_attr_init(&attr);
    pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
    double start = read_timer();
    pthread_create(&worker, &attr, quicksort, (void *) &array_range);
    pthread_attr_destroy(&attr);
    pthread_join(worker, NULL);
    double end = read_timer();
    printf("Time: %f\n", (end - start));



}
static void write_intr(void)
{
	struct request *req = hd_req;
	int i;
	int retries = 100000;

	do {
		i = (unsigned) inb_p(HD_STATUS);
		if (i & BUSY_STAT)
			continue;
		if (!OK_STATUS(i))
			break;
		if ((blk_rq_sectors(req) <= 1) || (i & DRQ_STAT))
			goto ok_to_write;
	} while (--retries > 0);
	dump_status("write_intr", i);
	bad_rw_intr();
	hd_request();
	return;

ok_to_write:
	if (hd_end_request(0, 512)) {
		SET_HANDLER(&write_intr);
		outsw(HD_DATA, req->buffer, 256);
		return;
	}

#if (HD_DELAY > 0)
	last_req = read_timer();
#endif
	hd_request();
}
Beispiel #14
0
/* Each worker sums the values in one strip of the matrix.
   After a barrier, worker(0) computes and prints the total */
void *Worker(void *arg) {
  long myid = (long) arg;
  int total, i, j, first, last;

#ifdef DEBUG
  printf("worker %d (pthread id %d) has started\n", myid, pthread_self());
#endif

  /* determine first and last rows of my strip */
  first = myid*stripSize;
  last = (myid == numWorkers - 1) ? (size - 1) : (first + stripSize - 1);

  /* sum values in my strip */
  total = 0;
  for (i = first; i <= last; i++)
    for (j = 0; j < size; j++)
      total += matrix[i][j];
  sums[myid] = total;
  Barrier();
  if (myid == 0) {
    total = 0;
    for (i = 0; i < numWorkers; i++)
      total += sums[i];
    /* get end time */
    end_time = read_timer();
    /* print results */
    printf("The total is %d\n", total);
    printf("The execution time is %g sec\n", end_time - start_time);
  }
}
Beispiel #15
0
void reset_timer_masked(void)
{
	/* reset time */
	gd->lastinc = read_timer();
	gd->timer_reset_value = 0;

}
Beispiel #16
0
static void hd_out(struct hd_i_struct *disk,
		   unsigned int nsect,
		   unsigned int sect,
		   unsigned int head,
		   unsigned int cyl,
		   unsigned int cmd,
		   void (*intr_addr)(void))
{
	unsigned short port;

#if (HD_DELAY > 0)
	while (read_timer() - last_req < HD_DELAY)
		/* nothing */;
#endif
	if (reset)
		return;
	if (!controller_ready(disk->unit, head)) {
		reset = 1;
		return;
	}
	SET_HANDLER(intr_addr);
	outb_p(disk->ctl,HD_CMD);
	port=HD_DATA;
	outb_p(disk->wpcom>>2,++port);
	outb_p(nsect,++port);
	outb_p(sect,++port);
	outb_p(cyl,++port);
	outb_p(cyl>>8,++port);
	outb_p(0xA0|(disk->unit<<4)|head,++port);
	outb_p(cmd,++port);
}
Beispiel #17
0
/*
 * init the Timer
 */
int timer_init(void)
{
	struct panthapb_registers *apb1clkres =
		(struct panthapb_registers *) PANTHEON_APBC_BASE;
	struct panthtmr_registers *panthtimers =
		(struct panthtmr_registers *) PANTHEON_TIMER_BASE;

	/* Enable Timer clock at 3.25 MHZ */
	writel(APBC_APBCLK | APBC_FNCLK | APBC_FNCLKSEL(3), &apb1clkres->timers);

	/* load value into timer */
	writel(0x0, &panthtimers->clk_ctrl);
	/* Use Timer 0 Match Resiger 0 */
	writel(TIMER_LOAD_VAL, &panthtimers->match[MATCH_CMP(0)]);
	/* Preload value is 0 */
	writel(0x0, &panthtimers->preload[TIMER]);
	/* Enable match comparator 0 for Timer 0 */
	writel(0x1, &panthtimers->preload_ctrl[TIMER]);

	/* Enable timer 0 */
	writel(0x1, &panthtimers->cer);
	/* init the gd->tbu and gd->tbl value */
	gd->tbl = read_timer();
	gd->tbu = 0;

	return 0;
}
Beispiel #18
0
test_loop_speed_inversetransform(void)
{
	struct weston_matrix m;
	struct inverse_matrix inv;
	struct weston_vector v = { { 0.5, 0.5, 0.5, 1.0 } };
	unsigned long count = 0;
	double t;

	printf("\nRunning 3 s test on inverse_transform()...\n");

	weston_matrix_init(&m);
	matrix_invert(inv.LU, inv.perm, &m);

	running = 1;
	alarm(3);
	reset_timer();
	while (running) {
		inverse_transform(inv.LU, inv.perm, v.f);
		count++;
	}
	t = read_timer();

	printf("%lu iterations in %f seconds, avg. %.1f ns/iter.\n",
	       count, t, 1e9 * t / count);
}
Beispiel #19
0
static void recal_intr(void)
{
	check_status();
#if (HD_DELAY > 0)
	last_req = read_timer();
#endif
	hd_request();
}
Beispiel #20
0
int32
next_timer_event(void)
{
	if (Timers)
		return read_timer(Timers);
	else
		return 0x7fffffff;
}
Beispiel #21
0
/*
 * Reset the timer
 */
void reset_timer(void)
{
	/* capture current decrementer value time */
	gd->lastinc = read_timer() /
		(CONFIG_TIMER_CLOCK_KHZ * 1000 / CONFIG_SYS_HZ);
	/* start "advancing" time stamp from 0 */
	gd->tbl = 0;
}
int main(int argc, char *argv[])
{
    int n;
    REAL *y_omp, *y_ompacc, *x;
    REAL a = 123.456;

    #pragma omp target device(mpi:all) begin
    n = VEC_LEN;
    y_omp = (REAL *) malloc(n * sizeof(REAL));
    y_ompacc = (REAL *) malloc(n * sizeof(REAL));
    x = (REAL *) malloc(n * sizeof(REAL));
    #pragma omp target device(mpi:all) end

    #pragma omp target device(mpi:master) begin
    srand48(1<<12);
    init(x, n);
    init(y_ompacc, n);
    memcpy(y_ompacc, y_omp, n*sizeof(REAL));
    #pragma omp target device(mpi:master) end

    int num_threads;
//  #pragma omp parallel shared (num_threads)
    {
        if (omp_get_thread_num() == 0)
            num_threads = omp_get_num_threads();
    }

    /* CPU threading version*/
    double omp_time = read_timer();
    axpy_omp(x, y_omp, n, a);
    omp_time = read_timer() - omp_time;

    /* openmp acc version */
    double ompacc_time = read_timer();
    axpy_ompacc(x, y_ompacc, n, a);
    ompacc_time = read_timer() - ompacc_time;

    printf("axpy(%d): checksum: %g; time(s):\tOMP(%d threads)\tOMPACC\n", n, check(y_omp, y_ompacc, n),num_threads);
    printf("\t\t\t\t\t\t%4f\t%4f\n", omp_time, ompacc_time);

    free(y_omp);
    free(y_ompacc);
    free(x);
    return 0;
}
int main(int argc, char *argv[]) {
    int N = VECTOR_LENGTH;
    int num_threads = 4; /* 4 is default number of threads */
    if (argc < 2) {
        fprintf(stderr, "Usage: axpy <n> [<#threads(%d)>] (n should be dividable by #threads)\n", num_threads);
        exit(1);
    }
    N = atoi(argv[1]);
    if (argc > 2) num_threads = atoi(argv[2]);
    omp_set_num_threads(num_threads);
    REAL a = 123.456;
    REAL *Y_base = malloc(sizeof(REAL)*N);
    REAL *Y_parallel = malloc(sizeof(REAL)*N);
    REAL *X = malloc(sizeof(REAL)* N);

    srand48((1 << 12));
    init(X, N);
    init(Y_base, N);
    memcpy(Y_parallel, Y_base, N * sizeof(REAL));


    int i;
    int num_runs = 10;
    
    double elapsed_omp_parallel_for = read_timer();
    for (i=0; i<num_runs; i++) axpy_omp_parallel_for(N, Y_parallel, X, a);
    elapsed_omp_parallel_for = (read_timer() - elapsed_omp_parallel_for)/num_runs;
    
  
    
    
    /* you should add the call to each function and time the execution */
    printf("======================================================================================================\n");
    printf("\tAXPY: Y[N] = Y[N] + a*X[N], N=%d, %d threads for dist\n", N, num_threads);
    printf("------------------------------------------------------------------------------------------------------\n");
    printf("Performance:\t\t\tRuntime (ms)\t MFLOPS \t\tError (compared to base)\n");
    printf("------------------------------------------------------------------------------------------------------\n");
     printf("axpy_omp_parallel_for:\t\t%4f\t%4f \t\t%g\n", elapsed_omp_parallel_for * 1.0e3, (2.0 * N) / (1.0e6 * elapsed_omp_parallel_for), check(Y_base,Y_parallel, N));
    free(Y_base);
    free(Y_parallel);
    free(X);

    return 0;
}
Beispiel #24
0
void cmd_add(int socket)
{
	char line[MAX_LINE];
	Book *book = book_load_file(BOOK_PATH);
	Timer *timer, *new_timer;
	int i;
	FILE *fp;

	new_timer = read_timer(socket);
	if(new_timer == NULL)
	{
		book_free(book);
		return;
	}

	fp = fopen(BOOK_PATH, "w");

	fwrite(book_xml_header, 1, sizeof(book_xml_header)-1,fp);
	printf("%s", book_xml_header);

	fwrite(book_xml_timerlist_start, 1, sizeof(book_xml_timerlist_start)-1,fp);
	printf("%s", book_xml_timerlist_start);

	for(i=0,timer=book->timers;i<book->n_timers;i++,timer++)
	{
		sprintf(line,"        <Timer fname=\"%s\" startMjd=\"%d\" nextMjd=\"%d\" start=\"%d\" duration=\"%d\" repeat=\"%d\" play=\"%d\" lock=\"%d\" onId=\"%d\" tsId=\"%d\" svcId=\"%d\" />\n",
			timer->filename, timer->startmjd, timer->nextmjd, timer->start, timer->duration, 
			timer->repeat, timer->play, timer->lock, timer->onid, timer->tsid, timer->svcid);
		fwrite(line, 1, strlen(line),fp);

		printf("%s",line);
	}

	timer = new_timer;

	sprintf(line,"        <Timer fname=\"%s\" startMjd=\"%d\" nextMjd=\"%d\" start=\"%d\" duration=\"%d\" repeat=\"%d\" play=\"%d\" lock=\"%d\" onId=\"%d\" tsId=\"%d\" svcId=\"%d\" />\n",
		timer->filename, timer->startmjd, timer->nextmjd, timer->start, timer->duration, 
		timer->repeat, timer->play, timer->lock, timer->onid, timer->tsid, timer->svcid);
	fwrite(line, 1, strlen(line),fp);

	printf("%s",line);
	free(new_timer->filename);
	free(new_timer);

	fwrite(book_xml_timerlist_end, 1, sizeof(book_xml_timerlist_end)-1,fp);
	printf("%s", book_xml_timerlist_end);
		
	fwrite(book_xml_footer, 1, sizeof(book_xml_footer)-1, fp);
	printf("%s", book_xml_footer); 
	fclose(fp);

	book_free(book);

	return;
}
Beispiel #25
0
int main () {
	
	struct timeval tv;
	struct timezone tz;
	struct tm*tm;
	tm = localtime(&tv.tv_sec);
	gettimeofday(&tv, &tz);
	//srand(tv.tv_usec * tv.tv_sec);
	
	v_o = 4; v_th = sqrt(.2);
	
    //Lx = 40; Ly = 20;
	Lx = 40; Ly = 20;
    dx = 1; dy = 1; delta2 = dx*dx;
	imax = Lx - 1; jmax = Ly;
	nmax = imax*jmax;
	//ppc = 1200;
    ppc = 200; 
    LeftBC = 0; RightBC = -10;
    pcn = 1/(double)ppc;
	Npart = Lx*Ly*ppc;
	
	pi = 4*atan(1);
	nt = .5;
	dt = nt/(v_o*(1 + erf(v_th/v_o)));
	//finaltime = 50;
	finaltime = 10;
	omega = 1;
	
	initial_conditions();
    seconds = read_timer();
	inject_node_move();
    elapsed = read_timer() - seconds;
	outputs();
	
	FILE *file1;
	file1 = fopen("Sys_Cond.txt", "w");
	fprintf(file1, "%d\t%d\t%d\t%d\t%d",Lx,Ly,dx,dy,finaltime);
	fclose(file1);
	printf("Elapsed time (serial): %f seconds\n", elapsed); 
    return EXIT_SUCCESS;
}
Beispiel #26
0
/*
 * Get the number of ticks (in CONFIG_SYS_HZ resolution)
 */
unsigned long long get_ticks(void)
{
    unsigned long long sys_ticks;

    read_timer();

    sys_ticks = timer.ticks * CONFIG_SYS_HZ;
    do_div(sys_ticks, TIMER_FREQ);

    return sys_ticks;
}
int main(){

	printf("Dense Linear Algebra Tests.\n") ;

	int i;
	int numTests = 2;
	char *pass = (char *) malloc(numTests * sizeof(char));
	char allPass = 1;

	double startTime, endTime; 
	
	startTime = read_timer();
	
	pass[0] = checkLU() ;
	pass[1] = checkQR() ;
	
	endTime = read_timer(); 
	
	printf("Total time for all tests = %f seconds.\n\n", endTime - startTime); 
	
	// Check whether all tests passed.
	for(i=0; i<numTests; i++){
		if(pass[i]){
			printf("Test %d passed.\n", i) ;
			allPass &= 1;
		}
		else{
			fprintf(stderr, "Test %d failed.\n", i) ;
			allPass = 0;
		}
	}

	if( allPass )
		printf("\nAll tests passed.\n\n") ;
	else
		fprintf(stderr, "\nTests failed!\n") ;
	
	free(pass) ; 
	
	return allPass;
}
Beispiel #28
0
void udelay(unsigned usec)
{
	u32 curr_tick, last_tick;
	s32 ticks_left;

	last_tick = read_timer();
	/* 24 timer ticks per microsecond (24 MHz, divided by 1) */
	ticks_left = usec * 24;

	/* FIXME: Should we consider timer rollover?
	 * From when we start the timer, we have almost three minutes before it
	 * rolls over, so we should be long into having booted our payload.
	 */
	while (ticks_left > 0) {
		curr_tick = read_timer();
		/* Timer value decreases with each tick */
		ticks_left -= last_tick - curr_tick;
		last_tick = curr_tick;
	}

}
Beispiel #29
0
/*
 * Delay x useconds
 */
void __udelay(unsigned long usec)
{
	unsigned long now, last;
	/*
	 * get the tmo value based on timer clock speed
	 * tmo = delay required / period of timer clock
	 */
	long tmo = usec * CONFIG_TIMER_CLOCK_KHZ / 1000;

	last = read_timer();
	while (tmo > 0) {
		now = read_timer();
		if (last >= now)
			/* normal mode (non roll) */
			tmo -= last - now;
		else
			/* we have overflow of the count down timer */
			tmo -= TIMER_LOAD_VAL - last + now;
		last = now;
	}
}
Beispiel #30
0
int main()
{
uint32_t x;

DDRB = 1;

lcd_init();
start_timer();
delay_ms(950);
x = read_timer();
lcd_put_long(x);
return 0;
}