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)
26 ao_arch_block_interrupts();
27 ao_ignition[igniter].request = 1;
28 ao_wakeup(&ao_ignition);
29 ao_arch_release_interrupts();
32 #ifndef AO_SENSE_DROGUE
33 #define AO_SENSE_DROGUE(p) ((p)->adc.sense_d)
34 #define AO_SENSE_MAIN(p) ((p)->adc.sense_m)
37 enum ao_igniter_status
38 ao_igniter_status(enum ao_igniter igniter)
40 __xdata struct ao_data packet;
41 __pdata int16_t value;
42 __pdata uint8_t request, firing, fired;
46 request = ao_ignition[igniter].request;
47 fired = ao_ignition[igniter].fired;
48 firing = ao_ignition[igniter].firing;
50 if (firing || (request && !fired))
51 return ao_igniter_active;
53 value = (AO_IGNITER_CLOSED>>1);
55 case ao_igniter_drogue:
56 value = AO_SENSE_DROGUE(&packet);
59 value = AO_SENSE_MAIN(&packet);
62 if (value < AO_IGNITER_OPEN)
63 return ao_igniter_open;
64 else if (value > AO_IGNITER_CLOSED)
65 return ao_igniter_ready;
67 return ao_igniter_unknown;
70 #ifndef AO_IGNITER_SET_DROGUE
71 #define AO_IGNITER_SET_DROGUE(v) AO_IGNITER_DROGUE = (v)
72 #define AO_IGNITER_SET_MAIN(v) AO_IGNITER_MAIN = (v)
75 #ifndef AO_IGNITER_FIRE_TIME
76 #define AO_IGNITER_FIRE_TIME AO_MS_TO_TICKS(50)
79 #ifndef AO_IGNITER_CHARGE_TIME
80 #define AO_IGNITER_CHARGE_TIME AO_MS_TO_TICKS(2000)
84 ao_igniter_fire(enum ao_igniter igniter)
86 ao_ignition[igniter].firing = 1;
87 switch(ao_config.ignite_mode) {
88 case AO_IGNITE_MODE_DUAL:
90 case ao_igniter_drogue:
91 AO_IGNITER_SET_DROGUE(1);
92 ao_delay(AO_IGNITER_FIRE_TIME);
93 AO_IGNITER_SET_DROGUE(0);
96 AO_IGNITER_SET_MAIN(1);
97 ao_delay(AO_IGNITER_FIRE_TIME);
98 AO_IGNITER_SET_MAIN(0);
102 case AO_IGNITE_MODE_APOGEE:
104 case ao_igniter_drogue:
105 AO_IGNITER_SET_DROGUE(1);
106 ao_delay(AO_IGNITER_FIRE_TIME);
107 AO_IGNITER_SET_DROGUE(0);
108 ao_delay(AO_IGNITER_CHARGE_TIME);
109 AO_IGNITER_SET_MAIN(1);
110 ao_delay(AO_IGNITER_FIRE_TIME);
111 AO_IGNITER_SET_MAIN(0);
115 case AO_IGNITE_MODE_MAIN:
117 case ao_igniter_main:
118 AO_IGNITER_SET_DROGUE(1);
119 ao_delay(AO_IGNITER_FIRE_TIME);
120 AO_IGNITER_SET_DROGUE(0);
121 ao_delay(AO_IGNITER_CHARGE_TIME);
122 AO_IGNITER_SET_MAIN(1);
123 ao_delay(AO_IGNITER_FIRE_TIME);
124 AO_IGNITER_SET_MAIN(0);
129 ao_ignition[igniter].firing = 0;
135 __xdata enum ao_igniter igniter;
139 ao_sleep(&ao_ignition);
140 for (igniter = ao_igniter_drogue; igniter <= ao_igniter_main; igniter++) {
141 if (ao_ignition[igniter].request && !ao_ignition[igniter].fired) {
142 if (igniter == ao_igniter_drogue && ao_config.apogee_delay)
143 ao_delay(AO_SEC_TO_TICKS(ao_config.apogee_delay));
145 ao_igniter_fire(igniter);
146 ao_delay(AO_IGNITER_CHARGE_TIME);
147 ao_ignition[igniter].fired = 1;
154 ao_ignite_manual(void)
157 if (!ao_match_word("DoIt"))
160 if (ao_cmd_lex_c == 'm') {
161 if(ao_match_word("main"))
162 ao_igniter_fire(ao_igniter_main);
164 if(ao_match_word("drogue"))
165 ao_igniter_fire(ao_igniter_drogue);
169 static __code char * __code igniter_status_names[] = {
170 "unknown", "ready", "active", "open"
174 ao_ignite_print_status(enum ao_igniter igniter, __code char *name) __reentrant
176 enum ao_igniter_status status = ao_igniter_status(igniter);
177 printf("Igniter: %6s Status: %s\n",
179 igniter_status_names[status]);
185 ao_ignite_print_status(ao_igniter_drogue, "drogue");
186 ao_ignite_print_status(ao_igniter_main, "main");
189 __code struct ao_cmds ao_ignite_cmds[] = {
190 { ao_ignite_manual, "i <key> {main|drogue}\0Fire igniter. <key> is doit with D&I" },
191 { ao_ignite_test, "t\0Test igniter" },
195 __xdata struct ao_task ao_igniter_task;
198 ao_ignite_set_pins(void)
200 ao_enable_output(AO_IGNITER_DROGUE_PORT, AO_IGNITER_DROGUE_PIN, AO_IGNITER_DROGUE, 0);
201 ao_enable_output(AO_IGNITER_MAIN_PORT, AO_IGNITER_MAIN_PIN, AO_IGNITER_MAIN, 0);
205 ao_igniter_init(void)
207 ao_ignite_set_pins();
208 ao_cmd_register(&ao_ignite_cmds[0]);
209 ao_add_task(&ao_igniter_task, ao_igniter, "igniter");