--- /dev/null
+#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;
+}