ee94eca35c5c22c461cc576b3bf04cd7a4fadd8b
[fw/altos] / src / kernel / ao_pyro.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 #ifndef AO_FLIGHT_TEST
20 #include <ao.h>
21 #include <ao_sample.h>
22 #include <ao_flight.h>
23 #endif
24 #include <ao_pyro.h>
25
26 #if IS_COMPANION
27 #include <ao_companion.h>
28 #define ao_accel ao_companion_command.accel
29 #define ao_speed ao_companion_command.speed
30 #define ao_height ao_companion_command.height
31 #define ao_flight_state ao_companion_command.flight_state
32 #define ao_motor_number ao_companion_command.motor_number
33 #endif
34
35 #define ao_lowbit(x)    ((x) & (-x))
36
37 #ifndef AO_FLIGHT_TEST
38 enum ao_igniter_status
39 ao_pyro_status(uint8_t p)
40 {
41         struct ao_data packet;
42         int16_t value;
43
44         ao_arch_critical(
45                 ao_data_get(&packet);
46                 );
47
48         value = (AO_IGNITER_CLOSED>>1);
49         value = AO_SENSE_PYRO(&packet, p);
50         if (value < AO_IGNITER_OPEN)
51                 return ao_igniter_open;
52         else if (value > AO_IGNITER_CLOSED)
53                 return ao_igniter_ready;
54         else
55                 return ao_igniter_unknown;
56 }
57
58 void
59 ao_pyro_print_status(void)
60 {
61         uint8_t p;
62
63         for(p = 0; p < AO_PYRO_NUM; p++) {
64                 enum ao_igniter_status status = ao_pyro_status(p);
65                 printf("Igniter: %d Status: %s\n",
66                        p, ao_igniter_status_names[status]);
67         }
68 }
69 #endif
70
71 uint16_t        ao_pyro_fired;
72 uint16_t        ao_pyro_inhibited;
73
74 #ifndef PYRO_DBG
75 #define PYRO_DBG        0
76 #endif
77
78 #if PYRO_DBG
79 int pyro_dbg;
80 #define DBG(...)        do { if (pyro_dbg) { printf("\t%d: ", (int) (pyro - ao_config.pyro)); printf(__VA_ARGS__); } } while (0)
81 #else
82 #define DBG(...)
83 #endif
84
85 static angle_t
86 ao_sample_max_orient(void)
87 {
88         uint8_t i;
89         angle_t max = ao_sample_orients[0];
90
91         for (i = 1; i < AO_NUM_ORIENT; i++) {
92                 angle_t a = ao_sample_orients[i];
93                 if (a > max)
94                         max = a;
95         }
96         return max;
97 }
98 /*
99  * Given a pyro structure, figure out
100  * if the current flight state satisfies all
101  * of the requirements
102  */
103 static uint8_t
104 ao_pyro_ready(const struct ao_pyro *pyro)
105 {
106         enum ao_pyro_flag flag, flags;
107 #if HAS_GYRO
108         angle_t max_orient;
109 #endif
110
111         flags = pyro->flags;
112         while (flags != ao_pyro_none) {
113                 flag = ao_lowbit(flags);
114                 flags &= ~flag;
115                 switch (flag) {
116
117                 case ao_pyro_accel_less:
118                         if (ao_accel <= pyro->accel_less)
119                                 continue;
120                         DBG("accel %d > %d\n", ao_accel, pyro->accel_less);
121                         break;
122                 case ao_pyro_accel_greater:
123                         if (ao_accel >= pyro->accel_greater)
124                                 continue;
125                         DBG("accel %d < %d\n", ao_accel, pyro->accel_greater);
126                         break;
127                 case ao_pyro_speed_less:
128                         if (ao_speed <= pyro->speed_less)
129                                 continue;
130                         DBG("speed %d > %d\n", ao_speed, pyro->speed_less);
131                         break;
132                 case ao_pyro_speed_greater:
133                         if (ao_speed >= pyro->speed_greater)
134                                 continue;
135                         DBG("speed %d < %d\n", ao_speed, pyro->speed_greater);
136                         break;
137                 case ao_pyro_height_less:
138                         if (ao_height <= pyro->height_less)
139                                 continue;
140                         DBG("height %d > %d\n", ao_height, pyro->height_less);
141                         break;
142                 case ao_pyro_height_greater:
143                         if (ao_height >= pyro->height_greater)
144                                 continue;
145                         DBG("height %d < %d\n", ao_height, pyro->height_greater);
146                         break;
147
148 #if HAS_GYRO
149                 case ao_pyro_orient_less:
150                         max_orient = ao_sample_max_orient();
151                         if (max_orient <= pyro->orient_less)
152                                 continue;
153                         DBG("orient %d > %d\n", max_orient, pyro->orient_less);
154                         break;
155                 case ao_pyro_orient_greater:
156                         max_orient = ao_sample_max_orient();
157                         if (max_orient >= pyro->orient_greater)
158                                 continue;
159                         DBG("orient %d < %d\n", max_orient, pyro->orient_greater);
160                         break;
161 #endif
162
163                 case ao_pyro_time_less:
164                         if ((AO_TICK_SIGNED) (ao_time() - ao_launch_tick) <= pyro->time_less)
165                                 continue;
166                         DBG("time %d > %d\n", (AO_TICK_SIGNED)(ao_time() - ao_launch_tick), pyro->time_less);
167                         break;
168                 case ao_pyro_time_greater:
169                         if ((AO_TICK_SIGNED) (ao_time() - ao_launch_tick) >= pyro->time_greater)
170                                 continue;
171                         DBG("time %d < %d\n", (AO_TICK_SIGNED)(ao_time() - ao_launch_tick), pyro->time_greater);
172                         break;
173
174                 case ao_pyro_ascending:
175                         if (ao_speed > 0)
176                                 continue;
177                         DBG("not ascending speed %d\n", ao_speed);
178                         break;
179                 case ao_pyro_descending:
180                         if (ao_speed < 0)
181                                 continue;
182                         DBG("not descending speed %d\n", ao_speed);
183                         break;
184
185                 case ao_pyro_after_motor:
186                         if (ao_motor_number >= pyro->motor)
187                                 continue;
188                         DBG("motor %d != %d\n", ao_motor_number, pyro->motor);
189                         break;
190
191                 case ao_pyro_delay:
192                         /* handled separately */
193                         continue;
194
195                 case ao_pyro_state_less:
196                         if (ao_flight_state < pyro->state_less)
197                                 continue;
198                         DBG("state %d >= %d\n", ao_flight_state, pyro->state_less);
199                         break;
200                 case ao_pyro_state_greater_or_equal:
201                         if (ao_flight_state >= pyro->state_greater_or_equal)
202                                 continue;
203                         DBG("state %d < %d\n", ao_flight_state, pyro->state_greater_or_equal);
204                         break;
205
206                 default:
207                         continue;
208                 }
209                 return false;
210         }
211         return true;
212 }
213
214 #ifndef AO_FLIGHT_TEST
215 static void
216 ao_pyro_pin_set(uint8_t p, uint8_t v)
217 {
218         switch (p) {
219 #if AO_PYRO_NUM > 0
220         case 0: ao_gpio_set(AO_PYRO_PORT_0, AO_PYRO_PIN_0, v); break;
221 #endif
222 #if AO_PYRO_NUM > 1
223         case 1: ao_gpio_set(AO_PYRO_PORT_1, AO_PYRO_PIN_1, v); break;
224 #endif
225 #if AO_PYRO_NUM > 2
226         case 2: ao_gpio_set(AO_PYRO_PORT_2, AO_PYRO_PIN_2, v); break;
227 #endif
228 #if AO_PYRO_NUM > 3
229         case 3: ao_gpio_set(AO_PYRO_PORT_3, AO_PYRO_PIN_3, v); break;
230 #endif
231 #if AO_PYRO_NUM > 4
232         case 4: ao_gpio_set(AO_PYRO_PORT_4, AO_PYRO_PIN_4, v); break;
233 #endif
234 #if AO_PYRO_NUM > 5
235         case 5: ao_gpio_set(AO_PYRO_PORT_5, AO_PYRO_PIN_5, v); break;
236 #endif
237 #if AO_PYRO_NUM > 6
238         case 6: ao_gpio_set(AO_PYRO_PORT_6, AO_PYRO_PIN_6, v); break;
239 #endif
240 #if AO_PYRO_NUM > 7
241         case 7: ao_gpio_set(AO_PYRO_PORT_7, AO_PYRO_PIN_7, v); break;
242 #endif
243         default: break;
244         }
245 }
246 #endif
247
248 uint8_t ao_pyro_wakeup;
249
250 static void
251 ao_pyro_pins_fire(uint16_t fire)
252 {
253         uint8_t p;
254
255         for (p = 0; p < AO_PYRO_NUM; p++) {
256                 if (fire & (1 << p))
257                         ao_pyro_pin_set(p, 1);
258         }
259         ao_delay(ao_config.pyro_time);
260         for (p = 0; p < AO_PYRO_NUM; p++) {
261                 if (fire & (1 << p))
262                         ao_pyro_pin_set(p, 0);
263         }
264         ao_delay(AO_MS_TO_TICKS(50));
265 }
266
267 static AO_TICK_TYPE pyro_delay_done[AO_PYRO_NUM];
268
269 static uint8_t
270 ao_pyro_check(void)
271 {
272         const struct ao_pyro    *pyro;
273         uint8_t         p, any_waiting;
274         uint16_t        fire = 0;
275
276         any_waiting = 0;
277         for (p = 0; p < AO_PYRO_NUM; p++) {
278                 pyro = &ao_config.pyro[p];
279
280                 /* Ignore igniters which have already fired or inhibited
281                  */
282                 if ((ao_pyro_fired|ao_pyro_inhibited) & (1 << p))
283                         continue;
284
285                 /* Ignore disabled igniters
286                  */
287                 if (!pyro->flags)
288                         continue;
289
290                 any_waiting = 1;
291                 /* Check pyro state to see if it should fire
292                  */
293                 if (!pyro_delay_done[p]) {
294                         if (!ao_pyro_ready(pyro))
295                                 continue;
296
297                         /* If there's a delay set, then remember when
298                          * it expires
299                          */
300                         if (pyro->flags & ao_pyro_delay) {
301                                 AO_TICK_TYPE delay_done;
302                                 AO_TICK_SIGNED delay = pyro->delay;
303                                 if (delay < 0)
304                                         delay = 0;
305                                 delay_done = ao_time() + (AO_TICK_TYPE) delay;
306                                 if (!delay_done)
307                                         delay_done = 1;
308                                 pyro_delay_done[p] = delay_done;
309                         }
310                 }
311
312                 /* Check to see if we're just waiting for
313                  * the delay to expire
314                  */
315                 if (pyro_delay_done[p]) {
316
317                         /* Check to make sure the required conditions
318                          * remain valid. If not, inhibit the channel
319                          * by setting the inhibited bit
320                          */
321                         if (!ao_pyro_ready(pyro)) {
322                                 ao_pyro_inhibited |= (uint16_t) (1 << p);
323                                 continue;
324                         }
325
326                         if ((AO_TICK_SIGNED) (ao_time() - pyro_delay_done[p]) < 0)
327                                 continue;
328                 }
329
330                 fire |= (uint16_t) (1U << p);
331         }
332
333         if (fire) {
334                 ao_pyro_fired |= fire;
335                 ao_pyro_pins_fire(fire);
336         }
337
338         return any_waiting;
339 }
340
341 #define NO_VALUE        0xff
342
343 #define AO_PYRO_NAME_LEN        4
344
345 #if !DISABLE_HELP
346 #define ENABLE_HELP 1
347 #endif
348
349 #if ENABLE_HELP
350 #define HELP(s) (s)
351 #else
352 #define HELP(s)
353 #endif
354
355 const struct {
356         char                    name[AO_PYRO_NAME_LEN];
357         enum ao_pyro_flag       flag;
358         uint8_t                 offset;
359 #if ENABLE_HELP
360         char                    *help;
361 #endif
362 } ao_pyro_values[] = {
363         { "a<", ao_pyro_accel_less,     offsetof(struct ao_pyro, accel_less), HELP("accel less (m/ss * 16)") },
364         { "a>", ao_pyro_accel_greater,  offsetof(struct ao_pyro, accel_greater), HELP("accel greater (m/ss * 16)") },
365
366         { "s<", ao_pyro_speed_less,     offsetof(struct ao_pyro, speed_less), HELP("speed less (m/s * 16)") },
367         { "s>", ao_pyro_speed_greater,  offsetof(struct ao_pyro, speed_greater), HELP("speed greater (m/s * 16)") },
368
369         { "h<", ao_pyro_height_less,    offsetof(struct ao_pyro, height_less), HELP("height less (m)") },
370         { "h>", ao_pyro_height_greater, offsetof(struct ao_pyro, height_greater), HELP("height greater (m)") },
371
372 #if HAS_GYRO
373         { "o<", ao_pyro_orient_less,    offsetof(struct ao_pyro, orient_less), HELP("orient less (deg)") },
374         { "o>", ao_pyro_orient_greater, offsetof(struct ao_pyro, orient_greater), HELP("orient greater (deg)")  },
375 #endif
376
377         { "t<", ao_pyro_time_less,      offsetof(struct ao_pyro, time_less), HELP("time less (s * 100)") },
378         { "t>", ao_pyro_time_greater,   offsetof(struct ao_pyro, time_greater), HELP("time greater (s * 100)")  },
379
380         { "f<", ao_pyro_state_less,     offsetof(struct ao_pyro, state_less), HELP("state less") },
381         { "f>=",ao_pyro_state_greater_or_equal, offsetof(struct ao_pyro, state_greater_or_equal), HELP("state greater or equal")  },
382
383         { "A", ao_pyro_ascending,       NO_VALUE, HELP("ascending") },
384         { "D", ao_pyro_descending,      NO_VALUE, HELP("descending") },
385
386         { "m", ao_pyro_after_motor,     offsetof(struct ao_pyro, motor), HELP("after motor") },
387
388         { "d", ao_pyro_delay,           offsetof(struct ao_pyro, delay), HELP("delay before firing (s * 100)") },
389         { "", ao_pyro_none,             NO_VALUE, HELP(NULL) },
390 };
391
392 #define NUM_PYRO_VALUES (sizeof ao_pyro_values / sizeof ao_pyro_values[0])
393
394 #ifndef AO_FLIGHT_TEST
395 static void
396 ao_pyro(void)
397 {
398         uint8_t         any_waiting;
399
400         ao_config_get();
401         while (ao_flight_state < ao_flight_boost)
402                 ao_sleep(&ao_flight_state);
403
404         for (;;) {
405                 ao_sleep_for(&ao_pyro_wakeup, AO_MS_TO_TICKS(100));
406                 if (ao_flight_state >= ao_flight_landed)
407                         break;
408                 any_waiting = ao_pyro_check();
409                 if (!any_waiting)
410                         break;
411         }
412         ao_exit();
413 }
414
415 struct ao_task ao_pyro_task;
416
417
418 static void
419 ao_pyro_print_name(uint8_t v)
420 {
421         const char *s = ao_pyro_values[v].name;
422         printf ("%s%s", s, "   " + strlen(s));
423 }
424
425 #if ENABLE_HELP
426 static void
427 ao_pyro_help(void)
428 {
429         uint8_t v;
430         for (v = 0; ao_pyro_values[v].flag != ao_pyro_none; v++) {
431                 ao_pyro_print_name(v);
432                 if (ao_pyro_values[v].offset != NO_VALUE)
433                         printf ("<n> ");
434                 else
435                         printf ("    ");
436                 printf ("%s\n", ao_pyro_values[v].help);
437         }
438 }
439 #endif
440
441 static int32_t
442 ao_pyro_get(void *base, uint8_t offset, uint8_t size)
443 {
444         int32_t value;
445         switch (size) {
446         case 8:
447                 value = *((uint8_t *) ((char *) base + offset));
448                 break;
449         case 16:
450         default:
451                 value = *((int16_t *) (void *) ((char *) base + offset));
452                 break;
453         case 32:
454                 value = *((int32_t *) (void *) ((char *) base + offset));
455                 break;
456         }
457         return value;
458 }
459
460 static bool
461 ao_pyro_put(void *base, uint8_t offset, uint8_t size, int32_t value)
462 {
463         switch (size) {
464         case 8:
465                 if (value < 0)
466                         return false;
467                 *((uint8_t *) ((char *) base + offset)) = (uint8_t) value;
468                 break;
469         case 16:
470         default:
471                 *((int16_t *) (void *) ((char *) base + offset)) = (int16_t) value;
472                 break;
473         case 32:
474                 *((int32_t *) (void *) ((char *) base + offset)) = value;
475                 break;
476         }
477         return true;
478 }
479
480 static uint8_t
481 ao_pyro_size(enum ao_pyro_flag flag)
482 {
483         if (flag & AO_PYRO_8_BIT_VALUE)
484                 return 8;
485         if (flag & AO_PYRO_32_BIT_VALUE)
486                 return 32;
487         return 16;
488 }
489
490 void
491 ao_pyro_show(void)
492 {
493         uint8_t         p;
494         uint8_t         v;
495         struct ao_pyro  *pyro;
496
497         printf ("Pyro-count: %d\n", AO_PYRO_NUM);
498         for (p = 0; p < AO_PYRO_NUM; p++) {
499                 printf ("Pyro %2d: ", p);
500                 pyro = &ao_config.pyro[p];
501                 if (!pyro->flags) {
502                         printf ("<disabled>\n");
503                         continue;
504                 }
505                 for (v = 0; ao_pyro_values[v].flag != ao_pyro_none; v++) {
506                         if (!(pyro->flags & ao_pyro_values[v].flag))
507                                 continue;
508                         ao_pyro_print_name(v);
509                         if (ao_pyro_values[v].offset != NO_VALUE) {
510                                 printf ("%6ld ",
511                                         (long) ao_pyro_get(pyro,
512                                                            ao_pyro_values[v].offset,
513                                                            ao_pyro_size(ao_pyro_values[v].flag)));
514                         } else {
515                                 printf ("       ");
516                         }
517                 }
518                 printf ("\n");
519         }
520 }
521
522 void
523 ao_pyro_set(void)
524 {
525         uint32_t        p;
526         struct ao_pyro pyro_tmp;
527         char    name[AO_PYRO_NAME_LEN];
528         uint8_t c;
529         uint8_t v;
530
531         ao_cmd_white();
532
533 #if ENABLE_HELP
534         switch (ao_cmd_lex_c) {
535         case '?':
536                 ao_pyro_help();
537                 return;
538         }
539 #endif
540
541         p = ao_cmd_decimal();
542         if (ao_cmd_status != ao_cmd_success)
543                 return;
544         if (AO_PYRO_NUM <= p) {
545                 printf ("invalid pyro channel %lu\n", p);
546                 return;
547         }
548         memset(&pyro_tmp, '\0', sizeof (pyro_tmp));
549         for (;;) {
550                 ao_cmd_white();
551                 if (ao_cmd_lex_c == '\n')
552                         break;
553
554                 for (c = 0; c < AO_PYRO_NAME_LEN - 1; c++) {
555                         if (ao_cmd_is_white() || ao_cmd_lex_c == '\n')
556                                 break;
557                         name[c] = ao_cmd_lex_c;
558                         ao_cmd_lex();
559                 }
560                 name[c] = '\0';
561                 for (v = 0; ao_pyro_values[v].flag != ao_pyro_none; v++) {
562                         if (!strcmp (ao_pyro_values[v].name, name))
563                                 break;
564                 }
565                 if (ao_pyro_values[v].flag == ao_pyro_none) {
566                         printf ("invalid pyro field %s\n", name);
567                         ao_cmd_status = ao_cmd_syntax_error;
568                         return;
569                 }
570                 pyro_tmp.flags |= ao_pyro_values[v].flag;
571                 if (ao_pyro_values[v].offset != NO_VALUE) {
572                         int32_t r = 1;
573                         ao_cmd_white();
574                         if (ao_cmd_lex_c == '-') {
575                                 r = -1;
576                                 ao_cmd_lex();
577                         }
578                         r *= (int32_t) ao_cmd_decimal();
579                         if (ao_cmd_status != ao_cmd_success)
580                                 return;
581                         if (!ao_pyro_put(&pyro_tmp, ao_pyro_values[v].offset,
582                                          ao_pyro_size(ao_pyro_values[v].flag), r))
583                         {
584                                 ao_cmd_status = ao_cmd_syntax_error;
585                                 return;
586                         }
587                 }
588         }
589         _ao_config_edit_start();
590         ao_config.pyro[p] = pyro_tmp;
591         _ao_config_edit_finish();
592 }
593
594 void
595 ao_pyro_manual(uint8_t p)
596 {
597         printf ("ao_pyro_manual %d\n", p);
598         if (p >= AO_PYRO_NUM) {
599                 ao_cmd_status = ao_cmd_syntax_error;
600                 return;
601         }
602         ao_pyro_pins_fire(1 << p);
603 }
604
605 struct ao_pyro_old_values {
606         enum ao_pyro_flag       flag;
607         uint8_t                 offset;
608         uint8_t                 size;
609 };
610
611 static const struct ao_pyro_old_values ao_pyro_1_24_values[] = {
612         { .flag = ao_pyro_accel_less, .offset = offsetof(struct ao_pyro_1_24, accel_less), 16 },
613         { .flag = ao_pyro_accel_greater, .offset = offsetof(struct ao_pyro_1_24, accel_greater), 16 },
614         { .flag = ao_pyro_speed_less, .offset = offsetof(struct ao_pyro_1_24, speed_less), 16 },
615         { .flag = ao_pyro_speed_greater, .offset = offsetof(struct ao_pyro_1_24, speed_greater), 16 },
616         { .flag = ao_pyro_height_less, .offset = offsetof(struct ao_pyro_1_24, height_less), 16 },
617         { .flag = ao_pyro_height_greater, .offset = offsetof(struct ao_pyro_1_24, height_greater), 16 },
618         { .flag = ao_pyro_orient_less, .offset = offsetof(struct ao_pyro_1_24, orient_less), 16 },
619         { .flag = ao_pyro_orient_greater, .offset = offsetof(struct ao_pyro_1_24, orient_greater), 16 },
620         { .flag = ao_pyro_time_less, .offset = offsetof(struct ao_pyro_1_24, time_less), 16 },
621         { .flag = ao_pyro_time_greater, .offset = offsetof(struct ao_pyro_1_24, time_greater), 16 },
622         { .flag = ao_pyro_delay, .offset = offsetof(struct ao_pyro_1_24, delay), 16 },
623         { .flag = ao_pyro_state_less, .offset = offsetof(struct ao_pyro_1_24, state_less), 8 },
624         { .flag = ao_pyro_state_greater_or_equal, .offset = offsetof(struct ao_pyro_1_24, state_greater_or_equal), 8 },
625         { .flag = ao_pyro_after_motor, .offset = offsetof(struct ao_pyro_1_24, motor), 16 },
626 };
627
628 #define NUM_PYRO_1_24_VALUES (sizeof ao_pyro_1_24_values / sizeof ao_pyro_1_24_values[0])
629
630 static int32_t
631 ao_pyro_get_1_24(void *base, enum ao_pyro_flag flag)
632 {
633         unsigned v;
634
635         for (v = 0; v < NUM_PYRO_1_24_VALUES; v++) {
636                 if (ao_pyro_1_24_values[v].flag == flag)
637                         return ao_pyro_get(base, ao_pyro_1_24_values[v].offset, ao_pyro_1_24_values[v].size);
638         }
639         return 0;
640 }
641
642 void
643 ao_pyro_update_version(void)
644 {
645         if (ao_config.minor <= 24)
646         {
647
648                 /* First, move all of the config bits that follow the pyro data */
649
650                 struct ao_config_1_24 *ao_config_1_24 = (void *) &ao_config;
651                 struct ao_pyro          *pyro_1_25 = &ao_config.pyro[0];
652                 struct ao_pyro_1_24     *pyro_1_24 = &(ao_config_1_24->pyro)[0];
653
654
655                 char    *pyro_base_1_25 = (void *) pyro_1_25;
656                 char    *pyro_base_1_24 = (void *) pyro_1_24;
657                 char    *after_pyro_1_25 = pyro_base_1_25 + AO_PYRO_NUM * sizeof (struct ao_pyro);
658                 char    *after_pyro_1_24 = pyro_base_1_24 + AO_PYRO_NUM * sizeof (struct ao_pyro_1_24);
659
660                 char    *config_end_1_25 = (void *) (&ao_config + 1);
661                 size_t  to_move = (size_t) (config_end_1_25 - after_pyro_1_25);
662
663                 memmove(after_pyro_1_25, after_pyro_1_24, to_move);
664
665                 /* Now, adjust all of the pyro entries */
666
667                 int p = AO_PYRO_NUM;
668
669                 /* New struct is larger than the old, so start at the
670                  * last one and work towards the first
671                  */
672                 while (p-- > 0) {
673                         unsigned v;
674                         int32_t value;
675                         struct ao_pyro  tmp;
676
677                         memset(&tmp, '\0', sizeof(tmp));
678                         tmp.flags = pyro_1_24[p].flags;
679
680                         for (v = 0; v < NUM_PYRO_VALUES; v++)
681                         {
682                                 value = ao_pyro_get_1_24(&pyro_1_24[p], ao_pyro_values[v].flag);
683                                 ao_pyro_put(&tmp, ao_pyro_values[v].offset,
684                                             ao_pyro_size(ao_pyro_values[v].flag), value);
685                         }
686                         memcpy(&pyro_1_25[p], &tmp, sizeof(tmp));
687                 }
688         }
689 }
690
691 void
692 ao_pyro_init(void)
693 {
694 #if AO_PYRO_NUM > 0
695         ao_enable_output(AO_PYRO_PORT_0, AO_PYRO_PIN_0, 0);
696 #endif
697 #if AO_PYRO_NUM > 1
698         ao_enable_output(AO_PYRO_PORT_1, AO_PYRO_PIN_1, 0);
699 #endif
700 #if AO_PYRO_NUM > 2
701         ao_enable_output(AO_PYRO_PORT_2, AO_PYRO_PIN_2, 0);
702 #endif
703 #if AO_PYRO_NUM > 3
704         ao_enable_output(AO_PYRO_PORT_3, AO_PYRO_PIN_3, 0);
705 #endif
706 #if AO_PYRO_NUM > 4
707         ao_enable_output(AO_PYRO_PORT_4, AO_PYRO_PIN_4, 0);
708 #endif
709 #if AO_PYRO_NUM > 5
710         ao_enable_output(AO_PYRO_PORT_5, AO_PYRO_PIN_5, 0);
711 #endif
712 #if AO_PYRO_NUM > 6
713         ao_enable_output(AO_PYRO_PORT_6, AO_PYRO_PIN_6, 0);
714 #endif
715 #if AO_PYRO_NUM > 7
716         ao_enable_output(AO_PYRO_PORT_7, AO_PYRO_PIN_7, 0);
717 #endif
718         ao_add_task(&ao_pyro_task, ao_pyro, "pyro");
719 }
720 #endif