d5ef558e2ee09e361fa6a81e5c683544679b24b5
[aversive.git] / modules / debug / diagnostic / test / test_int_show.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: test_int_show.c,v 1.3.4.2 2007-05-23 17:18:12 zer0 Exp $
19  *
20  */
21
22 #include <avr/io.h>
23 #include <aversive.h>
24
25
26 #include <uart.h>
27 #include <aversive/wait.h>
28 #include <stdio.h>
29
30 #include <diagnostic.h>
31
32 int delay = 0;
33 int charcount = 0;
34
35 char buf[20] = "toto";
36 int buf_index = 0;
37
38
39 void interrupt(void)
40 {
41
42   // introduces a delay
43   wait_4cyc(delay *4);
44   
45   
46   // increments the delay, and prepares the string to print
47   if(charcount-- == 0)
48     {
49     charcount = 200;
50     sprintf(buf, "\n%i", delay++);
51     buf_index = 0;
52     }
53   
54   // prints the string
55   if (buf[buf_index] == 0)
56     uart0_send(' ');
57   else
58     uart0_send(buf[buf_index++]);
59
60 }
61
62
63
64 int test_int_show(void)
65 {
66
67   // uart stuff
68   uart_init();  
69   sei();
70   fdevopen(uart0_dev_send,NULL);
71
72   // bonjour
73   printf("\nhello, we will now test the int_show function\n");
74   printf("the counter shoud increment while you see the voltage decreasing on the pin\n");
75   printf("this is due to increasing processor charge\n");
76
77   wait_ms(500);
78
79   // should be replaced by the scheduler
80   uart0_register_tx_event((void *) interrupt);
81
82   // start characters
83   printf("\n");
84
85   show_int_loop();
86
87   return 0;
88 }