revision 262:bc96e0b79308
summary |
tree |
shortlog |
changelog |
graph |
changeset |
raw | bz2 | zip | gz changeset | 262:bc96e0b79308 |
parent | 261:93fdb2a70e18 |
child | 263:6f641270b2aa |
author | nkeynes |
date | Wed Jan 03 09:03:50 2007 +0000 (17 years ago) |
Fix to actually work (need the write read/write sizes)
Implement the microsecond conversion function
Implement the microsecond conversion function
test/timer.c | view | annotate | diff | log | ||
test/timer.h | view | annotate | diff | log |
1.1 --- a/test/timer.c Wed Jan 03 09:01:51 2007 +00001.2 +++ b/test/timer.c Wed Jan 03 09:03:50 2007 +00001.3 @@ -1,6 +1,7 @@1.4 #include "../lib.h"1.5 #define TMU_CHANNEL 21.6 -1.7 +#define BASE_TICKS_PER_US 2001.8 +#define CLOCK_DIVIDER 161.9 #define TOCR 0xFFD80000 /* Output control register */1.10 #define TSTR 0xFFD80004 /* Start register */1.11 #define TCOR(c) (0xFFD80008 + (c*12)) /* Constant register */1.12 @@ -12,25 +13,25 @@1.13 * highest resolution mode, and start it counting down from max_int.1.14 */1.15 void timer_start() {1.16 - unsigned int val = long_read(TSTR);1.17 - long_write( TSTR, val & (~(1<<TMU_CHANNEL)) ); /* Stop counter */1.18 + unsigned int val = byte_read(TSTR);1.19 + byte_write( TSTR, val & (~(1<<TMU_CHANNEL)) ); /* Stop counter */1.20 long_write( TCOR(TMU_CHANNEL), 0xFFFFFFFF );1.21 long_write( TCNT(TMU_CHANNEL), 0xFFFFFFFF );1.22 - long_write( TCR(TMU_CHANNEL), 0x00000000 );1.23 - long_write( TSTR, val | (1<<TMU_CHANNEL) );1.24 + word_write( TCR(TMU_CHANNEL), 0x00000000 );1.25 + byte_write( TSTR, val | (1<<TMU_CHANNEL) );1.26 }1.28 /**1.29 * Report the current value of TMU2.1.30 */1.31 -long timer_gettime() {1.32 +unsigned int timer_gettime() {1.33 return long_read(TCNT(TMU_CHANNEL));1.34 }1.36 /**1.37 * Stop TMU2 and report the current value.1.38 */1.39 -long timer_stop() {1.40 +unsigned int timer_stop() {1.41 long_write( TSTR, long_read(TSTR) & (~(1<<TMU_CHANNEL)) );1.42 return long_read( TCNT(TMU_CHANNEL) );1.43 }1.44 @@ -40,6 +41,10 @@1.45 * Convert the supplied timer value to a number of micro seconds since the timer1.46 * was started.1.47 */1.48 -long timer_to_microsecs( long value ) {1.49 - return value;1.50 +unsigned int timer_to_microsecs( unsigned int value ) {1.51 + return (0xFFFFFFFF - value) * CLOCK_DIVIDER / BASE_TICKS_PER_US;1.52 }1.53 +1.54 +unsigned int timer_gettime_us() {1.55 + return timer_to_microsecs( timer_gettime() );1.56 +}
2.1 --- a/test/timer.h Wed Jan 03 09:01:51 2007 +00002.2 +++ b/test/timer.h Wed Jan 03 09:03:50 2007 +00002.3 @@ -1,5 +1,6 @@2.5 void timer_start();2.6 -long timer_gettime();2.7 -long timer_stop();2.8 -long timer_to_microsecs( long value );2.9 +unsigned int timer_gettime();2.10 +unsigned int timer_gettime_us();2.11 +unsigned int timer_stop();2.12 +unsigned int timer_to_microsecs( long value );
.