Revision 2005
Added forklift_demo for carnival
trunk/code/projects/forklift_demo/Forklift.cpp | ||
---|---|---|
1 |
#include "Forklift.h" |
|
2 |
#include "libdragonfly/i2c.h" |
|
3 |
#include <util/delay.h> |
|
4 |
|
|
5 |
#define SCOUT_AVR_ADDR 0x01 |
|
6 |
|
|
7 |
#define FORKLIFT_ADDR 0x41 |
|
8 |
|
|
9 |
// indicies for forklift internal data |
|
10 |
#define FORKLIFT_TRACKING_ID 0 |
|
11 |
#define FORKLIFT_SERIAL_NUMBER 1 |
|
12 |
#define FORKLIFT_HEIGHT 2 |
|
13 |
#define FORKLIFT_HEIGHT_SETPOINT 3 // r/w |
|
14 |
#define FORKLIFT_LINE_POS 4 |
|
15 |
#define FORKLIFT_LINE_THRESH_HIGH 5 // r/w |
|
16 |
#define FORKLIFT_LINE_THRESH_LOW 6 // r/w |
|
17 |
|
|
18 |
#define FORKLIFT_DATA_LEN 7 |
|
19 |
|
|
20 |
using namespace Forklift; |
|
21 |
|
|
22 |
char volatile response; |
|
23 |
char volatile received; |
|
24 |
|
|
25 |
int mrecv(char data) |
|
26 |
{ |
|
27 |
response = data; |
|
28 |
received = 1; |
|
29 |
} |
|
30 |
|
|
31 |
void srecv(char) {} |
|
32 |
char ssend() {} |
|
33 |
|
|
34 |
int read_addr(char addr) |
|
35 |
{ |
|
36 |
if (i2c_send(FORKLIFT_ADDR, &addr, 1)) |
|
37 |
return FORKLIFT_ERROR; |
|
38 |
received = 0; |
|
39 |
if (i2c_request(FORKLIFT_ADDR)) |
|
40 |
return FORKLIFT_ERROR; |
|
41 |
for (int i = 0; i < 500; i++) // waits up to ~50 ms |
|
42 |
{ |
|
43 |
_delay_ms(.1); |
|
44 |
if (received) |
|
45 |
return response; |
|
46 |
} |
|
47 |
return FORKLIFT_ERROR; |
|
48 |
} |
|
49 |
|
|
50 |
int write_addr(char addr, char data) |
|
51 |
{ |
|
52 |
char buf[2]; |
|
53 |
buf[0] = addr; |
|
54 |
buf[1] = data; |
|
55 |
if (i2c_send(FORKLIFT_ADDR, buf, 2)) |
|
56 |
return FORKLIFT_ERROR; |
|
57 |
else |
|
58 |
return 0; |
|
59 |
} |
|
60 |
|
|
61 |
void forklift_init() |
|
62 |
{ |
|
63 |
i2c_init(SCOUT_AVR_ADDR, mrecv, srecv, ssend); |
|
64 |
} |
|
65 |
|
|
66 |
int get_tracking_id() |
|
67 |
{ |
|
68 |
return read_addr(FORKLIFT_TRACKING_ID); |
|
69 |
} |
|
70 |
|
|
71 |
int get_serial_number() |
|
72 |
{ |
|
73 |
return read_addr(FORKLIFT_SERIAL_NUMBER); |
|
74 |
} |
|
75 |
|
|
76 |
int get_height() |
|
77 |
{ |
|
78 |
return read_addr(FORKLIFT_HEIGHT); |
|
79 |
} |
|
80 |
|
|
81 |
int get_height_setpoint() |
|
82 |
{ |
|
83 |
return read_addr(FORKLIFT_HEIGHT_SETPOINT); |
|
84 |
} |
|
85 |
|
|
86 |
int set_height_setpoint(char setpoint) |
|
87 |
{ |
|
88 |
return write_addr(FORKLIFT_HEIGHT_SETPOINT, setpoint); |
|
89 |
} |
trunk/code/projects/forklift_demo/Forklift.h | ||
---|---|---|
1 |
#ifndef _FORKLIFT_H_ |
|
2 |
#define _FORKLIFT_H_ |
|
3 |
|
|
4 |
#define FORKLIFT_ERROR -1 |
|
5 |
|
|
6 |
namespace Forklift |
|
7 |
{ |
|
8 |
void forklift_init(); |
|
9 |
int get_tracking_id(); // 0x41 for all forklifts |
|
10 |
int get_serial_number(); // unique to each forklift |
|
11 |
int get_height(); |
|
12 |
int get_height_setpoint(); |
|
13 |
int set_height_setpoint(int setpoint); |
|
14 |
}; |
|
15 |
|
|
16 |
#endif |
trunk/code/projects/forklift_demo/Makefile | ||
---|---|---|
1 |
# This is the root makefile |
|
2 |
# |
|
3 |
# Make global makefile changes here |
|
4 |
# |
|
5 |
################################### |
|
6 |
|
|
7 |
# Relative path to the root directory (containing lib directory) |
|
8 |
ifndef COLONYROOT |
|
9 |
COLONYROOT := .. |
|
10 |
else |
|
11 |
COLONYROOT := ../$(COLONYROOT) |
|
12 |
endif |
|
13 |
|
|
14 |
# Hey Emacs, this is a -*- makefile -*- |
|
15 |
#---------------------------------------------------------------------------- |
|
16 |
# WinAVR Makefile Template written by Eric B. Weddington, J?rg Wunsch, et al. |
|
17 |
# |
|
18 |
# Released to the Public Domain |
|
19 |
# |
|
20 |
# Additional material for this makefile was written by: |
|
21 |
# Peter Fleury |
|
22 |
# Tim Henigan |
|
23 |
# Colin O'Flynn |
|
24 |
# Reiner Patommel |
|
25 |
# Markus Pfaff |
|
26 |
# Sander Pool |
|
27 |
# Frederik Rouleau |
|
28 |
# |
|
29 |
#---------------------------------------------------------------------------- |
|
30 |
# On command line: |
|
31 |
# |
|
32 |
# make all = Make software. |
|
33 |
# |
|
34 |
# make clean = Clean out built project files. |
|
35 |
# |
|
36 |
# make coff = Convert ELF to AVR COFF. |
|
37 |
# |
|
38 |
# make extcoff = Convert ELF to AVR Extended COFF. |
|
39 |
# |
|
40 |
# make program = Download the hex file to the device, using avrdude. |
|
41 |
# Please customize the avrdude settings below first! |
|
42 |
# |
|
43 |
# make debug = Start either simulavr or avarice as specified for debugging, |
|
44 |
# with avr-gdb or avr-insight as the front end for debugging. |
|
45 |
# |
|
46 |
# make library = Build the library, then make software |
|
47 |
# |
|
48 |
# make demo = copy this directory and all subdirectories to the demos folder |
|
49 |
# |
|
50 |
# make filename.s = Just compile filename.c into the assembler code only. |
|
51 |
# |
|
52 |
# make filename.i = Create a preprocessed source file for use in submitting |
|
53 |
# bug reports to the GCC project. |
|
54 |
# |
|
55 |
# To rebuild project do "make clean" then "make all". |
|
56 |
#---------------------------------------------------------------------------- |
|
57 |
|
|
58 |
#if you want your code to work on the Firefly++ and not Firefly+ |
|
59 |
#then add the -DFFPP line to CDEFS |
|
60 |
CDEFS = |
|
61 |
#-DFFPP |
|
62 |
|
|
63 |
# MCU name |
|
64 |
MCU = atmega128 |
|
65 |
|
|
66 |
# Processor frequency. |
|
67 |
# This will define a symbol, F_CPU, in all source code files equal to the |
|
68 |
# processor frequency. You can then use this symbol in your source code to |
|
69 |
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done |
|
70 |
# automatically to create a 32-bit value in your source code. |
|
71 |
F_CPU = 8000000 |
|
72 |
|
|
73 |
# Output format. (can be srec, ihex, binary) |
|
74 |
FORMAT = ihex |
|
75 |
|
|
76 |
# List C source files here. (C dependencies are automatically generated.) |
|
77 |
SRC = $(wildcard *.c) |
|
78 |
|
|
79 |
# List Assembler source files here. |
|
80 |
# Make them always end in a capital .S. Files ending in a lowercase .s |
|
81 |
# will not be considered source files but generated files (assembler |
|
82 |
# output from the compiler), and will be deleted upon "make clean"! |
|
83 |
# Even though the DOS/Win* filesystem matches both .s and .S the same, |
|
84 |
# it will preserve the spelling of the filenames, and gcc itself does |
|
85 |
# care about how the name is spelled on its command-line. |
|
86 |
ASRC = |
|
87 |
|
|
88 |
# Optimization level, can be [0, 1, 2, 3, s]. |
|
89 |
# 0 = turn off optimization. s = optimize for size. |
|
90 |
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.) |
|
91 |
OPT = s |
|
92 |
|
|
93 |
# Debugging format. |
|
94 |
# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs. |
|
95 |
# AVR Studio 4.10 requires dwarf-2. |
|
96 |
# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run. |
|
97 |
DEBUG = |
|
98 |
|
|
99 |
# Compiler flag to set the C Standard level. |
|
100 |
# c89 = "ANSI" C |
|
101 |
# gnu89 = c89 plus GCC extensions |
|
102 |
# c99 = ISO C99 standard (not yet fully implemented) |
|
103 |
# gnu99 = c99 plus GCC extensions |
|
104 |
CSTANDARD = -std=gnu99 |
|
105 |
|
|
106 |
# Place -D or -U options here |
|
107 |
CDEFS += -DF_CPU=$(F_CPU)UL |
|
108 |
CDEFS += -DFFP |
|
109 |
# for wireless library |
|
110 |
ifdef USE_WIRELESS |
|
111 |
CDEFS += -DROBOT |
|
112 |
endif |
|
113 |
|
|
114 |
# Place -I, -L options here |
|
115 |
CINCS = -I$(COLONYROOT)/code/lib/include/libdragonfly |
|
116 |
CINCS += -L$(COLONYROOT)/code/lib/bin |
|
117 |
ifdef USE_WIRELESS |
|
118 |
CINCS += -I$(COLONYROOT)/code/lib/include/libwireless |
|
119 |
endif |
|
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 = |
|
129 |
# CFLAGS = -g$(DEBUG) |
|
130 |
CFLAGS += $(CDEFS) $(CINCS) |
|
131 |
CFLAGS += -O$(OPT) |
|
132 |
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums |
|
133 |
CFLAGS += -Wall -Wstrict-prototypes |
|
134 |
CFLAGS += -Wa,-adhlns=$(<:.c=.lst) |
|
135 |
CFLAGS += $(CSTANDARD) |
|
136 |
|
|
137 |
#---------------- Assembler Options ---------------- |
|
138 |
# -Wa,...: tell GCC to pass this to the assembler. |
|
139 |
# -ahlms: create listing |
|
140 |
# -gstabs: have the assembler create line number information; note that |
|
141 |
# for use in COFF files, additional information about filenames |
|
142 |
# and function names needs to be present in the assembler source |
|
143 |
# files -- see avr-libc docs [FIXME: not yet described there] |
|
144 |
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs |
|
145 |
|
|
146 |
|
|
147 |
#---------------- Library Options ---------------- |
|
148 |
# Minimalistic printf version |
|
149 |
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min |
|
150 |
|
|
151 |
# Floating point printf version (requires MATH_LIB = -lm below) |
|
152 |
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt |
|
153 |
|
|
154 |
# If this is left blank, then it will use the Standard printf version. |
|
155 |
PRINTF_LIB = |
|
156 |
#PRINTF_LIB = $(PRINTF_LIB_MIN) |
|
157 |
#PRINTF_LIB = $(PRINTF_LIB_FLOAT) |
|
158 |
|
|
159 |
|
|
160 |
# Minimalistic scanf version |
|
161 |
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min |
|
162 |
|
|
163 |
# Floating point + %[ scanf version (requires MATH_LIB = -lm below) |
|
164 |
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt |
|
165 |
|
|
166 |
# If this is left blank, then it will use the Standard scanf version. |
|
167 |
SCANF_LIB = |
|
168 |
#SCANF_LIB = $(SCANF_LIB_MIN) |
|
169 |
#SCANF_LIB = $(SCANF_LIB_FLOAT) |
|
170 |
|
|
171 |
MATH_LIB = -lm |
|
172 |
|
|
173 |
#---------------- External Memory Options ---------------- |
|
174 |
|
|
175 |
# 64 KB of external RAM, starting after internal RAM (ATmega128!), |
|
176 |
# used for variables (.data/.bss) and heap (malloc()). |
|
177 |
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff |
|
178 |
|
|
179 |
# 64 KB of external RAM, starting after internal RAM (ATmega128!), |
|
180 |
# only used for heap (malloc()). |
|
181 |
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff |
|
182 |
|
|
183 |
EXTMEMOPTS = |
|
184 |
|
|
185 |
#---------------- Linker Options ---------------- |
|
186 |
# -Wl,...: tell GCC to pass this to linker. |
|
187 |
# -Map: create map file |
|
188 |
# --cref: add cross reference to map file |
|
189 |
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref |
|
190 |
LDFLAGS += $(EXTMEMOPTS) |
|
191 |
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) |
|
192 |
ifdef USE_WIRELESS |
|
193 |
LDFLAGS += -lwireless |
|
194 |
endif |
|
195 |
LDFLAGS += -ldragonfly |
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
#---------------- Programming Options (avrdude) ---------------- |
|
200 |
|
|
201 |
# Programming hardware: alf avr910 avrisp bascom bsd |
|
202 |
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500 |
|
203 |
# |
|
204 |
# Type: avrdude -c ? |
|
205 |
# to get a full listing. |
|
206 |
# |
|
207 |
AVRDUDE_PROGRAMMER = avrisp |
|
208 |
|
|
209 |
# programmer connected to serial device |
|
210 |
|
|
211 |
AVRDUDE_WRITE_FLASH = -b 57600 -U flash:w:$(TARGET).hex |
|
212 |
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep |
|
213 |
|
|
214 |
|
|
215 |
# Uncomment the following if you want avrdude's erase cycle counter. |
|
216 |
# Note that this counter needs to be initialized first using -Yn, |
|
217 |
# see avrdude manual. |
|
218 |
#AVRDUDE_ERASE_COUNTER = -y |
|
219 |
|
|
220 |
# Uncomment the following if you do /not/ wish a verification to be |
|
221 |
# performed after programming the device. |
|
222 |
#AVRDUDE_NO_VERIFY = -V |
|
223 |
|
|
224 |
# Increase verbosity level. Please use this when submitting bug |
|
225 |
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> |
|
226 |
# to submit bug reports. |
|
227 |
#AVRDUDE_VERBOSE = -v -v |
|
228 |
|
|
229 |
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) |
|
230 |
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY) |
|
231 |
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE) |
|
232 |
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) |
|
233 |
|
|
234 |
#don't check for device signature |
|
235 |
AVRDUDE_FLAGS += -F |
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
#---------------- Debugging Options ---------------- |
|
240 |
|
|
241 |
# For simulavr only - target MCU frequency. |
|
242 |
DEBUG_MFREQ = $(F_CPU) |
|
243 |
|
|
244 |
# Set the DEBUG_UI to either gdb or insight. |
|
245 |
# DEBUG_UI = gdb |
|
246 |
DEBUG_UI = insight |
|
247 |
|
|
248 |
# Set the debugging back-end to either avarice, simulavr. |
|
249 |
DEBUG_BACKEND = avarice |
|
250 |
#DEBUG_BACKEND = simulavr |
|
251 |
|
|
252 |
# GDB Init Filename. |
|
253 |
GDBINIT_FILE = __avr_gdbinit |
|
254 |
|
|
255 |
# When using avarice settings for the JTAG |
|
256 |
JTAG_DEV = /dev/com1 |
|
257 |
|
|
258 |
# Debugging port used to communicate between GDB / avarice / simulavr. |
|
259 |
DEBUG_PORT = 4242 |
|
260 |
|
|
261 |
# Debugging host used to communicate between GDB / avarice / simulavr, normally |
|
262 |
# just set to localhost unless doing some sort of crazy debugging when |
|
263 |
# avarice is running on a different computer. |
|
264 |
DEBUG_HOST = localhost |
|
265 |
|
|
266 |
|
|
267 |
|
|
268 |
#============================================================================ |
|
269 |
|
|
270 |
|
|
271 |
# Define programs and commands. |
|
272 |
SHELL = sh |
|
273 |
CC = avr-g++ |
|
274 |
OBJCOPY = avr-objcopy |
|
275 |
OBJDUMP = avr-objdump |
|
276 |
SIZE = avr-size |
|
277 |
NM = avr-nm |
|
278 |
AVRDUDE = avrdude |
|
279 |
REMOVE = rm -f |
|
280 |
REMOVEDIR = rm -rf |
|
281 |
COPY = cp |
|
282 |
WINSHELL = cmd |
|
283 |
|
|
284 |
|
|
285 |
# Define Messages |
|
286 |
# English |
|
287 |
MSG_ERRORS_NONE = Errors: none |
|
288 |
MSG_BEGIN = -------- begin -------- |
|
289 |
MSG_END = -------- end -------- |
|
290 |
MSG_SIZE_BEFORE = Size before: |
|
291 |
MSG_SIZE_AFTER = Size after: |
|
292 |
MSG_COFF = Converting to AVR COFF: |
|
293 |
MSG_EXTENDED_COFF = Converting to AVR Extended COFF: |
|
294 |
MSG_FLASH = Creating load file for Flash: |
|
295 |
MSG_EEPROM = Creating load file for EEPROM: |
|
296 |
MSG_EXTENDED_LISTING = Creating Extended Listing: |
|
297 |
MSG_SYMBOL_TABLE = Creating Symbol Table: |
|
298 |
MSG_LINKING = Linking: |
|
299 |
MSG_COMPILING = Compiling: |
|
300 |
MSG_ASSEMBLING = Assembling: |
|
301 |
MSG_CLEANING = Cleaning project: |
|
302 |
MSG_LIBRARY_BUILD = Building library: |
|
303 |
MSG_LIBRARY_CHECK = Checking if we need to rebuild the library: |
|
304 |
|
|
305 |
|
|
306 |
|
|
307 |
# Define all object files. |
|
308 |
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) |
|
309 |
|
|
310 |
# Define all listing files. |
|
311 |
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst) |
|
312 |
|
|
313 |
|
|
314 |
# Compiler flags to generate dependency files. |
|
315 |
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d |
|
316 |
|
|
317 |
|
|
318 |
# Combine all necessary flags and optional flags. |
|
319 |
# Add target processor to flags. |
|
320 |
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS) |
|
321 |
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) |
|
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
|
326 |
|
|
327 |
# Default target. |
|
328 |
all: begin gccversion lib sizebefore build sizeafter checksize end |
|
329 |
|
|
330 |
build: elf hex eep lss sym |
|
331 |
|
|
332 |
elf: $(TARGET).elf |
|
333 |
hex: $(TARGET).hex |
|
334 |
eep: $(TARGET).eep |
|
335 |
lss: $(TARGET).lss |
|
336 |
sym: $(TARGET).sym |
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
# Eye candy. |
|
341 |
# AVR Studio 3.x does not check make's exit code but relies on |
|
342 |
# the following magic strings to be generated by the compile job. |
|
343 |
begin: |
|
344 |
@echo |
|
345 |
@echo $(MSG_BEGIN) |
|
346 |
|
|
347 |
end: |
|
348 |
@echo $(MSG_END) |
|
349 |
@echo |
|
350 |
|
|
351 |
|
|
352 |
# Display size of file. |
|
353 |
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex |
|
354 |
ELFSIZE = $(SIZE) -A $(TARGET).elf |
|
355 |
AVRMEM = avr-mem.sh $(TARGET).elf $(MCU) |
|
356 |
|
|
357 |
# Check RAM size (make sure under 4 kB) |
|
358 |
AWK = $(shell if uname -s |grep -i w32 >/dev/null; then echo 'gawk'; else echo 'awk'; fi) |
|
359 |
DATASIZE = avr-size -A $(TARGET).elf | grep 'data' | $(AWK) '{ print $$2 }' > 1.tmp |
|
360 |
BSSSIZE = avr-size -A $(TARGET).elf | grep 'bss' | $(AWK) '{ print $$2 }' > 2.tmp |
|
361 |
ADD = expr `cat 1.tmp` + `cat 2.tmp` > 3.tmp |
|
362 |
CLEANSIZE = rm 1.tmp 2.tmp 3.tmp |
|
363 |
checksize: |
|
364 |
@$(DATASIZE) |
|
365 |
@$(BSSSIZE) |
|
366 |
@$(ADD) |
|
367 |
@if test `cat 3.tmp` -gt 4096; \ |
|
368 |
then echo "RAM size exceeded. Make .data or .bss smaller.";echo;exit 1; \ |
|
369 |
else echo ".data and .bss size fine";echo; fi |
|
370 |
@$(CLEANSIZE) |
|
371 |
|
|
372 |
# Display size before |
|
373 |
sizebefore: |
|
374 |
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \ |
|
375 |
$(AVRMEM) 2>/dev/null; echo; fi |
|
376 |
|
|
377 |
# Display size after |
|
378 |
sizeafter: |
|
379 |
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \ |
|
380 |
$(AVRMEM) 2>/dev/null; echo; fi |
|
381 |
|
|
382 |
|
|
383 |
|
|
384 |
# Display compiler version information. |
|
385 |
gccversion : |
|
386 |
@$(CC) --version |
|
387 |
|
|
388 |
|
|
389 |
# Build the library |
|
390 |
library: |
|
391 |
@echo $(MSG_LIBRARY_BUILD) |
|
392 |
make clean -C $(COLONYROOT)/code/projects/libdragonfly |
|
393 |
make dist -C $(COLONYROOT)/code/projects/libdragonfly |
|
394 |
ifdef USE_WIRELESS |
|
395 |
make clean -C $(COLONYROOT)/code/projects/libwireless/lib |
|
396 |
make dist -C $(COLONYROOT)/code/projects/libwireless/lib |
|
397 |
endif |
|
398 |
|
|
399 |
# Check if library needs to be built |
|
400 |
lib: |
|
401 |
@echo $(MSG_LIBRARY_CHECK) |
|
402 |
make dist -C $(COLONYROOT)/code/projects/libdragonfly |
|
403 |
ifdef USE_WIRELESS |
|
404 |
make dist -C $(COLONYROOT)/code/projects/libwireless/lib |
|
405 |
endif |
|
406 |
|
|
407 |
|
|
408 |
# Program the device. |
|
409 |
program: $(TARGET).hex $(TARGET).eep |
|
410 |
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) |
|
411 |
|
|
412 |
|
|
413 |
# Generate avr-gdb config/init file which does the following: |
|
414 |
# define the reset signal, load the target file, connect to target, and set |
|
415 |
# a breakpoint at main(). |
|
416 |
gdb-config: |
|
417 |
@$(REMOVE) $(GDBINIT_FILE) |
|
418 |
@echo define reset >> $(GDBINIT_FILE) |
|
419 |
@echo SIGNAL SIGHUP >> $(GDBINIT_FILE) |
|
420 |
@echo end >> $(GDBINIT_FILE) |
|
421 |
@echo file $(TARGET).elf >> $(GDBINIT_FILE) |
|
422 |
@echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE) |
|
423 |
ifeq ($(DEBUG_BACKEND),simulavr) |
|
424 |
@echo load >> $(GDBINIT_FILE) |
|
425 |
endif |
|
426 |
@echo break main >> $(GDBINIT_FILE) |
|
427 |
|
|
428 |
debug: gdb-config $(TARGET).elf |
|
429 |
ifeq ($(DEBUG_BACKEND), avarice) |
|
430 |
@echo Starting AVaRICE - Press enter when "waiting to connect" message displays. |
|
431 |
@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \ |
|
432 |
$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT) |
|
433 |
@$(WINSHELL) /c pause |
|
434 |
|
|
435 |
else |
|
436 |
@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \ |
|
437 |
$(DEBUG_MFREQ) --port $(DEBUG_PORT) |
|
438 |
endif |
|
439 |
@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE) |
|
440 |
|
|
441 |
|
|
442 |
|
|
443 |
|
|
444 |
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. |
|
445 |
COFFCONVERT=$(OBJCOPY) --debugging \ |
|
446 |
--change-section-address .data-0x800000 \ |
|
447 |
--change-section-address .bss-0x800000 \ |
|
448 |
--change-section-address .noinit-0x800000 \ |
|
449 |
--change-section-address .eeprom-0x810000 |
|
450 |
|
|
451 |
|
|
452 |
coff: $(TARGET).elf |
|
453 |
@echo |
|
454 |
@echo $(MSG_COFF) $(TARGET).cof |
|
455 |
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof |
|
456 |
|
|
457 |
|
|
458 |
extcoff: $(TARGET).elf |
|
459 |
@echo |
|
460 |
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof |
|
461 |
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof |
|
462 |
|
|
463 |
|
|
464 |
|
|
465 |
# Create final output files (.hex, .eep) from ELF output file. |
|
466 |
%.hex: %.elf |
|
467 |
@echo |
|
468 |
@echo $(MSG_FLASH) $@ |
|
469 |
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ |
|
470 |
|
|
471 |
%.eep: %.elf |
|
472 |
@echo |
|
473 |
@echo $(MSG_EEPROM) $@ |
|
474 |
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ |
|
475 |
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@ |
|
476 |
|
|
477 |
# Create extended listing file from ELF output file. |
|
478 |
%.lss: %.elf |
|
479 |
@echo |
|
480 |
@echo $(MSG_EXTENDED_LISTING) $@ |
|
481 |
$(OBJDUMP) -h -S $< > $@ |
|
482 |
|
|
483 |
# Create a symbol table from ELF output file. |
|
484 |
%.sym: %.elf |
|
485 |
@echo |
|
486 |
@echo $(MSG_SYMBOL_TABLE) $@ |
|
487 |
$(NM) -n $< > $@ |
|
488 |
|
|
489 |
|
|
490 |
|
|
491 |
# Link: create ELF output file from object files. |
|
492 |
.SECONDARY : $(TARGET).elf |
|
493 |
.PRECIOUS : $(OBJ) |
|
494 |
%.elf: $(OBJ) |
|
495 |
@echo |
|
496 |
@echo $(MSG_LINKING) $@ |
|
497 |
$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS) |
|
498 |
|
|
499 |
|
|
500 |
# Compile: create object files from C source files. |
|
501 |
%.o : %.c |
|
502 |
@echo |
|
503 |
@echo $(MSG_COMPILING) $< |
|
504 |
$(CC) -c $(ALL_CFLAGS) $< -o $@ |
|
505 |
|
|
506 |
|
|
507 |
# Compile: create assembler files from C source files. |
|
508 |
%.s : %.c |
|
509 |
$(CC) -S $(ALL_CFLAGS) $< -o $@ |
|
510 |
|
|
511 |
|
|
512 |
# Assemble: create object files from assembler source files. |
|
513 |
%.o : %.S |
|
514 |
@echo |
|
515 |
@echo $(MSG_ASSEMBLING) $< |
|
516 |
$(CC) -c $(ALL_ASFLAGS) $< -o $@ |
|
517 |
|
|
518 |
# Create preprocessed source for use in sending a bug report. |
|
519 |
%.i : %.c |
|
520 |
$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ |
|
521 |
|
|
522 |
|
|
523 |
# Target: clean project. |
|
524 |
clean: begin clean_list end |
|
525 |
|
|
526 |
clean_list : |
|
527 |
@echo |
|
528 |
@echo $(MSG_CLEANING) |
|
529 |
$(REMOVE) $(TARGET).hex |
|
530 |
$(REMOVE) $(TARGET).eep |
|
531 |
$(REMOVE) $(TARGET).cof |
|
532 |
$(REMOVE) $(TARGET).elf |
|
533 |
$(REMOVE) $(TARGET).map |
|
534 |
$(REMOVE) $(TARGET).sym |
|
535 |
$(REMOVE) $(TARGET).lss |
|
536 |
$(REMOVE) $(OBJ) |
|
537 |
$(REMOVE) $(LST) |
|
538 |
$(REMOVE) $(SRC:.c=.s) |
|
539 |
$(REMOVE) $(SRC:.c=.d) |
|
540 |
$(REMOVEDIR) .dep |
|
541 |
|
|
542 |
|
|
543 |
|
|
544 |
# Include the dependency files. |
|
545 |
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) |
|
546 |
|
|
547 |
|
|
548 |
# Listing of phony targets. |
|
549 |
.PHONY : all begin finish end sizebefore sizeafter gccversion \ |
|
550 |
build elf hex eep lss sym coff extcoff \ |
|
551 |
clean clean_list program debug gdb-config |
|
552 |
|
|
553 |
# copy to demo folder |
|
554 |
DEMO_NAME := $(shell sh -c 'echo $${PWD\#\#*/}') |
|
555 |
ECHO := $(shell if uname -s |grep -i w32 >/dev/null; then echo 'echo -e'; else echo 'echo'; fi) |
|
556 |
MAKEFILE_ADD := sh -c '$(ECHO) "\n.PHONY:$(DEMO_NAME)\n$(DEMO_NAME):\n\t@make all program -C $(DEMO_NAME)"'|cat - >> $(COLONYROOT)/../demos/Makefile |
|
557 |
demo: |
|
558 |
@echo "Copying to demo folder..." |
|
559 |
@echo "$(DEMO_NAME)" |
|
560 |
@make clean |
|
561 |
make clean -C $(COLONYROOT)/code/projects/libdragonfly |
|
562 |
make clean -C $(COLONYROOT)/code/projects/libwireless/lib |
|
563 |
@svn mkdir $(COLONYROOT)/../demos/$(DEMO_NAME) |
|
564 |
@svn mkdir $(COLONYROOT)/../demos/$(DEMO_NAME)/src |
|
565 |
@svn copy $(COLONYROOT)/../demos/template/lib $(COLONYROOT)/../demos/$(DEMO_NAME)/ |
|
566 |
@svn copy $(COLONYROOT)/../demos/template/Makefile $(COLONYROOT)/../demos/$(DEMO_NAME)/ |
|
567 |
@svn copy * $(COLONYROOT)/../demos/$(DEMO_NAME)/src/ |
|
568 |
@cp $(COLONYROOT)/../demos/template/src/Makefile $(COLONYROOT)/../demos/$(DEMO_NAME)/src/ |
|
569 |
@svn copy $(COLONYROOT)/code/projects/libdragonfly $(COLONYROOT)/../demos/$(DEMO_NAME)/lib/src/ |
|
570 |
@cp $(COLONYROOT)/../demos/template/dragonflyMakefile $(COLONYROOT)/../demos/$(DEMO_NAME)/lib/src/libdragonfly/Makefile |
|
571 |
@svn copy $(COLONYROOT)/code/projects/libwireless/lib/* $(COLONYROOT)/../demos/$(DEMO_NAME)/lib/src/libwireless/ |
|
572 |
@cp $(COLONYROOT)/../demos/template/wirelessMakefile $(COLONYROOT)/../demos/$(DEMO_NAME)/lib/src/libwireless/Makefile |
|
573 |
@$(MAKEFILE_ADD) |
|
574 |
@echo "Don't forget to commit your new demo folder!" |
Also available in: Unified diff