-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmakefile
208 lines (160 loc) · 4.32 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
208
##
## zero - pre-emptive multitasking kernel for AVR
##
## Techno Cosmic Research Institute Dirk Mahoney dirk@tcri.com.au
## Catchpole Robotics Christian Catchpole christian@catchpole.net
##
##########################################################################################
########################### DEVELOPER-ADJUSTABLE SETTINGS HERE ###########################
##########################################################################################
# output file and project name
OUTPUT = zero
# generate Doxygen documentation (requires Doxygen and Graphviz)
DOXYGEN = 0
# flashing settings
AVRDUDE_PART = m328p
AVRDUDE_CFG = pi
# general kernel settings
F_CPU_MHZ = 16
QUANTUM_TICKS = 15
PAGE_BYTES = 16
# enabled drivers
ZERO_DRIVERS_SPIMEM = 1
ZERO_DRIVERS_USART = 1
ZERO_DRIVERS_SUART = 1
ZERO_DRIVERS_GPIO = 1
ZERO_DRIVERS_ADC = 1
ZERO_DRIVERS_PIPE = 1
# WDT
ZERO_DRIVERS_WDT = 1
WATCHDOG_TIMEOUT = WDTO_8S
# comms
DEBUG_PIN = D1
DEBUG_BAUD = 9600
# Thread pools
NUM_POOL_THREADS = 0
POOL_THREAD_STACK_BYTES = 256
# some standard MCU settings
LFUSE = 0xFF
HFUSE = 0xD9
EFUSE = 0xFF
# All SRAM except 1K
DYNAMIC_BYTES = "( ( RAMEND - 255 ) - 1024 )"
# MCU mappings
ifeq ($(AVRDUDE_PART),m328)
# 1KB for allocator
MCU = atmega328
SPI_CFG = 1
endif
ifeq ($(AVRDUDE_PART),m328p)
# 1KB for allocator
MCU = atmega328p
SPI_CFG = 1
endif
ifeq ($(AVRDUDE_PART),m644p)
# 3KB for allocator
MCU = atmega644p
SPI_CFG = 2
endif
ifeq ($(AVRDUDE_PART),m1284p)
# 15KB for allocator
MCU = atmega1284p
SPI_CFG = 2
endif
##########################################################################################
######################### END DEVELOPER-ADJUSTABLE SETTINGS HERE #########################
##########################################################################################
PC_COUNT = 2
# general flags
FLAGS += -g
FLAGS += -Os
FLAGS += --std=c++17
FLAGS += -mmcu=$(MCU)
FLAGS += -fshort-enums
FLAGS += -ffunction-sections
FLAGS += -fdata-sections
FLAGS += -Wl,-gc-sections
# paths
FLAGS += -Icore/
FLAGS += -Idrivers/
FLAGS += -Ihelpers/
# warnings control
FLAGS += -Wall
FLAGS += -Wextra
FLAGS += -Wno-return-type
FLAGS += -Wno-sized-deallocation
FLAGS += -Wlogical-op
FLAGS += -Wshadow
# #define pass-throughs
FLAGS += -DPROJ_NAME=\"$(OUTPUT)\"
FLAGS += -DF_CPU_MHZ=$(F_CPU_MHZ)U
FLAGS += -DF_CPU=$(F_CPU_MHZ)'000'000UL
FLAGS += -DPC_COUNT=$(PC_COUNT)
FLAGS += -DPAGE_BYTES=$(PAGE_BYTES)
FLAGS += -DDYNAMIC_BYTES=$(DYNAMIC_BYTES)
FLAGS += -DQUANTUM_TICKS=$(QUANTUM_TICKS)
FLAGS += -DNUM_POOL_THREADS=$(NUM_POOL_THREADS)
FLAGS += -DPOOL_THREAD_STACK_BYTES=$(POOL_THREAD_STACK_BYTES)
FLAGS += -DSPI_CFG=$(SPI_CFG)
FLAGS += -DWATCHDOG_TIMEOUT=$(WATCHDOG_TIMEOUT)
# drivers
ifeq ($(ZERO_DRIVERS_SPIMEM),1)
FLAGS += -DZERO_DRIVERS_SPIMEM
endif
ifeq ($(ZERO_DRIVERS_USART),1)
FLAGS += -DZERO_DRIVERS_USART
endif
ifeq ($(ZERO_DRIVERS_SUART),1)
FLAGS += -DZERO_DRIVERS_SUART
endif
ifeq ($(ZERO_DRIVERS_GPIO),1)
FLAGS += -DZERO_DRIVERS_GPIO
endif
ifeq ($(ZERO_DRIVERS_ADC),1)
FLAGS += -DZERO_DRIVERS_ADC
endif
ifeq ($(ZERO_DRIVERS_WDT),1)
FLAGS += -DZERO_DRIVERS_WDT
endif
ifeq ($(ZERO_DRIVERS_PIPE),1)
FLAGS += -DZERO_DRIVERS_PIPE
endif
ifneq ($(DEBUG_PIN),)
FLAGS += -DDEBUG_ENABLED
FLAGS += -DDEBUG_PIN=ZERO_PIN$(DEBUG_PIN)
FLAGS += -DDEBUG_BAUD=$(DEBUG_BAUD)
endif
# build targets
CC = avr-g++
SRC := $(wildcard *.cpp)
SRC += $(wildcard core/*.cpp)
SRC += $(wildcard drivers/*.cpp)
SRC += $(wildcard helpers/*.cpp)
.PHONY: push fuses upload clean gettools
$(OUTPUT).elf: $(SRC)
@echo -n "Building..."
@$(CC) $(FLAGS) -o $@ $^
@echo " done"
@avr-size -A -x --mcu=$(MCU) $@
@avr-size -C -x --mcu=$(MCU) $@
ifeq ($(DOXYGEN),1)
@echo -n "Documenting..."
@rm -rf docs/*
@doxygen > /dev/null
@echo " done"
endif
upload: $(OUTPUT).elf
@sudo avrdude -p $(AVRDUDE_PART) -c $(AVRDUDE_CFG) -U flash:w:$(OUTPUT).elf
fuses:
@sudo avrdude -p $(AVRDUDE_PART) -c $(AVRDUDE_CFG) -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m
push: $(OUTPUT).elf
@echo -n "Pushing files to RPi..."
@rsync -avr --exclude '.git' ~/dev/$(OUTPUT)/ pi:dev/$(OUTPUT)/ > /dev/null
@rm -f *.o *.elf *.hex
@echo " done"
clean:
@echo -n "Cleaning up..."
@rm -f *.o *.elf *.hex
@echo " done"
gettools:
@sudo apt-get -y install gcc-avr binutils-avr gdb-avr avr-libc avrdude cloc clang-format doxygen graphviz