telelco-v0.2: Make config.pad_box override switches
[fw/altos] / src / drivers / ao_pad.c
1 /*
2  * Copyright © 2012 Keith Packard <keithp@keithp.com>
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 #include <ao.h>
20 #include <ao_exti.h>
21 #include <ao_pad.h>
22 #include <ao_74hc165.h>
23 #include <ao_radio_cmac.h>
24
25 static __xdata uint8_t ao_pad_ignite;
26 static __xdata struct ao_pad_command    command;
27 static __xdata struct ao_pad_query      query;
28 static __pdata uint8_t  ao_pad_armed;
29 static __pdata uint16_t ao_pad_arm_time;
30 static __pdata uint8_t  ao_pad_box;
31 static __xdata uint8_t  ao_pad_disabled;
32 static __pdata uint16_t ao_pad_packet_time;
33
34 #ifndef AO_PAD_RSSI_MINIMUM
35 #define AO_PAD_RSSI_MINIMUM     -90
36 #endif
37
38 #define DEBUG   1
39
40 #if DEBUG
41 static __pdata uint8_t  ao_pad_debug;
42 #define PRINTD(...) do { if (ao_pad_debug) { printf(__VA_ARGS__); flush(); } } while(0)
43 #define FLUSHD()
44 #else
45 #define PRINTD(...)
46 #define FLUSHD()
47 #endif
48
49 static void
50 ao_siren(uint8_t v)
51 {
52 #ifdef AO_SIREN
53         ao_gpio_set(AO_SIREN_PORT, AO_SIREN_PIN, AO_SIREN, v);
54 #else
55 #if HAS_BEEP
56         ao_beep(v ? AO_BEEP_MID : 0);
57 #else
58         (void) v;
59 #endif
60 #endif
61 }
62
63 static void
64 ao_strobe(uint8_t v)
65 {
66 #ifdef AO_STROBE
67         ao_gpio_set(AO_STROBE_PORT, AO_STROBE_PIN, AO_STROBE, v);
68 #else
69         (void) v;
70 #endif
71 }
72
73 #ifdef AO_PAD_PORT_0
74 #define pins_pad(pad)   (*((AO_PAD_ ## pad ## _PORT) == AO_PAD_PORT_0 ? (&pins0) : (&pins1)))
75 #else
76 #define pins_pad(pad)   pins0
77 #define AO_PAD_PORT_0 AO_PAD_PORT
78 #endif
79
80 static void
81 ao_pad_run(void)
82 {
83         AO_PORT_TYPE    pins0;
84 #ifdef AO_PAD_PORT_1
85         AO_PORT_TYPE    pins1;
86 #endif
87
88         for (;;) {
89                 while (!ao_pad_ignite)
90                         ao_sleep(&ao_pad_ignite);
91                 /*
92                  * Actually set the pad bits
93                  */
94                 pins0 = 0;
95 #ifdef AO_PAD_PORT_1
96                 pins1 = 0;
97 #endif
98 #if AO_PAD_NUM > 0
99                 if (ao_pad_ignite & (1 << 0))
100                         pins_pad(0) |= (1 << AO_PAD_PIN_0);
101 #endif
102 #if AO_PAD_NUM > 1
103                 if (ao_pad_ignite & (1 << 1))
104                         pins_pad(1) |= (1 << AO_PAD_PIN_1);
105 #endif
106 #if AO_PAD_NUM > 2
107                 if (ao_pad_ignite & (1 << 2))
108                         pins_pad(2) |= (1 << AO_PAD_PIN_2);
109 #endif
110 #if AO_PAD_NUM > 3
111                 if (ao_pad_ignite & (1 << 3))
112                         pins_pad(3) |= (1 << AO_PAD_PIN_3);
113 #endif
114 #if AO_PAD_NUM > 4
115                 if (ao_pad_ignite & (1 << 4))
116                         pins_pad(4) |= (1 << AO_PAD_PIN_4);
117 #endif
118 #if AO_PAD_NUM > 5
119                 if (ao_pad_ignite & (1 << 5))
120                         pins_pad(5) |= (1 << AO_PAD_PIN_5);
121 #endif
122 #if AO_PAD_NUM > 6
123                 if (ao_pad_ignite & (1 << 6))
124                         pins_pad(6) |= (1 << AO_PAD_PIN_6);
125 #endif
126 #if AO_PAD_NUM > 7
127                 if (ao_pad_ignite & (1 << 7))
128                         pins_pad(7) |= (1 << AO_PAD_PIN_7);
129 #endif
130 #ifdef AO_PAD_PORT_1
131                 PRINTD("ignite pins 0x%x 0x%x\n", pins0, pins1);
132                 ao_gpio_set_bits(AO_PAD_PORT_0, pins0);
133                 ao_gpio_set_bits(AO_PAD_PORT_1, pins1);
134 #else
135                 PRINTD("ignite pins 0x%x\n", pins0);
136                 ao_gpio_set_bits(AO_PAD_PORT_0, pins0);
137 #endif
138                 while (ao_pad_ignite) {
139                         ao_pad_ignite = 0;
140
141                         ao_delay(AO_PAD_FIRE_TIME);
142                         PRINTD("ao_pad_ignite now %d\n", ao_pad_ignite);
143                 }
144 #ifdef AO_PAD_PORT_1
145                 ao_gpio_clr_bits(AO_PAD_PORT_0, pins0);
146                 ao_gpio_clr_bits(AO_PAD_PORT_1, pins1);
147                 PRINTD("turn off pins 0x%x 0x%x\n", pins0, pins1);
148 #else
149                 ao_gpio_clr_bits(AO_PAD_PORT_0, pins0);
150                 PRINTD("turn off pins 0x%x\n", pins0);
151 #endif
152         }
153 }
154
155 #define AO_PAD_ARM_SIREN_INTERVAL       200
156
157 /* Resistor values needed for various voltage test ratios:
158  *
159  *      Net names involved:
160  *
161  *      V_BATT          Battery power, after the initial power switch
162  *      V_PYRO          Pyro power, after the pyro power switch (and initial power switch)
163  *      PYRO_SENSE      ADC input to sense V_PYRO voltage
164  *      BATT_SENSE      ADC input to sense V_BATT voltage
165  *      IGNITER         FET output to pad (the other pad lead hooks to V_PYRO)
166  *      IGNITER_SENSE   ADC input to sense igniter voltage
167  *
168  *      AO_PAD_R_V_BATT_BATT_SENSE      Resistor from battery rail to battery sense input
169  *      AO_PAD_R_BATT_SENSE_GND         Resistor from battery sense input to ground
170  *
171  *      AO_PAD_R_V_BATT_V_PYRO          Resistor from battery rail to pyro rail
172  *      AO_PAD_R_V_PYRO_PYRO_SENSE      Resistor from pyro rail to pyro sense input
173  *      AO_PAD_R_PYRO_SENSE_GND         Resistor from pyro sense input to ground
174  *
175  *      AO_PAD_R_V_PYRO_IGNITER         Optional resistors from pyro rail to FET igniter output
176  *      AO_PAD_R_IGNITER_IGNITER_SENSE  Resistors from FET igniter output to igniter sense ADC inputs
177  *      AO_PAD_R_IGNITER_SENSE_GND      Resistors from igniter sense ADC inputs to ground
178  */
179
180 int16_t
181 ao_pad_decivolt(int16_t adc, int16_t r_plus, int16_t r_minus)
182 {
183         int32_t mul = (int32_t) AO_ADC_REFERENCE_DV * (r_plus + r_minus);
184         int32_t div = (int32_t) AO_ADC_MAX * r_minus;
185         return ((int32_t) adc * mul + mul/2) / div;
186 }
187
188 static void
189 ao_pad_monitor(void)
190 {
191         uint8_t                 c;
192         uint8_t                 sample;
193         __pdata AO_LED_TYPE     prev = 0, cur = 0;
194         __pdata uint8_t         beeping = 0;
195         __xdata volatile struct ao_data *packet;
196         __pdata uint16_t        arm_beep_time = 0;
197
198         sample = ao_data_head;
199         ao_led_set(LEDS_AVAILABLE);
200         ao_delay(AO_MS_TO_TICKS(1000));
201         ao_led_set(0);
202         for (;;) {
203                 __pdata int16_t                 pyro;
204
205                 ao_arch_critical(
206                         while (sample == ao_data_head)
207                                 ao_sleep((void *) DATA_TO_XDATA(&ao_data_head));
208                         );
209
210
211                 packet = &ao_data_ring[sample];
212                 sample = ao_data_ring_next(sample);
213
214                 /* Reply battery voltage */
215                 query.battery = ao_pad_decivolt(packet->adc.batt, AO_PAD_R_V_BATT_BATT_SENSE, AO_PAD_R_BATT_SENSE_GND);
216
217                 /* Current pyro voltage */
218                 pyro = ao_pad_decivolt(packet->adc.pyro,
219                                        AO_PAD_R_V_PYRO_PYRO_SENSE,
220                                        AO_PAD_R_PYRO_SENSE_GND);
221
222                 cur = 0;
223                 if (pyro > query.battery * 7 / 8) {
224                         query.arm_status = AO_PAD_ARM_STATUS_ARMED;
225                         cur |= AO_LED_ARMED;
226                 } else {
227                         query.arm_status = AO_PAD_ARM_STATUS_DISARMED;
228                         arm_beep_time = 0;
229                 }
230                 if ((ao_time() - ao_pad_packet_time) > AO_SEC_TO_TICKS(2))
231                         cur |= AO_LED_RED;
232                 else if (ao_radio_cmac_rssi < AO_PAD_RSSI_MINIMUM)
233                         cur |= AO_LED_AMBER;
234                 else
235                         cur |= AO_LED_GREEN;
236
237                 for (c = 0; c < AO_PAD_NUM; c++) {
238                         int16_t         sense = ao_pad_decivolt(packet->adc.sense[c],
239                                                                 AO_PAD_R_IGNITER_IGNITER_SENSE,
240                                                                 AO_PAD_R_IGNITER_SENSE_GND);
241                         uint8_t status = AO_PAD_IGNITER_STATUS_UNKNOWN;
242
243                         /*
244                          *      Here's the resistor stack on each
245                          *      igniter channel. Note that
246                          *      AO_PAD_R_V_PYRO_IGNITER is optional
247                          *
248                          *                                      v_pyro \
249                          *      AO_PAD_R_V_PYRO_IGNITER                 igniter
250                          *                                      output /
251                          *      AO_PAD_R_IGNITER_IGNITER_SENSE         \
252                          *                                      sense   relay
253                          *      AO_PAD_R_IGNITER_SENSE_GND             /
254                          *                                      gnd ---
255                          *
256                          */
257
258 #ifdef AO_PAD_R_V_PYRO_IGNITER
259                         if (sense <= pyro / 8) {
260                                 /* close to zero → relay is closed */
261                                 status = AO_PAD_IGNITER_STATUS_NO_IGNITER_RELAY_CLOSED;
262                                 if ((ao_time() % 100) < 50)
263                                         cur |= AO_LED_CONTINUITY(c);
264                         }
265                         else
266 #endif
267                         {
268                                 if (sense >= (pyro * 7) / 8) {
269
270                                         /* sense close to pyro voltage; igniter is good
271                                          */
272                                         status = AO_PAD_IGNITER_STATUS_GOOD_IGNITER_RELAY_OPEN;
273                                         cur |= AO_LED_CONTINUITY(c);
274                                 } else {
275
276                                         /* relay not shorted (if we can tell),
277                                          * and igniter not obviously present
278                                          */
279                                         status = AO_PAD_IGNITER_STATUS_NO_IGNITER_RELAY_OPEN;
280                                 }
281                         }
282                         query.igniter_status[c] = status;
283                 }
284                 if (cur != prev) {
285 //                      PRINTD("change leds from %02x to %02x\n",
286 //                             prev, cur);
287 //                      FLUSHD();
288                         ao_led_set(cur);
289                         prev = cur;
290                 }
291
292                 if (ao_pad_armed && (int16_t) (ao_time() - ao_pad_arm_time) > AO_PAD_ARM_TIME)
293                         ao_pad_armed = 0;
294
295                 if (ao_pad_armed) {
296                         ao_strobe(1);
297                         ao_siren(1);
298                         beeping = 1;
299                 } else if (query.arm_status == AO_PAD_ARM_STATUS_ARMED && !beeping) {
300                         if (arm_beep_time == 0) {
301                                 arm_beep_time = AO_PAD_ARM_SIREN_INTERVAL;
302                                 beeping = 1;
303                                 ao_siren(1);
304                         }
305                         --arm_beep_time;
306                 } else if (beeping) {
307                         beeping = 0;
308                         ao_siren(0);
309                         ao_strobe(0);
310                 }
311         }
312 }
313
314 void
315 ao_pad_disable(void)
316 {
317         if (!ao_pad_disabled) {
318                 ao_pad_disabled = 1;
319                 ao_radio_recv_abort();
320         }
321 }
322
323 void
324 ao_pad_enable(void)
325 {
326         ao_pad_disabled = 0;
327         ao_wakeup (&ao_pad_disabled);
328 }
329
330 #if HAS_74HC165
331 static uint8_t
332 ao_pad_read_box(void)
333 {
334         uint8_t         byte = ao_74hc165_read();
335         uint8_t         h, l;
336
337         PRINTD("box %02x\n", byte);
338         h = byte >> 4;
339         l = byte & 0xf;
340         return h * 10 + l;
341 }
342 #endif
343
344 #ifdef AO_PAD_SELECTOR_PORT
345 static int ao_pad_read_box(void) {
346         AO_PORT_TYPE    value = ao_gpio_get_all(AO_PAD_SELECTOR_PORT);
347         unsigned        pin;
348         int             select = 1;
349
350         for (pin = 0; pin < sizeof (AO_PORT_TYPE) * 8; pin++) {
351                 if (AO_PAD_SELECTOR_PINS & (1 << pin)) {
352                         if ((value & (1 << pin)) == 0)
353                                 return select;
354                         select++;
355                 }
356         }
357         return ao_config.pad_box;
358 }
359 #else
360
361 #ifdef PAD_BOX
362 #define ao_pad_read_box()       PAD_BOX
363 #endif
364
365 #endif
366
367 static void
368 ao_pad(void)
369 {
370         int16_t time_difference;
371         int8_t  ret;
372
373         ao_pad_box = 0;
374         for (;;) {
375                 FLUSHD();
376                 while (ao_pad_disabled)
377                         ao_sleep(&ao_pad_disabled);
378                 ret = ao_radio_cmac_recv(&command, sizeof (command), 0);
379                 PRINTD ("cmac_recv %d %d\n", ret, ao_radio_cmac_rssi);
380                 if (ret != AO_RADIO_CMAC_OK)
381                         continue;
382                 ao_pad_packet_time = ao_time();
383
384                 ao_pad_box = ao_config.pad_box;
385 #ifndef HAS_FIXED_PAD_BOX
386                 if (ao_pad_box == 0 || ao_pad_box == 0xff)
387                         ao_pad_box = ao_pad_read_box();
388 #endif
389
390                 PRINTD ("tick %d box %d (me %d) cmd %d channels %02x\n",
391                         command.tick, command.box, ao_pad_box, command.cmd, command.channels);
392
393                 switch (command.cmd) {
394                 case AO_PAD_ARM:
395                         if (command.box != ao_pad_box) {
396                                 PRINTD ("box number mismatch\n");
397                                 break;
398                         }
399
400                         if (command.channels & ~(AO_PAD_ALL_CHANNELS))
401                                 break;
402
403                         time_difference = command.tick - ao_time();
404                         PRINTD ("arm tick %d local tick %d\n", command.tick, ao_time());
405                         if (time_difference < 0)
406                                 time_difference = -time_difference;
407                         if (time_difference > 10) {
408                                 PRINTD ("time difference too large %d\n", time_difference);
409                                 break;
410                         }
411                         PRINTD ("armed\n");
412                         ao_pad_armed = command.channels;
413                         ao_pad_arm_time = ao_time();
414                         break;
415
416                 case AO_PAD_QUERY:
417                         if (command.box != ao_pad_box) {
418                                 PRINTD ("box number mismatch\n");
419                                 break;
420                         }
421
422                         query.tick = ao_time();
423                         query.box = ao_pad_box;
424                         query.channels = AO_PAD_ALL_CHANNELS;
425                         query.armed = ao_pad_armed;
426                         PRINTD ("query tick %d box %d channels %02x arm %d arm_status %d igniter %d,%d,%d,%d\n",
427                                 query.tick, query.box, query.channels, query.armed,
428                                 query.arm_status,
429                                 query.igniter_status[0],
430                                 query.igniter_status[1],
431                                 query.igniter_status[2],
432                                 query.igniter_status[3]);
433                         ao_radio_cmac_send(&query, sizeof (query));
434                         break;
435                 case AO_PAD_FIRE:
436                         if (!ao_pad_armed) {
437                                 PRINTD ("not armed\n");
438                                 break;
439                         }
440                         if ((uint16_t) (ao_time() - ao_pad_arm_time) > AO_SEC_TO_TICKS(20)) {
441                                 PRINTD ("late pad arm_time %d time %d\n",
442                                         ao_pad_arm_time, ao_time());
443                                 break;
444                         }
445                         PRINTD ("ignite\n");
446                         ao_pad_ignite = ao_pad_armed;
447                         ao_pad_arm_time = ao_time();
448                         ao_wakeup(&ao_pad_ignite);
449                         break;
450                 case AO_PAD_STATIC:
451                         if (!ao_pad_armed) {
452                                 PRINTD ("not armed\n");
453                                 break;
454                         }
455 #if HAS_LOG
456                         if (!ao_log_running) ao_log_start();
457 #endif
458                         if ((uint16_t) (ao_time() - ao_pad_arm_time) > AO_SEC_TO_TICKS(20)) {
459                                 PRINTD ("late pad arm_time %d time %d\n",
460                                         ao_pad_arm_time, ao_time());
461                                 break;
462                         }
463                         PRINTD ("ignite\n");
464                         ao_pad_ignite = ao_pad_armed;
465                         ao_pad_arm_time = ao_time();
466                         ao_wakeup(&ao_pad_ignite);
467                         break;
468                 case AO_PAD_ENDSTATIC:
469 #if HAS_LOG
470                         ao_log_stop();
471 #endif
472                         break;
473                 }
474         }
475 }
476
477 void
478 ao_pad_test(void)
479 {
480         uint8_t c;
481
482         printf ("Arm switch: ");
483         switch (query.arm_status) {
484         case AO_PAD_ARM_STATUS_ARMED:
485                 printf ("Armed\n");
486                 break;
487         case AO_PAD_ARM_STATUS_DISARMED:
488                 printf ("Disarmed\n");
489                 break;
490         case AO_PAD_ARM_STATUS_UNKNOWN:
491                 printf ("Unknown\n");
492                 break;
493         }
494
495         for (c = 0; c < AO_PAD_NUM; c++) {
496                 printf ("Pad %d: ", c);
497                 switch (query.igniter_status[c]) {
498                 case AO_PAD_IGNITER_STATUS_NO_IGNITER_RELAY_CLOSED:     printf ("No igniter. Relay closed\n"); break;
499                 case AO_PAD_IGNITER_STATUS_NO_IGNITER_RELAY_OPEN:       printf ("No igniter. Relay open\n"); break;
500                 case AO_PAD_IGNITER_STATUS_GOOD_IGNITER_RELAY_OPEN:     printf ("Good igniter. Relay open\n"); break;
501                 case AO_PAD_IGNITER_STATUS_UNKNOWN:                     printf ("Unknown\n"); break;
502                 }
503         }
504 }
505
506 void
507 ao_pad_manual(void)
508 {
509         uint8_t ignite;
510         int     repeat;
511         ao_cmd_white();
512         if (!ao_match_word("DoIt"))
513                 return;
514         ao_cmd_decimal();
515         if (ao_cmd_status != ao_cmd_success)
516                 return;
517         ignite = 1 << ao_cmd_lex_i;
518         ao_cmd_decimal();
519         if (ao_cmd_status != ao_cmd_success) {
520                 repeat = 1;
521                 ao_cmd_status = ao_cmd_success;
522         } else
523                 repeat = ao_cmd_lex_i;
524         while (repeat-- > 0) {
525                 ao_pad_ignite = ignite;
526                 ao_wakeup(&ao_pad_ignite);
527                 ao_delay(AO_PAD_FIRE_TIME>>1);
528         }
529 }
530
531 static __xdata struct ao_task ao_pad_task;
532 static __xdata struct ao_task ao_pad_ignite_task;
533 static __xdata struct ao_task ao_pad_monitor_task;
534
535 #if DEBUG
536 void
537 ao_pad_set_debug(void)
538 {
539         ao_cmd_decimal();
540         if (ao_cmd_status == ao_cmd_success)
541                 ao_pad_debug = ao_cmd_lex_i != 0;
542 }
543
544
545 static void
546 ao_pad_alarm_debug(void)
547 {
548         uint8_t which, value;
549         ao_cmd_decimal();
550         if (ao_cmd_status != ao_cmd_success)
551                 return;
552         which = ao_cmd_lex_i;
553         ao_cmd_decimal();
554         if (ao_cmd_status != ao_cmd_success)
555                 return;
556         value = ao_cmd_lex_i;
557         printf ("Set %s to %d\n", which ? "siren" : "strobe", value);
558         if (which)
559                 ao_siren(value);
560         else
561                 ao_strobe(value);
562 }
563 #endif
564
565 __code struct ao_cmds ao_pad_cmds[] = {
566         { ao_pad_test,  "t\0Test pad continuity" },
567         { ao_pad_manual,        "i <key> <n>\0Fire igniter. <key> is doit with D&I" },
568 #if DEBUG
569         { ao_pad_set_debug,     "D <0 off, 1 on>\0Debug" },
570         { ao_pad_alarm_debug,   "S <0 strobe, 1 siren> <0 off, 1 on>\0Set alarm output" },
571 #endif
572         { 0, NULL }
573 };
574
575 #ifndef AO_PAD_PORT_1
576 #define AO_PAD_0_PORT   AO_PAD_PORT
577 #define AO_PAD_1_PORT   AO_PAD_PORT
578 #define AO_PAD_2_PORT   AO_PAD_PORT
579 #define AO_PAD_3_PORT   AO_PAD_PORT
580 #define AO_PAD_4_PORT   AO_PAD_PORT
581 #define AO_PAD_5_PORT   AO_PAD_PORT
582 #define AO_PAD_6_PORT   AO_PAD_PORT
583 #define AO_PAD_7_PORT   AO_PAD_PORT
584 #endif
585
586 void
587 ao_pad_init(void)
588 {
589 #ifdef AO_PAD_SELECTOR_PORT
590         unsigned pin;
591
592         for (pin = 0; pin < sizeof (AO_PORT_TYPE) * 8; pin++) {
593                 if (AO_PAD_SELECTOR_PINS & (1 << pin))
594                         ao_enable_input(AO_PAD_SELECTOR_PORT, pin, AO_EXTI_MODE_PULL_UP);
595         }
596 #endif
597 #if AO_PAD_NUM > 0
598         ao_enable_output(AO_PAD_0_PORT, AO_PAD_PIN_0, AO_PAD_0, 0);
599 #endif
600 #if AO_PAD_NUM > 1
601         ao_enable_output(AO_PAD_1_PORT, AO_PAD_PIN_1, AO_PAD_1, 0);
602 #endif
603 #if AO_PAD_NUM > 2
604         ao_enable_output(AO_PAD_2_PORT, AO_PAD_PIN_2, AO_PAD_2, 0);
605 #endif
606 #if AO_PAD_NUM > 3
607         ao_enable_output(AO_PAD_3_PORT, AO_PAD_PIN_3, AO_PAD_3, 0);
608 #endif
609 #if AO_PAD_NUM > 4
610         ao_enable_output(AO_PAD_4_PORT, AO_PAD_PIN_4, AO_PAD_4, 0);
611 #endif
612 #if AO_PAD_NUM > 5
613         ao_enable_output(AO_PAD_5_PORT, AO_PAD_PIN_5, AO_PAD_5, 0);
614 #endif
615 #if AO_PAD_NUM > 5
616         ao_enable_output(AO_PAD_6_PORT, AO_PAD_PIN_6, AO_PAD_6, 0);
617 #endif
618 #if AO_PAD_NUM > 7
619         ao_enable_output(AO_PAD_7_PORT, AO_PAD_PIN_7, AO_PAD_7, 0);
620 #endif
621 #ifdef AO_STROBE
622         ao_enable_output(AO_STROBE_PORT, AO_STROBE_PIN, AO_STROBE, 0);
623 #endif
624 #ifdef AO_SIREN
625         ao_enable_output(AO_SIREN_PORT, AO_SIREN_PIN, AO_SIREN, 0);
626 #endif
627         ao_cmd_register(&ao_pad_cmds[0]);
628         ao_add_task(&ao_pad_task, ao_pad, "pad listener");
629         ao_add_task(&ao_pad_ignite_task, ao_pad_run, "pad igniter");
630         ao_add_task(&ao_pad_monitor_task, ao_pad_monitor, "pad monitor");
631 }