blob: f11c67c03d0ba2d1d55cff096d9a82cbec6d582f [file] [log] [blame]
Brian Silverman3240e102019-02-16 18:24:24 -08001load("//tools:environments.bzl", "mcu_cpus")
2load("//motors:macros.bzl", "hex_from_elf")
Parker Schuh13696b32019-02-16 15:51:20 -08003
Brian Silverman0a5e7db2019-02-17 13:45:27 -08004jevois_crc_args = [
Brian Silverman246cb222019-02-02 16:38:18 -08005 "$(location //third_party/pycrc:pycrc_main)",
6 "--width=16",
7 # This is the recommendation from
8 # http://users.ece.cmu.edu/~koopman/roses/dsn04/koopman04_crc_poly_embedded.pdf
9 # for messages of 242 - 2048 bits, which covers what we want.
10 # That's an analysis from an exhaustive search of all polynomials for
11 # various CRCs to find the best ones. This is 0xBAAD, converted from the
12 # weird format used there to the standard one used by pycrc.
13 "--poly=0x755b",
14 "--reflect-in=False",
15 "--xor-in=0xffff",
16 "--reflect-out=False",
17 "--xor-out=0xffff",
18 "--std=C99",
19 "--algorithm=table-driven",
Brian Silverman0a5e7db2019-02-17 13:45:27 -080020 "--symbol-prefix=jevois_crc_",
Brian Silverman246cb222019-02-02 16:38:18 -080021 "--crc-type=uint16_t",
22]
23
24genrule(
Brian Silverman0a5e7db2019-02-17 13:45:27 -080025 name = "gen_jevois_crc",
Brian Silverman246cb222019-02-02 16:38:18 -080026 outs = [
Brian Silverman0a5e7db2019-02-17 13:45:27 -080027 "jevois_crc.h",
28 "jevois_crc.c",
Brian Silverman246cb222019-02-02 16:38:18 -080029 ],
30 cmd = " && ".join([
Brian Silverman0a5e7db2019-02-17 13:45:27 -080031 " ".join(jevois_crc_args + [
Brian Silverman246cb222019-02-02 16:38:18 -080032 "--generate=h",
Brian Silverman0a5e7db2019-02-17 13:45:27 -080033 "--output=$(location jevois_crc.h)",
Austin Schuh4a4495d2019-12-06 21:30:18 -080034 "&&",
35 "sed",
36 "-i",
37 "'s/\\(Generated on \\).*/\\1redacted/'",
38 "$(location jevois_crc.h)",
Brian Silverman246cb222019-02-02 16:38:18 -080039 ]),
Brian Silverman0a5e7db2019-02-17 13:45:27 -080040 " ".join(jevois_crc_args + [
Brian Silverman246cb222019-02-02 16:38:18 -080041 "--generate=c",
Brian Silverman0a5e7db2019-02-17 13:45:27 -080042 "--output=$(location jevois_crc.c)",
Austin Schuh4a4495d2019-12-06 21:30:18 -080043 "&&",
44 "sed",
45 "-i",
46 "'s/\\(Generated on \\).*/\\1redacted/'",
47 "$(location jevois_crc.c)",
Brian Silverman246cb222019-02-02 16:38:18 -080048 ]),
49 ]),
Brian Silvermanfdfb3132019-02-24 15:27:27 -080050 compatible_with = mcu_cpus,
Brian Silverman246cb222019-02-02 16:38:18 -080051 tools = [
52 "//third_party/pycrc:pycrc_main",
53 ],
54)
55
56cc_library(
Brian Silverman0a5e7db2019-02-17 13:45:27 -080057 name = "jevois_crc",
Brian Silverman246cb222019-02-02 16:38:18 -080058 srcs = [
Brian Silverman0a5e7db2019-02-17 13:45:27 -080059 "jevois_crc.c",
Brian Silverman246cb222019-02-02 16:38:18 -080060 ],
61 hdrs = [
Brian Silverman0a5e7db2019-02-17 13:45:27 -080062 "jevois_crc.h",
Brian Silverman246cb222019-02-02 16:38:18 -080063 ],
Brian Silvermanfdfb3132019-02-24 15:27:27 -080064 compatible_with = mcu_cpus,
Brian Silverman246cb222019-02-02 16:38:18 -080065 deps = [
66 "//third_party/GSL",
67 ],
68)
69
Brian Silverman1c0612e2019-01-26 17:26:08 -080070cc_library(
71 name = "structures",
72 hdrs = [
73 "structures.h",
74 ],
75 visibility = ["//visibility:public"],
76 deps = [
77 "//aos/containers:sized_array",
Brian Silvermana3688802019-02-16 19:31:26 -080078 "//aos/time",
Alex Perrycb7da4b2019-08-28 19:35:56 -070079 "@org_tuxfamily_eigen//:eigen",
Brian Silverman1c0612e2019-01-26 17:26:08 -080080 ],
81)
Brian Silverman246cb222019-02-02 16:38:18 -080082
83cc_library(
Brian Silvermanfdfb3132019-02-24 15:27:27 -080084 name = "structures_mcu",
85 hdrs = [
86 "structures.h",
87 ],
88 restricted_to = mcu_cpus,
89 deps = [
90 "//aos/containers:sized_array",
91 "//aos/time:time_mcu",
Alex Perrycb7da4b2019-08-28 19:35:56 -070092 "@org_tuxfamily_eigen//:eigen",
Brian Silvermanfdfb3132019-02-24 15:27:27 -080093 ],
94)
95
96cc_library(
Brian Silverman246cb222019-02-02 16:38:18 -080097 name = "spi",
98 srcs = [
99 "spi.cc",
100 ],
101 hdrs = [
102 "spi.h",
103 ],
Brian Silvermance4825f2019-02-17 18:28:39 -0800104 visibility = ["//visibility:public"],
Brian Silverman246cb222019-02-02 16:38:18 -0800105 deps = [
Brian Silverman0a5e7db2019-02-17 13:45:27 -0800106 ":jevois_crc",
Brian Silverman246cb222019-02-02 16:38:18 -0800107 ":structures",
Brian Silverman2eb89762019-02-17 15:16:37 -0800108 "//aos/logging",
Brian Silverman246cb222019-02-02 16:38:18 -0800109 "//aos/util:bitpacking",
110 "//third_party/GSL",
Brian Silverman246cb222019-02-02 16:38:18 -0800111 ],
112)
113
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800114cc_library(
Brian Silvermanfdfb3132019-02-24 15:27:27 -0800115 name = "spi_mcu",
116 srcs = [
117 "spi.cc",
118 ],
119 hdrs = [
120 "spi.h",
121 ],
122 restricted_to = mcu_cpus,
123 deps = [
124 ":jevois_crc",
125 ":structures_mcu",
126 "//aos/util:bitpacking",
127 "//third_party/GSL",
Brian Silvermanfdfb3132019-02-24 15:27:27 -0800128 ],
129)
130
131cc_library(
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800132 name = "uart",
133 srcs = [
134 "uart.cc",
135 ],
136 hdrs = [
137 "uart.h",
138 ],
Brian Silvermance4825f2019-02-17 18:28:39 -0800139 visibility = ["//visibility:public"],
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800140 deps = [
Brian Silverman2eb89762019-02-17 15:16:37 -0800141 ":cobs",
142 ":jevois_crc",
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800143 ":structures",
144 "//aos/containers:sized_array",
Brian Silverman2eb89762019-02-17 15:16:37 -0800145 "//aos/logging",
146 "//aos/util:bitpacking",
147 "//third_party/GSL",
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800148 ],
149)
150
Brian Silvermanfdfb3132019-02-24 15:27:27 -0800151cc_library(
152 name = "uart_mcu",
153 srcs = [
154 "uart.cc",
155 ],
156 hdrs = [
157 "uart.h",
158 ],
159 restricted_to = mcu_cpus,
160 deps = [
161 ":cobs_mcu",
162 ":jevois_crc",
163 ":structures_mcu",
164 "//aos/containers:sized_array",
165 "//aos/util:bitpacking",
166 "//third_party/GSL",
Brian Silvermanfdfb3132019-02-24 15:27:27 -0800167 ],
168)
169
Brian Silverman246cb222019-02-02 16:38:18 -0800170cc_test(
Brian Silverman2eb89762019-02-17 15:16:37 -0800171 name = "uart_test",
172 srcs = [
173 "uart_test.cc",
174 ],
175 deps = [
176 ":uart",
177 "//aos/testing:googletest",
178 ],
179)
180
181cc_test(
Brian Silverman246cb222019-02-02 16:38:18 -0800182 name = "spi_test",
183 srcs = [
184 "spi_test.cc",
185 ],
186 deps = [
187 ":spi",
188 "//aos/testing:googletest",
189 ],
190)
Brian Silverman41709732019-02-09 20:53:08 -0800191
192cc_library(
193 name = "cobs",
194 hdrs = [
195 "cobs.h",
196 ],
197 deps = [
Brian Silverman41709732019-02-09 20:53:08 -0800198 "//third_party/GSL",
199 ],
200)
201
Brian Silvermanfdfb3132019-02-24 15:27:27 -0800202cc_library(
203 name = "cobs_mcu",
204 hdrs = [
205 "cobs.h",
206 ],
207 restricted_to = mcu_cpus,
208 deps = [
209 "//third_party/GSL",
210 ],
211)
212
Brian Silverman41709732019-02-09 20:53:08 -0800213cc_test(
214 name = "cobs_test",
215 srcs = [
216 "cobs_test.cc",
217 ],
218 deps = [
219 ":cobs",
220 "//aos/testing:googletest",
221 "//aos/testing:test_logging",
222 "//third_party/GSL",
223 ],
224)
Parker Schuh13696b32019-02-16 15:51:20 -0800225
226cc_library(
227 name = "serial",
Parker Schuh13696b32019-02-16 15:51:20 -0800228 srcs = ["serial.cc"],
Brian Silverman3240e102019-02-16 18:24:24 -0800229 hdrs = ["serial.h"],
Parker Schuh7c42f0d2019-02-17 14:02:33 -0800230 visibility = ["//visibility:public"],
Parker Schuh13696b32019-02-16 15:51:20 -0800231 deps = [
Brian Silverman3240e102019-02-16 18:24:24 -0800232 "//aos/logging",
Parker Schuh13696b32019-02-16 15:51:20 -0800233 ],
234)
Brian Silverman3240e102019-02-16 18:24:24 -0800235
236cc_binary(
237 name = "teensy.elf",
238 srcs = [
239 "teensy.cc",
240 ],
241 restricted_to = ["//tools:cortex-m4f"],
242 deps = [
Brian Silvermand7d01102019-02-24 16:11:21 -0800243 ":cobs_mcu",
244 ":spi_mcu",
245 ":uart_mcu",
Brian Silverman3240e102019-02-16 18:24:24 -0800246 "//aos/time:time_mcu",
247 "//motors:util",
248 "//motors/core",
249 "//motors/peripheral:configuration",
Brian Silvermand7d01102019-02-24 16:11:21 -0800250 "//motors/peripheral:spi",
Brian Silverman3240e102019-02-16 18:24:24 -0800251 "//motors/peripheral:uart",
252 "//motors/print:usb",
Brian Silvermand7d01102019-02-24 16:11:21 -0800253 "//third_party/GSL",
Brian Silvermana498bbb2019-03-03 17:18:04 -0800254 "//y2019/vision:constants",
Brian Silverman3240e102019-02-16 18:24:24 -0800255 ],
256)
257
258hex_from_elf(
259 name = "teensy",
260 restricted_to = ["//tools:cortex-m4f"],
261)