vt100: include pgmspace.h as we use PROGMEM macro
[aversive.git] / modules / hardware / timer / test / main.c
1 /*  
2  *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)
3  * 
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  *  Revision : $Id: main.c,v 1.1.2.4 2007-05-23 17:18:15 zer0 Exp $
19  *
20  */
21
22 #include <uart.h>
23 #include <aversive.h>
24 #include <aversive/wait.h>
25 #include <stdio.h>
26 #include <timer.h>
27
28
29 void callback_ov(void)
30 {
31         static int i=0;
32         printf("CB%d\n", i++);
33 }
34
35 void callback_oc(void)
36 {
37         static int i=0;
38
39         i++;
40         if ( (i%1000) == 0 ) {
41                 printf("%d\n", i/1000);
42                 if (i==5000) {
43                         timer3A_register_OC_intr_in_us(NULL, 0);
44                         return;
45                 }
46         }
47
48         timer3A_register_OC_intr_in_us(callback_oc, 1000);
49 }
50
51 /* Todo :
52  * timer 8bits are differents...
53  * timer1A_register_OC_intr_in_tics
54  * functions with timer num as a parameter
55  * return an error in timer1A_register_OC_intr_in_us if not adapted to presc
56  * synch des timers (eventuellement)
57  * clear on compare match could be useful
58  * enhance help for funcs. Note that register_in_us is 100us long on a 16Mhz ATmega128 in dynamic mode
59  *
60  * aversive/parts.h can be included twice... bad
61  * aversive/ATxxx.h can be included directly... bad too
62  */
63
64 int main(void)
65 {
66         int16_t a,b,c;
67
68         uart_init();
69         fdevopen(uart0_dev_send, uart0_dev_recv);
70         timer_init();
71         sei();
72
73         //      printf("init\n");
74
75         a=timer3_get();
76         timer3A_register_OC_intr_in_us(callback_oc, 1000);
77         b=timer3_get();
78         c=timer3_get();
79         printf("%d %d %d %d\n", a, b, c, OCR3A);
80
81         timer1_register_OV_intr(callback_ov);
82         printf("timer = %d\n", timer1_get());
83         wait_ms(10);
84         printf("timer = %d\n", timer1_get());
85         wait_ms(10);
86         printf("timer = %d\n", timer1_get());
87
88         while(1);
89
90         return 0;
91 }