tourel beacon
[aversive.git] / projects / microb2010 / mechboard / ax12_user.h
1 /*  
2  *  Copyright Droids Corporation
3  *  Olivier Matz <zer0@droids-corp.org>
4  * 
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  *  Revision : $Id: ax12_user.h,v 1.3 2009-04-07 20:03:48 zer0 Exp $
20  *
21  */
22
23 /* This is the ax12 user interface. It initializes the aversive AX12
24  * module so that it works in background, using interrupt driver uart.
25  *
26  * Be carreful, a call to AX12 module is synchronous and uses
27  * interruptions, so interrupts must be enabled. On the other side, a
28  * call _must not_ interrupt another one. That's why all calls to the
29  * module are done either in init() functions or in a scheduler event
30  * with prio=ARM_PRIO.
31  */
32
33 /* XXX do a safe_ax12() function that will retry once or twice if we
34  * see some problems. */
35
36 #define UART_AX12_NUM 0
37
38 void ax12_user_init(void);
39
40 void ax12_dump_stats(void);
41
42 #define ax12_user_write_byte(ax12, id, addr, data)              \
43         __ax12_user_write_byte(ax12, id, addr, data, __LINE__)
44
45 #define ax12_user_write_int(ax12, id, addr, data)               \
46         __ax12_user_write_int(ax12, id, addr, data, __LINE__)
47
48 #define ax12_user_read_byte(ax12, id, addr, data)               \
49         __ax12_user_read_byte(ax12, id, addr, data, __LINE__)
50
51 #define ax12_user_read_int(ax12, id, addr, data)                \
52         __ax12_user_read_int(ax12, id, addr, data, __LINE__)
53
54 /** @brief Write byte in AX-12 memory 
55  * @return Error code from AX-12 (0 means okay) */
56 uint8_t __ax12_user_write_byte(AX12 *ax12, uint8_t id, AX12_ADDRESS address,
57                                uint8_t data, uint16_t line);
58
59 /** @brief Write integer (2 bytes) in AX-12 memory 
60  * @return Error code from AX-12 (0 means okay)
61  *
62  * address   : data low
63  * address+1 : data high
64  */
65 uint8_t __ax12_user_write_int(AX12 *ax12, uint8_t id, AX12_ADDRESS address,
66                               uint16_t data, uint16_t line);
67
68 /** @brief Read byte from AX-12 memory 
69  * @return Error code from AX-12 (0 means okay) */
70 uint8_t __ax12_user_read_byte(AX12 *ax12, uint8_t id, AX12_ADDRESS address,
71                               uint8_t *val, uint16_t line);
72
73 /** @brief Write integer (2 bytes) from AX-12 memory
74  * @return Error code from AX-12 (0 means okay) */
75 uint8_t __ax12_user_read_int(AX12 *ax12, uint8_t id, AX12_ADDRESS address,
76                              uint16_t *val, uint16_t line);