altos/test: Adjust CRC error rate after FEC fix
[fw/altos] / src / product / ao_test.c
1 /*
2  * Copyright © 2009 Keith Packard <keithp@keithp.com>
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, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #include "ao.h"
20
21 struct ao_task blink_0_task;
22 struct ao_task blink_1_task;
23 struct ao_task wakeup_task;
24 struct ao_task beep_task;
25 struct ao_task echo_task;
26
27 void delay(int n) 
28 {
29         uint8_t j = 0;
30         while (--n)
31                 while (--j)
32                         ao_yield();
33 }
34
35 static uint8_t blink_chan;
36
37 void
38 blink_0(void)
39 {
40         uint8_t b = 0;
41         for (;;) {
42                 b = 1 - b;
43                 if (b)
44                         ao_led_on(AO_LED_GREEN);
45                 else
46                         ao_led_off(AO_LED_GREEN);
47                 ao_sleep(&blink_chan);
48         }
49 }
50
51 void
52 blink_1(void)
53 {
54         static struct ao_adc adc;
55
56         for (;;) {
57                 ao_sleep(&ao_adc_head);
58                 ao_adc_get(&adc);
59                 if (adc.accel < 15900)
60                         ao_led_on(AO_LED_RED);
61                 else
62                         ao_led_off(AO_LED_RED);
63         }
64 }
65
66 void
67 wakeup(void)
68 {
69         for (;;) {
70                 ao_delay(AO_MS_TO_TICKS(100));
71                 ao_wakeup(&blink_chan);
72         }
73 }
74
75 void
76 beep(void)
77 {
78         static struct ao_adc adc;
79
80         for (;;) {
81                 ao_delay(AO_SEC_TO_TICKS(1));
82                 ao_adc_get(&adc);
83                 if (adc.temp > 7400)
84                         ao_beep_for(AO_BEEP_LOW, AO_MS_TO_TICKS(50));
85         }
86 }
87
88 void
89 echo(void)
90 {
91         char    c;
92         for (;;) {
93                 ao_usb_flush();
94                 c = ao_usb_getchar();
95                 ao_usb_putchar(c);
96                 if (c == '\r')
97                         ao_usb_putchar('\n');
98         }
99 }
100
101 void
102 main(void)
103 {
104         ao_clock_init();
105
106         ao_task_init();
107
108 //      ao_add_task(&blink_0_task, blink_0);
109 //      ao_add_task(&blink_1_task, blink_1);
110 //      ao_add_task(&wakeup_task, wakeup);
111 //      ao_add_task(&beep_task, beep);
112         ao_add_task(&echo_task, echo);
113         ao_timer_init();
114         ao_adc_init();
115         ao_beep_init();
116         ao_led_init();
117         ao_usb_init();
118
119         ao_start_scheduler();
120 }