forked from brodykenrick/ANTPlus_Arduino
-
Notifications
You must be signed in to change notification settings - Fork 4
/
antdefines.h
241 lines (194 loc) · 13.4 KB
/
antdefines.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
Copyright 2012 Dynastream Innovations, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef ANTDEFINES_H
#define ANTDEFINES_H
#include "types.h"
//////////////////////////////////////////////
// ANT Clock Definition
//////////////////////////////////////////////
#define ANT_CLOCK_FREQUENCY ((ULONG)32768) ///< ANT system clock frequency
//////////////////////////////////////////////
// Radio TX Power Definitions
//////////////////////////////////////////////
#define RADIO_TX_POWER_MASK ((UCHAR)0x03)
#define RADIO_TX_POWER_MINUS20DB ((UCHAR)0x00)
#define RADIO_TX_POWER_MINUS10DB ((UCHAR)0x01)
#define RADIO_TX_POWER_MINUS5DB ((UCHAR)0x02)
#define RADIO_TX_POWER_0DB ((UCHAR)0x03)
//////////////////////////////////////////////
// Default System Definitions
//////////////////////////////////////////////
#define DEFAULT_CHANNEL_MESSAGE_FREQUENCY ((ULONG)4)
#define DEFAULT_CHANNEL_MESSAGE_PERIOD ((USHORT)( ANT_CLOCK_FREQUENCY / DEFAULT_CHANNEL_MESSAGE_FREQUENCY )) ///< 8192 (4Hz)
#define DEFAULT_RADIO_TX_POWER RADIO_TX_POWER_0DB ///< ANT default RF power
#define DEFAULT_RADIO_CHANNEL ((UCHAR)66) ///< 2400MHz + 1MHz * Channel Number = 2466MHz
#define DEFAULT_RX_SEARCH_TIMEOUT ((UCHAR)12) ///< 12 * 2.5 seconds = 30 seconds
//////////////////////////////////////////////
// ID Definitions
//////////////////////////////////////////////
#define ID_MANUFACTURER_OFFSET ((UCHAR)3)
#define ID_DEVICE_TYPE_OFFSET ((UCHAR)2)
#define ID_DEVICE_NUMBER_HIGH_OFFSET ((UCHAR)1)
#define ID_DEVICE_NUMBER_LOW_OFFSET ((UCHAR)0)
#define ID_DEVICE_TYPE_PAIRING_FLAG ((UCHAR)0x80)
//////////////////////////////////////////////
// Assign Channel Parameters
//////////////////////////////////////////////
#define PARAMETER_TX_NOT_RX ((UCHAR)0x10)
#define PARAMETER_MULTIPLE_ACCESS_CHANNEL ((UCHAR)0x20)
#define PARAMETER_NO_TX_GUARD_BAND ((UCHAR)0x40)
#define PARAMETER_ALWAYS_RX_WILD_CARD_SEARCH_ID ((UCHAR)0x40)
//////////////////////////////////////////////
// Assign Channel Types
//////////////////////////////////////////////
#define CHANNEL_TYPE_SLAVE ((UCHAR) 0x00)
#define CHANNEL_TYPE_MASTER ((UCHAR) 0x10)
#define CHANNEL_TYPE_MASTER_TX_ONLY ((UCHAR) 0x50)
#define CHANNEL_TYPE_SHARED_SLAVE ((UCHAR) 0x20)
#define CHANNEL_TYPE_SHARED_MASTER ((UCHAR) 0x30)
//////////////////////////////////////////////
// Channel Status
//////////////////////////////////////////////
#define STATUS_UNASSIGNED_CHANNEL ((UCHAR)0x00)
#define STATUS_ASSIGNED_CHANNEL ((UCHAR)0x01)
#define STATUS_SEARCHING_CHANNEL ((UCHAR)0x02)
#define STATUS_TRACKING_CHANNEL ((UCHAR)0x03)
#define STATUS_OVERRUN ((UCHAR)0x40)
#define STATUS_UNDERRUN ((UCHAR)0x80)
//////////////////////////////////////////////
// Standard capabilities defines
//////////////////////////////////////////////
#define CAPABILITIES_NO_RX_CHANNELS ((UCHAR)0x01)
#define CAPABILITIES_NO_TX_CHANNELS ((UCHAR)0x02)
#define CAPABILITIES_NO_RX_MESSAGES ((UCHAR)0x04)
#define CAPABILITIES_NO_TX_MESSAGES ((UCHAR)0x08)
#define CAPABILITIES_NO_ACKD_MESSAGES ((UCHAR)0x10)
#define CAPABILITIES_NO_BURST_TRANSFER ((UCHAR)0x20)
//////////////////////////////////////////////
// Advanced capabilities defines
//////////////////////////////////////////////
#define CAPABILITIES_DETECT_OVERRUN_UNDERRUN ((UCHAR)0x01)
#define CAPABILITIES_NETWORK_ENABLED ((UCHAR)0x02)
//////////////////////////////////////////////
// Burst Message Sequence
//////////////////////////////////////////////
#define CHANNEL_NUMBER_MASK ((UCHAR)0x1F)
#define SEQUENCE_NUMBER_MASK ((UCHAR)0xE0)
#define SEQUENCE_NUMBER_INC ((UCHAR)0x20)
#define SEQUENCE_NUMBER_ROLLOVER ((UCHAR)0x60)
#define SEQUENCE_LAST_MESSAGE ((UCHAR)0x80)
//////////////////////////////////////////////
// Shared Channel Commands / Datatypes
//////////////////////////////////////////////
#define SHARED_CMD_SLOT_AVALIBLE ((UCHAR)0xFF)
#define SHARED_CMD_BUSY_ACQUIRING ((UCHAR)0xFE)
#define SHARED_CMD_COMMAND_REQUEST_TO_ACQUIRE ((UCHAR)0xFD)
#define SHARED_CMD_CONFIRM_ACQUIRED ((UCHAR)0xFC)
#define SHARED_CMD_NO_SLOTS_AVAILABLE ((UCHAR)0xFB)
//...
#define SHARED_TYPE_RELAY ((UCHAR)0x43)
#define SHARED_TYPE_COUNTER ((UCHAR)0x42)
#define SHARED_TYPE_A_TO_D ((UCHAR)0x41)
#define SHARED_TYPE_DIGITAL ((UCHAR)0x40)
#define SHARED_TYPE_UNDEFINED ((UCHAR)0x00)
///////////////////////////////////////////////////////////////////////
// AtoD SubTypes
///////////////////////////////////////////////////////////////////////
#define TEMPERATURE ((UCHAR)0xFE)
#define BATT_VOLTAGE ((UCHAR)0xFF)
//////////////////////////////////////////////
// Response / Event Codes
//////////////////////////////////////////////
#define RESPONSE_NO_ERROR ((UCHAR)0x00)
#define EVENT_RX_SEARCH_TIMEOUT ((UCHAR)0x01)
#define EVENT_RX_FAIL ((UCHAR)0x02)
#define EVENT_TX ((UCHAR)0x03)
#define EVENT_TRANSFER_RX_FAILED ((UCHAR)0x04)
#define EVENT_TRANSFER_TX_COMPLETED ((UCHAR)0x05)
#define EVENT_TRANSFER_TX_FAILED ((UCHAR)0x06)
#define EVENT_CHANNEL_CLOSED ((UCHAR)0x07)
#define EVENT_RX_FAIL_GO_TO_SEARCH ((UCHAR)0x08)
#define EVENT_CHANNEL_COLLISION ((UCHAR)0x09)
#define CHANNEL_IN_WRONG_STATE ((UCHAR)0x15) // returned on attempt to perform an action from the wrong channel state
#define CHANNEL_NOT_OPENED ((UCHAR)0x16) // returned on attempt to communicate on a channel that is not open
#define CHANNEL_ID_NOT_SET ((UCHAR)0x18) // returned on attempt to open a channel without setting the channel ID
#define TRANSFER_IN_PROGRESS ((UCHAR)0x1F) // returned on attempt to communicate on a channel with a TX transfer in progress
#define TRANSFER_SEQUENCE_NUMBER_ERROR ((UCHAR)0x20) // returned when sequence number is out of order on a Burst transfer
#define INVALID_MESSAGE ((UCHAR)0x28) // returned when the message has an invalid parameter
#define INVALID_NETWORK_NUMBER ((UCHAR)0x29) // returned when an invalid network number is provided
#define NO_RESPONSE_MESSAGE ((UCHAR)0x50) // returned to the Command_SerialMessageProcess function, so no reply message is generated
#define FIT_ACTIVE_SEARCH_TIMEOUT ((UCHAR)0x60) // event added for timeout of the pairing state after the Fit module becomes active
#define FIT_WATCH_PAIRED ((UCHAR)0x61) // event added for timeout of the pairing state after the Fit module becomes active
#define FIT_WATCH_UNPAIRED ((UCHAR)0x62) // event added for timeout of the pairing state after the Fit module becomes active
#define EVENT_COMMAND_TIMEOUT ((UCHAR)0xA9) // (Host Only)returned when no response is recieved from ANT module after a command has been sent
#define EVENT_ACK_TIMEOUT ((UCHAR)0xAA) // (Host Only) returned if not response to an Ack command is recieved for a set period of time.
///////////////////////////////////////////////////////////////
// Application Level defines
///////////////////////////////////////////////////////////////
#define USE_FREQUENCY_HOPPER
// #define USE_AUTO_SHARED_MASTER
#define NUM_CHANNELS ((UCHAR)0x04) // Number of channels to be initialized and used by the application
#define NUM_FREQUENCY_HOPS ((UCHAR)0x04) // Number of frequency hops to make if using frequency hopper
///////////////////////////////////////////////////////////////
// +LINK Mode Commands
///////////////////////////////////////////////////////////////
#define PLUS_LINK_MSG_STATUS ((UCHAR)0x01)
#define PLUS_LINK_MSG_CONNECT ((UCHAR)0x02)
#define PLUS_LINK_MSG_DISCONNECT ((UCHAR)0x03)
#define PLUS_LINK_MSG_AUTHENTICATE ((UCHAR)0x04)
#define PLUS_LINK_MSG_PAIR ((UCHAR)0x05)
#define PLUS_LINK_MSG_DOWNLOAD ((UCHAR)0x06)
#define PLUS_LINK_MSG_UPLOAD ((UCHAR)0x07)
#define PLUS_LINK_MSG_ERASE ((UCHAR)0x08)
#define TRANSFER_BUSY ((UCHAR)0x22)
#define CHANNEL_0 0
///////////////////////////////////////////////////////////////
// State Machine Return Flags
///////////////////////////////////////////////////////////////
#define STATE_STATUS_NONE ((UCHAR)0x00) // State machine did not handle event in any way
#define STATE_STATUS_TRANSMIT ((UCHAR)0x01) // State machine requires tx buffer to be transmitted.
#define STATE_STATUS_HANDLED ((UCHAR)0x02) // State machine handled input events, no further processing required
//////////////////////////////////////////////
// PC Application Event Codes
//////////////////////////////////////////////
//NOTE: These events are not generated by the embedded ANT module
#define EVENT_RX_BROADCAST ((UCHAR)0x9A) // returned when module receives broadcast data
#define EVENT_RX_ACKNOWLEDGED ((UCHAR)0x9B) // returned when module receives acknowledged data
#define EVENT_RX_BURST_PACKET ((UCHAR)0x9C) // returned when module receives burst data
#define EVENT_RX_EXT_BROADCAST ((UCHAR)0x9D) // returned when module receives broadcast data
#define EVENT_RX_EXT_ACKNOWLEDGED ((UCHAR)0x9E) // returned when module receives acknowledged data
#define EVENT_RX_EXT_BURST_PACKET ((UCHAR)0x9F) // returned when module receives burst data
#define EVENT_RX_RSSI_BROADCAST ((UCHAR)0xA0) // returned when module receives broadcast data
#define EVENT_RX_RSSI_ACKNOWLEDGED ((UCHAR)0xA1) // returned when module receives acknowledged data
#define EVENT_RX_RSSI_BURST_PACKET ((UCHAR)0xA2) // returned when module receives burst data
#define EVENT_RX_BTH_BROADCAST ((UCHAR)0xA3) // returned when module receives broadcast data
#define EVENT_RX_BTH_ACKNOWLEDGED ((UCHAR)0xA4) // returned when module receives acknowledged data
#define EVENT_RX_BTH_BURST_PACKET ((UCHAR)0xA5) // returned when module receives burst data
#define EVENT_RX_BTH_EXT_BROADCAST ((UCHAR)0xA6) // returned when module receives broadcast data
#define EVENT_RX_BTH_EXT_ACKNOWLEDGED ((UCHAR)0xA7) // returned when module receives acknowledged data
#define EVENT_RX_BTH_EXT_BURST_PACKET ((UCHAR)0xA8) // returned when module receives burst data
//////////////////////////////////////////////
// NVM Command Codes
//////////////////////////////////////////////
///////////////////////////////////////////////////////////////
// Macros
///////////////////////////////////////////////////////////////
#define HIGH_BYTE(usWord) (UCHAR)((usWord >> 8) & 0x00FF)
#define LOW_BYTE(usWord) (UCHAR)(usWord & 0x00FF)
#define BYTE0(x) ((UCHAR) x & 0xFF)
#define BYTE1(x) ((UCHAR) (x >> 8) & 0xFF)
#define BYTE2(x) ((UCHAR) (x >> 16) & 0xFF)
#define BYTE3(x) ((UCHAR) (x >> 24) & 0xFF)
#define MIN(x,y) (((x)<(y))?(x):(y))
#define MAX(x,y) (((x)>(y))?(x):(y))
#endif // !ANTDEFINES_H