blob: dc170be4ef3458f346d0700b6683c385654f3c26 [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",
Alex Perrycb7da4b2019-08-28 19:35:56 -070069 "@org_tuxfamily_eigen//:eigen",
Brian Silverman1c0612e2019-01-26 17:26:08 -080070 ],
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",
Alex Perrycb7da4b2019-08-28 19:35:56 -070082 "@org_tuxfamily_eigen//:eigen",
Brian Silvermanfdfb3132019-02-24 15:27:27 -080083 ],
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",
Brian Silverman246cb222019-02-02 16:38:18 -0800101 ],
102)
103
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800104cc_library(
Brian Silvermanfdfb3132019-02-24 15:27:27 -0800105 name = "spi_mcu",
106 srcs = [
107 "spi.cc",
108 ],
109 hdrs = [
110 "spi.h",
111 ],
112 restricted_to = mcu_cpus,
113 deps = [
114 ":jevois_crc",
115 ":structures_mcu",
116 "//aos/util:bitpacking",
117 "//third_party/GSL",
Brian Silvermanfdfb3132019-02-24 15:27:27 -0800118 ],
119)
120
121cc_library(
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800122 name = "uart",
123 srcs = [
124 "uart.cc",
125 ],
126 hdrs = [
127 "uart.h",
128 ],
Brian Silvermance4825f2019-02-17 18:28:39 -0800129 visibility = ["//visibility:public"],
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800130 deps = [
Brian Silverman2eb89762019-02-17 15:16:37 -0800131 ":cobs",
132 ":jevois_crc",
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800133 ":structures",
134 "//aos/containers:sized_array",
Brian Silverman2eb89762019-02-17 15:16:37 -0800135 "//aos/logging",
136 "//aos/util:bitpacking",
137 "//third_party/GSL",
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800138 ],
139)
140
Brian Silvermanfdfb3132019-02-24 15:27:27 -0800141cc_library(
142 name = "uart_mcu",
143 srcs = [
144 "uart.cc",
145 ],
146 hdrs = [
147 "uart.h",
148 ],
149 restricted_to = mcu_cpus,
150 deps = [
151 ":cobs_mcu",
152 ":jevois_crc",
153 ":structures_mcu",
154 "//aos/containers:sized_array",
155 "//aos/util:bitpacking",
156 "//third_party/GSL",
Brian Silvermanfdfb3132019-02-24 15:27:27 -0800157 ],
158)
159
Brian Silverman246cb222019-02-02 16:38:18 -0800160cc_test(
Brian Silverman2eb89762019-02-17 15:16:37 -0800161 name = "uart_test",
162 srcs = [
163 "uart_test.cc",
164 ],
165 deps = [
166 ":uart",
167 "//aos/testing:googletest",
168 ],
169)
170
171cc_test(
Brian Silverman246cb222019-02-02 16:38:18 -0800172 name = "spi_test",
173 srcs = [
174 "spi_test.cc",
175 ],
176 deps = [
177 ":spi",
178 "//aos/testing:googletest",
179 ],
180)
Brian Silverman41709732019-02-09 20:53:08 -0800181
182cc_library(
183 name = "cobs",
184 hdrs = [
185 "cobs.h",
186 ],
187 deps = [
Brian Silverman41709732019-02-09 20:53:08 -0800188 "//third_party/GSL",
189 ],
190)
191
Brian Silvermanfdfb3132019-02-24 15:27:27 -0800192cc_library(
193 name = "cobs_mcu",
194 hdrs = [
195 "cobs.h",
196 ],
197 restricted_to = mcu_cpus,
198 deps = [
199 "//third_party/GSL",
200 ],
201)
202
Brian Silverman41709732019-02-09 20:53:08 -0800203cc_test(
204 name = "cobs_test",
205 srcs = [
206 "cobs_test.cc",
207 ],
208 deps = [
209 ":cobs",
210 "//aos/testing:googletest",
211 "//aos/testing:test_logging",
212 "//third_party/GSL",
213 ],
214)
Parker Schuh13696b32019-02-16 15:51:20 -0800215
216cc_library(
217 name = "serial",
Parker Schuh13696b32019-02-16 15:51:20 -0800218 srcs = ["serial.cc"],
Brian Silverman3240e102019-02-16 18:24:24 -0800219 hdrs = ["serial.h"],
Parker Schuh7c42f0d2019-02-17 14:02:33 -0800220 visibility = ["//visibility:public"],
Parker Schuh13696b32019-02-16 15:51:20 -0800221 deps = [
Brian Silverman3240e102019-02-16 18:24:24 -0800222 "//aos/logging",
Parker Schuh13696b32019-02-16 15:51:20 -0800223 ],
224)
Brian Silverman3240e102019-02-16 18:24:24 -0800225
226cc_binary(
227 name = "teensy.elf",
228 srcs = [
229 "teensy.cc",
230 ],
231 restricted_to = ["//tools:cortex-m4f"],
232 deps = [
Brian Silvermand7d01102019-02-24 16:11:21 -0800233 ":cobs_mcu",
234 ":spi_mcu",
235 ":uart_mcu",
Brian Silverman3240e102019-02-16 18:24:24 -0800236 "//aos/time:time_mcu",
237 "//motors:util",
238 "//motors/core",
239 "//motors/peripheral:configuration",
Brian Silvermand7d01102019-02-24 16:11:21 -0800240 "//motors/peripheral:spi",
Brian Silverman3240e102019-02-16 18:24:24 -0800241 "//motors/peripheral:uart",
242 "//motors/print:usb",
Brian Silvermand7d01102019-02-24 16:11:21 -0800243 "//third_party/GSL",
Brian Silvermana498bbb2019-03-03 17:18:04 -0800244 "//y2019/vision:constants",
Brian Silverman3240e102019-02-16 18:24:24 -0800245 ],
246)
247
248hex_from_elf(
249 name = "teensy",
250 restricted_to = ["//tools:cortex-m4f"],
251)