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.
25 __xdata struct ao_ignition ao_ignition[2];
28 ao_ignite(enum ao_igniter igniter)
30 ao_arch_block_interrupts();
31 ao_ignition[igniter].request = 1;
32 ao_wakeup(&ao_ignition);
33 ao_arch_release_interrupts();
36 #ifndef AO_SENSE_DROGUE
37 #define AO_SENSE_DROGUE(p) ((p)->adc.sense_d)
38 #define AO_SENSE_MAIN(p) ((p)->adc.sense_m)
41 enum ao_igniter_status
42 ao_igniter_status(enum ao_igniter igniter)
44 __xdata struct ao_data packet;
45 __pdata int16_t value;
46 __pdata uint8_t request, firing, fired;
50 request = ao_ignition[igniter].request;
51 fired = ao_ignition[igniter].fired;
52 firing = ao_ignition[igniter].firing;
54 if (firing || (request && !fired))
55 return ao_igniter_active;
57 value = (AO_IGNITER_CLOSED>>1);
59 case ao_igniter_drogue:
60 value = AO_SENSE_DROGUE(&packet);
63 value = AO_SENSE_MAIN(&packet);
66 if (value < AO_IGNITER_OPEN)
67 return ao_igniter_open;
68 else if (value > AO_IGNITER_CLOSED)
69 return ao_igniter_ready;
71 return ao_igniter_unknown;
74 #ifndef AO_IGNITER_SET_DROGUE
75 #define AO_IGNITER_SET_DROGUE(v) AO_IGNITER_DROGUE = (v)
76 #define AO_IGNITER_SET_MAIN(v) AO_IGNITER_MAIN = (v)
79 #ifndef AO_IGNITER_FIRE_TIME
80 #define AO_IGNITER_FIRE_TIME AO_MS_TO_TICKS(50)
83 #ifndef AO_IGNITER_CHARGE_TIME
84 #define AO_IGNITER_CHARGE_TIME AO_MS_TO_TICKS(2000)
88 ao_igniter_fire(enum ao_igniter igniter)
90 ao_ignition[igniter].firing = 1;
91 switch(ao_config.ignite_mode) {
92 case AO_IGNITE_MODE_DUAL:
94 case ao_igniter_drogue:
95 AO_IGNITER_SET_DROGUE(1);
96 ao_delay(AO_IGNITER_FIRE_TIME);
97 AO_IGNITER_SET_DROGUE(0);
100 AO_IGNITER_SET_MAIN(1);
101 ao_delay(AO_IGNITER_FIRE_TIME);
102 AO_IGNITER_SET_MAIN(0);
106 case AO_IGNITE_MODE_APOGEE:
108 case ao_igniter_drogue:
109 AO_IGNITER_SET_DROGUE(1);
110 ao_delay(AO_IGNITER_FIRE_TIME);
111 AO_IGNITER_SET_DROGUE(0);
112 ao_delay(AO_IGNITER_CHARGE_TIME);
113 AO_IGNITER_SET_MAIN(1);
114 ao_delay(AO_IGNITER_FIRE_TIME);
115 AO_IGNITER_SET_MAIN(0);
121 case AO_IGNITE_MODE_MAIN:
123 case ao_igniter_main:
124 AO_IGNITER_SET_DROGUE(1);
125 ao_delay(AO_IGNITER_FIRE_TIME);
126 AO_IGNITER_SET_DROGUE(0);
127 ao_delay(AO_IGNITER_CHARGE_TIME);
128 AO_IGNITER_SET_MAIN(1);
129 ao_delay(AO_IGNITER_FIRE_TIME);
130 AO_IGNITER_SET_MAIN(0);
137 ao_ignition[igniter].firing = 0;
143 __xdata enum ao_igniter igniter;
147 ao_sleep(&ao_ignition);
148 for (igniter = ao_igniter_drogue; igniter <= ao_igniter_main; igniter++) {
149 if (ao_ignition[igniter].request && !ao_ignition[igniter].fired) {
150 if (igniter == ao_igniter_drogue && ao_config.apogee_delay)
151 ao_delay(AO_SEC_TO_TICKS(ao_config.apogee_delay));
153 ao_igniter_fire(igniter);
154 ao_delay(AO_IGNITER_CHARGE_TIME);
155 ao_ignition[igniter].fired = 1;
164 ao_ignite_manual(void)
167 if (!ao_match_word("DoIt"))
171 if (ao_cmd_lex_c == 'm' && ao_match_word("main")) {
172 ao_igniter_fire(ao_igniter_main);
175 if (ao_cmd_lex_c == 'd' && ao_match_word("drogue")) {
176 ao_igniter_fire(ao_igniter_drogue);
181 if ('0' <= ao_cmd_lex_c && ao_cmd_lex_c <= '9') {
182 ao_pyro_manual(ao_cmd_lex_c - '0');
186 ao_cmd_status = ao_cmd_syntax_error;
189 __code char * __code ao_igniter_status_names[] = {
190 "unknown", "ready", "active", "open"
195 ao_ignite_print_status(enum ao_igniter igniter, __code char *name) __reentrant
197 enum ao_igniter_status status = ao_igniter_status(igniter);
198 printf("Igniter: %6s Status: %s\n",
200 ao_igniter_status_names[status]);
208 ao_ignite_print_status(ao_igniter_drogue, "drogue");
209 ao_ignite_print_status(ao_igniter_main, "main");
212 ao_pyro_print_status();
216 __code struct ao_cmds ao_ignite_cmds[] = {
217 { ao_ignite_manual, "i <key> {main|drogue}\0Fire igniter. <key> is doit with D&I" },
218 { ao_ignite_test, "t\0Test igniter" },
223 __xdata struct ao_task ao_igniter_task;
226 ao_ignite_set_pins(void)
228 ao_enable_output(AO_IGNITER_DROGUE_PORT, AO_IGNITER_DROGUE_PIN, AO_IGNITER_DROGUE, 0);
229 ao_enable_output(AO_IGNITER_MAIN_PORT, AO_IGNITER_MAIN_PIN, AO_IGNITER_MAIN, 0);
234 ao_igniter_init(void)
237 ao_ignite_set_pins();
238 ao_add_task(&ao_igniter_task, ao_igniter, "igniter");
240 ao_cmd_register(&ao_ignite_cmds[0]);