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 __xdata struct ao_ignition ao_ignition[2];
24 ao_ignite(enum ao_igniter igniter) __critical
26 ao_ignition[igniter].request = 1;
27 ao_wakeup(&ao_ignition);
30 #ifndef AO_SENSE_DROGUE
31 #define AO_SENSE_DROGUE(p) ((p)->adc.sense_d)
32 #define AO_SENSE_MAIN(p) ((p)->adc.sense_m)
35 enum ao_igniter_status
36 ao_igniter_status(enum ao_igniter igniter)
38 __xdata struct ao_data packet;
39 __pdata int16_t value;
40 __pdata uint8_t request, firing, fired;
44 request = ao_ignition[igniter].request;
45 fired = ao_ignition[igniter].fired;
46 firing = ao_ignition[igniter].firing;
48 if (firing || (request && !fired))
49 return ao_igniter_active;
51 value = (AO_IGNITER_CLOSED>>1);
53 case ao_igniter_drogue:
54 value = AO_SENSE_DROGUE(&packet);
57 value = AO_SENSE_MAIN(&packet);
60 if (value < AO_IGNITER_OPEN)
61 return ao_igniter_open;
62 else if (value > AO_IGNITER_CLOSED)
63 return ao_igniter_ready;
65 return ao_igniter_unknown;
68 #ifndef AO_IGNITER_SET_DROGUE
69 #define AO_IGNITER_SET_DROGUE(v) AO_IGNITER_DROGUE = (v)
70 #define AO_IGNITER_SET_MAIN(v) AO_IGNITER_MAIN = (v)
73 #ifndef AO_IGNITER_FIRE_TIME
74 #define AO_IGNITER_FIRE_TIME AO_MS_TO_TICKS(50)
77 #ifndef AO_IGNITER_CHARGE_TIME
78 #define AO_IGNITER_CHARGE_TIME AO_MS_TO_TICKS(2000)
82 ao_igniter_fire(enum ao_igniter igniter) __critical
84 ao_ignition[igniter].firing = 1;
85 switch(ao_config.ignite_mode) {
86 case AO_IGNITE_MODE_DUAL:
88 case ao_igniter_drogue:
89 AO_IGNITER_SET_DROGUE(1);
90 ao_delay(AO_IGNITER_FIRE_TIME);
91 AO_IGNITER_SET_DROGUE(0);
94 AO_IGNITER_SET_MAIN(1);
95 ao_delay(AO_IGNITER_FIRE_TIME);
96 AO_IGNITER_SET_MAIN(0);
100 case AO_IGNITE_MODE_APOGEE:
102 case ao_igniter_drogue:
103 AO_IGNITER_SET_DROGUE(1);
104 ao_delay(AO_IGNITER_FIRE_TIME);
105 AO_IGNITER_SET_DROGUE(0);
106 ao_delay(AO_IGNITER_CHARGE_TIME);
107 AO_IGNITER_SET_MAIN(1);
108 ao_delay(AO_IGNITER_FIRE_TIME);
109 AO_IGNITER_SET_MAIN(0);
113 case AO_IGNITE_MODE_MAIN:
115 case ao_igniter_main:
116 AO_IGNITER_SET_DROGUE(1);
117 ao_delay(AO_IGNITER_FIRE_TIME);
118 AO_IGNITER_SET_DROGUE(0);
119 ao_delay(AO_IGNITER_CHARGE_TIME);
120 AO_IGNITER_SET_MAIN(1);
121 ao_delay(AO_IGNITER_FIRE_TIME);
122 AO_IGNITER_SET_MAIN(0);
127 ao_ignition[igniter].firing = 0;
133 __xdata enum ao_igniter igniter;
137 ao_sleep(&ao_ignition);
138 for (igniter = ao_igniter_drogue; igniter <= ao_igniter_main; igniter++) {
139 if (ao_ignition[igniter].request && !ao_ignition[igniter].fired) {
140 if (igniter == ao_igniter_drogue && ao_config.apogee_delay)
141 ao_delay(AO_SEC_TO_TICKS(ao_config.apogee_delay));
143 ao_igniter_fire(igniter);
144 ao_delay(AO_IGNITER_CHARGE_TIME);
145 ao_ignition[igniter].fired = 1;
152 ao_ignite_manual(void)
155 if (!ao_match_word("DoIt"))
158 if (ao_cmd_lex_c == 'm') {
159 if(ao_match_word("main"))
160 ao_igniter_fire(ao_igniter_main);
162 if(ao_match_word("drogue"))
163 ao_igniter_fire(ao_igniter_drogue);
167 static __code char * __code igniter_status_names[] = {
168 "unknown", "ready", "active", "open"
172 ao_ignite_print_status(enum ao_igniter igniter, __code char *name) __reentrant
174 enum ao_igniter_status status = ao_igniter_status(igniter);
175 printf("Igniter: %6s Status: %s\n",
177 igniter_status_names[status]);
183 ao_ignite_print_status(ao_igniter_drogue, "drogue");
184 ao_ignite_print_status(ao_igniter_main, "main");
187 __code struct ao_cmds ao_ignite_cmds[] = {
188 { ao_ignite_manual, "i <key> {main|drogue}\0Fire igniter. <key> is doit with D&I" },
189 { ao_ignite_test, "t\0Test igniter" },
193 __xdata struct ao_task ao_igniter_task;
196 ao_ignite_set_pins(void)
198 ao_enable_output(AO_IGNITER_DROGUE_PORT, AO_IGNITER_DROGUE_PIN, AO_IGNITER_DROGUE, 0);
199 ao_enable_output(AO_IGNITER_MAIN_PORT, AO_IGNITER_MAIN_PIN, AO_IGNITER_MAIN, 0);
203 ao_igniter_init(void)
205 ao_ignite_set_pins();
206 ao_cmd_register(&ao_ignite_cmds[0]);
207 ao_add_task(&ao_igniter_task, ao_igniter, "igniter");