Search
lxdream.org :: lxdream :: r262:bc96e0b79308
lxdream 0.9.1
released Jun 29
Download Now
changeset262:bc96e0b79308
parent261:93fdb2a70e18
child263:6f641270b2aa
authornkeynes
dateWed 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
test/timer.c
test/timer.h
1.1 --- a/test/timer.c Wed Jan 03 09:01:51 2007 +0000
1.2 +++ b/test/timer.c Wed Jan 03 09:03:50 2007 +0000
1.3 @@ -1,6 +1,7 @@
1.4 #include "../lib.h"
1.5 #define TMU_CHANNEL 2
1.6 -
1.7 +#define BASE_TICKS_PER_US 200
1.8 +#define CLOCK_DIVIDER 16
1.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.27
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.35
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 timer
1.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 +0000
2.2 +++ b/test/timer.h Wed Jan 03 09:03:50 2007 +0000
2.3 @@ -1,5 +1,6 @@
2.4
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 );
.