Subversion Repositories HomeAutomation

Rev

Rev 387 | Rev 392 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 387 Rev 388
Line 1... Line 1...
1
PRG            = main
1
include bios.inc
2
OBJ            = main.o\
-
 
3
				../lib/src/actuator/rc_servo.o\
-
 
4
				../lib/src/sensor/tc1047/tc1047.o\
-
 
5
 
2
 
6
MCU_TARGET     = atmega88
-
 
7
OPTIMIZE       = -Os -mcall-prologues
-
 
8
# grep bios.map for __bios_ram_end to retreive this value
-
 
9
# In the future, this should be automatically inserted into *_app.ld at every bios compilation
-
 
10
BIOS_RAM_END   = 0x0080012a
-
 
11
#0x0080015d
-
 
12
ifeq ($(MCU_TARGET),atmega88)
-
 
13
	#uncomment this line if you're using m88, remove line when gcc-bug fixed
-
 
14
	EXTRA_LD        = avr-ld -m avr4 -o $(PRG).elf /usr/avr/lib/avr4/crtm88.o -L/usr/lib/gcc/avr/4.1.0/avr4 -L/usr/lib/gcc/avr/4.1.0/avr4 -L/usr/avr/lib/avr4 -Map $(PRG).map -L../AVR-Bios --defsym __bios_ram_end=$(BIOS_RAM_END) -T$(MCU_TARGET)_app.ld $(PRG).o -lgcc -lc -lgcc
3
# Target file name (without extension).
15
endif
-
 
16
BIOS_RAM_END   = 0x0080012a
-
 
17
 
-
 
18
DEFS           = -I../AVR-Bios\
-
 
19
				-I../lib/funcdefs\
-
 
20
				-I../lib/src/actuator\
-
 
21
				-I../lib/src/sensor/tc1047\
-
 
22
 
-
 
23
LIBS           =
4
TARGET = main
24
 
-
 
25
# You should not have to change anything below here.
-
 
26
 
-
 
27
CC             = avr-gcc
-
 
28
 
-
 
29
# Override is only needed by avr-lib build system.
-
 
30
 
-
 
31
override CFLAGS        = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
-
 
32
override LDFLAGS       = -v -Wl,-Map,$(PRG).map,-L../AVR-Bios,--defsym,__bios_ram_end=$(BIOS_RAM_END),-T$(MCU_TARGET)_app.ld
-
 
33
override ASFLAGS       = -x assembler-with-cpp -Wa,-gstabs -mmcu=$(MCU_TARGET) $(DEFS)
-
 
34
 
5
 
-
 
6
LIBDIR = ../avr-lib
-
 
7
 
-
 
8
# List C source files here. (C dependencies are automatically generated.)
-
 
9
CSRC =	$(TARGET).c\
-
 
10
		$(LIBDIR)/drivers/timer/timebase.c\
-
 
11
		$(LIBDIR)/drivers/uart/serial.c\
-
 
12
		$(LIBDIR)/drivers/uart/uart.c\
-
 
13
		$(LIBDIR)/drivers/mcu/mcu.c\
-
 
14
		../lib/src/sensor/tc1047/tc1047.c\
-
 
15
		../lib/src/actuator/rc_servo.c
-
 
16
 
-
 
17
# List Assembler source files here.
-
 
18
# Make them always end in a capital .S.  Files ending in a lowercase .s
-
 
19
# will not be considered source files but generated files (assembler
-
 
20
# output from the compiler), and will be deleted upon "make clean"!
-
 
21
# Even though the DOS/Win* filesystem matches both .s and .S the same,
-
 
22
# it will preserve the spelling of the filenames, and gcc itself does
-
 
23
# care about how the name is spelled on its command-line.
-
 
24
ASRC = 
-
 
25
 
-
 
26
 
-
 
27
# Optimization level, can be [0, 1, 2, 3, s]. 
-
 
28
# 0 = turn off optimization. s = optimize for size.
-
 
29
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
-
 
30
OPT = s
-
 
31
#OPT = 3
-
 
32
 
-
 
33
# Debugging format.
-
 
34
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
-
 
35
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
-
 
36
DEBUG = stabs
-
 
37
#DEBUG = dwarf-2
-
 
38
 
-
 
39
# List any extra directories to look for include files here.
-
 
40
#     Each directory must be seperated by a space.
-
 
41
EXTRAINCDIRS = $(LIBDIR)\
-
 
42
		../lib/funcdefs\
-
 
