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)
31 uint16_t timeout = AO_MS_TO_TICKS(10);
34 switch (ao_config.radio_rate) {
35 case AO_RADIO_RATE_38400:
38 case AO_RADIO_RATE_9600:
39 timeout = AO_MS_TO_TICKS(20);
41 case AO_RADIO_RATE_2400:
42 timeout = AO_MS_TO_TICKS(80);
46 ao_mutex_get(&ao_lco_mutex);
47 command.tick = ao_time();
49 command.cmd = AO_LAUNCH_QUERY;
51 ao_radio_cmac_send(&command, sizeof (command));
52 sent_time = ao_time();
53 r = ao_radio_cmac_recv(query, sizeof (*query), timeout);
54 if (r == AO_RADIO_CMAC_OK)
55 *tick_offset = sent_time - query->tick;
56 ao_mutex_put(&ao_lco_mutex);
61 ao_lco_arm(uint16_t box, uint8_t channels, uint16_t tick_offset)
63 ao_mutex_get(&ao_lco_mutex);
64 command.tick = ao_time() - tick_offset;
66 command.cmd = AO_LAUNCH_ARM;
67 command.channels = channels;
68 ao_radio_cmac_send(&command, sizeof (command));
69 ao_mutex_put(&ao_lco_mutex);
75 ao_mutex_get(&ao_lco_mutex);
78 command.cmd = AO_LAUNCH_FIRE;
80 ao_radio_cmac_send(&command, sizeof (command));
81 ao_mutex_put(&ao_lco_mutex);