blob: d6d3dfc691dd9fa8a71c26a0e4bd9d66b6b40b00 [file] [log] [blame]
Brian Silverman3240e102019-02-16 18:24:24 -08001load("//motors:macros.bzl", "hex_from_elf")
Parker Schuh13696b32019-02-16 15:51:20 -08002
Brian Silverman0a5e7db2019-02-17 13:45:27 -08003jevois_crc_args = [
Brian Silverman246cb222019-02-02 16:38:18 -08004 "$(location //third_party/pycrc:pycrc_main)",
5 "--width=16",
6 # This is the recommendation from
7 # http://users.ece.cmu.edu/~koopman/roses/dsn04/koopman04_crc_poly_embedded.pdf
8 # for messages of 242 - 2048 bits, which covers what we want.
9 # That's an analysis from an exhaustive search of all polynomials for
10 # various CRCs to find the best ones. This is 0xBAAD, converted from the
11 # weird format used there to the standard one used by pycrc.
12 "--poly=0x755b",
13 "--reflect-in=False",
14 "--xor-in=0xffff",
15 "--reflect-out=False",
16 "--xor-out=0xffff",
17 "--std=C99",
18 "--algorithm=table-driven",
Brian Silverman0a5e7db2019-02-17 13:45:27 -080019 "--symbol-prefix=jevois_crc_",
Brian Silverman246cb222019-02-02 16:38:18 -080020 "--crc-type=uint16_t",
21]
22
23genrule(
Brian Silverman0a5e7db2019-02-17 13:45:27 -080024 name = "gen_jevois_crc",
Brian Silverman246cb222019-02-02 16:38:18 -080025 outs = [
Brian Silverman0a5e7db2019-02-17 13:45:27 -080026 "jevois_crc.h",
27 "jevois_crc.c",
Brian Silverman246cb222019-02-02 16:38:18 -080028 ],
29 cmd = " && ".join([
Brian Silverman0a5e7db2019-02-17 13:45:27 -080030 " ".join(jevois_crc_args + [
Brian Silverman246cb222019-02-02 16:38:18 -080031 "--generate=h",
Brian Silverman0a5e7db2019-02-17 13:45:27 -080032 "--output=$(location jevois_crc.h)",
Austin Schuh4a4495d2019-12-06 21:30:18 -080033 "&&",
34 "sed",
35 "-i",
36 "'s/\\(Generated on \\).*/\\1redacted/'",
37 "$(location jevois_crc.h)",
Brian Silverman246cb222019-02-02 16:38:18 -080038 ]),
Brian Silverman0a5e7db2019-02-17 13:45:27 -080039 " ".join(jevois_crc_args + [
Brian Silverman246cb222019-02-02 16:38:18 -080040 "--generate=c",
Brian Silverman0a5e7db2019-02-17 13:45:27 -080041 "--output=$(location jevois_crc.c)",
Austin Schuh4a4495d2019-12-06 21:30:18 -080042 "&&",
43 "sed",
44 "-i",
45 "'s/\\(Generated on \\).*/\\1redacted/'",
46 "$(location jevois_crc.c)",
Brian Silverman246cb222019-02-02 16:38:18 -080047 ]),
48 ]),
Philipp Schraderdada1072020-11-24 11:34:46 -080049 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman246cb222019-02-02 16:38:18 -080050 tools = [
51 "//third_party/pycrc:pycrc_main",
52 ],
53)
54
55cc_library(
Brian Silverman0a5e7db2019-02-17 13:45:27 -080056 name = "jevois_crc",
Brian Silverman246cb222019-02-02 16:38:18 -080057 srcs = [
Brian Silverman0a5e7db2019-02-17 13:45:27 -080058 "jevois_crc.c",
Brian Silverman246cb222019-02-02 16:38:18 -080059 ],
60 hdrs = [
Brian Silverman0a5e7db2019-02-17 13:45:27 -080061 "jevois_crc.h",
Brian Silverman246cb222019-02-02 16:38:18 -080062 ],
Philipp Schraderdada1072020-11-24 11:34:46 -080063 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman246cb222019-02-02 16:38:18 -080064 deps = [
65 "//third_party/GSL",
66 ],
67)
68
Brian Silverman1c0612e2019-01-26 17:26:08 -080069cc_library(
70 name = "structures",
71 hdrs = [
72 "structures.h",
73 ],
74 visibility = ["//visibility:public"],
75 deps = [
76 "//aos/containers:sized_array",
Brian Silvermana3688802019-02-16 19:31:26 -080077 "//aos/time",
Alex Perrycb7da4b2019-08-28 19:35:56 -070078 "@org_tuxfamily_eigen//:eigen",
Brian Silverman1c0612e2019-01-26 17:26:08 -080079 ],
80)
Brian Silverman246cb222019-02-02 16:38:18 -080081
82cc_library(
83 name = "spi",
84 srcs = [
85 "spi.cc",
86 ],
87 hdrs = [
88 "spi.h",
89 ],
Brian Silvermance4825f2019-02-17 18:28:39 -080090 visibility = ["//visibility:public"],
Brian Silverman246cb222019-02-02 16:38:18 -080091 deps = [
Brian Silverman0a5e7db2019-02-17 13:45:27 -080092 ":jevois_crc",
Brian Silverman246cb222019-02-02 16:38:18 -080093 ":structures",
94 "//aos/util:bitpacking",
95 "//third_party/GSL",
Philipp Schraderdada1072020-11-24 11:34:46 -080096 ] + select({
97 "@platforms//os:linux": ["//aos/logging"],
98 "//conditions:default": [],
99 }),
Brian Silvermanfdfb3132019-02-24 15:27:27 -0800100)
101
102cc_library(
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800103 name = "uart",
104 srcs = [
105 "uart.cc",
106 ],
107 hdrs = [
108 "uart.h",
109 ],
Brian Silvermance4825f2019-02-17 18:28:39 -0800110 visibility = ["//visibility:public"],
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800111 deps = [
Brian Silverman2eb89762019-02-17 15:16:37 -0800112 ":cobs",
113 ":jevois_crc",
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800114 ":structures",
115 "//aos/containers:sized_array",
Brian Silverman2eb89762019-02-17 15:16:37 -0800116 "//aos/util:bitpacking",
117 "//third_party/GSL",
Philipp Schraderdada1072020-11-24 11:34:46 -0800118 ] + select({
119 "@platforms//os:linux": ["//aos/logging"],
120 "//conditions:default": [],
121 }),
Brian Silvermanfdfb3132019-02-24 15:27:27 -0800122)
123
Brian Silverman246cb222019-02-02 16:38:18 -0800124cc_test(
Brian Silverman2eb89762019-02-17 15:16:37 -0800125 name = "uart_test",
126 srcs = [
127 "uart_test.cc",
128 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800129 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman2eb89762019-02-17 15:16:37 -0800130 deps = [
131 ":uart",
132 "//aos/testing:googletest",
133 ],
134)
135
136cc_test(
Brian Silverman246cb222019-02-02 16:38:18 -0800137 name = "spi_test",
138 srcs = [
139 "spi_test.cc",
140 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800141 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman246cb222019-02-02 16:38:18 -0800142 deps = [
143 ":spi",
144 "//aos/testing:googletest",
145 ],
146)
Brian Silverman41709732019-02-09 20:53:08 -0800147
148cc_library(
149 name = "cobs",
150 hdrs = [
151 "cobs.h",
152 ],
153 deps = [
Brian Silverman41709732019-02-09 20:53:08 -0800154 "//third_party/GSL",
155 ],
156)
157
158cc_test(
159 name = "cobs_test",
160 srcs = [
161 "cobs_test.cc",
162 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800163 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman41709732019-02-09 20:53:08 -0800164 deps = [
165 ":cobs",
166 "//aos/testing:googletest",
167 "//aos/testing:test_logging",
168 "//third_party/GSL",
169 ],
170)
Parker Schuh13696b32019-02-16 15:51:20 -0800171
172cc_library(
173 name = "serial",
Parker Schuh13696b32019-02-16 15:51:20 -0800174 srcs = ["serial.cc"],
Brian Silverman3240e102019-02-16 18:24:24 -0800175 hdrs = ["serial.h"],
Philipp Schraderdada1072020-11-24 11:34:46 -0800176 target_compatible_with = ["@platforms//os:linux"],
Parker Schuh7c42f0d2019-02-17 14:02:33 -0800177 visibility = ["//visibility:public"],
Parker Schuh13696b32019-02-16 15:51:20 -0800178 deps = [
Brian Silverman3240e102019-02-16 18:24:24 -0800179 "//aos/logging",
Parker Schuh13696b32019-02-16 15:51:20 -0800180 ],
181)
Brian Silverman3240e102019-02-16 18:24:24 -0800182
183cc_binary(
184 name = "teensy.elf",
185 srcs = [
186 "teensy.cc",
187 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800188 target_compatible_with = ["//tools/platforms/hardware:cortex_m4f"],
Brian Silverman3240e102019-02-16 18:24:24 -0800189 deps = [
Philipp Schraderdada1072020-11-24 11:34:46 -0800190 ":cobs",
191 ":spi",
192 ":uart",
193 "//aos/time:time",
Brian Silverman3240e102019-02-16 18:24:24 -0800194 "//motors:util",
195 "//motors/core",
196 "//motors/peripheral:configuration",
Brian Silvermand7d01102019-02-24 16:11:21 -0800197 "//motors/peripheral:spi",
Brian Silverman3240e102019-02-16 18:24:24 -0800198 "//motors/peripheral:uart",
199 "//motors/print:usb",
Brian Silvermand7d01102019-02-24 16:11:21 -0800200 "//third_party/GSL",
Brian Silvermana498bbb2019-03-03 17:18:04 -0800201 "//y2019/vision:constants",
Brian Silverman3240e102019-02-16 18:24:24 -0800202 ],
203)
204
205hex_from_elf(
206 name = "teensy",
Philipp Schraderdada1072020-11-24 11:34:46 -0800207 target_compatible_with = ["//tools/platforms/hardware:cortex_m4f"],
Brian Silverman3240e102019-02-16 18:24:24 -0800208)