43
		../lib/src/actuator\
-
 
44
		../lib/src/sensor/tc1047\
-
 
45
 
-
 
46
# Compiler flag to set the C Standard level.
-
 
47
# c89   - "ANSI" C
-
 
48
# gnu89 - c89 plus GCC extensions
-
 
49
# c99   - ISO C99 standard (not yet fully implemented)
-
 
50
# gnu99 - c99 plus GCC extensions
-
 
51
CSTANDARD = -std=gnu99
-
 
52
 
-
 
53
# Place -D or -U options here
-
 
54
CDEFS =
-
 
55
 
-
 
56
# Place -I options here
-
 
57
CINCS =
-
 
58
 
-
 
59
 
-
 
60
# Compiler flags.
-
 
61
#  -g*:          generate debugging information
-
 
62
#  -O*:          optimization level
-
 
63
#  -f...:        tuning, see GCC manual and avr-libc documentation
-
 
64
#  -Wall...:     warning level
-
 
65
#  -Wa,...:      tell GCC to pass this to the assembler.
-
 
66
#    -adhlns...: create assembler listing
-
 
67
CFLAGS = -mmcu=$(MCU) -I.
-
 
68
CFLAGS += -g$(DEBUG)
-
 
69
CFLAGS += $(CDEFS) $(CINCS)
-
 
70
CFLAGS += -O$(OPT)
-
 
71
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
-
 
72
CFLAGS += -Wall -Wstrict-prototypes
-
 
73
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
-
 
74
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
-
 
75
CFLAGS += $(CSTANDARD)
-
 
76
 
-
 
77
 
-
 
78
 
-
 
79
# Assembler flags.
-
 
80
#  -Wa,...:   tell GCC to pass this to the assembler.
-
 
81
#  -ahlms:    create listing
-
 
82
#  -gstabs:   have the assembler create line number information; note that
-
 
83
#             for use in COFF files, additional information about filenames
-
 
84
#             and function names needs to be present in the assembler source
-
 
85
#             files -- see avr-libc docs [FIXME: not yet described there]
-
 
86
##ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
-
 
87
ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp
-
 
88
ASFLAGS += -Wa,-adhlns=$(<:.S=.lst),-g$(DEBUG)
-
 
89
 
-
 
90
 
-
 
91
#Additional libraries.
-
 
92
 
-
 
93
# Minimalistic printf version
-
 
94
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
-
 
95
 
-
 
96
# Floating point printf version (requires MATH_LIB = -lm below)
-
 
97
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
-
 
98
 
-
 
99
PRINTF_LIB = 
-
 
100
 
-
 
101
# Minimalistic scanf version
-
 
102
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
-
 
103
 
-
 
104
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
-
 
105
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
-
 
106
 
-
 
107
SCANF_LIB = 
-
 
108
 
-
 
109
MATH_LIB = -lm
-
 
110
 
-
 
111
# External memory options
-
 
112
 
-
 
113
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
-
 
114
# used for variables (.data/.bss) and heap (malloc()).
-
 
115
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
-
 
116
 
-
 
117
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
-
 
118
# only used for heap (malloc()).
-
 
119
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
-
 
120
 
-
 
121
EXTMEMOPTS =
-
 
122
 
-
 
123
BIOSOPTS = -Wl,-L.,-Tdata,$(BIOS_RAM_END) -lbios
-
 
124
 
-
 
125
# Linker flags.
-
 
126
#  -Wl,...:     tell GCC to pass this to linker.
-
 
127
#    -Map:      create map file
-
 
128
#    --cref:    add cross reference to  map file
-
 
129
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
-
 
130
LDFLAGS += $(EXTMEMOPTS)
-
 
131
LDFLAGS += $(BIOSOPTS)
-
 
132
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
-
 
133
 
-
 
134
# ---------------------------------------------------------------------------
-
 
135
 
-
 
136
# Define directories, if needed.
-
 
137
DIRAVR = c:/progra~1/winavr
-
 
138
DIRAVRBIN = $(DIRAVR)/bin
-
 
139
DIRAVRUTILS = $(DIRAVR)/utils/bin
-
 
140
DIRINC = .
-
 
141
DIRLIB = $(DIRAVR)/avr/lib
-
 
142
 
-
 
143
 
-
 
144
# Define programs and commands.
-
 
145
SHELL = sh
-
 
