]> rtime.felk.cvut.cz Git - mirosot.git/blob - autodemo/timer3.c
259a3ece8704c8ed73bf3c01886e95e1beb6b450
[mirosot.git] / autodemo / timer3.c
1 #include <timer3.h>
2 #include <mcu_regs.h>
3 #include <cpu_def.h>
4
5 static volatile timer_t timer;
6
7 static void  timer_isr(void) __attribute__ ((interrupt_handler));
8
9 static void 
10 timer_isr(void)
11 {
12     timer++;
13     *TPU_TSR3 &= ~TSR2_TCFVm ; //reset overflow flag (clear interrupt)
14 }    
15
16 //timer initialisation
17 /*free running counter*/
18 void init_timer3()
19 {
20     *SYS_MSTPCRA &= ~MSTPCRA_TPUm; // power TPU unit
21
22     *TPU_TCR3 =0x00 | 0x06;     //rising edge, f divided by 256
23     *TPU_TMDR3 =0x00;           // normal mode
24     *TPU_TSR3 &= ~TSR3_TCFVm ;  //reset overflow flag
25     *TPU_TIER3 |=TIER3_TCIEVm;  //enable overflow interrupt
26
27     *TPU_TSTR |=TSTR_CST3m;     //start timer
28
29     excptvec_set(52, timer_isr); 
30 }
31
32 timer_t get_timer()
33 {
34   return timer;
35 }