2 * Copyright © 2012 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.
20 #include <ao_radio_cmac.h>
21 #include <ao_lco_func.h>
23 static __xdata struct ao_pad_command command;
24 static __xdata uint8_t ao_lco_mutex;
27 ao_lco_query(uint16_t box, struct ao_pad_query *query, uint16_t *tick_offset)
33 ao_mutex_get(&ao_lco_mutex);
34 command.tick = ao_time() - *tick_offset;
36 command.cmd = AO_LAUNCH_QUERY;
38 ao_radio_cmac_send(&command, sizeof (command));
39 sent_time = ao_time();
40 r = ao_radio_cmac_recv(query, sizeof (*query), AO_MS_TO_TICKS(20));
41 if (r == AO_RADIO_CMAC_OK)
42 *tick_offset = sent_time - query->tick;
43 ao_mutex_put(&ao_lco_mutex);
48 ao_lco_arm(uint16_t box, uint8_t channels, uint16_t tick_offset)
50 ao_mutex_get(&ao_lco_mutex);
51 command.tick = ao_time() - tick_offset;
53 command.cmd = AO_LAUNCH_ARM;
54 command.channels = channels;
55 ao_radio_cmac_send(&command, sizeof (command));
56 ao_mutex_put(&ao_lco_mutex);
60 ao_lco_ignite(uint16_t box, uint8_t channels, uint16_t tick_offset)
62 ao_mutex_get(&ao_lco_mutex);
63 command.tick = ao_time() - tick_offset;
65 command.cmd = AO_LAUNCH_FIRE;
66 command.channels = channels;
67 ao_radio_cmac_send(&command, sizeof (command));
68 ao_mutex_put(&ao_lco_mutex);