Revision 17
Added wireless library project folder.
trunk/code/projects/libwireless/test/test.c | ||
---|---|---|
1 |
#include "stdlib.h" |
|
2 |
#include "stdio.h" |
|
3 |
|
|
4 |
#include "../lib/wireless.h" |
|
5 |
#include "../lib/wl_error_group.h" |
|
6 |
#include "../lib/wl_token_ring.h" |
|
7 |
//#include "../lib/xbee.h" |
|
8 |
|
|
9 |
#include <time.h> |
|
10 |
|
|
11 |
int main() |
|
12 |
{ |
|
13 |
/*unsigned char buffer[128]; |
|
14 |
xbee_lib_init(0x3331); |
|
15 |
printf("%i\n", xbee_get_address()); |
|
16 |
struct timespec delay; |
|
17 |
delay.tv_sec = 0; |
|
18 |
delay.tv_nsec = 100000000; |
|
19 |
while (1) |
|
20 |
{ |
|
21 |
int len = xbee_get_packet(buffer); |
|
22 |
if (len != -1) |
|
23 |
{ |
|
24 |
int i; |
|
25 |
for (i = 0; i < len; i++) |
|
26 |
printf("%c", buffer[i]); |
|
27 |
printf("\n\r"); |
|
28 |
} |
|
29 |
nanosleep(&delay, 0); |
|
30 |
wl_send_global_packet(1, 1, "CHECK", 3, |
|
31 |
0); |
|
32 |
} |
|
33 |
xbee_terminate();*/ |
|
34 |
wl_init(); |
|
35 |
printf("Wireless initialized.\n"); |
|
36 |
wl_error_register(); |
|
37 |
wl_token_ring_register(); |
|
38 |
wl_token_ring_join(); |
|
39 |
printf("Packet groups initialized.\n"); |
|
40 |
|
|
41 |
struct timespec delay; |
|
42 |
delay.tv_sec = 0; |
|
43 |
delay.tv_nsec = 100000000; |
|
44 |
while (1) |
|
45 |
{ |
|
46 |
//wl_error_send_string("s"); |
|
47 |
wl_do(); |
|
48 |
nanosleep(&delay, 0); |
|
49 |
} |
|
50 |
|
|
51 |
wl_terminate(); |
|
52 |
|
|
53 |
return 0; |
|
54 |
} |
|
55 |
|
trunk/code/projects/libwireless/test/Makefile | ||
---|---|---|
1 |
CC = gcc |
|
2 |
CFLAGS = -Wall -g |
|
3 |
|
|
4 |
all: test |
|
5 |
|
|
6 |
test: *.c ../lib/*.c |
|
7 |
$(CC) $(CFLAGS) *.c -L../lib -o test -pthread -lrt -lwireless |
|
8 |
|
|
9 |
clean: |
|
10 |
rm *.o test ../lib/*.o |
|
11 |
|
trunk/code/projects/libwireless/robotTest/main.c | ||
---|---|---|
1 |
#include <dragonfly_lib.h> |
|
2 |
#include <wireless.h> |
|
3 |
#include <wl_token_ring.h> |
|
4 |
|
|
5 |
int main(void) |
|
6 |
{ |
|
7 |
dragonfly_init(ALL_ON); |
|
8 |
usb_puts("Start.\r\n"); |
|
9 |
wl_init(); |
|
10 |
usb_puts("Wireless initialized.\n"); |
|
11 |
wl_token_ring_register(); |
|
12 |
wl_token_ring_join(); |
|
13 |
while (1) |
|
14 |
wl_do(); |
|
15 |
} |
trunk/code/projects/libwireless/robotTest/Makefile | ||
---|---|---|
1 |
# Hey Emacs, this is a -*- makefile -*- |
|
2 |
#---------------------------------------------------------------------------- |
|
3 |
# WinAVR Makefile Template written by Eric B. Weddington, J?rg Wunsch, et al. |
|
4 |
# |
|
5 |
# Released to the Public Domain |
|
6 |
# |
|
7 |
# Additional material for this makefile was written by: |
|
8 |
# Peter Fleury |
|
9 |
# Tim Henigan |
|
10 |
# Colin O'Flynn |
|
11 |
# Reiner Patommel |
|
12 |
# Markus Pfaff |
|
13 |
# Sander Pool |
|
14 |
# Frederik Rouleau |
|
15 |
# |
|
16 |
#---------------------------------------------------------------------------- |
|
17 |
# On command line: |
|
18 |
# |
|
19 |
# make all = Make software. |
|
20 |
# |
|
21 |
# make clean = Clean out built project files. |
|
22 |
# |
|
23 |
# make coff = Convert ELF to AVR COFF. |
|
24 |
# |
|
25 |
# make extcoff = Convert ELF to AVR Extended COFF. |
|
26 |
# |
|
27 |
# make program = Download the hex file to the device, using avrdude. |
|
28 |
# Please customize the avrdude settings below first! |
|
29 |
# |
|
30 |
# make debug = Start either simulavr or avarice as specified for debugging, |
|
31 |
# with avr-gdb or avr-insight as the front end for debugging. |
|
32 |
# |
|
33 |
# make filename.s = Just compile filename.c into the assembler code only. |
|
34 |
# |
|
35 |
# make filename.i = Create a preprocessed source file for use in submitting |
|
36 |
# bug reports to the GCC project. |
|
37 |
# |
|
38 |
# To rebuild project do "make clean" then "make all". |
|
39 |
#---------------------------------------------------------------------------- |
|
40 |
|
|
41 |
#if you want your code to work on the Firefly++ and not Firefly+ |
|
42 |
#then add the -DFFPP line to CDEFS |
|
43 |
COLONYROOT = y: |
|
44 |
CDEFS = |
|
45 |
#-DFFPP |
|
46 |
|
|
47 |
# MCU name |
|
48 |
MCU = atmega128 |
|
49 |
|
|
50 |
|
|
51 |
# Processor frequency. |
|
52 |
# This will define a symbol, F_CPU, in all source code files equal to the |
|
53 |
# processor frequency. You can then use this symbol in your source code to |
|
54 |
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done |
|
55 |
# automatically to create a 32-bit value in your source code. |
|
56 |
F_CPU = 8000000 |
|
57 |
|
|
58 |
|
|
59 |
# Output format. (can be srec, ihex, binary) |
|
60 |
FORMAT = ihex |
|
61 |
|
|
62 |
|
|
63 |
# Target file name (without extension). |
|
64 |
TARGET = main |
|
65 |
|
|
66 |
|
|
67 |
# List C source files here. (C dependencies are automatically generated.) |
|
68 |
SRC = $(wildcard *.c) |
|
69 |
#$(TARGET).c |
|
70 |
|
|
71 |
|
|
72 |
# List Assembler source files here. |
|
73 |
# Make them always end in a capital .S. Files ending in a lowercase .s |
|
74 |
# will not be considered source files but generated files (assembler |
|
75 |
# output from the compiler), and will be deleted upon "make clean"! |
|
76 |
# Even though the DOS/Win* filesystem matches both .s and .S the same, |
|
77 |
# it will preserve the spelling of the filenames, and gcc itself does |
|
78 |
# care about how the name is spelled on its command-line. |
|
79 |
ASRC = |
|
80 |
|
|
81 |
|
|
82 |
# Optimization level, can be [0, 1, 2, 3, s]. |
|
83 |
# 0 = turn off optimization. s = optimize for size. |
|
84 |
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.) |
|
85 |
OPT = s |
|
86 |
|
|
87 |
|
|
88 |
# Debugging format. |
|
89 |
# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs. |
|
90 |
# AVR Studio 4.10 requires dwarf-2. |
|
91 |
# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run. |
|
92 |
DEBUG = |
|
93 |
|
|
94 |
|
|
95 |
# List any extra directories to look for include files here. |
|
96 |
# Each directory must be seperated by a space. |
|
97 |
# Use forward slashes for directory separators. |
|
98 |
# For a directory that has spaces, enclose it in quotes. |
|
99 |
EXTRAINCDIRS = $(COLONYROOT)/code/firefly_plus_lib |
|
100 |
#C:\WinAVR\include\fwr |
|
101 |
|
|
102 |
|
|
103 |
# Compiler flag to set the C Standard level. |
|
104 |
# c89 = "ANSI" C |
|
105 |
# gnu89 = c89 plus GCC extensions |
|
106 |
# c99 = ISO C99 standard (not yet fully implemented) |
|
107 |
# gnu99 = c99 plus GCC extensions |
|
108 |
CSTANDARD = -std=gnu99 |
|
109 |
|
|
110 |
|
|
111 |
# Place -D or -U options here |
|
112 |
CDEFS += -DF_CPU=$(F_CPU)UL |
|
113 |
CDEFS += -DFFP |
|
114 |
|
|
115 |
|
|
116 |
# Place -I options here |
|
117 |
CINCS = -I../lib -I../../libs_general/libdragonfly -L../lib -L../../libs_general/libdragonfly |
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
#---------------- Compiler Options ---------------- |
|
122 |
# -g*: generate debugging information |
|
123 |
# -O*: optimization level |
|
124 |
# -f...: tuning, see GCC manual and avr-libc documentation |
|
125 |
# -Wall...: warning level |
|
126 |
# -Wa,...: tell GCC to pass this to the assembler. |
|
127 |
# -adhlns...: create assembler listing |
|
128 |
CFLAGS = -g$(DEBUG) |
|
129 |
CFLAGS += $(CDEFS) $(CINCS) |
|
130 |
CFLAGS += -O$(OPT) |
|
131 |
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums |
|
132 |
CFLAGS += -Wall -Wstrict-prototypes |
|
133 |
CFLAGS += -Wa,-adhlns=$(<:.c=.lst) |
|
134 |
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) |
|
135 |
CFLAGS += $(CSTANDARD) |
|
136 |
CFLAGS += -DROBOT |
|
137 |
|
|
138 |
|
|
139 |
#---------------- Assembler Options ---------------- |
|
140 |
# -Wa,...: tell GCC to pass this to the assembler. |
|
141 |
# -ahlms: create listing |
|
142 |
# -gstabs: have the assembler create line number information; note that |
|
143 |
# for use in COFF files, additional information about filenames |
|
144 |
# and function names needs to be present in the assembler source |
|
145 |
# files -- see avr-libc docs [FIXME: not yet described there] |
|
146 |
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs |
|
147 |
|
|
148 |
|
|
149 |
#---------------- Library Options ---------------- |
|
150 |
# Minimalistic printf version |
|
151 |
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min |
|
152 |
|
|
153 |
# Floating point printf version (requires MATH_LIB = -lm below) |
|
154 |
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt |
|
155 |
|
|
156 |
# If this is left blank, then it will use the Standard printf version. |
|
157 |
PRINTF_LIB = |
|
158 |
#PRINTF_LIB = $(PRINTF_LIB_MIN) |
|
159 |
#PRINTF_LIB = $(PRINTF_LIB_FLOAT) |
|
160 |
|
|
161 |
|
|
162 |
# Minimalistic scanf version |
|
163 |
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min |
|
164 |
|
|
165 |
# Floating point + %[ scanf version (requires MATH_LIB = -lm below) |
|
166 |
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt |
|
167 |
|
|
168 |
# If this is left blank, then it will use the Standard scanf version. |
|
169 |
SCANF_LIB = |
|
170 |
#SCANF_LIB = $(SCANF_LIB_MIN) |
|
171 |
#SCANF_LIB = $(SCANF_LIB_FLOAT) |
|
172 |
|
|
173 |
|
|
174 |
MATH_LIB = -lm |
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
#---------------- External Memory Options ---------------- |
|
179 |
|
|
180 |
# 64 KB of external RAM, starting after internal RAM (ATmega128!), |
|
181 |
# used for variables (.data/.bss) and heap (malloc()). |
|
182 |
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff |
|
183 |
|
|
184 |
# 64 KB of external RAM, starting after internal RAM (ATmega128!), |
|
185 |
# only used for heap (malloc()). |
|
186 |
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff |
|
187 |
|
|
188 |
EXTMEMOPTS = |
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
#---------------- Linker Options ---------------- |
|
193 |
# -Wl,...: tell GCC to pass this to linker. |
|
194 |
# -Map: create map file |
|
195 |
# --cref: add cross reference to map file |
|
196 |
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref |
|
197 |
LDFLAGS += $(EXTMEMOPTS) |
|
198 |
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) |
|
199 |
LDFLAGS += -lwireless -ldragonfly |
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
#---------------- Programming Options (avrdude) ---------------- |
|
204 |
|
|
205 |
# Programming hardware: alf avr910 avrisp bascom bsd |
|
206 |
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500 |
|
207 |
# |
|
208 |
# Type: avrdude -c ? |
|
209 |
# to get a full listing. |
|
210 |
# |
|
211 |
AVRDUDE_PROGRAMMER = avrisp |
|
212 |
|
|
213 |
# com1 = serial port. Use lpt1 to connect to parallel port. |
|
214 |
AVRDUDE_PORT = com4 |
|
215 |
# programmer connected to serial device |
|
216 |
|
|
217 |
AVRDUDE_WRITE_FLASH = -b 57600 -U flash:w:$(TARGET).hex |
|
218 |
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep |
|
219 |
|
|
220 |
|
|
221 |
# Uncomment the following if you want avrdude's erase cycle counter. |
|
222 |
# Note that this counter needs to be initialized first using -Yn, |
|
223 |
# see avrdude manual. |
|
224 |
#AVRDUDE_ERASE_COUNTER = -y |
|
225 |
|
|
226 |
# Uncomment the following if you do /not/ wish a verification to be |
|
227 |
# performed after programming the device. |
|
228 |
#AVRDUDE_NO_VERIFY = -V |
|
229 |
|
|
230 |
# Increase verbosity level. Please use this when submitting bug |
|
231 |
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> |
|
232 |
# to submit bug reports. |
|
233 |
#AVRDUDE_VERBOSE = -v -v |
|
234 |
|
|
235 |
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) |
|
236 |
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY) |
|
237 |
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE) |
|
238 |
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) |
|
239 |
|
|
240 |
#don't check for device signature |
|
241 |
AVRDUDE_FLAGS += -F |
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
#---------------- Debugging Options ---------------- |
|
246 |
|
|
247 |
# For simulavr only - target MCU frequency. |
|
248 |
DEBUG_MFREQ = $(F_CPU) |
|
249 |
|
|
250 |
# Set the DEBUG_UI to either gdb or insight. |
|
251 |
# DEBUG_UI = gdb |
|
252 |
DEBUG_UI = insight |
|
253 |
|
|
254 |
# Set the debugging back-end to either avarice, simulavr. |
|
255 |
DEBUG_BACKEND = avarice |
|
256 |
#DEBUG_BACKEND = simulavr |
|
257 |
|
|
258 |
# GDB Init Filename. |
|
259 |
GDBINIT_FILE = __avr_gdbinit |
|
260 |
|
|
261 |
# When using avarice settings for the JTAG |
|
262 |
JTAG_DEV = /dev/com1 |
|
263 |
|
|
264 |
# Debugging port used to communicate between GDB / avarice / simulavr. |
|
265 |
DEBUG_PORT = 4242 |
|
266 |
|
|
267 |
# Debugging host used to communicate between GDB / avarice / simulavr, normally |
|
268 |
# just set to localhost unless doing some sort of crazy debugging when |
|
269 |
# avarice is running on a different computer. |
|
270 |
DEBUG_HOST = localhost |
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
#============================================================================ |
|
275 |
|
|
276 |
|
|
277 |
# Define programs and commands. |
|
278 |
SHELL = sh |
|
279 |
CC = avr-gcc |
|
280 |
OBJCOPY = avr-objcopy |
|
281 |
OBJDUMP = avr-objdump |
|
282 |
SIZE = avr-size |
|
283 |
NM = avr-nm |
|
284 |
AVRDUDE = avrdude |
|
285 |
REMOVE = rm -f |
|
286 |
REMOVEDIR = rm -rf |
|
287 |
COPY = cp |
|
288 |
WINSHELL = cmd |
|
289 |
|
|
290 |
|
|
291 |
# Define Messages |
|
292 |
# English |
|
293 |
MSG_ERRORS_NONE = Errors: none |
|
294 |
MSG_BEGIN = -------- begin -------- |
|
295 |
MSG_END = -------- end -------- |
|
296 |
MSG_SIZE_BEFORE = Size before: |
|
297 |
MSG_SIZE_AFTER = Size after: |
|
298 |
MSG_COFF = Converting to AVR COFF: |
|
299 |
MSG_EXTENDED_COFF = Converting to AVR Extended COFF: |
|
300 |
MSG_FLASH = Creating load file for Flash: |
|
301 |
MSG_EEPROM = Creating load file for EEPROM: |
|
302 |
MSG_EXTENDED_LISTING = Creating Extended Listing: |
|
303 |
MSG_SYMBOL_TABLE = Creating Symbol Table: |
|
304 |
MSG_LINKING = Linking: |
|
305 |
MSG_COMPILING = Compiling: |
|
306 |
MSG_ASSEMBLING = Assembling: |
|
307 |
MSG_CLEANING = Cleaning project: |
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
# Define all object files. |
|
313 |
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) |
|
314 |
|
|
315 |
# Define all listing files. |
|
316 |
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst) |
|
317 |
|
|
318 |
|
|
319 |
# Compiler flags to generate dependency files. |
|
320 |
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d |
|
321 |
|
|
322 |
|
|
323 |
# Combine all necessary flags and optional flags. |
|
324 |
# Add target processor to flags. |
|
325 |
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS) |
|
326 |
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) |
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
|
332 |
# Default target. |
|
333 |
all: begin gccversion sizebefore build sizeafter end |
|
334 |
|
|
335 |
build: elf hex eep lss sym |
|
336 |
|
|
337 |
elf: $(TARGET).elf |
|
338 |
hex: $(TARGET).hex |
|
339 |
eep: $(TARGET).eep |
|
340 |
lss: $(TARGET).lss |
|
341 |
sym: $(TARGET).sym |
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
# Eye candy. |
|
346 |
# AVR Studio 3.x does not check make's exit code but relies on |
|
347 |
# the following magic strings to be generated by the compile job. |
|
348 |
begin: |
|
349 |
@echo |
|
350 |
@echo $(MSG_BEGIN) |
|
351 |
|
|
352 |
end: |
|
353 |
@echo $(MSG_END) |
|
354 |
@echo |
|
355 |
|
|
356 |
|
|
357 |
# Display size of file. |
|
358 |
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex |
|
359 |
ELFSIZE = $(SIZE) -A $(TARGET).elf |
|
360 |
AVRMEM = avr-mem.sh $(TARGET).elf $(MCU) |
|
361 |
|
|
362 |
sizebefore: |
|
363 |
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \ |
|
364 |
$(AVRMEM) 2>/dev/null; echo; fi |
|
365 |
|
|
366 |
sizeafter: |
|
367 |
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \ |
|
368 |
$(AVRMEM) 2>/dev/null; echo; fi |
|
369 |
|
|
370 |
|
|
371 |
|
|
372 |
# Display compiler version information. |
|
373 |
gccversion : |
|
374 |
@$(CC) --version |
|
375 |
|
|
376 |
|
|
377 |
|
|
378 |
# Program the device. |
|
379 |
program: $(TARGET).hex $(TARGET).eep |
|
380 |
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) |
|
381 |
|
|
382 |
|
|
383 |
# Generate avr-gdb config/init file which does the following: |
|
384 |
# define the reset signal, load the target file, connect to target, and set |
|
385 |
# a breakpoint at main(). |
|
386 |
gdb-config: |
|
387 |
@$(REMOVE) $(GDBINIT_FILE) |
|
388 |
@echo define reset >> $(GDBINIT_FILE) |
|
389 |
@echo SIGNAL SIGHUP >> $(GDBINIT_FILE) |
|
390 |
@echo end >> $(GDBINIT_FILE) |
|
391 |
@echo file $(TARGET).elf >> $(GDBINIT_FILE) |
|
392 |
@echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE) |
|
393 |
ifeq ($(DEBUG_BACKEND),simulavr) |
|
394 |
@echo load >> $(GDBINIT_FILE) |
|
395 |
endif |
|
396 |
@echo break main >> $(GDBINIT_FILE) |
|
397 |
|
|
398 |
debug: gdb-config $(TARGET).elf |
|
399 |
ifeq ($(DEBUG_BACKEND), avarice) |
|
400 |
@echo Starting AVaRICE - Press enter when "waiting to connect" message displays. |
|
401 |
@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \ |
|
402 |
$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT) |
|
403 |
@$(WINSHELL) /c pause |
|
404 |
|
|
405 |
else |
|
406 |
@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \ |
|
407 |
$(DEBUG_MFREQ) --port $(DEBUG_PORT) |
|
408 |
endif |
|
409 |
@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE) |
|
410 |
|
|
411 |
|
|
412 |
|
|
413 |
|
|
414 |
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. |
|
415 |
COFFCONVERT=$(OBJCOPY) --debugging \ |
|
416 |
--change-section-address .data-0x800000 \ |
|
417 |
--change-section-address .bss-0x800000 \ |
|
418 |
--change-section-address .noinit-0x800000 \ |
|
419 |
--change-section-address .eeprom-0x810000 |
|
420 |
|
|
421 |
|
|
422 |
coff: $(TARGET).elf |
|
423 |
@echo |
|
424 |
@echo $(MSG_COFF) $(TARGET).cof |
|
425 |
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof |
|
426 |
|
|
427 |
|
|
428 |
extcoff: $(TARGET).elf |
|
429 |
@echo |
|
430 |
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof |
|
431 |
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof |
|
432 |
|
|
433 |
|
|
434 |
|
|
435 |
# Create final output files (.hex, .eep) from ELF output file. |
|
436 |
%.hex: %.elf |
|
437 |
@echo |
|
438 |
@echo $(MSG_FLASH) $@ |
|
439 |
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ |
|
440 |
|
|
441 |
%.eep: %.elf |
|
442 |
@echo |
|
443 |
@echo $(MSG_EEPROM) $@ |
|
444 |
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ |
|
445 |
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@ |
|
446 |
|
|
447 |
# Create extended listing file from ELF output file. |
|
448 |
%.lss: %.elf |
|
449 |
@echo |
|
450 |
@echo $(MSG_EXTENDED_LISTING) $@ |
|
451 |
$(OBJDUMP) -h -S $< > $@ |
|
452 |
|
|
453 |
# Create a symbol table from ELF output file. |
|
454 |
%.sym: %.elf |
|
455 |
@echo |
|
456 |
@echo $(MSG_SYMBOL_TABLE) $@ |
|
457 |
$(NM) -n $< > $@ |
|
458 |
|
|
459 |
|
|
460 |
|
|
461 |
# Link: create ELF output file from object files. |
|
462 |
.SECONDARY : $(TARGET).elf |
|
463 |
.PRECIOUS : $(OBJ) |
|
464 |
%.elf: $(OBJ) |
|
465 |
@echo |
|
466 |
@echo $(MSG_LINKING) $@ |
|
467 |
$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS) |
|
468 |
|
|
469 |
|
|
470 |
# Compile: create object files from C source files. |
|
471 |
%.o : %.c |
|
472 |
@echo |
|
473 |
@echo $(MSG_COMPILING) $< |
|
474 |
$(CC) -c $(ALL_CFLAGS) $< -o $@ |
|
475 |
|
|
476 |
|
|
477 |
# Compile: create assembler files from C source files. |
|
478 |
%.s : %.c |
|
479 |
$(CC) -S $(ALL_CFLAGS) $< -o $@ |
|
480 |
|
|
481 |
|
|
482 |
# Assemble: create object files from assembler source files. |
|
483 |
%.o : %.S |
|
484 |
@echo |
|
485 |
@echo $(MSG_ASSEMBLING) $< |
|
486 |
$(CC) -c $(ALL_ASFLAGS) $< -o $@ |
|
487 |
|
|
488 |
# Create preprocessed source for use in sending a bug report. |
|
489 |
%.i : %.c |
|
490 |
$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ |
|
491 |
|
|
492 |
|
|
493 |
# Target: clean project. |
|
494 |
clean: begin clean_list end |
|
495 |
|
|
496 |
clean_list : |
|
497 |
@echo |
|
498 |
@echo $(MSG_CLEANING) |
|
499 |
$(REMOVE) $(TARGET).hex |
|
500 |
$(REMOVE) $(TARGET).eep |
|
501 |
$(REMOVE) $(TARGET).cof |
|
502 |
$(REMOVE) $(TARGET).elf |
|
503 |
$(REMOVE) $(TARGET).map |
|
504 |
$(REMOVE) $(TARGET).sym |
|
505 |
$(REMOVE) $(TARGET).lss |
|
506 |
$(REMOVE) $(OBJ) |
|
507 |
$(REMOVE) $(LST) |
|
508 |
$(REMOVE) $(SRC:.c=.s) |
|
509 |
$(REMOVE) $(SRC:.c=.d) |
|
510 |
$(REMOVEDIR) .dep |
|
511 |
|
|
512 |
|
|
513 |
|
|
514 |
# Include the dependency files. |
|
515 |
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) |
|
516 |
|
|
517 |
|
|
518 |
# Listing of phony targets. |
|
519 |
.PHONY : all begin finish end sizebefore sizeafter gccversion \ |
|
520 |
build elf hex eep lss sym coff extcoff \ |
|
521 |
clean clean_list program debug gdb-config |
|
522 |
|
trunk/code/projects/libwireless/lib/wl_token_ring.c | ||
---|---|---|
1 |
#include <wl_token_ring.h> |
|
2 |
|
|
3 |
#include <stdlib.h> |
|
4 |
#include <stdio.h> |
|
5 |
|
|
6 |
#include <wl_defs.h> |
|
7 |
#include <wireless.h> |
|
8 |
#include <sensor_matrix.h> |
|
9 |
#include <queue.h> |
|
10 |
|
|
11 |
#ifdef ROBOT |
|
12 |
#include <bom.h> |
|
13 |
#include <time.h> |
|
14 |
#endif |
|
15 |
|
|
16 |
#define DEFAULT_SENSOR_MATRIX_SIZE 20 |
|
17 |
|
|
18 |
//TODO: idea: if the xbee can handle many packets at once, we could have everyone |
|
19 |
//send their BOM reading for a particular robot right after getting it. |
|
20 |
|
|
21 |
/*Ring States*/ |
|
22 |
|
|
23 |
#define NONMEMBER 0 |
|
24 |
#define MEMBER 1 |
|
25 |
#define JOINING 2 |
|
26 |
#define ACCEPTED 3 |
|
27 |
#define LEAVING 4 |
|
28 |
|
|
29 |
/*Frame Types*/ |
|
30 |
#define TOKEN_JOIN_ACCEPT_FRAME 1 |
|
31 |
|
|
32 |
/*Function Prototypes*/ |
|
33 |
|
|
34 |
/*Wireless Library Prototypes*/ |
|
35 |
void wl_token_ring_timeout_handler(void); |
|
36 |
void wl_token_ring_response_handler(int frame, int received); |
|
37 |
void wl_token_ring_receive_handler(char type, int source, unsigned char* packet, |
|
38 |
int length); |
|
39 |
void wl_token_ring_cleanup(void); |
|
40 |
|
|
41 |
/*Helper Functions*/ |
|
42 |
void wl_token_pass_token(void); |
|
43 |
int get_token_distance(int robot1, int robot2); |
|
44 |
void wl_token_get_token(void); |
|
45 |
|
|
46 |
/*Packet Handling Routines*/ |
|
47 |
void wl_token_pass_receive(int source, char nextRobot, unsigned char* sensorData, int sensorDataLength); |
|
48 |
void wl_token_interrupt_request_receive(int source, int robot); |
|
49 |
void wl_token_interrupt_pass_receive(int source, int robot); |
|
50 |
void wl_token_bom_on_receive(int source); |
|
51 |
void wl_token_join_receive(int source); |
|
52 |
void wl_token_join_accept_receive(int source); |
|
53 |
|
|
54 |
/*Global Variables*/ |
|
55 |
|
|
56 |
//the sensor matrix |
|
57 |
SensorMatrix* sensorMatrix; |
|
58 |
|
|
59 |
//the robot we are waiting to say it has received the token. -1 if unspecified |
|
60 |
int wl_token_next_robot = -1; |
|
61 |
|
|
62 |
//true if the robot should be in the token ring, 0 otherwise |
|
63 |
int ringState = NONMEMBER; |
|
64 |
//the id of the robot who accepted us into the token ring, only used in ACCEPTED state |
|
65 |
int acceptor = -1; |
|
66 |
//id of the robot we are accepting |
|
67 |
int accepted = -1; |
|
68 |
|
|
69 |
//the counter for when we assume a robot is dead |
|
70 |
int deathDelay = -1; |
|
71 |
//the counter for joining, before we form our own token ring |
|
72 |
int joinDelay = -1; |
|
73 |
//queue containing ids of interruption requests |
|
74 |
Queue* interrupting = NULL; |
|
75 |
|
|
76 |
#ifdef ROBOT |
|
77 |
void (*bom_on_function) (void) = bom_on; |
|
78 |
void (*bom_off_function) (void) = bom_off; |
|
79 |
int (*get_max_bom_function) (void) = get_max_bom; |
|
80 |
#else |
|
81 |
void do_nothing(void) {} |
|
82 |
int get_nothing(void) {return -1;} |
|
83 |
void (*bom_on_function) (void) = do_nothing; |
|
84 |
void (*bom_off_function) (void) = do_nothing; |
|
85 |
int (*get_max_bom_function) (void) = get_nothing; |
|
86 |
#endif |
|
87 |
|
|
88 |
PacketGroupHandler wl_token_ring_handler = |
|
89 |
{WL_TOKEN_RING_GROUP, wl_token_ring_timeout_handler, |
|
90 |
wl_token_ring_response_handler, wl_token_ring_receive_handler, |
|
91 |
wl_token_ring_cleanup}; |
|
92 |
|
|
93 |
/** |
|
94 |
* Initialize the token ring packet group and register it with the |
|
95 |
* wireless library. The robot will not join a token ring. |
|
96 |
**/ |
|
97 |
void wl_token_ring_register() |
|
98 |
{ |
|
99 |
if (wl_get_xbee_id() > 0xFF) |
|
100 |
{ |
|
101 |
//Note: if this becomes an issue (unlikely), we could limit sensor information |
|
102 |
//to half a byte and use 12 bits for the id |
|
103 |
WL_DEBUG_PRINT("XBee ID must be single byte for token ring, is "); |
|
104 |
WL_DEBUG_PRINT_INT(wl_get_xbee_id()); |
|
105 |
WL_DEBUG_PRINT(".\r\n"); |
|
106 |
return; |
|
107 |
} |
|
108 |
|
|
109 |
sensorMatrix = sensor_matrix_create(); |
|
110 |
interrupting = queue_create(); |
|
111 |
//add ourselves to the sensor matrix |
|
112 |
sensor_matrix_set_in_ring(sensorMatrix, wl_get_xbee_id(), 0); |
|
113 |
|
|
114 |
wl_register_packet_group(&wl_token_ring_handler); |
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* Removes the packet group from the wireless library. |
|
119 |
**/ |
|
120 |
void wl_token_ring_unregister() |
|
121 |
{ |
|
122 |
wl_unregister_packet_group(&wl_token_ring_handler); |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* Sets the functions that are called when the BOM ought to be |
|
127 |
* turned on or off. This could be used for things such as |
|
128 |
* charging stations, which have multiple BOMs. |
|
129 |
* |
|
130 |
* @param on_function the function to be called when the BOM |
|
131 |
* should be turned on |
|
132 |
* @param off_function the function to be called when the BOM |
|
133 |
* should be turned off |
|
134 |
* @param max_bom_function the function to be called when a |
|
135 |
* measurement of the maximum BOM reading is needed. |
|
136 |
**/ |
|
137 |
void wl_token_ring_set_bom_functions(void (*on_function) (void), |
|
138 |
void (*off_function) (void), int (*max_bom_function) (void)) |
|
139 |
{ |
|
140 |
bom_on_function = on_function; |
|
141 |
bom_off_function = off_function; |
|
142 |
get_max_bom_function = max_bom_function; |
|
143 |
} |
|
144 |
|
|
145 |
/** |
|
146 |
* Called to cleanup the token ring packet group. |
|
147 |
**/ |
|
148 |
void wl_token_ring_cleanup() |
|
149 |
{ |
|
150 |
sensor_matrix_destroy(sensorMatrix); |
|
151 |
queue_destroy(interrupting); |
|
152 |
} |
|
153 |
|
|
154 |
/** |
|
155 |
* Called approximately every quarter second by the wireless library. |
|
156 |
**/ |
|
157 |
void wl_token_ring_timeout_handler() |
|
158 |
{ |
|
159 |
//someone is not responding, assume they are dead |
|
160 |
if (deathDelay == 0) |
|
161 |
{ |
|
162 |
//pass the token to the next robot if we think someone has died |
|
163 |
//also, declare that person dead, as long as it isn't us |
|
164 |
if (wl_token_next_robot != wl_get_xbee_id()) |
|
165 |
{ |
|
166 |
sensor_matrix_set_in_ring(sensorMatrix, wl_token_next_robot, 0); |
|
167 |
WL_DEBUG_PRINT("Robot "); |
|
168 |
WL_DEBUG_PRINT_INT(wl_token_next_robot); |
|
169 |
WL_DEBUG_PRINT(" has died.\r\n"); |
|
170 |
} |
|
171 |
wl_token_pass_token(); |
|
172 |
} |
|
173 |
|
|
174 |
//we must start our own token ring, no one is responding to us |
|
175 |
if (joinDelay == 0) |
|
176 |
{ |
|
177 |
if (sensor_matrix_get_joined(sensorMatrix) == 0) |
|
178 |
{ |
|
179 |
WL_DEBUG_PRINT("Creating our own token ring, no robots seem to exist.\r\n"); |
|
180 |
sensor_matrix_set_in_ring(sensorMatrix, wl_get_xbee_id(), 1); |
|
181 |
ringState = MEMBER; |
|
182 |
//this will make us pass the token to ourself |
|
183 |
//repeatedly, and other robots when they join |
|
184 |
deathDelay = DEATH_DELAY; |
|
185 |
wl_token_next_robot = wl_get_xbee_id(); |
|
186 |
} |
|
187 |
else |
|
188 |
{ |
|
189 |
WL_DEBUG_PRINT("Attempting to join the token ring again.\r\n"); |
|
190 |
//attempt to rejoin with a random delay |
|
191 |
wl_token_ring_join(); |
|
192 |
joinDelay = rand() / (RAND_MAX / JOIN_DELAY) + 1; |
|
193 |
} |
|
194 |
} |
|
195 |
|
|
196 |
if (deathDelay >= 0) |
|
197 |
deathDelay--; |
|
198 |
if (joinDelay >= 0) |
|
199 |
joinDelay--; |
|
200 |
} |
|
201 |
|
|
202 |
/** |
|
203 |
* Called when the XBee tells us if a packet we sent has been received. |
|
204 |
* |
|
205 |
* @param frame the frame number assigned when the packet was sent |
|
206 |
* @param received 1 if the packet was received, 0 otherwise |
|
207 |
**/ |
|
208 |
void wl_token_ring_response_handler(int frame, int received) |
|
209 |
{ |
|
210 |
if (!received) |
|
211 |
{ |
|
212 |
WL_DEBUG_PRINT("FAILED.\r\n"); |
|
213 |
} |
|
214 |
} |
|
215 |
|
|
216 |
/** |
|
217 |
* Called when we recieve a token ring packet. |
|
218 |
* @param type the type of the packet |
|
219 |
* @param source the id of the robot who sent the packet |
|
220 |
* @param packet the data in the packet |
|
221 |
* @param length the length of the packet in bytes |
|
222 |
**/ |
|
223 |
void wl_token_ring_receive_handler(char type, int source, unsigned char* packet, |
|
224 |
int length) |
|
225 |
{ |
|
226 |
switch (type) |
|
227 |
{ |
|
228 |
case WL_TOKEN_PASS: |
|
229 |
if (length < 1) |
|
230 |
{ |
|
231 |
WL_DEBUG_PRINT("Malformed Token Pass packet received.\r\n"); |
|
232 |
return; |
|
233 |
} |
|
234 |
wl_token_pass_receive(source, packet[0], packet + 1, length - 1); |
|
235 |
break; |
|
236 |
case WL_TOKEN_BOM_ON: |
|
237 |
//add the robot to the sensor matrix if it is not already there |
|
238 |
wl_token_bom_on_receive(source); |
|
239 |
break; |
|
240 |
case WL_TOKEN_INTERRUPT_REQUEST: |
|
241 |
wl_token_interrupt_request_receive(source, packet[0]); |
|
242 |
break; |
|
243 |
case WL_TOKEN_INTERRUPT_PASS: |
|
244 |
wl_token_interrupt_pass_receive(source, packet[0]); |
|
245 |
break; |
|
246 |
case WL_TOKEN_JOIN: |
|
247 |
wl_token_join_receive(source); |
|
248 |
break; |
|
249 |
case WL_TOKEN_JOIN_ACCEPT: |
|
250 |
wl_token_join_accept_receive(source); |
|
251 |
break; |
|
252 |
default: |
|
253 |
WL_DEBUG_PRINT("Unimplemented token ring packet received.\r\n"); |
|
254 |
break; |
|
255 |
} |
|
256 |
} |
|
257 |
|
|
258 |
/** |
|
259 |
* Causes the robot to join an existing token ring, or create one |
|
260 |
* if no token ring exists. The token ring uses global and robot to robot |
|
261 |
* packets, and does not rely on any PAN. |
|
262 |
**/ |
|
263 |
void wl_token_ring_join() |
|
264 |
{ |
|
265 |
WL_DEBUG_PRINT("Joining the token ring.\r\n"); |
|
266 |
ringState = JOINING; |
|
267 |
joinDelay = JOIN_DELAY; |
|
268 |
wl_send_global_packet(WL_TOKEN_RING_GROUP, WL_TOKEN_JOIN, |
|
269 |
NULL, 0, 0); |
|
270 |
} |
|
271 |
|
|
272 |
/** |
|
273 |
* Causes the robot to leave the token ring. The robot stops |
|
274 |
* alerting others of its location, but continues storing the |
|
275 |
* locations of other robots. |
|
276 |
**/ |
|
277 |
void wl_token_ring_leave() |
|
278 |
{ |
|
279 |
ringState = LEAVING; |
|
280 |
} |
|
281 |
|
|
282 |
/** |
|
283 |
* Requests that the specified robot be given the token and |
|
284 |
* allowed to flash its BOM. After its BOM is flashed, the |
|
285 |
* token will return to the robot who sent it. |
|
286 |
* |
|
287 |
* @param robot the ID of the robot which should flash its BOM |
|
288 |
**/ |
|
289 |
void wl_token_request(int robot) |
|
290 |
{ |
|
291 |
char buf[1]; |
|
292 |
buf[0] = robot; |
|
293 |
wl_send_global_packet(WL_TOKEN_RING_GROUP, WL_TOKEN_INTERRUPT_REQUEST, |
|
294 |
buf, 1, 0); |
|
295 |
} |
|
296 |
|
|
297 |
/** |
|
298 |
* Returns the BOM reading robot source has for robot dest. |
|
299 |
* |
|
300 |
* @param source the robot that made the BOM reading |
|
301 |
* @param dest the robot whose relative location is returned |
|
302 |
* |
|
303 |
* @return a BOM reading from robot source to robot dest, |
|
304 |
* in the range 0-15, or -1 if it is unknown |
|
305 |
**/ |
|
306 |
int wl_token_get_sensor_reading(int source, int dest) |
|
307 |
{ |
|
308 |
return sensor_matrix_get_reading(sensorMatrix, source, dest); |
|
309 |
} |
|
310 |
|
|
311 |
/** |
|
312 |
* Returns the BOM reading we have for robot dest. |
|
313 |
* |
|
314 |
* @param dest the robot whose relative location is returned |
|
315 |
* |
|
316 |
* @return a BOM reading from us to robot dest, in the range |
|
317 |
* 0-15, or -1 if it is unkown |
|
318 |
**/ |
|
319 |
int wl_token_get_my_sensor_reading(int dest) |
|
320 |
{ |
|
321 |
return wl_token_get_sensor_reading(wl_get_xbee_id(), dest); |
|
322 |
} |
|
323 |
|
|
324 |
/** |
|
325 |
* This method is called when we receive a token pass packet. |
|
326 |
* @param source is the robot it came from |
|
327 |
* @param nextRobot is the robot the token was passed to |
|
328 |
* @param sensorData a char with an id followed by a char with the sensor |
|
329 |
* reading for that robot, repeated for sensorDataLength bytes |
|
330 |
* @param sensorDataLength the length in bytes of sensorData |
|
331 |
*/ |
|
332 |
void wl_token_pass_receive(int source, char nextRobot, unsigned char* sensorData, int sensorDataLength) |
|
333 |
{ |
|
334 |
int i, j; |
|
335 |
deathDelay = -1; |
|
336 |
|
|
337 |
WL_DEBUG_PRINT("Received the token, next robot is "); |
|
338 |
WL_DEBUG_PRINT_INT((int)nextRobot); |
|
339 |
WL_DEBUG_PRINT(" \r\n"); |
|
340 |
sensor_matrix_set_in_ring(sensorMatrix, source, 1); |
|
341 |
|
|
342 |
//with this packet, we are passed the id of the next robot in the ring |
|
343 |
//and the sensor matrix, a list of id and sensor reading pairs (two bytes for both) |
|
344 |
j = 0; |
|
345 |
for (i = 0; i < sensor_matrix_get_size(sensorMatrix); i++) |
|
346 |
{ |
|
347 |
if (i == source) |
|
348 |
continue; |
|
349 |
|
|
350 |
//set the sensor information we receive |
|
351 |
if (j < sensorDataLength / 2 && sensorData[2 * j] == i) |
|
352 |
{ |
|
353 |
//the robot we were going to accept has already been accepted |
|
354 |
if (accepted == i) |
|
355 |
{ |
|
356 |
accepted = -1; |
|
357 |
WL_DEBUG_PRINT("Someone accepted the robot we did.\r\n"); |
|
358 |
} |
|
359 |
sensor_matrix_set_reading(sensorMatrix, source, i, |
|
360 |
sensorData[2 * j + 1]); |
|
361 |
sensor_matrix_set_in_ring(sensorMatrix, i, 1); |
|
362 |
j++; |
|
363 |
} |
|
364 |
else |
|
365 |
{ |
|
366 |
if (sensor_matrix_get_in_ring(sensorMatrix, i)) |
|
367 |
{ |
|
368 |
WL_DEBUG_PRINT("Robot "); |
|
369 |
WL_DEBUG_PRINT_INT(i); |
|
370 |
WL_DEBUG_PRINT(" has been removed from the sensor matrix of robot "); |
|
371 |
WL_DEBUG_PRINT_INT(wl_get_xbee_id()); |
|
372 |
WL_DEBUG_PRINT(" due to a packet from robot "); |
|
373 |
WL_DEBUG_PRINT_INT(source); |
|
374 |
WL_DEBUG_PRINT(".\r\n"); |
|
375 |
sensor_matrix_set_in_ring(sensorMatrix, i, 0); |
|
376 |
} |
|
377 |
|
|
378 |
if (i == wl_get_xbee_id() && ringState == MEMBER) |
|
379 |
{ |
|
380 |
sensor_matrix_set_in_ring(sensorMatrix, |
|
381 |
wl_get_xbee_id(), 1); |
|
382 |
ringState = NONMEMBER; |
|
383 |
wl_token_ring_join(); |
|
384 |
|
|
385 |
WL_DEBUG_PRINT("We have been removed from the ring "); |
|
386 |
WL_DEBUG_PRINT("and are rejoining.\r\n"); |
|
387 |
} |
|
388 |
|
|
389 |
//the person who accepted us is dead... let's ask again |
|
390 |
if (i == acceptor) |
|
391 |
{ |
|
392 |
sensor_matrix_set_in_ring(sensorMatrix, |
|
393 |
wl_get_xbee_id(), 1); |
|
394 |
ringState = NONMEMBER; |
|
395 |
acceptor = -1; |
|
396 |
wl_token_ring_join(); |
|
397 |
} |
|
398 |
} |
|
399 |
} |
|
400 |
|
|
401 |
wl_token_next_robot = nextRobot; |
|
402 |
|
|
403 |
deathDelay = get_token_distance(wl_get_xbee_id(), nextRobot) * DEATH_DELAY; |
|
404 |
|
|
405 |
//we have the token |
|
406 |
if (wl_token_next_robot == wl_get_xbee_id()) |
|
407 |
wl_token_get_token(); |
|
408 |
} |
|
409 |
|
|
410 |
/** |
|
411 |
* Gets the distance in the token ring between two robots. |
|
412 |
* |
|
413 |
* @param robot1 the first robot |
|
414 |
* @param robot2 the second robot |
|
415 |
* |
|
416 |
* @return the number of passes before the token is expected |
|
417 |
* to reach robot2 from robot1 |
|
418 |
**/ |
|
419 |
int get_token_distance(int robot1, int robot2) |
|
420 |
{ |
|
421 |
int curr = robot1 + 1; |
|
422 |
int count = 1; |
|
423 |
while (1) |
|
424 |
{ |
|
425 |
if (curr == sensor_matrix_get_size(sensorMatrix)) |
|
426 |
curr = 0; |
|
427 |
if (curr == robot2) |
|
428 |
break; |
|
429 |
if (sensor_matrix_get_in_ring(sensorMatrix, curr)) |
|
430 |
count++; |
|
431 |
curr++; |
|
432 |
} |
|
433 |
return count; |
|
434 |
} |
|
435 |
|
|
436 |
/** |
|
437 |
* Passes the token to the next robot in the token ring. |
|
438 |
**/ |
|
439 |
void wl_token_pass_token() |
|
440 |
{ |
|
441 |
char nextRobot; |
|
442 |
int i = wl_get_xbee_id() + 1; |
|
443 |
if (accepted == -1) |
|
444 |
{ |
|
445 |
while (1) |
|
446 |
{ |
|
447 |
if (i == sensor_matrix_get_size(sensorMatrix)) |
|
448 |
i = 0; |
|
449 |
if (sensor_matrix_get_in_ring(sensorMatrix, i)) |
|
450 |
{ |
|
451 |
nextRobot = (char)i; |
|
452 |
break; |
|
453 |
} |
|
454 |
i++; |
|
455 |
} |
|
456 |
} |
|
457 |
else |
|
458 |
{ |
|
459 |
WL_DEBUG_PRINT("Accepting new robot, sending it the token.\r\n"); |
|
460 |
//add a new robot to the token ring |
|
461 |
sensor_matrix_set_in_ring(sensorMatrix, accepted, 1); |
|
462 |
nextRobot = accepted; |
|
463 |
accepted = -1; |
|
464 |
} |
|
465 |
|
|
466 |
//we don't include ourself |
|
467 |
int packetSize = 1 + 2 * (sensor_matrix_get_joined(sensorMatrix) - 1); |
|
468 |
char* buf = (char*)malloc(packetSize * sizeof(char)); |
|
469 |
if (!buf) |
|
470 |
{ |
|
471 |
WL_DEBUG_PRINT_INT(packetSize); |
|
472 |
WL_DEBUG_PRINT("Out of memory - pass token.\r\n"); |
|
473 |
return; |
|
474 |
} |
|
475 |
buf[0] = nextRobot; |
|
476 |
|
|
477 |
int j = 0; |
|
478 |
for (i = 0; i < sensor_matrix_get_size(sensorMatrix); i++) |
|
479 |
if (sensor_matrix_get_in_ring(sensorMatrix, i) && i != wl_get_xbee_id()) |
|
480 |
{ |
|
481 |
buf[2*j + 1] = i; |
|
482 |
buf[2*j + 2] = sensor_matrix_get_reading(sensorMatrix, wl_get_xbee_id(), i); |
|
483 |
j++; |
|
484 |
} |
|
485 |
|
|
486 |
WL_DEBUG_PRINT("Passing the token to robot "); |
|
487 |
WL_DEBUG_PRINT_INT(buf[0]); |
|
488 |
WL_DEBUG_PRINT(".\r\n"); |
|
489 |
wl_send_global_packet(WL_TOKEN_RING_GROUP, WL_TOKEN_PASS, |
|
490 |
buf, packetSize, 3); |
|
491 |
|
|
492 |
wl_token_next_robot = nextRobot; |
|
493 |
deathDelay = DEATH_DELAY; |
|
494 |
free(buf); |
|
495 |
} |
|
496 |
|
|
497 |
/** |
|
498 |
* Called when a packet is received stating that another robot has turned |
|
499 |
* its BOM on. Our BOM is then read, and the data is added to the sensor |
|
500 |
* matrix. |
|
501 |
* |
|
502 |
* @param source the robot whose BOM is on |
|
503 |
**/ |
|
504 |
void wl_token_bom_on_receive(int source) |
|
505 |
{ |
|
506 |
WL_DEBUG_PRINT("Robot "); |
|
507 |
WL_DEBUG_PRINT_INT(source); |
|
508 |
WL_DEBUG_PRINT(" has flashed its bom.\r\n"); |
|
509 |
sensor_matrix_set_reading(sensorMatrix, wl_get_xbee_id(), |
|
510 |
source, get_max_bom_function()); |
|
511 |
} |
|
512 |
|
|
513 |
/** |
|
514 |
* This method is called when we receive the token. Upon receiving |
|
515 |
* the token, we must send a BOM_ON packet, flash the BOM, and send |
|
516 |
* the token to the next robot. |
|
517 |
* |
|
518 |
* If there is a pending request for the token, this is processed first. |
|
519 |
**/ |
|
520 |
void wl_token_get_token() |
|
521 |
{ |
|
522 |
WL_DEBUG_PRINT("We have the token.\r\n"); |
|
523 |
if (ringState == ACCEPTED) |
|
524 |
{ |
|
525 |
sensor_matrix_set_in_ring(sensorMatrix, |
|
526 |
wl_get_xbee_id(), 1); |
|
527 |
WL_DEBUG_PRINT("Now a member of the token ring.\r\n"); |
|
528 |
ringState = MEMBER; |
|
529 |
} |
|
530 |
|
|
531 |
if (ringState == LEAVING || ringState == NONMEMBER) |
|
532 |
{ |
|
533 |
sensor_matrix_set_in_ring(sensorMatrix, wl_get_xbee_id(), 0); |
|
534 |
if (ringState == NONMEMBER) |
|
535 |
{ |
|
536 |
WL_DEBUG_PRINT("We should have left the token ring, but didn't.\r\n"); |
|
537 |
} |
|
538 |
} |
|
539 |
|
|
540 |
//check for interruption requests |
|
541 |
if (queue_size(interrupting) > 0) |
|
542 |
{ |
|
543 |
char buf[1]; |
|
544 |
buf[0] = (char)(int)queue_remove(interrupting); |
|
545 |
|
|
546 |
//in case this robot has requested multiple times |
|
547 |
queue_remove_all(interrupting, (void*)(int)buf[0]); |
|
548 |
|
|
549 |
wl_send_global_packet(WL_TOKEN_RING_GROUP, WL_TOKEN_INTERRUPT_PASS, |
|
550 |
buf, 1, 0); |
|
551 |
|
|
552 |
deathDelay = DEATH_DELAY; |
|
553 |
wl_token_next_robot = buf[0]; |
|
554 |
return; |
|
555 |
} |
|
556 |
|
|
557 |
WL_DEBUG_PRINT("Our BOM has been flashed.\r\n"); |
|
558 |
wl_send_global_packet(WL_TOKEN_RING_GROUP, WL_TOKEN_BOM_ON, |
|
559 |
NULL, 0, 0); |
|
560 |
|
|
561 |
bom_on_function(); |
|
562 |
#ifdef ROBOT |
|
563 |
delay_ms(BOM_DELAY); |
|
564 |
#endif |
|
565 |
bom_off_function(); |
|
566 |
|
|
567 |
if (!sensor_matrix_get_in_ring(sensorMatrix, wl_get_xbee_id())) |
|
568 |
{ |
|
569 |
WL_DEBUG_PRINT("Removed from sensor matrix while flashing BOM.\r\n"); |
|
570 |
} |
|
571 |
|
|
572 |
wl_token_pass_token(); |
|
573 |
} |
|
574 |
|
|
575 |
/** |
|
576 |
* Called when a request to join the token ring is received. |
|
577 |
* If we are the robot preceding the requester in the ring, |
|
578 |
* we respond with a JOIN_ACCEPT packet and pass the token to |
|
579 |
* this robot when we receive the token. |
|
580 |
* |
|
581 |
* @param source the robot who requested to join |
|
582 |
**/ |
|
583 |
void wl_token_join_receive(int source) |
|
584 |
{ |
|
585 |
WL_DEBUG_PRINT("Received joining request from robot "); |
|
586 |
WL_DEBUG_PRINT_INT(source); |
|
587 |
WL_DEBUG_PRINT(".\r\n"); |
|
588 |
|
|
589 |
//we cannot accept the request if we are not a member |
|
590 |
if (ringState != MEMBER) |
|
591 |
return; |
|
592 |
//if they didn't get our response, see if we should respond again |
|
593 |
if (accepted == source) |
|
594 |
accepted = -1; |
|
595 |
//we can only accept one request at a time |
|
596 |
if (accepted != -1) |
|
597 |
return; |
|
598 |
|
|
599 |
//check if we are the preceding robot in the token ring |
|
600 |
int i = source - 1; |
|
601 |
while (1) |
|
602 |
{ |
|
603 |
if (i < 0) |
|
604 |
i = sensor_matrix_get_size(sensorMatrix) - 1; |
|
605 |
//we must send a join acceptance |
|
606 |
if (i == wl_get_xbee_id()) |
|
607 |
break; |
|
608 |
|
|
609 |
//another robot will handle it |
|
610 |
if (sensor_matrix_get_in_ring(sensorMatrix, i)) |
|
611 |
return; |
|
612 |
i--; |
|
613 |
} |
|
614 |
|
|
615 |
accepted = source; |
|
616 |
wl_send_robot_to_robot_global_packet(WL_TOKEN_RING_GROUP, WL_TOKEN_JOIN_ACCEPT, |
|
617 |
NULL, 0, source, TOKEN_JOIN_ACCEPT_FRAME); |
|
618 |
|
|
619 |
WL_DEBUG_PRINT("Accepting robot "); |
|
620 |
WL_DEBUG_PRINT_INT(source); |
|
621 |
WL_DEBUG_PRINT(" into the token ring.\r\n"); |
|
622 |
|
|
623 |
joinDelay = -1; |
|
624 |
|
|
625 |
// the token ring has not started yet |
|
626 |
if (sensor_matrix_get_joined(sensorMatrix) == 1) |
|
627 |
wl_token_pass_token(); |
|
628 |
} |
|
629 |
|
|
630 |
/** |
|
631 |
* Called when we receive a JOIN_ACCEPT packet in attempting to join |
|
632 |
* the token ring. |
|
633 |
* Our attempt to join the ring is stopped, and we wait for the token. |
|
634 |
* |
|
635 |
* @param source the robot who accepted us |
|
636 |
**/ |
|
637 |
void wl_token_join_accept_receive(int source) |
|
638 |
{ |
|
639 |
WL_DEBUG_PRINT("Accepted into the token ring by robot "); |
|
640 |
WL_DEBUG_PRINT_INT(source); |
|
641 |
WL_DEBUG_PRINT(".\r\n"); |
|
642 |
joinDelay = -1; |
|
643 |
ringState = ACCEPTED; |
|
644 |
acceptor = source; |
|
645 |
|
|
646 |
//add ourselves to the token ring |
|
647 |
sensor_matrix_set_in_ring(sensorMatrix, wl_get_xbee_id(), 1); |
|
648 |
} |
|
649 |
|
|
650 |
/** |
|
651 |
* Called when we receive a packet passing the token and interrupting |
|
652 |
* the token ring. |
|
653 |
* If the token has been passed to us, we flash our BOM |
|
654 |
* and pass it back. |
|
655 |
* |
|
656 |
* @param source the robot who sent the interrupt packet |
|
657 |
* @param robot the robot the token has been passed to |
|
658 |
**/ |
|
659 |
void wl_token_interrupt_pass_receive(int source, int robot) |
|
660 |
{ |
|
661 |
if (wl_get_xbee_id() != robot) |
|
662 |
{ |
|
663 |
queue_remove_all(interrupting, (void*)robot); |
|
664 |
wl_token_next_robot = robot; |
|
665 |
deathDelay = DEATH_DELAY + rand() / (RAND_MAX / (2 * DEATH_DELAY)); |
|
666 |
return; |
|
667 |
} |
|
668 |
wl_send_global_packet(WL_TOKEN_RING_GROUP, WL_TOKEN_BOM_ON, |
|
669 |
NULL, 0, 0); |
|
670 |
|
|
671 |
bom_on_function(); |
|
672 |
#ifdef ROBOT |
|
673 |
delay_ms(BOM_DELAY); |
|
674 |
#endif |
|
675 |
bom_off_function(); |
|
676 |
|
|
677 |
//we don't include ourself, only if we are in the ring |
|
678 |
int packetSize = 1 + 2 * (sensor_matrix_get_joined(sensorMatrix) - 1); |
|
679 |
if (!sensor_matrix_get_in_ring(sensorMatrix, wl_get_xbee_id())) |
|
680 |
packetSize += 2; |
|
681 |
char* buf = (char*)malloc(packetSize * sizeof(char)); |
|
682 |
if (!buf) |
|
683 |
{ |
|
684 |
WL_DEBUG_PRINT("Out of memory - pass_receive.\r\n"); |
|
685 |
return; |
|
686 |
} |
|
687 |
|
|
688 |
//return the token to where we got it from |
|
689 |
buf[0] = source; |
|
690 |
|
|
691 |
int i = 0, j = 0; |
|
692 |
for (i = 0; i < sensor_matrix_get_size(sensorMatrix); i++) |
|
693 |
if (sensor_matrix_get_in_ring(sensorMatrix, i) && i != wl_get_xbee_id()) |
|
694 |
{ |
|
695 |
buf[2*j + 1] = i; |
|
696 |
buf[2*j + 2] = sensor_matrix_get_reading(sensorMatrix, wl_get_xbee_id(), i); |
|
697 |
j++; |
|
698 |
} |
|
699 |
|
|
700 |
wl_send_global_packet(WL_TOKEN_RING_GROUP, WL_TOKEN_PASS, |
|
701 |
buf, packetSize, 0); |
|
702 |
|
|
703 |
wl_token_next_robot = source; |
|
704 |
deathDelay = DEATH_DELAY; |
|
705 |
free(buf); |
|
706 |
} |
|
707 |
|
|
708 |
/** |
|
709 |
* Called when we receive a request to interrupt the token ring. |
|
710 |
* We add the robot to our list of interrupt requests, |
|
711 |
* and will send the token to this robot when we next receive the |
|
712 |
* token, unless someone else does so first. |
|
713 |
* |
|
714 |
* @param source the robot requesting interruption |
|
715 |
* @param robt the robot requested to interrupt the token ring |
|
716 |
**/ |
|
717 |
void wl_token_interrupt_request_receive(int source, int robot) |
|
718 |
{ |
|
719 |
queue_add(interrupting, (void*)robot); |
|
720 |
} |
|
721 |
|
trunk/code/projects/libwireless/lib/Doxyfile | ||
---|---|---|
1 |
# Doxyfile 1.4.6 |
|
2 |
|
|
3 |
# This file describes the settings to be used by the documentation system |
|
4 |
# doxygen (www.doxygen.org) for a project |
|
5 |
# |
|
6 |
# All text after a hash (#) is considered a comment and will be ignored |
|
7 |
# The format is: |
|
8 |
# TAG = value [value, ...] |
|
9 |
# For lists items can also be appended using: |
|
10 |
# TAG += value [value, ...] |
|
11 |
# Values that contain spaces should be placed between quotes (" ") |
|
12 |
|
|
13 |
#--------------------------------------------------------------------------- |
|
14 |
# Project related configuration options |
|
15 |
#--------------------------------------------------------------------------- |
|
16 |
|
|
17 |
# The PROJECT_NAME tag is a single word (or a sequence of words surrounded |
|
18 |
# by quotes) that should identify the project. |
|
19 |
|
|
20 |
PROJECT_NAME = libwireless |
|
21 |
|
|
22 |
# The PROJECT_NUMBER tag can be used to enter a project or revision number. |
|
23 |
# This could be handy for archiving the generated documentation or |
|
24 |
# if some version control system is used. |
|
25 |
|
|
26 |
PROJECT_NUMBER = 1.0 |
|
27 |
|
|
28 |
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) |
|
29 |
# base path where the generated documentation will be put. |
|
30 |
# If a relative path is entered, it will be relative to the location |
|
31 |
# where doxygen was started. If left blank the current directory will be used. |
|
32 |
|
|
33 |
OUTPUT_DIRECTORY = docs |
|
34 |
|
|
35 |
# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create |
|
36 |
# 4096 sub-directories (in 2 levels) under the output directory of each output |
|
37 |
# format and will distribute the generated files over these directories. |
|
38 |
# Enabling this option can be useful when feeding doxygen a huge amount of |
|
39 |
# source files, where putting all generated files in the same directory would |
|
40 |
# otherwise cause performance problems for the file system. |
|
41 |
|
|
42 |
CREATE_SUBDIRS = NO |
|
43 |
|
|
44 |
# The OUTPUT_LANGUAGE tag is used to specify the language in which all |
|
45 |
# documentation generated by doxygen is written. Doxygen will use this |
|
46 |
# information to generate all constant output in the proper language. |
|
47 |
# The default language is English, other supported languages are: |
|
48 |
# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, |
|
49 |
# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese, |
|
50 |
# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian, |
|
51 |
# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, |
|
52 |
# Swedish, and Ukrainian. |
|
53 |
|
|
54 |
OUTPUT_LANGUAGE = English |
|
55 |
|
|
56 |
# This tag can be used to specify the encoding used in the generated output. |
|
57 |
# The encoding is not always determined by the language that is chosen, |
|
58 |
# but also whether or not the output is meant for Windows or non-Windows users. |
|
59 |
# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES |
|
60 |
# forces the Windows encoding (this is the default for the Windows binary), |
|
61 |
# whereas setting the tag to NO uses a Unix-style encoding (the default for |
|
62 |
# all platforms other than Windows). |
|
63 |
|
|
64 |
USE_WINDOWS_ENCODING = NO |
|
65 |
|
|
66 |
# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will |
|
67 |
# include brief member descriptions after the members that are listed in |
|
68 |
# the file and class documentation (similar to JavaDoc). |
|
69 |
# Set to NO to disable this. |
|
70 |
|
|
71 |
BRIEF_MEMBER_DESC = YES |
|
72 |
|
|
73 |
# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend |
|
74 |
# the brief description of a member or function before the detailed description. |
|
75 |
# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the |
|
76 |
# brief descriptions will be completely suppressed. |
|
77 |
|
|
78 |
REPEAT_BRIEF = YES |
|
79 |
|
|
80 |
# This tag implements a quasi-intelligent brief description abbreviator |
|
81 |
# that is used to form the text in various listings. Each string |
|
82 |
# in this list, if found as the leading text of the brief description, will be |
|
83 |
# stripped from the text and the result after processing the whole list, is |
|
84 |
# used as the annotated text. Otherwise, the brief description is used as-is. |
|
85 |
# If left blank, the following values are used ("$name" is automatically |
|
86 |
# replaced with the name of the entity): "The $name class" "The $name widget" |
|
87 |
# "The $name file" "is" "provides" "specifies" "contains" |
|
88 |
# "represents" "a" "an" "the" |
|
89 |
|
|
90 |
ABBREVIATE_BRIEF = |
|
91 |
|
|
92 |
# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then |
|
93 |
# Doxygen will generate a detailed section even if there is only a brief |
|
94 |
# description. |
|
95 |
|
|
96 |
ALWAYS_DETAILED_SEC = NO |
|
97 |
|
|
98 |
# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all |
|
99 |
# inherited members of a class in the documentation of that class as if those |
|
100 |
# members were ordinary class members. Constructors, destructors and assignment |
|
101 |
# operators of the base classes will not be shown. |
|
102 |
|
|
103 |
INLINE_INHERITED_MEMB = NO |
|
104 |
|
|
105 |
# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full |
|
106 |
# path before files name in the file list and in the header files. If set |
|
107 |
# to NO the shortest path that makes the file name unique will be used. |
|
108 |
|
|
109 |
FULL_PATH_NAMES = YES |
|
110 |
|
|
111 |
# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag |
|
112 |
# can be used to strip a user-defined part of the path. Stripping is |
|
113 |
# only done if one of the specified strings matches the left-hand part of |
|
114 |
# the path. The tag can be used to show relative paths in the file list. |
|
115 |
# If left blank the directory from which doxygen is run is used as the |
|
116 |
# path to strip. |
|
117 |
|
|
118 |
STRIP_FROM_PATH = |
|
119 |
|
|
120 |
# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of |
|
121 |
# the path mentioned in the documentation of a class, which tells |
|
122 |
# the reader which header file to include in order to use a class. |
|
123 |
# If left blank only the name of the header file containing the class |
|
124 |
# definition is used. Otherwise one should specify the include paths that |
|
125 |
# are normally passed to the compiler using the -I flag. |
|
126 |
|
|
127 |
STRIP_FROM_INC_PATH = |
|
128 |
|
|
129 |
# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter |
|
130 |
# (but less readable) file names. This can be useful is your file systems |
|
131 |
# doesn't support long names like on DOS, Mac, or CD-ROM. |
|
132 |
|
|
133 |
SHORT_NAMES = NO |
|
134 |
|
|
135 |
# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen |
|
136 |
# will interpret the first line (until the first dot) of a JavaDoc-style |
|
137 |
# comment as the brief description. If set to NO, the JavaDoc |
|
138 |
# comments will behave just like the Qt-style comments (thus requiring an |
|
139 |
# explicit @brief command for a brief description. |
|
140 |
|
|
141 |
JAVADOC_AUTOBRIEF = NO |
|
142 |
|
|
143 |
# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen |
Also available in: Unified diff