Subversion Repositories HomeAutomation

Rev

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

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