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; either version 2 of the License, or
7 * (at your option) any later version.
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.
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.
26 __xdata struct ao_ignition ao_ignition[2];
29 ao_ignite(enum ao_igniter igniter)
31 ao_arch_block_interrupts();
32 ao_ignition[igniter].request = 1;
33 ao_wakeup(&ao_ignition);
34 ao_arch_release_interrupts();
37 #ifndef AO_SENSE_DROGUE
38 #define AO_SENSE_DROGUE(p) ((p)->adc.sense_d)
39 #define AO_SENSE_MAIN(p) ((p)->adc.sense_m)
42 enum ao_igniter_status
43 ao_igniter_status(enum ao_igniter igniter)
45 __xdata struct ao_data packet;
46 __pdata int16_t value;
47 __pdata uint8_t request, firing, fired;
51 request = ao_ignition[igniter].request;
52 fired = ao_ignition[igniter].fired;
53 firing = ao_ignition[igniter].firing;
55 if (firing || (request && !fired))
56 return ao_igniter_active;
58 value = (AO_IGNITER_CLOSED>>1);
60 case ao_igniter_drogue:
61 value = AO_SENSE_DROGUE(&packet);
64 value = AO_SENSE_MAIN(&packet);
67 if (value < AO_IGNITER_OPEN)
68 return ao_igniter_open;
69 else if (value > AO_IGNITER_CLOSED)
70 return ao_igniter_ready;
72 return ao_igniter_unknown;
75 #ifndef AO_IGNITER_SET_DROGUE
76 #define AO_IGNITER_SET_DROGUE(v) AO_IGNITER_DROGUE = (v)
77 #define AO_IGNITER_SET_MAIN(v) AO_IGNITER_MAIN = (v)
80 #ifndef AO_IGNITER_FIRE_TIME
81 #define AO_IGNITER_FIRE_TIME AO_MS_TO_TICKS(50)
84 #ifndef AO_IGNITER_CHARGE_TIME
85 #define AO_IGNITER_CHARGE_TIME AO_MS_TO_TICKS(2000)
89 ao_igniter_fire(enum ao_igniter igniter)
91 ao_ignition[igniter].firing = 1;
92 switch(ao_config.ignite_mode) {
93 case AO_IGNITE_MODE_DUAL:
95 case ao_igniter_drogue:
96 AO_IGNITER_SET_DROGUE(1);
97 ao_delay(AO_IGNITER_FIRE_TIME);
98 AO_IGNITER_SET_DROGUE(0);
100 case ao_igniter_main:
101 AO_IGNITER_SET_MAIN(1);
102 ao_delay(AO_IGNITER_FIRE_TIME);
103 AO_IGNITER_SET_MAIN(0);
107 case AO_IGNITE_MODE_APOGEE:
109 case ao_igniter_drogue:
110 AO_IGNITER_SET_DROGUE(1);
111 ao_delay(AO_IGNITER_FIRE_TIME);
112 AO_IGNITER_SET_DROGUE(0);
113 ao_delay(AO_IGNITER_CHARGE_TIME);
114 AO_IGNITER_SET_MAIN(1);
115 ao_delay(AO_IGNITER_FIRE_TIME);
116 AO_IGNITER_SET_MAIN(0);
122 case AO_IGNITE_MODE_MAIN:
124 case ao_igniter_main:
125 AO_IGNITER_SET_DROGUE(1);
126 ao_delay(AO_IGNITER_FIRE_TIME);
127 AO_IGNITER_SET_DROGUE(0);
128 ao_delay(AO_IGNITER_CHARGE_TIME);
129 AO_IGNITER_SET_MAIN(1);
130 ao_delay(AO_IGNITER_FIRE_TIME);
131 AO_IGNITER_SET_MAIN(0);
138 ao_ignition[igniter].firing = 0;
144 __xdata enum ao_igniter igniter;
148 ao_sleep(&ao_ignition);
149 for (igniter = ao_igniter_drogue; igniter <= ao_igniter_main; igniter++) {
150 if (ao_ignition[igniter].request && !ao_ignition[igniter].fired) {
151 if (igniter == ao_igniter_drogue && ao_config.apogee_delay)
152 ao_delay(AO_SEC_TO_TICKS(ao_config.apogee_delay));
154 ao_igniter_fire(igniter);
155 ao_delay(AO_IGNITER_CHARGE_TIME);
156 ao_ignition[igniter].fired = 1;
165 ao_ignite_manual(void)
168 if (!ao_match_word("DoIt"))
172 if (ao_cmd_lex_c == 'm' && ao_match_word("main")) {
173 ao_igniter_fire(ao_igniter_main);
176 if (ao_cmd_lex_c == 'd' && ao_match_word("drogue")) {
177 ao_igniter_fire(ao_igniter_drogue);
182 if ('0' <= ao_cmd_lex_c && ao_cmd_lex_c <= '9') {
183 ao_pyro_manual(ao_cmd_lex_c - '0');
187 ao_cmd_status = ao_cmd_syntax_error;
190 __code char * __code ao_igniter_status_names[] = {
191 "unknown", "ready", "active", "open"
196 ao_ignite_print_status(enum ao_igniter igniter, __code char *name) __reentrant
198 enum ao_igniter_status status = ao_igniter_status(igniter);
199 printf("Igniter: %6s Status: %s\n",
201 ao_igniter_status_names[status]);
209 ao_ignite_print_status(ao_igniter_drogue, "drogue");
210 ao_ignite_print_status(ao_igniter_main, "main");
213 ao_pyro_print_status();
217 __code struct ao_cmds ao_ignite_cmds[] = {
218 { ao_ignite_manual, "i <key> {main|drogue}\0Fire igniter. <key> is doit with D&I" },
219 { ao_ignite_test, "t\0Test igniter" },
224 __xdata struct ao_task ao_igniter_task;
227 ao_ignite_set_pins(void)
229 ao_enable_output(AO_IGNITER_DROGUE_PORT, AO_IGNITER_DROGUE_PIN, AO_IGNITER_DROGUE, 0);
230 ao_enable_output(AO_IGNITER_MAIN_PORT, AO_IGNITER_MAIN_PIN, AO_IGNITER_MAIN, 0);
235 ao_igniter_init(void)
238 ao_ignite_set_pins();
239 ao_add_task(&ao_igniter_task, ao_igniter, "igniter");
241 ao_cmd_register(&ao_ignite_cmds[0]);