Subversion Repositories HomeAutomation

Rev

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

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