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);
119 case AO_IGNITE_MODE_MAIN:
121 case ao_igniter_main:
122 AO_IGNITER_SET_DROGUE(1);
123 ao_delay(AO_IGNITER_FIRE_TIME);
124 AO_IGNITER_SET_DROGUE(0);
125 ao_delay(AO_IGNITER_CHARGE_TIME);
126 AO_IGNITER_SET_MAIN(1);
127 ao_delay(AO_IGNITER_FIRE_TIME);
128 AO_IGNITER_SET_MAIN(0);
133 ao_ignition[igniter].firing = 0;
139 __xdata enum ao_igniter igniter;
143 ao_sleep(&ao_ignition);
144 for (igniter = ao_igniter_drogue; igniter <= ao_igniter_main; igniter++) {
145 if (ao_ignition[igniter].request && !ao_ignition[igniter].fired) {
146 if (igniter == ao_igniter_drogue && ao_config.apogee_delay)
147 ao_delay(AO_SEC_TO_TICKS(ao_config.apogee_delay));
149 ao_igniter_fire(igniter);
150 ao_delay(AO_IGNITER_CHARGE_TIME);
151 ao_ignition[igniter].fired = 1;
160 ao_ignite_manual(void)
163 if (!ao_match_word("DoIt"))
167 if (ao_cmd_lex_c == 'm' && ao_match_word("main")) {
168 ao_igniter_fire(ao_igniter_main);
171 if (ao_cmd_lex_c == 'd' && ao_match_word("drogue")) {
172 ao_igniter_fire(ao_igniter_drogue);
177 if ('0' <= ao_cmd_lex_c && ao_cmd_lex_c <= '9') {
178 ao_pyro_manual(ao_cmd_lex_c - '0');
182 ao_cmd_status = ao_cmd_syntax_error;
185 __code char * __code ao_igniter_status_names[] = {
186 "unknown", "ready", "active", "open"
191 ao_ignite_print_status(enum ao_igniter igniter, __code char *name) __reentrant
193 enum ao_igniter_status status = ao_igniter_status(igniter);
194 printf("Igniter: %6s Status: %s\n",
196 ao_igniter_status_names[status]);
204 ao_ignite_print_status(ao_igniter_drogue, "drogue");
205 ao_ignite_print_status(ao_igniter_main, "main");
208 ao_pyro_print_status();
212 __code struct ao_cmds ao_ignite_cmds[] = {
213 { ao_ignite_manual, "i <key> {main|drogue}\0Fire igniter. <key> is doit with D&I" },
214 { ao_ignite_test, "t\0Test igniter" },
219 __xdata struct ao_task ao_igniter_task;
222 ao_ignite_set_pins(void)
224 ao_enable_output(AO_IGNITER_DROGUE_PORT, AO_IGNITER_DROGUE_PIN, AO_IGNITER_DROGUE, 0);
225 ao_enable_output(AO_IGNITER_MAIN_PORT, AO_IGNITER_MAIN_PIN, AO_IGNITER_MAIN, 0);
230 ao_igniter_init(void)
233 ao_ignite_set_pins();
234 ao_add_task(&ao_igniter_task, ao_igniter, "igniter");
236 ao_cmd_register(&ao_ignite_cmds[0]);