blob: afca4efe240e2215685287fc58bb692313275f41 [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)",
Brian Silverman246cb222019-02-02 16:38:18 -080034 ]),
Brian Silverman0a5e7db2019-02-17 13:45:27 -080035 " ".join(jevois_crc_args + [
Brian Silverman246cb222019-02-02 16:38:18 -080036 "--generate=c",
Brian Silverman0a5e7db2019-02-17 13:45:27 -080037 "--output=$(location jevois_crc.c)",
Brian Silverman246cb222019-02-02 16:38:18 -080038 ]),
39 ]),
Brian Silvermanfdfb3132019-02-24 15:27:27 -080040 compatible_with = mcu_cpus,
Brian Silverman246cb222019-02-02 16:38:18 -080041 tools = [
42 "//third_party/pycrc:pycrc_main",
43 ],
44)
45
46cc_library(
Brian Silverman0a5e7db2019-02-17 13:45:27 -080047 name = "jevois_crc",
Brian Silverman246cb222019-02-02 16:38:18 -080048 srcs = [
Brian Silverman0a5e7db2019-02-17 13:45:27 -080049 "jevois_crc.c",
Brian Silverman246cb222019-02-02 16:38:18 -080050 ],
51 hdrs = [
Brian Silverman0a5e7db2019-02-17 13:45:27 -080052 "jevois_crc.h",
Brian Silverman246cb222019-02-02 16:38:18 -080053 ],
Brian Silvermanfdfb3132019-02-24 15:27:27 -080054 compatible_with = mcu_cpus,
Brian Silverman246cb222019-02-02 16:38:18 -080055 deps = [
56 "//third_party/GSL",
57 ],
58)
59
Brian Silverman1c0612e2019-01-26 17:26:08 -080060cc_library(
61 name = "structures",
62 hdrs = [
63 "structures.h",
64 ],
65 visibility = ["//visibility:public"],
66 deps = [
67 "//aos/containers:sized_array",
Brian Silvermana3688802019-02-16 19:31:26 -080068 "//aos/time",
Brian Silverman1c0612e2019-01-26 17:26:08 -080069 "//third_party/eigen",
70 ],
71)
Brian Silverman246cb222019-02-02 16:38:18 -080072
73cc_library(
Brian Silvermanfdfb3132019-02-24 15:27:27 -080074 name = "structures_mcu",
75 hdrs = [
76 "structures.h",
77 ],
78 restricted_to = mcu_cpus,
79 deps = [
80 "//aos/containers:sized_array",
81 "//aos/time:time_mcu",
82 "//third_party/eigen",
83 ],
84)
85
86cc_library(
Brian Silverman246cb222019-02-02 16:38:18 -080087 name = "spi",
88 srcs = [
89 "spi.cc",
90 ],
91 hdrs = [
92 "spi.h",
93 ],
Brian Silvermance4825f2019-02-17 18:28:39 -080094 visibility = ["//visibility:public"],
Brian Silverman246cb222019-02-02 16:38:18 -080095 deps = [
Brian Silverman0a5e7db2019-02-17 13:45:27 -080096 ":jevois_crc",
Brian Silverman246cb222019-02-02 16:38:18 -080097 ":structures",
Brian Silverman2eb89762019-02-17 15:16:37 -080098 "//aos/logging",
Brian Silverman246cb222019-02-02 16:38:18 -080099 "//aos/util:bitpacking",
100 "//third_party/GSL",
101 "//third_party/optional",
102 ],
103)
104
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800105cc_library(
Brian Silvermanfdfb3132019-02-24 15:27:27 -0800106 name = "spi_mcu",
107 srcs = [
108 "spi.cc",
109 ],
110 hdrs = [
111 "spi.h",
112 ],
113 restricted_to = mcu_cpus,
114 deps = [
115 ":jevois_crc",
116 ":structures_mcu",
117 "//aos/util:bitpacking",
118 "//third_party/GSL",
119 "//third_party/optional",
120 ],
121)
122
123cc_library(
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800124 name = "uart",
125 srcs = [
126 "uart.cc",
127 ],
128 hdrs = [
129 "uart.h",
130 ],
Brian Silvermance4825f2019-02-17 18:28:39 -0800131 visibility = ["//visibility:public"],
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800132 deps = [
Brian Silverman2eb89762019-02-17 15:16:37 -0800133 ":cobs",
134 ":jevois_crc",
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800135 ":structures",
136 "//aos/containers:sized_array",
Brian Silverman2eb89762019-02-17 15:16:37 -0800137 "//aos/logging",
138 "//aos/util:bitpacking",
139 "//third_party/GSL",
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800140 "//third_party/optional",
141 ],
142)
143
Brian Silvermanfdfb3132019-02-24 15:27:27 -0800144cc_library(
145 name = "uart_mcu",
146 srcs = [
147 "uart.cc",
148 ],
149 hdrs = [
150 "uart.h",
151 ],
152 restricted_to = mcu_cpus,
153 deps = [
154 ":cobs_mcu",
155 ":jevois_crc",
156 ":structures_mcu",
157 "//aos/containers:sized_array",
158 "//aos/util:bitpacking",
159 "//third_party/GSL",
160 "//third_party/optional",
161 ],
162)
163
Brian Silverman246cb222019-02-02 16:38:18 -0800164cc_test(
Brian Silverman2eb89762019-02-17 15:16:37 -0800165 name = "uart_test",
166 srcs = [
167 "uart_test.cc",
168 ],
169 deps = [
170 ":uart",
171 "//aos/testing:googletest",
172 ],
173)
174
175cc_test(
Brian Silverman246cb222019-02-02 16:38:18 -0800176 name = "spi_test",
177 srcs = [
178 "spi_test.cc",
179 ],
180 deps = [
181 ":spi",
182 "//aos/testing:googletest",
183 ],
184)
Brian Silverman41709732019-02-09 20:53:08 -0800185
186cc_library(
187 name = "cobs",
188 hdrs = [
189 "cobs.h",
190 ],
191 deps = [
192 "//aos/logging",
193 "//third_party/GSL",
194 ],
195)
196
Brian Silvermanfdfb3132019-02-24 15:27:27 -0800197cc_library(
198 name = "cobs_mcu",
199 hdrs = [
200 "cobs.h",
201 ],
202 restricted_to = mcu_cpus,
203 deps = [
204 "//third_party/GSL",
205 ],
206)
207
Brian Silverman41709732019-02-09 20:53:08 -0800208cc_test(
209 name = "cobs_test",
210 srcs = [
211 "cobs_test.cc",
212 ],
213 deps = [
214 ":cobs",
215 "//aos/testing:googletest",
216 "//aos/testing:test_logging",
217 "//third_party/GSL",
218 ],
219)
Parker Schuh13696b32019-02-16 15:51:20 -0800220
221cc_library(
222 name = "serial",
Parker Schuh13696b32019-02-16 15:51:20 -0800223 srcs = ["serial.cc"],
Brian Silverman3240e102019-02-16 18:24:24 -0800224 hdrs = ["serial.h"],
Parker Schuh7c42f0d2019-02-17 14:02:33 -0800225 visibility = ["//visibility:public"],
Parker Schuh13696b32019-02-16 15:51:20 -0800226 deps = [
Brian Silverman3240e102019-02-16 18:24:24 -0800227 "//aos/logging",
Parker Schuh13696b32019-02-16 15:51:20 -0800228 ],
229)
Brian Silverman3240e102019-02-16 18:24:24 -0800230
231cc_binary(
232 name = "teensy.elf",
233 srcs = [
234 "teensy.cc",
235 ],
236 restricted_to = ["//tools:cortex-m4f"],
237 deps = [
Brian Silvermand7d01102019-02-24 16:11:21 -0800238 ":cobs_mcu",
239 ":spi_mcu",
240 ":uart_mcu",
Brian Silverman3240e102019-02-16 18:24:24 -0800241 "//aos/time:time_mcu",
242 "//motors:util",
243 "//motors/core",
244 "//motors/peripheral:configuration",
Brian Silvermand7d01102019-02-24 16:11:21 -0800245 "//motors/peripheral:spi",
Brian Silverman3240e102019-02-16 18:24:24 -0800246 "//motors/peripheral:uart",
247 "//motors/print:usb",
Brian Silvermand7d01102019-02-24 16:11:21 -0800248 "//third_party/GSL",
Brian Silvermana498bbb2019-03-03 17:18:04 -0800249 "//y2019/vision:constants",
Brian Silverman3240e102019-02-16 18:24:24 -0800250 ],
251)
252
253hex_from_elf(
254 name = "teensy",
255 restricted_to = ["//tools:cortex-m4f"],
256)