ini
[aversive.git] / modules / debug / diagnostic / test / test_stack_size.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_stack_size.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
33
34 // this functions calls itself and consumes stack every time
35 // the stack space indication should decrement every time
36 // when the stack is all consumed, the processor can do crazy things.
37 // most time it will reset
38 void recursive_call(void)
39 {
40   volatile int stack_size; // volatile necessary to put variable on stack
41
42   // printing the stacck space
43   stack_size = min_stack_space_available();
44   printf("stack size : %i\n", stack_size);
45   
46   
47   wait_ms(50);
48   
49   // consuming stack space
50   recursive_call();
51 }
52
53
54
55 int test_stack_size(void)
56 {
57
58   // uart stuff
59   uart_init();  
60   sei();
61   fdevopen(uart0_dev_send,NULL);
62
63   // bonjour
64   printf("\n\nhello, I just reset !\nperhaps a lack of stack space\n");
65
66   // the beginning of the loop
67   recursive_call();
68
69   return 0;
70 }