blob: 674924aa7cd411cac1aaea6e02037a9b1e24c837 [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 ]),
49 tools = [
50 "//third_party/pycrc:pycrc_main",
51 ],
52)
53
54cc_library(
Brian Silverman0a5e7db2019-02-17 13:45:27 -080055 name = "jevois_crc",
Brian Silverman246cb222019-02-02 16:38:18 -080056 srcs = [
Brian Silverman0a5e7db2019-02-17 13:45:27 -080057 "jevois_crc.c",
Brian Silverman246cb222019-02-02 16:38:18 -080058 ],
59 hdrs = [
Brian Silverman0a5e7db2019-02-17 13:45:27 -080060 "jevois_crc.h",
Brian Silverman246cb222019-02-02 16:38:18 -080061 ],
62 deps = [
Austin Schuhb72be802022-01-02 12:26:28 -080063 "@com_google_absl//absl/types:span",
Brian Silverman246cb222019-02-02 16:38:18 -080064 ],
65)
66
Brian Silverman1c0612e2019-01-26 17:26:08 -080067cc_library(
68 name = "structures",
69 hdrs = [
70 "structures.h",
71 ],
72 visibility = ["//visibility:public"],
73 deps = [
74 "//aos/containers:sized_array",
Brian Silvermana3688802019-02-16 19:31:26 -080075 "//aos/time",
Alex Perrycb7da4b2019-08-28 19:35:56 -070076 "@org_tuxfamily_eigen//:eigen",
Brian Silverman1c0612e2019-01-26 17:26:08 -080077 ],
78)
Brian Silverman246cb222019-02-02 16:38:18 -080079
80cc_library(
81 name = "spi",
82 srcs = [
83 "spi.cc",
84 ],
85 hdrs = [
86 "spi.h",
87 ],
Brian Silvermance4825f2019-02-17 18:28:39 -080088 visibility = ["//visibility:public"],
Brian Silverman246cb222019-02-02 16:38:18 -080089 deps = [
Brian Silverman0a5e7db2019-02-17 13:45:27 -080090 ":jevois_crc",
Brian Silverman246cb222019-02-02 16:38:18 -080091 ":structures",
92 "//aos/util:bitpacking",
Austin Schuhb72be802022-01-02 12:26:28 -080093 "@com_google_absl//absl/types:span",
Philipp Schraderdada1072020-11-24 11:34:46 -080094 ] + select({
95 "@platforms//os:linux": ["//aos/logging"],
96 "//conditions:default": [],
97 }),
Brian Silvermanfdfb3132019-02-24 15:27:27 -080098)
99
100cc_library(
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800101 name = "uart",
102 srcs = [
103 "uart.cc",
104 ],
105 hdrs = [
106 "uart.h",
107 ],
Brian Silvermance4825f2019-02-17 18:28:39 -0800108 visibility = ["//visibility:public"],
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800109 deps = [
Brian Silverman2eb89762019-02-17 15:16:37 -0800110 ":cobs",
111 ":jevois_crc",
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800112 ":structures",
113 "//aos/containers:sized_array",
Brian Silverman2eb89762019-02-17 15:16:37 -0800114 "//aos/util:bitpacking",
Austin Schuhb72be802022-01-02 12:26:28 -0800115 "@com_google_absl//absl/types:span",
Philipp Schraderdada1072020-11-24 11:34:46 -0800116 ] + select({
117 "@platforms//os:linux": ["//aos/logging"],
118 "//conditions:default": [],
119 }),
Brian Silvermanfdfb3132019-02-24 15:27:27 -0800120)
121
Brian Silverman246cb222019-02-02 16:38:18 -0800122cc_test(
Brian Silverman2eb89762019-02-17 15:16:37 -0800123 name = "uart_test",
124 srcs = [
125 "uart_test.cc",
126 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800127 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman2eb89762019-02-17 15:16:37 -0800128 deps = [
129 ":uart",
130 "//aos/testing:googletest",
131 ],
132)
133
134cc_test(
Brian Silverman246cb222019-02-02 16:38:18 -0800135 name = "spi_test",
136 srcs = [
137 "spi_test.cc",
138 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800139 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman246cb222019-02-02 16:38:18 -0800140 deps = [
141 ":spi",
142 "//aos/testing:googletest",
143 ],
144)
Brian Silverman41709732019-02-09 20:53:08 -0800145
146cc_library(
147 name = "cobs",
148 hdrs = [
149 "cobs.h",
150 ],
151 deps = [
Austin Schuhb72be802022-01-02 12:26:28 -0800152 "@com_google_absl//absl/types:span",
Brian Silverman41709732019-02-09 20:53:08 -0800153 ],
154)
155
156cc_test(
157 name = "cobs_test",
158 srcs = [
159 "cobs_test.cc",
160 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800161 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman41709732019-02-09 20:53:08 -0800162 deps = [
163 ":cobs",
164 "//aos/testing:googletest",
165 "//aos/testing:test_logging",
Austin Schuhb72be802022-01-02 12:26:28 -0800166 "@com_google_absl//absl/types:span",
Brian Silverman41709732019-02-09 20:53:08 -0800167 ],
168)
Parker Schuh13696b32019-02-16 15:51:20 -0800169
170cc_library(
171 name = "serial",
Parker Schuh13696b32019-02-16 15:51:20 -0800172 srcs = ["serial.cc"],
Brian Silverman3240e102019-02-16 18:24:24 -0800173 hdrs = ["serial.h"],
Philipp Schraderdada1072020-11-24 11:34:46 -0800174 target_compatible_with = ["@platforms//os:linux"],
Parker Schuh7c42f0d2019-02-17 14:02:33 -0800175 visibility = ["//visibility:public"],
Parker Schuh13696b32019-02-16 15:51:20 -0800176 deps = [
Brian Silverman3240e102019-02-16 18:24:24 -0800177 "//aos/logging",
Parker Schuh13696b32019-02-16 15:51:20 -0800178 ],
179)
Brian Silverman3240e102019-02-16 18:24:24 -0800180
181cc_binary(
182 name = "teensy.elf",
183 srcs = [
184 "teensy.cc",
185 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800186 target_compatible_with = ["//tools/platforms/hardware:cortex_m4f"],
Brian Silverman3240e102019-02-16 18:24:24 -0800187 deps = [
Philipp Schraderdada1072020-11-24 11:34:46 -0800188 ":cobs",
189 ":spi",
190 ":uart",
Austin Schuha2503a72020-12-15 20:57:57 -0800191 "//aos/time",
Brian Silverman3240e102019-02-16 18:24:24 -0800192 "//motors:util",
193 "//motors/core",
194 "//motors/peripheral:configuration",
Brian Silvermand7d01102019-02-24 16:11:21 -0800195 "//motors/peripheral:spi",
Brian Silverman3240e102019-02-16 18:24:24 -0800196 "//motors/peripheral:uart",
197 "//motors/print:usb",
Brian Silvermana498bbb2019-03-03 17:18:04 -0800198 "//y2019/vision:constants",
Austin Schuhb72be802022-01-02 12:26:28 -0800199 "@com_google_absl//absl/types:span",
Brian Silverman3240e102019-02-16 18:24:24 -0800200 ],
201)
202
203hex_from_elf(
204 name = "teensy",
Philipp Schraderdada1072020-11-24 11:34:46 -0800205 target_compatible_with = ["//tools/platforms/hardware:cortex_m4f"],
Brian Silverman3240e102019-02-16 18:24:24 -0800206)