2 * Copyright © 2009 Keith Packard <keithp@keithp.com>
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; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 #define AO_IGNITER_DROGUE P2_3
22 #define AO_IGNITER_MAIN P2_4
23 #define AO_IGNITER_DIR P2DIR
24 #define AO_IGNITER_DROGUE_BIT (1 << 3)
25 #define AO_IGNITER_MAIN_BIT (1 << 4)
29 #define AO_IGNITER_DROGUE P0_5
30 #define AO_IGNITER_MAIN P0_4
31 #define AO_IGNITER_DIR P0DIR
32 #define AO_IGNITER_DROGUE_BIT (1 << 5)
33 #define AO_IGNITER_MAIN_BIT (1 << 4)
36 /* test these values with real igniters */
37 #define AO_IGNITER_OPEN 1000
38 #define AO_IGNITER_CLOSED 7000
39 #define AO_IGNITER_FIRE_TIME AO_MS_TO_TICKS(50)
40 #define AO_IGNITER_CHARGE_TIME AO_MS_TO_TICKS(2000)
48 __xdata struct ao_ignition ao_ignition[2];
51 ao_ignite(enum ao_igniter igniter) __critical
53 ao_ignition[igniter].request = 1;
54 ao_wakeup(&ao_ignition);
57 enum ao_igniter_status
58 ao_igniter_status(enum ao_igniter igniter)
60 __xdata struct ao_adc adc;
61 __pdata int16_t value;
62 __pdata uint8_t request, firing, fired;
66 request = ao_ignition[igniter].request;
67 fired = ao_ignition[igniter].fired;
68 firing = ao_ignition[igniter].firing;
70 if (firing || (request && !fired))
71 return ao_igniter_active;
73 value = (AO_IGNITER_CLOSED>>1);
75 case ao_igniter_drogue:
82 if (value < AO_IGNITER_OPEN)
83 return ao_igniter_open;
84 else if (value > AO_IGNITER_CLOSED)
85 return ao_igniter_ready;
87 return ao_igniter_unknown;
91 ao_igniter_fire(enum ao_igniter igniter) __critical
93 ao_ignition[igniter].firing = 1;
94 switch(ao_config.ignite_mode) {
95 case AO_IGNITE_MODE_DUAL:
97 case ao_igniter_drogue:
98 AO_IGNITER_DROGUE = 1;
99 ao_delay(AO_IGNITER_FIRE_TIME);
100 AO_IGNITER_DROGUE = 0;
102 case ao_igniter_main:
104 ao_delay(AO_IGNITER_FIRE_TIME);
109 case AO_IGNITE_MODE_APOGEE:
111 case ao_igniter_drogue:
112 AO_IGNITER_DROGUE = 1;
113 ao_delay(AO_IGNITER_FIRE_TIME);
114 AO_IGNITER_DROGUE = 0;
115 ao_delay(AO_IGNITER_CHARGE_TIME);
117 ao_delay(AO_IGNITER_FIRE_TIME);
122 case AO_IGNITE_MODE_MAIN:
124 case ao_igniter_main:
125 AO_IGNITER_DROGUE = 1;
126 ao_delay(AO_IGNITER_FIRE_TIME);
127 AO_IGNITER_DROGUE = 0;
128 ao_delay(AO_IGNITER_CHARGE_TIME);
130 ao_delay(AO_IGNITER_FIRE_TIME);
136 ao_ignition[igniter].firing = 0;
142 __xdata enum ao_ignter igniter;
146 ao_sleep(&ao_ignition);
147 for (igniter = ao_igniter_drogue; igniter <= ao_igniter_main; igniter++) {
148 if (ao_ignition[igniter].request && !ao_ignition[igniter].fired) {
149 if (igniter == ao_igniter_drogue && ao_config.apogee_delay)
150 ao_delay(AO_SEC_TO_TICKS(ao_config.apogee_delay));
152 ao_igniter_fire(igniter);
153 ao_delay(AO_IGNITER_CHARGE_TIME);
154 ao_ignition[igniter].fired = 1;
161 ao_ignite_manual(void)
164 if (!ao_match_word("DoIt"))
167 if (ao_cmd_lex_c == 'm') {
168 if(ao_match_word("main"))
169 ao_igniter_fire(ao_igniter_main);
171 if(ao_match_word("drogue"))
172 ao_igniter_fire(ao_igniter_drogue);
176 static __code char * __code igniter_status_names[] = {
177 "unknown", "ready", "active", "open"
181 ao_ignite_print_status(enum ao_igniter igniter, __code char *name) __reentrant
183 enum ao_igniter_status status = ao_igniter_status(igniter);
184 printf("Igniter: %6s Status: %s\n",
186 igniter_status_names[status]);
192 ao_ignite_print_status(ao_igniter_drogue, "drogue");
193 ao_ignite_print_status(ao_igniter_main, "main");
196 __code struct ao_cmds ao_ignite_cmds[] = {
197 { ao_ignite_manual, "i <key> {main|drogue}\0Fire igniter. <key> is doit with D&I" },
198 { ao_ignite_test, "t\0Test igniter" },
202 __xdata struct ao_task ao_igniter_task;
205 ao_ignite_set_pins(void)
207 AO_IGNITER_DROGUE = 0;
209 AO_IGNITER_DIR |= AO_IGNITER_DROGUE_BIT | AO_IGNITER_MAIN_BIT;
213 ao_igniter_init(void)
215 ao_ignite_set_pins();
216 ao_cmd_register(&ao_ignite_cmds[0]);
217 ao_add_task(&ao_igniter_task, ao_igniter, "igniter");