]> rtime.felk.cvut.cz Git - mirosot.git/blobdiff - autodemo/timer3.c
Added simple autonomous demo. Robot follows preprogrammed trajectory.
[mirosot.git] / autodemo / timer3.c
diff --git a/autodemo/timer3.c b/autodemo/timer3.c
new file mode 100644 (file)
index 0000000..259a3ec
--- /dev/null
@@ -0,0 +1,35 @@
+#include <timer3.h>
+#include <mcu_regs.h>
+#include <cpu_def.h>
+
+static volatile timer_t timer;
+
+static void  timer_isr(void) __attribute__ ((interrupt_handler));
+
+static void 
+timer_isr(void)
+{
+    timer++;
+    *TPU_TSR3 &= ~TSR2_TCFVm ; //reset overflow flag (clear interrupt)
+}    
+
+//timer initialisation
+/*free running counter*/
+void init_timer3()
+{
+    *SYS_MSTPCRA &= ~MSTPCRA_TPUm; // power TPU unit
+
+    *TPU_TCR3 =0x00 | 0x06;     //rising edge, f divided by 256
+    *TPU_TMDR3 =0x00;           // normal mode
+    *TPU_TSR3 &= ~TSR3_TCFVm ;  //reset overflow flag
+    *TPU_TIER3 |=TIER3_TCIEVm;  //enable overflow interrupt
+
+    *TPU_TSTR |=TSTR_CST3m;     //start timer
+
+    excptvec_set(52, timer_isr); 
+}
+
+timer_t get_timer()
+{
+  return timer;
+}