view Makefile @ 5:1a405bda2ffe

rewrite gpib using state machine instead of procedural code, add proper timeout, command queueing, several new commands, improve hardcopy utility
author Frank Kingswood <frank@kingswood-consulting.co.uk>
date Sat, 29 Mar 2014 23:23:58 +0000
parents a70e0a8ac73e
children acbd0ddd002b
line wrap: on
line source

2 # export PATH:=/usr/local/avr/bin:$(PATH)
3 # export LIBRARY_PATH:=/usr/local/avr/lib
5 CPU:=atmega32u4
7 CFLAGS:=-mmcu=$(CPU) -mtiny-stack -O3 -Os -DCPU=$(CPU) -DF_CPU=16 \
8 -Wall -Wno-uninitialized -Werror \
9 -foptimize-sibling-calls -fpeephole -fpeephole2 \
10 --param max-unrolled-insns=3 --param max-unroll-times=3 \
11 --param inline-unit-growth=1 -fno-tree-scev-cprop -fsplit-wide-types
13 # http://www.tty1.net/blog/2008/avr-gcc-optimisations_en.html
14 LDFLAGS:=$(CFLAGS) -Wl,--relax
16 ifneq "$(LIST)" ""
17 _LIST=-g -Wa,-ahlmns
18 endif
20 V:=0
21 ifeq "$(V)" "0"
22 .SILENT:
23 DASHQ:=-q
24 else
25 DASHV:=-v
26 endif
28 all: main.hex main.avr
30 # --------------------------------------------------------------------------
32 o:
33 mkdir -p o
35 o/%.o:%.S | o#
36 @echo gcc $^
37 avr-gcc -c $(CFLAGS) -o $@ $^ $(_LIST)
39 o/%.o:%.c | o
40 @echo gcc $^
41 avr-gcc -c $(CFLAGS) -std=c99 -o $@ $^ $(_LIST)
43 o/%.o:%.cc | o
44 @echo g++ $^
45 avr-g++ -c $(CFLAGS) -o $@ $^
47 #%.avr:%.o
48 # avr-gcc -L/usr/local/avr/lib $(CFLAGS) -o $@ $^ -v
49 # @chmod -x $@
51 # Convert to hex with objcopy. We can NOT use ld --oformat here.
52 %.hex:%.avr
53 @echo objcopy $@
54 avr-objcopy -j .text -j .data -O ihex $^ $@
55 chmod -x $@
57 # --------------------------------------------------------------------------
59 # need something to pick up latest tag
60 # echo '"'$$(hg tags | sort | awk '/^v[0-9\.]+/||1 { V=$$1 } END { if(V!="") print " " V}')'"'
62 version.h: Makefile $(filter-out version.h,$(wildcard *.cc *.h))
63 ID=$$(hg id -i) ; \
64 TAG=$$(hg tags | sort | awk '/^v[0-9\.]+/ { V=$$1 } END { if(V!="") print " " V}') ; \
65 REV=$$(hg id -r $${TAG:-0}) ; \
66 if [ "$$ID" != "$$REV" ] ; then \
67 [ -n "$$TAG" ] && echo '"'$$TAG' "' ; \
68 echo '"'$$ID'"' ; \
69 fi >$@
71 o/commands.o: commands.cc version.h | o
72 @echo g++ $^
73 avr-g++ -c $(CFLAGS) -o $@ $<
75 main.avr: o/main.o o/formatting.o o/commands.o o/gpib.o o/serial.o o/usb_serial.o
76 @echo ld $^
77 avr-g++ -L/usr/local/avr/lib $(LDFLAGS) -o $@ $^ $(DASHV)
78 chmod -x $@
79 avr-size $@
80 CLEAN+=main.avr version.h
82 # --------------------------------------------------------------------------
84 .PHONY: disas fuses program term setspeed clean rebuild
85 disas: main.avr
86 avr-objdump -z -d $^ | avr-c++filt
88 LFUSE=0x62 # clkout=of sut=2 clksel=2 (rc)
89 LFUSE=0xb2 # clkout=on sut=3 clksel=2 (rc)
90 #HFUSE=0xc4 # extreset=off, debugwire=off, spi=off, wdt=on, eesave=on, bod=4=4.5V
91 # NEVER program HFUSE bit 7=0 or bit 5=1, because SPI can no longer be used
92 # HFUSE values should be 0b1X0XXXXX, or 0x8X, 0x9X, 0xCX, 0xDX
93 HFUSE=0xdf # extreset=off, debugwire=off, spi=off, wdt=off, eesave=on, bod=7
94 EFUSE=0xff # self-programming=on
96 fuses:
97 false Dangerous
98 avrdude -p t$(CPU) -u -U efuse:w:$$(($(EFUSE))):m -U hfuse:w:$$(($(HFUSE))):m -U lfuse:w:$$(($(LFUSE))):m
100 program: main.hex
101 ifeq "$(CPU)" "atmega32u4"
102 ./program --program $(CPU) $^
103 else
104 if lsusb -d 03eb:2104 ; then \
105 avrdude -c avrispmkII -p m32u4 $(DASHQ) -U flash:w:$^ ; \
106 elif lsusb -d 16c0:05dc ; then \
107 avrdude -c usbasp-clone -p $(CPU) $(DASHQ) -U flash:w:$^ ;\
108 fi
109 endif
111 term:
112 avrdude -p t$(CPU) -v -E noreset -t
114 setspeed:
115 avrdude -p t$(CPU) -v -E noreset -B300
117 clean:
118 -rm -r o
119 -rm $(CLEAN)
121 rebuild:
122 $(MAKE) clean ; $(MAKE)
124 # ----- EOF Makefile -----