summaryrefslogtreecommitdiffstats
path: root/pressure_control/firmware/Makefile
blob: 2b21b8e58d0449953372a2d4382be2fe6cf1d432 (plain)
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
ARCH		?= atmega8
AVRDUDE_ARCH	?= m8
AVRDUDE		?= avrdude
AVRDUDE_SPEED	?= 1
PROGRAMMER	?= avrisp2
PROGPORT	?= usb

CC		= avr-gcc
OBJCOPY		= avr-objcopy
SIZE		= avr-size

V		= @
Q		= $(V:1=)
QUIET_CC	= $(Q:@=@echo '     CC       '$@;)$(CC)
QUIET_OBJCOPY	= $(Q:@=@echo '     OBJCOPY  '$@;)$(OBJCOPY)
QUIET_SIZE	= $(Q:@=@echo '     SIZE     '$@;)$(SIZE)

CFLAGS		= -mmcu=$(ARCH) -std=gnu99 -g0 -O2 -Wall
CFLAGS		+= "-Dinline=inline __attribute__((__always_inline__))"


OBJECTS = main.o util.o valves.o sensor.o remote.o
NAME	= pressure_control

BIN	= $(NAME).bin
HEX	= $(NAME).hex
EEP	= $(NAME).eep.hex
FUSES	= $(NAME).fuses.bin

all: $(HEX) $(FUSES)

main.o: util.h calibration.h valves.h sensor.h remote.h main.h

util.o: util.h calibration.h

valves.o: util.h valves.h main.h

sensor.o: util.h sensor.h

remote.o: util.h remote.h calibration.h main.h valves.h

%.s: %.c
	$(QUIET_CC) $(CFLAGS) -S $*.c

%.o: %.c
	$(QUIET_CC) -o $@ -c $(CFLAGS) $<

$(BIN): $(OBJECTS)
	$(QUIET_CC) $(CFLAGS) -o $(BIN) $(OBJECTS) $(LDFLAGS)

$(HEX): $(BIN)
	$(QUIET_OBJCOPY) -R.eeprom -R.fuse -O ihex $(BIN) $(HEX)
	$(QUIET_OBJCOPY) -j.eeprom --set-section-flags=.eeprom="alloc,load" \
			 --change-section-lma .eeprom=0 -O ihex $(BIN) $(EEP)
	$(QUIET_SIZE) $(BIN)

avrdude:
	$(AVRDUDE) -B $(AVRDUDE_SPEED) -p $(AVRDUDE_ARCH) \
	 -c $(PROGRAMMER) -P $(PROGPORT) -t

install_flash:
	$(AVRDUDE) -B $(AVRDUDE_SPEED) -p $(AVRDUDE_ARCH) \
	 -c $(PROGRAMMER) -P $(PROGPORT) -U flash:w:$(HEX)

install_eeprom:
	$(AVRDUDE) -B $(AVRDUDE_SPEED) -p $(AVRDUDE_ARCH) \
	 -c $(PROGRAMMER) -P $(PROGPORT) -U eeprom:w:$(EEP)

install: all install_flash install_eeprom

# Reset the microcontroller through avrdude
reset:
	$(AVRDUDE) -B $(AVRDUDE_SPEED) -p $(AVRDUDE_ARCH) \
	 -c $(PROGRAMMER) -P $(PROGPORT) \
	 -U signature:r:/dev/null:i -q -q

$(FUSES): $(BIN)
	$(QUIET_OBJCOPY) -j.fuse -O binary $(BIN) $(FUSES)

writefuses: $(FUSES)
	@echo Low fuse is:  $$(hexdump -e '1/1 "0x%02X "' $(FUSES) | cut -d ' ' -f 1)
	@echo High fuse is: $$(hexdump -e '1/1 "0x%02X "' $(FUSES) | cut -d ' ' -f 2)
	$(AVRDUDE) -B 100 -p $(AVRDUDE_ARCH) \
	 -c $(PROGRAMMER) -P $(PROGPORT) -q -q \
	 -U lfuse:w:$$(hexdump -e '1/1 "0x%02X "' $(FUSES) | cut -d ' ' -f 1):m \
	 -U hfuse:w:$$(hexdump -e '1/1 "0x%02X "' $(FUSES) | cut -d ' ' -f 2):m

clean:
	-rm -f *~ *.o $(BIN)

distclean: clean
	-rm -f *.s $(HEX) $(EEP) $(FUSES)

help:
	@echo "Makefile"
	@echo ""
	@echo "Targets:"
	@echo "  all       - build the firmware (default target)"
	@echo "  clean     - remove object files"
	@echo "  distclean - remove object, binary and hex files"
	@echo ""
	@echo "Targets that operate on the device through avrdude:"
	@echo "  install   - flash the program code"
	@echo "  writefuse - write the fuse bits"
	@echo "  reset     - pull the external device reset pin"
	@echo "  avrdude   - run avrdude in interactive mode"
	@echo ""
	@echo "Generic targets:"
	@echo "  *.s       - create an assembly file from a *.c file"
bues.ch cgit interface