-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.h
359 lines (295 loc) · 13.1 KB
/
config.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/*
* ++++++++++++++++++
* +++++++++++++++++++++++++++++
* +++++++ +++++++++
* +++++++ +++++++++++++
* ++++++++++++++++++++ ++++++++++
* +++++++++++++++++++++ +++
* +++++ +++
* +++ ######### ######### ######## ######### ######### +++++++ ++
* +++ +++++ #### #### ######## #### #### ##### #### #### #### +++ ++++ +++
* +++ ++++ ### ## ### ### ### ### ### ### ### ++++++++ +++
* ++++ ++++ ########## ### ########## ### ### ### ### ++++ +++++
* +++++++ ###### ## ### ######## ### ## ## ### ++++++++++
*
* All primary configuration is in this file...if a module includes this file it
* will have the basic configuration it needs.
*
* Copyright 2017 Technolution BV [email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _CONFIG_
#define _CONFIG_
#ifdef CORE_M4
#define IAM_M4
#define INCLUDE_M0_APP
#define M0_APPBASE (0x1B000000)
#endif
#ifdef CORE_M0
#define IAM_M0APP
#endif
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include "timers.h"
#include "cmsis.h"
#include "datax.h"
/* Define one of these for the board revision you're building for */
#define VL_DISTANCE // <<< Using VL distance sensor rather than Ultrasonics
//#define DISABLE_DISTANCE_SENSORS // <<< Define to disable the ultrasonic distance sensors
#define LLB /* Just to confirm we're building for the LLB */
// ============================================================================================
// ============================================================================================
// ============================================================================================
// Configuration Setup
// ============================================================================================
// ============================================================================================
// ============================================================================================
#define DEBUG 1
#define DEBUG_ON_TERMINAL
// ----- Component Inclusion is done via the Makefile
// ----- Version numbering
// -----------------------
#define VERSION_STRING "3.70"
#define VERSION_NUMBER 0x03,0x70
#define COPYRIGHT_STATEMENT "(C) 2015-2016 Garonne"
#define PRODUCTNAME "Icarus_III"
#define UUID 0x53,0xce,0x1b,0x11,0xdd,0x8f,0x47,0x94,0xbf,0x1c,0xb0,0x62,0x64,0x71,0x4e,0xa1
#define MAGICNUMBER 0x12190405 /* Magic number showing that there's valid data in the store */
#define VERSION_SEQ 0x16122301
extern const uint8_t idSeq[]; /* Unique identifier for management operations */
// ----- CPU Targeting
// -------------------
#define CLOCK_INPUT CLKIN_CRYSTAL
#define XTAL_FREQ 12000000
// ---- USB String Definitions
// ---------------------------
// Include these definitions even if USB isn't in use. We leave it to the linker to remove
// the unused code.
//
// it is ESSENTIAL that the lengths match the definitions!!!
#define USB_VENDOR_ID (0x1FC9)
#define USB_DEVICE_ID (0xD083)
#define USB_MANUFACTURER 'T',0, 'e',0, 'c',0, 'h',0, 'n',0, 'o',0, 'l',0, 'u',0, 'i',0, 'o',0, 'n',0
#define USB_MANUFACTURER_LEN (11)
#define USB_PRODUCT 'G',0, 'a',0, 'r',0, 'o',0, 'n',0, 'n',0, 'e',0
#define USB_PRODUCT_LEN (7)
#define USB_SERIAL_NUMBER '0',0, '0',0, '0',0, '0',0, '0',0, '0',0, '0',0, '0',0, '-',0, \
'0',0, '0',0, '0',0, '0',0, '0',0, '0',0, '0',0, '0',0 ,'-',0, \
'0',0, '0',0, '0',0, '0',0, '0',0, '0',0, '0',0, '0',0 ,'-',0,\
'0',0, '0',0, '0',0, '0',0, '0',0, '0',0, '0',0, '0',0 ,'-',0,\
'0',0
#define USB_SERIAL_NUMBER_LEN (4*9+1)
#define USB_SETTING_NAME 'S',0, 'e',0, 'r',0, 'i',0, 'a',0, 'l',0
#define USB_SETTING_NAME_LEN (6)
#define USB_INTERRUPT_PRIORITY (7)
// Radio subsystem (radio.c)
// -------------------------
/* Addressing constructs for vehicles and infrastructure */
#define NOENTITY 0
#define NODISTANCE 0
#define NOLOCATION (0xFFFF)
#define ALL (0xFFFE)
// Sets the frame response timeout size ... keep as low as possible */
#define NUM_ADDRESSES (8)
#if defined(LPC4370)
#include "config-lpc4370.h"
#endif
#if defined(LPC4367)
#include "config-lpc4367.h"
#endif
// Flags describing remote entities
#define FLAG_CHARGING (1<<0) /* Device is charging its battery at the moment */
#define FLAG_EXTPWR (1<<1) /* Device is running on external power */
#define FLAG_NOMADIC (1<<2) /* Device is nomadic (i.e. should not be used for range calculations) */
// ============================================================================================
// ============================================================================================
// ============================================================================================
//Internal Setup
// ============================================================================================
// ============================================================================================
// ============================================================================================
typedef uint32_t BOOL;
#define EOL "\n\r"
// --- System Level Glue
// ---------------------
#ifndef FALSE
#define FALSE 0
#define TRUE (!FALSE)
#endif
#define OFF FALSE
#define ON TRUE
// --- Encode ports and pins a bit more compact
// --------------------------------------------
#define PINDEF(port,pin,iocon) ((port&0xFF)|((pin&0xFF)<<8)|((iocon&0xFFFF)<<16))
#define GPIOPINDEF(port,pin,iocon,gpioPort,gpioPin) ((port&0xFF) | ((pin&0xFF)<<8) | ((iocon&0xFFFF)<<16) | ((gpioPort&0x07)<<24) | ((gpioPin&0x1F)<<27))
#define GETPORT(x) (x & 0xFF)
#define GETPIN(x) ((x>>8) & 0xFF)
#define GETFUNC(x) ((x>>16) & 0xFFFF)
#define GETGPIOPORT(x) ((x>>24) & 0x07)
#define GETGPIOPIN(x) ((x>>27) & 0x1F)
#define GIMAPINDEF(port,pin,iocon,gimaSelect) ((port&0xFF) | ((pin&0xFF)<<8) | ((iocon&0xFFFF)<<16) | ((gimaSelect&0xFF)<<24))
#define GETGIMASELECT(x) ((x>>24) & 0xFF)
#define PWM_PINDEF(port,pin,iocon,channel) ((port&0xFF) | ((pin&0xFF)<<8) | ((iocon&0xFFFF)<<16) | ((channel&0xFF)<<24))
#define GETPWMCHANNEL(x) ((x>>24) & 0xFF)
#define SCT_PINDEF(port, pin, iocon, ctout) ((port&0xFF) | ((pin&0xFF)<<8) | ((iocon&0xFFFF)<<16) | ((ctout&0xFF)<<24))
#define GETCTOUT(x) ((x>>24) & 0xFF)
// --- a few FreeRTOS helpers
// --------------------------
#define TICKS_TO_MILLIS(ticks) ((ticks) * portTICK_RATE_MS)
#define MILLIS_TO_TICKS(millis) ((millis) / portTICK_RATE_MS)
// --- Some debug magic
// --------------------
extern void dbgprint(char *fmt, ...);
#ifdef DEBUG
#define DBG(x,...) dbgprint(x, ##__VA_ARGS__)
#define DBGQ(x,...) dbgprint(x, ##__VA_ARGS__)
#else
#define DBG(x,...) (void)x;
#endif
#ifdef DEBUG
#define CHECK(a,b) if (a!=b) { dbgprint("Check failed in %s (%s)",__FILE__,__func__); ASSERT(FALSE); }
#else
#define CHECK(a,b) b
#endif
// String printing macro ... XSTR(VAR) will preprint VAR value
// -----------------------------------------------------------
#define XSTR(x) STR(x)
#define STR(x) #x
// --- Simple event callbacks
// --------------------------
#define EVENT_CB(x) void (x)(uint32_t j)
#define CALLBACK(x,y) if ((x)) (x)((y))
#define EVENT_ISSET(x,y) (x&(1<<y))
#define EVENT_CLEAR(x,y) (x&=~(1<<y))
// --- Incantations for code marking
// ---------------------------------
#define PACKED __attribute__((packed))
#define WEAK __attribute__((weak))
#define ALIAS(f) __attribute__ ((weak, alias (#f)))
#define ALWAYS_INLINE inline __attribute__((always_inline))
#define __SECTION_EXT(type, bank, name) __attribute__ ((section("." #type ".$" #bank "." #name)))
#define __SECTION(type, bank) __attribute__ ((section("." #type ".$" #bank)))
// Macros to be used in preference to __RAM_FUNC to better match __DATA behaviour
#define __RAMFUNC_EXT(bank, name) __SECTION_EXT(ramfunc, bank, name)
#define __RAMFUNC(bank) __SECTION(ramfunc, bank)
// Number of columns that can be input
#define TERM_COLS 80
// ============================================================================================
// ============================================================================================
// ============================================================================================
// Config Control Routines
// ============================================================================================
// ============================================================================================
// ============================================================================================
struct calibFrame
{
int16_t ofs[3];
int16_t scale[3];
};
enum CalibFrameInstance { CF_Acc, CF_Mag, CF_Gyr, CF_Max };
#define AXIS_NAME (char *[]){"Acc","Mag","Gyr"}
typedef struct
{
uint32_t versionNumber;
uint32_t supplyV;
uint32_t id;
uint32_t x;
uint32_t y;
uint32_t z;
uint32_t distcheckInterval;
BOOL isNomadic;
struct calibFrame c[CF_Max];
} ConfigType;
// FIXME - need a real ID
#define DEFAULT_CONFIG { \
.versionNumber=VERSION_SEQ, \
.distcheckInterval = 100, \
.supplyV=3300, \
.id=32, \
.x=NOLOCATION, .y=NOLOCATION, .z=NOLOCATION, .isNomadic=TRUE,\
.c[CF_Mag] = { .ofs={291,-135,289}, .scale={128,128,128} }, \
.c[CF_Acc] = { .ofs={0,0,0}, .scale={128,128,128} }, \
.c[CF_Gyr] = { .ofs={0,0,0}, .scale={128,128,128} }, \
}
extern ConfigType ConfigStore;
extern ConfigType *ConfigStorePtr;
extern BOOL wasDefaulted;
extern BOOL isSaved;
ALWAYS_INLINE struct calibFrame *ConfigGetCalibFrame(enum CalibFrameInstance i)
{
if (i>=CF_Max)
return NULL;
return &(ConfigStorePtr->c[i]);
}
ALWAYS_INLINE BOOL ConfigWasDefaulted(void) { return wasDefaulted; }
ALWAYS_INLINE BOOL ConfigIsSaved(void) { return isSaved; }
ALWAYS_INLINE uint32_t ConfigVersionNumber(void) { return ConfigStorePtr->versionNumber; }
ALWAYS_INLINE uint32_t ConfigSupplyV(void) { return ConfigStorePtr->supplyV; }
ALWAYS_INLINE uint32_t ConfigDistcheckInterval(void) { return ConfigStorePtr->distcheckInterval; }
ALWAYS_INLINE uint32_t ConfigID(void) { return ConfigStorePtr->id; }
ALWAYS_INLINE uint32_t ConfigLocx(void) { return ConfigStorePtr->x; }
ALWAYS_INLINE uint32_t ConfigLocy(void) { return ConfigStorePtr->y; }
ALWAYS_INLINE uint32_t ConfigLocz(void) { return ConfigStorePtr->z; }
ALWAYS_INLINE BOOL ConfigNomadic(void) { return ConfigStorePtr->isNomadic; }
ALWAYS_INLINE BOOL ConfigSetdistcheckInterval(BOOL distcheckSet)
{
isSaved = FALSE;
ConfigStorePtr->distcheckInterval = distcheckSet;
return TRUE;
}
/* Only allow configuration to be saved by the M4 */
#ifdef IAM_M4
ALWAYS_INLINE BOOL ConfigSetID(uint32_t idSet)
{
isSaved = FALSE;
ConfigStorePtr->id = idSet;
return TRUE;
}
ALWAYS_INLINE BOOL ConfigSetCalibFrame(enum CalibFrameInstance i, int16_t ox, int16_t oy, int16_t oz, int16_t sx, int16_t sy, int16_t sz)
{
if (i>=CF_Max)
return FALSE;
ConfigStorePtr->c[i].ofs[0]=ox;
ConfigStorePtr->c[i].ofs[1]=oy;
ConfigStorePtr->c[i].ofs[2]=oz;
ConfigStorePtr->c[i].scale[0]=sx;
ConfigStorePtr->c[i].scale[1]=sy;
ConfigStorePtr->c[i].scale[2]=sz;
isSaved=FALSE;
return TRUE;
}
ALWAYS_INLINE BOOL ConfigSetNomadic(BOOL NomadicSet)
{
isSaved = FALSE;
ConfigStorePtr->isNomadic = NomadicSet;
return TRUE;
}
ALWAYS_INLINE BOOL ConfigSetSupplyV(uint32_t SupplyVSet)
{
isSaved = FALSE;
ConfigStorePtr->supplyV = SupplyVSet;
return TRUE;
}
ALWAYS_INLINE BOOL ConfigSetLocation(uint32_t xSet, uint32_t ySet) { ConfigStorePtr->x=xSet; ConfigStorePtr->y=ySet; return TRUE; }
#endif
void ConfigAssertDA(char *msg, char *file, uint32_t line);
BOOL ConfigCommit(void);
const uint32_t *ConfigGetSerialNumber(void);
void ConfigInit(void);
#endif