summary refs log tree commit diff
path: root/timer.c
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2011-09-17 22:39:50 +0900
committertmk <nobody@nowhere>2011-09-17 23:53:18 +0900
commite67c988824f5ec0c965beb412f8ee5953dfd3c8c (patch)
tree190543f5bddfd31a326234aad91a0a995e55863a /timer.c
parentb703de7b298f8463bf4654fa3730ba1958a7fa9e (diff)
Added Bulegiga iWRAP support into HHKB.(Bluetooth)
Diffstat (limited to 'timer.c')
-rw-r--r--timer.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/timer.c b/timer.c
index edbb4409d2..48a38c9b68 100644
--- a/timer.c
+++ b/timer.c
@@ -20,17 +20,31 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <stdint.h>
 #include "timer.h"
 
+
+// counter resolution 1ms
 volatile uint16_t timer_count = 0;
 
-// Configure timer 0 to generate a timer overflow interrupt every
-// 256*1024 clock cycles, or approx 61 Hz when using 16 MHz clock
-// This demonstrates how to use interrupts to implement a simple
-// inactivity timeout.
 void timer_init(void)
 {
-    TCCR0A = 0x00;
+    // Timer0 CTC mode
+    TCCR0A = 0x02;
+
+#if TIMER_PRESCALER == 1
+    TCCR0B = 0x01;
+#elif TIMER_PRESCALER == 8
+    TCCR0B = 0x02;
+#elif TIMER_PRESCALER == 64
+    TCCR0B = 0x03;
+#elif TIMER_PRESCALER == 256
+    TCCR0B = 0x04;
+#elif TIMER_PRESCALER == 1024
     TCCR0B = 0x05;
-    TIMSK0 = (1<<TOIE0);
+#else
+#   error "Timer prescaler value is NOT vaild."
+#endif
+
+    OCR0A = TIMER_RAW_TOP;
+    TIMSK0 = (1<<OCIE0A);
 }
 
 inline
@@ -65,14 +79,11 @@ uint16_t timer_elapsed(uint16_t last)
     t = timer_count;
     SREG = sreg;
 
-    return TIMER_DIFF(t, last);
+    return TIMER_DIFF_MS(t, last);
 }
 
-// This interrupt routine is run approx 61 times per second.
-// A very simple inactivity timeout is implemented, where we
-// will send a space character and print a message to the
-// hid_listen debug message window.
-ISR(TIMER0_OVF_vect)
+// excecuted once per 1ms.(excess for just timer count?)
+ISR(TIMER0_COMPA_vect)
 {
     timer_count++;
 }