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; either version 2 of the License, or
7 * (at your option) any later version.
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.
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.
21 #include <ao_radio_cmac.h>
22 #include <ao_lco_func.h>
24 static __xdata struct ao_pad_command command;
25 static __xdata uint8_t ao_lco_mutex;
28 ao_lco_query(uint16_t box, struct ao_pad_query *query, uint16_t *tick_offset)
32 uint16_t timeout = AO_MS_TO_TICKS(10);
35 switch (ao_config.radio_rate) {
36 case AO_RADIO_RATE_38400:
39 case AO_RADIO_RATE_9600:
40 timeout = AO_MS_TO_TICKS(20);
42 case AO_RADIO_RATE_2400:
43 timeout = AO_MS_TO_TICKS(80);
47 ao_mutex_get(&ao_lco_mutex);
48 command.tick = ao_time();
50 command.cmd = AO_PAD_QUERY;
52 ao_radio_cmac_send(&command, sizeof (command));
53 sent_time = ao_time();
54 r = ao_radio_cmac_recv(query, sizeof (*query), timeout);
55 if (r == AO_RADIO_CMAC_OK)
56 *tick_offset = sent_time - query->tick;
57 ao_mutex_put(&ao_lco_mutex);
62 ao_lco_arm(uint16_t box, uint8_t channels, uint16_t tick_offset)
64 ao_mutex_get(&ao_lco_mutex);
65 command.tick = ao_time() - tick_offset;
67 command.cmd = AO_PAD_ARM;
68 command.channels = channels;
69 ao_radio_cmac_send(&command, sizeof (command));
70 ao_mutex_put(&ao_lco_mutex);
74 ao_lco_ignite(uint8_t cmd)
76 ao_mutex_get(&ao_lco_mutex);
81 ao_radio_cmac_send(&command, sizeof (command));
82 ao_mutex_put(&ao_lco_mutex);