forked from nsayer/Crazy-Clock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
69 lines (49 loc) · 1.95 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
#
# To use this, you use 'make init TYPE={the kind of clock you want}'
# That will fuse, flash and seed the chip.
#
all: calibrate.hex normal.hex crazy.hex early.hex lazy.hex martian.hex sidereal.hex tidal.hex vetinari.hex warpy.hex wavy.hex whacky.hex tuney.hex zippy.hex
# Change this as appropriate! Don't screw it up!
# The clock is a 32.768 kHz crystal.
OPTS = -DF_CPU=32768L
# Change this to pick the correct programmer you're using
PROG = usbtiny
# Change this if you're not using a Tiny45
CHIP = attiny45
#CHIP = attiny44
# The SPI clock must be less than the system clock divided by 6. A -B argument of 250 should
# yield an SPI clock of around 4 kHz, which is fine. If your programmer doesn't respect -B,
# then you will have to find some other way to insure ISP operations don't go too fast.
SPICLOCK = 250
CC = avr-gcc
OBJCPY = avr-objcopy
AVRDUDE = avrdude
CFLAGS = -Os -g -mmcu=$(CHIP) -std=c99 $(OPTS) -Wall -Wno-main -fno-tree-switch-conversion
DUDE_OPTS = -c $(PROG) -p $(CHIP) -B $(SPICLOCK)
%.o: %.c Makefile
$(CC) $(CFLAGS) -c -o $@ $<
%.hex: %.elf
$(OBJCPY) -j .text -j .data -O ihex $^ $@
# Calibrate is special - it has its own main()
calibrate.elf: calibrate.o
$(CC) $(CFLAGS) -o $@ $^
%.elf: %.o base.o
$(CC) $(CFLAGS) -o $@ $^
clean:
rm -f *.o *.elf *.hex test-*
# The controller is fused for the extra-low frequency oscillator, no prescaling, and preserve
# the EEPROM content over code updates (to preserve the trim factor and PRNG seed).
fuse:
$(AVRDUDE) $(DUDE_OPTS) -U lfuse:w:0xe6:m -U hfuse:w:0xd7:m -U efuse:w:0xff:m
flash: $(TYPE).hex
$(AVRDUDE) $(DUDE_OPTS) -U flash:w:$(TYPE).hex
# This will perturb the stored PRNG seed.
seed:
dd if=/dev/urandom bs=4 count=1 of=seedfile
$(AVRDUDE) $(DUDE_OPTS) -U eeprom:w:seedfile:r
rm -f seedfile
init: fuse flash seed
test:
gcc -c -D_DEFAULT_SOURCE -std=c99 -DUNIT_TEST -O -o test-$(TYPE).o $(TYPE).c
gcc -c -D_DEFAULT_SOURCE -std=c99 -O test.c
gcc -o test-$(TYPE) test.o test-$(TYPE).o