weak current limit on spickles
[aversive.git] / projects / example2 / 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.4.6.3 2007-05-28 12:55:48 zer0 Exp $
19  *
20  */
21
22 #include <aversive.h>
23 #include <aversive/list.h>
24
25 #include <uart.h>
26
27 #include <stdio.h>
28 #include <string.h>
29
30 LIST_TYPEDEF(my_list_type, u08, 4);
31 LIST_TYPEDEF(my_another_list_type, u08, 10);
32
33 void dumplist(struct generic_list * l)
34 {
35         u08 i;
36
37         for(i=0 ; i < l->hdr.size ; i++)
38                 printf( (i != l->hdr.size-1 ? 
39                                     "|-------" : "|-------|"CR) );
40
41         for(i=0 ; i < l->hdr.size ; i++) {
42                 if (( i < l->hdr.beg_indice ) && (l->hdr.cur_size > 0)) {
43                         if (i < (l->hdr.beg_indice 
44                                     + l->hdr.cur_size)
45                             % l->hdr.size) {
46                                 printf("   %.3d  ", l->elt[i]);
47                                           
48                         }
49                         else {
50                                 printf("   XXX  ");
51                         }
52                 }
53                 else if (l->hdr.cur_size > 0){
54                         if (i < l->hdr.beg_indice + l->hdr.cur_size) {
55                                 printf("   %.3d  ", l->elt[i]);
56                         }
57                         else {
58                                 printf("   XXX  ");
59                         }
60                 }
61                 else {
62                         printf("   XXX  ");
63                 }
64         }
65         
66         printf("     cur_size=%d"CR,l->hdr.cur_size);
67
68         for(i=0 ; i < l->hdr.size ; i++)
69                 printf( (i != l->hdr.size-1 ? 
70                                     "|-------" : "|-------|"CR) );
71
72         for(i=0 ; i < l->hdr.size ; i++)
73                 {
74                         if((i == l->hdr.beg_indice) && (l->hdr.cur_size <= 1))
75                                 printf(" beg^end");
76                         else if(i == l->hdr.beg_indice) 
77                                 printf("  beg^  ");
78                         else if((l->hdr.cur_size > 1) && 
79                                    (i == ((l->hdr.beg_indice + l->hdr.cur_size -1)
80                                                 % l->hdr.size)))
81                                 printf("  end^  ");
82                         else
83                                 printf("        ");
84                         printf( (i != l->hdr.size-1 ? 
85                                     "" : CR) );
86                 }        
87
88         for(i=0 ; i < l->hdr.size ; i++)
89                 {
90                         if(i == ((l->hdr.beg_indice + l->hdr.read_cursor)
91                                                 % l->hdr.size))
92                                 printf("  cur^  ");
93                         else
94                                 printf("        ");
95                         printf( (i != l->hdr.size-1 ? 
96                                     "" : CR) );
97                 }        
98
99 }
100
101 int main(void)
102 {
103         u08 tmp=0;
104         u08 tab1[4]= "0123";
105         u08 tab2[4];
106
107 #ifndef HOST_VERSION 
108 /*      uart_init(); */
109 /*      fdevopen((int (*)(char))uart0_send,(int (*)(void))uart0_recv,0); */
110 #endif
111         my_list_type my_list ;
112         my_another_list_type another_list ;
113
114         LIST_INIT(my_list, 0);
115         LIST_INIT(another_list, 8);
116
117         dumplist((struct generic_list *)&my_list);
118         printf(CR CR);
119         
120         LIST_PUSH_END(my_list, 2);
121         dumplist((struct generic_list *)&my_list);
122         printf(CR CR);
123
124         LIST_PUSH_END(my_list, 3);
125         dumplist((struct generic_list *)&my_list);
126         printf(CR CR);
127
128         LIST_PUSH_START(my_list, 1);
129         dumplist((struct generic_list *)&my_list);
130         printf(CR CR);
131
132         LIST_PUSH_END(my_list, 4);
133         dumplist((struct generic_list *)&my_list);
134         printf(CR CR);
135
136         LIST_PUSH_END(my_list, 5);
137         dumplist((struct generic_list *)&my_list);
138         printf(CR CR);
139
140
141         LIST_PULL_END(my_list, &tmp);
142         dumplist((struct generic_list *)&my_list);
143         printf("tmp = %d"CR CR CR,tmp);
144
145
146         LIST_READ_START(my_list, &tmp);
147         dumplist((struct generic_list *)&my_list);
148         printf("tmp = %d"CR CR CR,tmp);
149
150         LIST_READ_END(my_list, &tmp);
151         dumplist((struct generic_list *)&my_list);
152         printf("tmp = %d"CR CR CR,tmp);
153         
154         LIST_READ_GOTO(my_list, &tmp, 0);
155         dumplist((struct generic_list *)&my_list);
156         printf("tmp = %d"CR CR CR,tmp);
157
158         LIST_READ_GOTO(my_list, &tmp, 1);
159         dumplist((struct generic_list *)&my_list);
160         printf("tmp = %d"CR CR CR,tmp);
161
162         LIST_READ_GOTO(my_list, &tmp, 2);
163         dumplist((struct generic_list *)&my_list);
164         printf("tmp = %d"CR CR CR,tmp);
165
166         LIST_READ_GOTO(my_list, &tmp, 3);
167         dumplist((struct generic_list *)&my_list);
168         printf("tmp = %d"CR CR CR,tmp);
169
170         LIST_READ_MOVE(my_list, &tmp, 1);
171         dumplist((struct generic_list *)&my_list);
172         printf("tmp = %d"CR CR CR,tmp);
173
174         LIST_READ_MOVE(my_list, &tmp, 1);
175         dumplist((struct generic_list *)&my_list);
176         printf("tmp = %d"CR CR CR,tmp);
177
178         LIST_READ_MOVE(my_list, &tmp, 1);
179         dumplist((struct generic_list *)&my_list);
180         printf("tmp = %d"CR CR CR,tmp);
181
182         LIST_READ_MOVE(my_list, &tmp, 1);
183         dumplist((struct generic_list *)&my_list);
184         printf("tmp = %d"CR CR CR,tmp);
185
186         LIST_READ_MOVE(my_list, &tmp, 2);
187         dumplist((struct generic_list *)&my_list);
188         printf("tmp = %d"CR CR CR,tmp);
189
190         LIST_READ_MOVE(my_list, &tmp, 3);
191         dumplist((struct generic_list *)&my_list);
192         printf("tmp = %d"CR CR CR,tmp);
193
194         LIST_READ_MOVE(my_list, &tmp, 1);
195         dumplist((struct generic_list *)&my_list);
196         printf("tmp = %d"CR CR CR,tmp);
197
198         LIST_READ_MOVE(my_list, &tmp, 2);
199         dumplist((struct generic_list *)&my_list);
200         printf("tmp = %d"CR CR CR,tmp);
201
202         LIST_READ_MOVE(my_list, &tmp, 3);
203         dumplist((struct generic_list *)&my_list);
204         printf("tmp = %d"CR CR CR,tmp);
205
206         LIST_READ_MOVE(my_list, &tmp, -1);
207         dumplist((struct generic_list *)&my_list);
208         printf("tmp = %d"CR CR CR,tmp);
209
210         LIST_READ_MOVE(my_list, &tmp, -2);
211         dumplist((struct generic_list *)&my_list);
212         printf("tmp = %d"CR CR CR,tmp);
213
214         LIST_READ_MOVE(my_list, &tmp, -3);
215         dumplist((struct generic_list *)&my_list);
216         printf("tmp = %d"CR CR CR,tmp);
217
218
219
220         LIST_PULL_END(my_list, &tmp);
221         dumplist((struct generic_list *)&my_list);
222         printf("tmp = %d"CR CR CR,tmp);
223
224         LIST_PULL_START(my_list, &tmp);
225         dumplist((struct generic_list *)&my_list);
226         printf("tmp = %d"CR CR CR,tmp);
227
228         LIST_PULL_START(my_list, &tmp);
229         dumplist((struct generic_list *)&my_list);
230         printf("tmp = %d"CR CR CR,tmp);
231
232         LIST_PULL_START(my_list, &tmp);
233         dumplist((struct generic_list *)&my_list);
234         printf(CR CR);
235         printf(CR CR);
236         
237
238         LIST_ARRAY_PUSH_START(another_list, tab1, 4);
239         dumplist((struct generic_list *)&another_list);
240         printf(CR CR);
241
242         LIST_ARRAY_PUSH_END(another_list, "abcde", 5);
243         dumplist((struct generic_list *)&another_list);
244         printf(CR CR);
245
246         LIST_ARRAY_PULL_START(another_list, tab2, 4);
247         dumplist((struct generic_list *)&another_list);
248         printf(CR CR);
249
250         LIST_ARRAY_PULL_END(another_list, tab2, 2);
251         dumplist((struct generic_list *)&another_list);
252         printf(CR CR);
253
254         LIST_ALIGN_LEFT(another_list);
255         dumplist((struct generic_list *)&another_list);
256         printf(CR CR);
257
258
259         LIST_INIT(my_list,0);
260         dumplist((struct generic_list *)&my_list);
261         printf(CR CR);
262
263         LIST_ARRAY_PUSH_START(my_list, tab1, 3);
264         dumplist((struct generic_list *)&my_list);
265         printf(CR CR);
266         
267         LIST_ALIGN_LEFT(my_list);
268         dumplist((struct generic_list *)&my_list);
269         printf(CR CR);
270
271
272         return 0;
273 }