146
CC = avr-gcc
35
OBJCOPY        = avr-objcopy
147
OBJCOPY = avr-objcopy
36
OBJDUMP        = avr-objdump
148
OBJDUMP = avr-objdump
37
SIZE           = avr-size
149
SIZE = avr-size
38
SZFLAGS        = 
-
 
39
UPLOAD         = avrdude
-
 
40
ULFLAGS        = -p $(MCU_TARGET) -D -P /dev/ttyUSB0 -c avrispv2 -b 115200 -U flash:w:$(PRG).hex
-
 
41
# -D disables erase!
-
 
42
 
-
 
43
default: $(PRG).elf lst text
-
 
44
	@$(SIZE) $(SZFLAGS) $(PRG).elf
-
 
45
 
-
 
46
all: $(PRG).elf lst text eeprom
-
 
47
 
-
 
48
$(PRG).elf: $(OBJ)
-
 
49
ifeq ($(MCU_TARGET),atmega88)
-
 
50
	#remove this workaround when gcc-bug fixed
-
 
51
	avr-ld -m avr4 -o $(PRG).elf /usr/avr/lib/avr4/crtm88.o -L/usr/lib/gcc/avr/4.1.0/avr4 -L/usr/lib/gcc/avr/4.1.0/avr4 -L/usr/avr/lib/avr4 -Map $(PRG).map -L../AVR-Bios --defsym __bios_ram_end=$(BIOS_RAM_END) -T$(MCU_TARGET)_app.ld $(OBJ) -lgcc -lc -lgcc
-
 
52
else
-
 
53
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
-
 
54
endif
-
 
55
 
-
 
56
clean:
150
NM = avr-nm
57
	rm -rf *.o $(PRG).elf *.eps *.png *.pdf *.bak 
-
 
58
	rm -rf *.lst *.map $(EXTRA_CLEAN_FILES)
-
 
59
 
-
 
60
lst:  $(PRG).lst
151
REMOVE = rm -f
61
 
-
 
62
%.lst: %.elf
152
COPY = cp
63
	$(OBJDUMP) -h -S $< > $@
-
 
64
 
-
 
65
# Rules for building the .text rom images
-
 
66
 
-
 
67
text: hex bin srec
-
 
68
 
-
 
69
hex:  $(PRG).hex
-
 
70
bin:  $(PRG).bin
-
 
71
srec: $(PRG).srec
-
 
72
 
153
 
-
 
154
 
-
 
155
 
-
 
156
 
-
 
157
# Define Messages
-
 
158
# English
-
 
159
MSG_ERRORS_NONE = Errors: none
-
 
160
MSG_BEGIN = -------- begin --------
-
 
161
MSG_END = --------  end  --------
-
 
162
MSG_SIZE_BEFORE = Size before: 
-
 
163
MSG_SIZE_AFTER = Size after:
-
 
164
MSG_COFF = Converting to AVR COFF:
-
 
165
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
-
 
166
MSG_FLASH = Creating load file for Flash:
-
 
167
MSG_EEPROM = Creating load file for EEPROM:
-
 
168
MSG_EXTENDED_LISTING = Creating Extended Listing:
-
 
169
MSG_SYMBOL_TABLE = Creating Symbol Table:
-
 
170
MSG_LINKING = Linking:
-
 
171
MSG_COMPILING = Compiling:
-
 
172
MSG_ASSEMBLING = Assembling:
-
 
173
MSG_DEPEND = Generating dependencies:
-
 
174
MSG_CLEANING = Cleaning project:
-
 
175
 
-
 
176
 
-
 
177
 
-
 
178
 
-
 
179
# Define all object files.
-
 
180
OBJ = $(CSRC:.c=.o) $(ASRC:.S=.o) 
-
 
181
 
-
 
182
# Define all listing files.
-
 
183
LST = $(ASRC:.S=.lst) $(CSRC:.c=.lst)
-
 
184
 
-
 
185
 
-
 
186
# Compiler flags to generate dependency files.
-
 
187
### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
-
 
188
GENDEPFLAGS = -M -MG -MP -MT "$(<:.c=.o) $@" -MF $@
-
 
189
 
-
 
190
# Combine all necessary flags and optional flags.
-
 
191
# Add target processor to flags.
-
 
192
#ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
-
 
193
#ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
-
 
194
 
-
 
195
 
-
 
196
 
-
 
197
 
-
 
198
 
-
 
199
# Default target.
-
 
200
all: begin sizebefore build sizeafter finished end
-
 
201
 
-
 
202
build: elf hex eep lss sym
-
 
203
 
-
 
