-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
208 lines (169 loc) · 7.74 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
######### AVR Project Makefile Template #########
###### ######
###### Copyright (C) 2003-2005,Pat Deegan, ######
###### Psychogenic Inc ######
###### All Rights Reserved ######
###### ######
###### You are free to use this code as part ######
###### of your own applications provided ######
###### you keep this copyright notice intact ######
###### and acknowledge its authorship with ######
###### the words: ######
###### ######
###### "Contains software by Pat Deegan of ######
###### Psychogenic Inc (www.psychogenic.com)" ######
###### ######
###### If you use it as part of a web site ######
###### please include a link to our site, ######
###### http://electrons.psychogenic.com or ######
###### http://www.psychogenic.com ######
###### ######
####################################################
MCU = atmega168
PROGRAMMER_MCU = atmega168
F_CPU = 8000000
AVRDUDE_PORT = /dev/tty.usbserial-A900a50a
# exectuables
CC=avr-gcc
OBJCOPY=avr-objcopy
OBJDUMP=avr-objdump
SIZE=avr-size
AVRDUDE=avrdude
REMOVE=rm -f
# linker
LDFLAGS=-Llib -Wl,-Map,$(TRG).map -mmcu=$(MCU) -Llib -lm $(LIBS)
# assembler
ASMFLAGS =-I. $(INC) -mmcu=$(MCU) \
-x assembler-with-cpp \
-Wa,-gstabs,-ahlms=$(firstword \
$(<:.S=.lst) $(<.s=.lst))
# compiler
CFLAGS=-I. $(INC) -g -mmcu=$(MCU) -Os -DF_CPU=$(F_CPU) \
-fpack-struct -fshort-enums \
-funsigned-bitfields -funsigned-char \
-Wall -Wstrict-prototypes -std=gnu99 \
-Wa,-ahlms=$(firstword \
$(filter %.lst, $(<:.c=.lst)))
.SUFFIXES : .c .cc .cpp .C .o .out .s .S \
.hex .ee.hex .h .hh .hpp
all: bin/Shwatt.out
MYOBJECTS = Shwatt.o Globals.o ShmittTrigger.o
MyLibs = lib/libMyMath.a lib/libCalibrate.a lib/libDAQ.a
#####################################################################################################
##################### Build math libraries ########################
#####################################################################################################
MATHSRC = Math/FastSqrt.c Math/FractSupport.c Math/TrigLookup.c
MATHOBJ = $(MATHSRC:.c=.o)
lib/libMyMath.a: $(MATHOBJ) Math/AbsFract.o
avr-ar rcs $@ $(MATHOBJ) Math/AbsFract.o
Math/AbsFract.o: Math/AbsFract.S Math/fixdef.h Math/asmdef.h
$(CC) $(ASMFLAGS) -c Math/AbsFract.S -o $@
#dependencies
Math/TrigLookup.o: Math/TrigLookup.h
Math/FastSqrt.o: Math/TrigLookup.h
Math/FractSupport.o: Math/FractSupport.h
#####################################################################################################
##################### Build DAQ libraries ########################
#####################################################################################################
DAQSRC = DAQ/Clock.c DAQ/ShwattDAQ.c DAQ/ShmittTrigger.c
DAQOBJ = $(DAQSRC:.c=.o)
lib/libDAQ.a: $(DAQOBJ)
avr-ar rcs $@ $(DAQOBJ)
$(DAQOBJ): DAQ/Clock.h DAQ/ShwattDAQ.h Core/ShwattGlobals.h Core/HardwareData.h Math/FractSupport.h
#####################################################################################################
##################### Build XBee libraries ########################
#####################################################################################################
XBEESRC = XBee/XBeeRX.c XBee/XBeeCommands.c XBee/XBeeApiTx.c XBee/XBeeApiTxFixedPoint.c \
XBee/XBeeSerialTX.c
XBEEOBJ = $(XBEESRC:.c=.o)
lib/libXBee.a: $(XBEEOBJ)
avr-ar rcs $@ $(XBEEOBJ)
$(XBEEOBJ): Math/FractSupport.h Core/ShwattGlobals.h XBee/XBee.h Core/Parameters.h
#####################################################################################################
##################### Calibration libraries ########################
#####################################################################################################
CALIBSRC = Calibration/Calibrate.c Calibration/CalibrateAverageVariance.c \
Calibration/checkSideUp.c Calibration/FakeCalibrate.c
CALIBOBJ = $(CALIBSRC:.c=.o)
lib/libCalib.a: $(CALIBOBJ)
avr-ar rcs $@ $(CALIBOBJ)
$(CALIBOBJ): Calibration/Calibrate.h Core/ShwattGlobals.h \
Math/FractSupport.h DAQ/Clock.h Algorithms/Kalman.h \
DAQ/ShwattDAQ.h Core/Parameters.h
#####################################################################################################
##################### Algorithm libraries ########################
#####################################################################################################
ALGOSRC = Algorithms/Kalman.c
ALGOOBJ = $(ALGOSRC:.c=.o)
lib/libAlgos.a: $(ALGOOBJ)
avr-ar rcs $@ $(ALGOOBJ)
$(ALGOOBJ): Algorithms/Kalman.h Core/ShwattGlobals.h Core/HardwareData.h Math/TrigLookup.h
#####################################################################################################
##################### Code entry point ########################
#####################################################################################################
## Main objects ##
Core/ShwattGlobals.o: Core/ShwattGlobals.h Core/HardwareData.h Core/Parameters.h
Shwatt.o: Calibration/Calibrate.h \
DAQ/ShmittTrigger.h \
Algorithms/Kalman.h \
XBee/XBee.h \
Math/FractSupport.h \
DAQ/Clock.h \
Core/ShwattGlobals.h
all: bin/Shwatt.out
#####################################################################################################
##################### Link everything into executable
#####################################################################################################
MYLIBS = lib/libCalib.a lib/libXBee.a lib/libDAQ.a lib/libMyMath.a lib/libAlgos.a
LIBS = -lCalib -lXBee -lDAQ -lAlgos -lMyMath
MYOBJS = Core/ShwattGlobals.o Shwatt.o
ALLDEPS = $(MYLIBS) $(MYOBJS)
# link everything into executable
bin/Shwatt.out: $(ALLDEPS)
$(CC) $(LDFLAGS) -o bin/Shwatt.out $(MYOBJS) $(LIBS)
# format into hex for upload
hex: bin/Shwatt.hex bin/Shwatt.ee.hex
#####################################################################################################
##################### Program device
#####################################################################################################
AVRDUDE_PROGRAMMERID=stk500v1
UPLOAD_RATE = 19200
write: hex
$(AVRDUDE) -V -F -C /Applications/Arduino/hardware/tools/avr/etc/avrdude.conf -c $(AVRDUDE_PROGRAMMERID) \
-p $(PROGRAMMER_MCU) -P $(AVRDUDE_PORT) -e \
-U flash:w:bin/Shwatt.hex -b $(UPLOAD_RATE)
size: bin/Shwatt.out
avr-size bin/Shwatt.out
stats: bin/Shwatt.out
$(OBJDUMP) -h bin/Shwatt.out
asm: bin/Shwatt.out
rm -rf DisAsm.s
$(OBJDUMP) -d bin/Shwatt.out > DisAsm.s
run: hex
open Monitor/Monitor.py -a /Applications/NodeBox/NodeBox.app
#### Compile object from source
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
#### Generating hex files ####
# hex files from elf
##### Generating a gdb initialisation file #####
HEXFORMAT=ihex
.out.hex:
$(OBJCOPY) -j .text \
-j .data \
-O $(HEXFORMAT) $< $@
.out.ee.hex:
$(OBJCOPY) -j .eeprom \
--change-section-lma .eeprom=0 \
-O $(HEXFORMAT) $< $@
#####################################################################################################
##################### Clean up
#####################################################################################################
clean:
rm -rf **/*.o
rm -rf **/*.lst
rm -rf lib/*.a
rm -rf bin/*
rm -rf Shwatt.o
rm -rf Shwatt.lst
rm -rf DisAsm.s