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 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 struct ao_data packet;
47 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 #define AO_IGNITER_SET_DROGUE(v) ao_gpio_set(AO_IGNITER_DROGUE_PORT, AO_IGNITER_DROGUE_PIN, v)
76 #define AO_IGNITER_SET_MAIN(v) ao_gpio_set(AO_IGNITER_MAIN_PORT, AO_IGNITER_MAIN_PIN, v)
78 #ifndef AO_IGNITER_FIRE_TIME
79 #define AO_IGNITER_FIRE_TIME AO_MS_TO_TICKS(50)
82 #ifndef AO_IGNITER_CHARGE_TIME
83 #define AO_IGNITER_CHARGE_TIME AO_MS_TO_TICKS(2000)
87 ao_igniter_fire(enum ao_igniter igniter)
89 ao_ignition[igniter].firing = 1;
90 switch(ao_config.ignite_mode) {
91 case AO_IGNITE_MODE_DUAL:
93 case ao_igniter_drogue:
94 AO_IGNITER_SET_DROGUE(1);
95 ao_delay(AO_IGNITER_FIRE_TIME);
96 AO_IGNITER_SET_DROGUE(0);
99 AO_IGNITER_SET_MAIN(1);
100 ao_delay(AO_IGNITER_FIRE_TIME);
101 AO_IGNITER_SET_MAIN(0);
105 case AO_IGNITE_MODE_APOGEE:
107 case ao_igniter_drogue:
108 AO_IGNITER_SET_DROGUE(1);
109 ao_delay(AO_IGNITER_FIRE_TIME);
110 AO_IGNITER_SET_DROGUE(0);
111 ao_delay(AO_IGNITER_CHARGE_TIME);
112 AO_IGNITER_SET_MAIN(1);
113 ao_delay(AO_IGNITER_FIRE_TIME);
114 AO_IGNITER_SET_MAIN(0);
120 case AO_IGNITE_MODE_MAIN:
122 case ao_igniter_main:
123 AO_IGNITER_SET_DROGUE(1);
124 ao_delay(AO_IGNITER_FIRE_TIME);
125 AO_IGNITER_SET_DROGUE(0);
126 ao_delay(AO_IGNITER_CHARGE_TIME);
127 AO_IGNITER_SET_MAIN(1);
128 ao_delay(AO_IGNITER_FIRE_TIME);
129 AO_IGNITER_SET_MAIN(0);
136 ao_ignition[igniter].firing = 0;
142 enum ao_igniter 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;
163 ao_ignite_manual(void)
166 if (!ao_match_word("DoIt"))
170 if (ao_cmd_lex_c == 'm' && ao_match_word("main")) {
171 ao_igniter_fire(ao_igniter_main);
174 if (ao_cmd_lex_c == 'd' && ao_match_word("drogue")) {
175 ao_igniter_fire(ao_igniter_drogue);
180 if ('0' <= ao_cmd_lex_c && ao_cmd_lex_c <= '9') {
181 ao_pyro_manual(ao_cmd_lex_c - '0');
185 ao_cmd_status = ao_cmd_syntax_error;
188 const char * const ao_igniter_status_names[] = {
189 "unknown", "ready", "active", "open"
194 ao_ignite_print_status(enum ao_igniter igniter, const char *name)
196 enum ao_igniter_status status = ao_igniter_status(igniter);
197 printf("Igniter: %6s Status: %s\n",
199 ao_igniter_status_names[status]);
207 ao_ignite_print_status(ao_igniter_drogue, "drogue");
208 ao_ignite_print_status(ao_igniter_main, "main");
211 ao_pyro_print_status();
215 const struct ao_cmds ao_ignite_cmds[] = {
216 { ao_ignite_manual, "i <key> {main|drogue}\0Fire igniter. <key> is doit with D&I" },
217 { ao_ignite_test, "t\0Test igniter" },
222 struct ao_task ao_igniter_task;
225 ao_ignite_set_pins(void)
227 ao_enable_output(AO_IGNITER_DROGUE_PORT, AO_IGNITER_DROGUE_PIN, 0);
228 ao_enable_output(AO_IGNITER_MAIN_PORT, AO_IGNITER_MAIN_PIN, 0);
233 ao_igniter_init(void)
236 ao_ignite_set_pins();
237 ao_add_task(&ao_igniter_task, ao_igniter, "igniter");
239 ao_cmd_register(&ao_ignite_cmds[0]);