204
elf: $(TARGET).elf
-
 
205
hex: $(TARGET).hex
-
 
206
eep: $(TARGET).eep
-
 
207
lss: $(TARGET).lss 
-
 
208
sym: $(TARGET).sym
-
 
209
config: config.h
-
 
210
 
-
 
211
 
-
 
212
# Eye candy.
-
 
213
# AVR Studio 3.x does not check make's exit code but relies on
-
 
214
# the following magic strings to be generated by the compile job.
-
 
215
begin:
-
 
216
	@echo
-
 
217
	@echo $(MSG_BEGIN)
-
 
218
 
-
 
219
finished:
-
 
220
	@echo $(MSG_ERRORS_NONE)
-
 
221
 
-
 
222
end:
-
 
223
	@echo $(MSG_END)
-
 
224
	@echo
-
 
225
 
-
 
226
 
-
 
227
# Display size of file.
-
 
228
HEXSIZE = $(SIZE) --target=ihex $(TARGET).hex
-
 
229
ELFSIZE = $(SIZE) $(TARGET).elf
-
 
230
sizebefore:
-
 
231
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
-
 
232
 
-
 
233
sizeafter:
-
 
234
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
-
 
235
 
-
 
236
 
-
 
237
# Generate config.h from bios.inc and config.inc
-
 
238
config.h: bios.inc config.inc
-
 
239
	@echo Generating $@
-
 
240
	@echo "/* This file is automatically generated. Do not edit. */\n" > $@
-
 
241
	@cat $^ | awk 'BEGIN { FS="="; print "#ifndef CONFIG_H_\n#define CONFIG_H_\n" } /^[^#].*=.*/ { print "#define "$$1,$$2 } END { print "\n#endif /*CONFIG_H_*/" }' >> $@
-
 
242
 
-
 
243
# Display compiler version information.
-
 
244
gccversion : 
-
 
245
	@$(CC) --version
-
 
246
 
-
 
247
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
-
 
248
COFFCONVERT=$(OBJCOPY) --debugging \
-
 
249
--change-section-address .data-0x800000 \
-
 
250
--change-section-address .bss-0x800000 \
-
 
251
--change-section-address .noinit-0x800000 \
-
 
252
--change-section-address .eeprom-0x810000 
-
 
253
 
-
 
254
 
-
 
255
coff: $(TARGET).elf
-
 
256
	@echo
-
 
257
	@echo $(MSG_COFF) $(TARGET).cof
-
 
258
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
-
 
259
 
-
 
260
 
-
 
261
extcoff: $(TARGET).elf
-
 
262
	@echo
-
 
263
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
-
 
264
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
-
 
265
 
-
 
266
 
-
 
267
 
-
 
268
# Create final output files (.hex, .eep) from ELF output file.
73
%.hex: %.elf
269
%.hex: %.elf
-
 
270
	@echo
-
 
271
	@echo $(MSG_FLASH) $@
74
	$(OBJCOPY) -j .text -j .data -O ihex $< $@
272
	$(OBJCOPY) -j .text -j .data -O ihex $< $@
75
 
273
 
76
%.srec: %.elf
274
%.eep: %.elf
-
 
275
	@echo
-
 
276
	@echo $(MSG_EEPROM) $@
-
 
277
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
77
	$(OBJCOPY) -j .text -j .data -O srec $< $@
278
	--change-section-lma .eeprom=0 -O ihex $< $@
78
 
279
 
-
 
280
# Create extended listing file from ELF output file.
79
%.bin: %.elf
281
%.lss: %.elf
-
 
282
	@echo
-
 
283
	@echo $(MSG_EXTENDED_LISTING) $@
80
	$(OBJCOPY) -j .text -j .data -O binary $< $@
284
	$(OBJDUMP) -h -S $<; >; $@
-
 
285
 
-
 
286
# Create a symbol table from ELF output file.
-
 
287
%.sym: %.elf
-
 
288
	@echo
-
 
289
	@echo $(MSG_SYMBOL_TABLE) $@
-
 
290
	$(NM) -n $< > $@
-
 
291
 
81
 
292
 
82
# Rules for uploading rom images to flash
-
 
83
 
293
 
-
 
294
# Link: create ELF output file from object files.
-
 
295
.SECONDARY : $(TARGET).elf
-
 
296
.PRECIOUS : $(OBJ)
-
 
297
ifneq (,$(filter atmega88 atmega168, $(MCU)))
84
install: hex
298
%.elf: $(OBJ)
-
 
299
	@echo
-
 
300
	@echo $(MSG_LINKING) $@
-
 
301
	@echo GCC bug workaround for ATmega88/ATmega168:
-
 
302
	eval $$($(CC) -v $(CFLAGS) -o $@ $^ $(LDFLAGS) 2>&1 | awk '{ if (gsub("0x800100","$(BIOS_RAM_END)") == 1) print }')
-
 
303
else
-
 
304
%.elf: $(OBJ)
-
 
305
	@echo
-
 
306
	@echo $(MSG_LINKING) $@
85
	$(UPLOAD) $(ULFLAGS)
307
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
-
 
308
endif
86
 
309
 
87
# Rules for building the .eeprom rom images
310
# Compile: create object files from C source files.
-
 
311
%.o : %.c
-
 
312
	@echo
-
 
313
	@echo $(MSG_COMPILING) $<
-
 
314
	$(CC) -c $(CFLAGS) $< -o $@ 
88
 
315
 
89
eeprom: ehex ebin esrec
-
 
90
 
316
 
91
ehex:  $(PRG)_eeprom.hex
317
# Compile: create assembler files from C source files.
92
ebin:  $(PRG)_eeprom.bin
318
%.s : %.c
93
esrec: $(PRG)_eeprom.srec
319
	$(CC) -S $(CFLAGS) $< -o $@
94
 
320
 
95
%_eeprom.hex: %.elf
-
 
96
	$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
-
 
97
 
321
 
-
 
322
# Assemble: create object files from assembler source files.
98
%_eeprom.srec: %.elf
323
%.o : %.S
-
 
324
	@echo
-
 
325
	@echo $(MSG_ASSEMBLING) $<
99
	$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@
326
	$(CC) -c $(ASFLAGS) $< -o $@
100
 
327
 
-
 
328
# Depends: create dependency files from c source files.
101
%_eeprom.bin: %.elf
329
%.d : %.c
-
 
330
	@echo $(MSG_DEPEND) $<
102
	$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@
331
	@$(CC) -c $(CFLAGS) $(GENDEPFLAGS) $<
103
 
332
 
104
# Every thing below here is used by avr-libc's build system and can be ignored
333
# Target: clean project.
105
# by the casual user.
334
clean: begin clean_list finished end
106
 
335
 
-
 
336
clean_list :
-
 
337
	@echo
-
 
338
	@echo $(MSG_CLEANING)
107
FIG2DEV                 = fig2dev
339
	$(REMOVE) $(TARGET).hex
108
EXTRA_CLEAN_FILES       = *.hex *.bin *.srec
340
	$(REMOVE) $(TARGET).eep
-
 
341
	$(REMOVE) $(TARGET).obj
-
 
342
	$(REMOVE) $(TARGET).cof
-
 
343
	$(REMOVE) $(TARGET).elf
-
 
344
	$(REMOVE) $(TARGET).map
-
 
345
	$(REMOVE) $(TARGET).obj
-
 
346
	$(REMOVE) $(TARGET).a90
-
 
347
	$(REMOVE) $(TARGET).sym
-
 
348
	$(REMOVE) $(TARGET).lnk
-
 
349
	$(REMOVE) $(TARGET).lss
-
 
350
	$(REMOVE) $(OBJ)
-
 
351
	$(REMOVE) $(LST)
-
 
352
	$(REMOVE) $(CSRC:.c=.s)
-
 
353
	$(REMOVE) $(CSRC:.c=.d)
-
 
354
	$(REMOVE) -r .dep
-
 
355
	$(REMOVE) config.h
109
 
356
 
110
dox: eps png pdf
-
 
111
 
357
 
112
eps: $(PRG).eps
-
 
113
png: $(PRG).png
-
 
114
pdf: $(PRG).pdf
-
 
115
 
358
 
116
%.eps: %.fig
359
# Include the dependency files.
117
	$(FIG2DEV) -L eps $< $@
360
-include $(CSRC:%.c=%.d)
118
 
361
 
119
%.pdf: %.fig
-
 
120
	$(FIG2DEV) -L pdf $< $@
-
 
121
 
362
 
122
%.png: %.fig
363
# Listing of phony targets.
-
 
364
.PHONY : all begin finish end sizebefore sizeafter gccversion \
123
	$(FIG2DEV) -L png $< $@
365
build elf hex eep lss sym config coff extcoff \
-
 
366
clean clean_list program programlock programinit
124
 
367