blob: adb1dd23a63751f4804f58e7d6d7d6c01497661c [file] [log] [blame]
Brian Silverman3240e102019-02-16 18:24:24 -08001load("//motors:macros.bzl", "hex_from_elf")
James Kuszmaul9776b392023-01-14 14:08:08 -08002load("@org_frc971//tools/build_rules:select.bzl", "compiler_select")
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 ]),
50 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 ],
63 deps = [
Austin Schuhb72be802022-01-02 12:26:28 -080064 "@com_google_absl//absl/types:span",
Brian Silverman246cb222019-02-02 16:38:18 -080065 ],
66)
67
Brian Silverman1c0612e2019-01-26 17:26:08 -080068cc_library(
69 name = "structures",
70 hdrs = [
71 "structures.h",
72 ],
73 visibility = ["//visibility:public"],
74 deps = [
75 "//aos/containers:sized_array",
Brian Silvermana3688802019-02-16 19:31:26 -080076 "//aos/time",
Alex Perrycb7da4b2019-08-28 19:35:56 -070077 "@org_tuxfamily_eigen//:eigen",
Brian Silverman1c0612e2019-01-26 17:26:08 -080078 ],
79)
Brian Silverman246cb222019-02-02 16:38:18 -080080
81cc_library(
82 name = "spi",
83 srcs = [
84 "spi.cc",
85 ],
86 hdrs = [
87 "spi.h",
88 ],
Brian Silvermance4825f2019-02-17 18:28:39 -080089 visibility = ["//visibility:public"],
Brian Silverman246cb222019-02-02 16:38:18 -080090 deps = [
Brian Silverman0a5e7db2019-02-17 13:45:27 -080091 ":jevois_crc",
Brian Silverman246cb222019-02-02 16:38:18 -080092 ":structures",
93 "//aos/util:bitpacking",
Austin Schuhb72be802022-01-02 12:26:28 -080094 "@com_google_absl//absl/types:span",
Philipp Schraderdada1072020-11-24 11:34:46 -080095 ] + select({
96 "@platforms//os:linux": ["//aos/logging"],
97 "//conditions:default": [],
98 }),
Brian Silvermanfdfb3132019-02-24 15:27:27 -080099)
100
101cc_library(
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800102 name = "uart",
103 srcs = [
104 "uart.cc",
105 ],
106 hdrs = [
107 "uart.h",
108 ],
Brian Silvermance4825f2019-02-17 18:28:39 -0800109 visibility = ["//visibility:public"],
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800110 deps = [
Brian Silverman2eb89762019-02-17 15:16:37 -0800111 ":cobs",
112 ":jevois_crc",
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800113 ":structures",
114 "//aos/containers:sized_array",
Brian Silverman2eb89762019-02-17 15:16:37 -0800115 "//aos/util:bitpacking",
Austin Schuhb72be802022-01-02 12:26:28 -0800116 "@com_google_absl//absl/types:span",
Philipp Schraderdada1072020-11-24 11:34:46 -0800117 ] + select({
118 "@platforms//os:linux": ["//aos/logging"],
119 "//conditions:default": [],
120 }),
Brian Silvermanfdfb3132019-02-24 15:27:27 -0800121)
122
Brian Silverman246cb222019-02-02 16:38:18 -0800123cc_test(
Brian Silverman2eb89762019-02-17 15:16:37 -0800124 name = "uart_test",
125 srcs = [
126 "uart_test.cc",
127 ],
James Kuszmaul9776b392023-01-14 14:08:08 -0800128 copts = compiler_select({
129 "gcc": ["-Wno-stringop-overflow"],
130 "clang": [],
131 }),
Philipp Schraderdada1072020-11-24 11:34:46 -0800132 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman2eb89762019-02-17 15:16:37 -0800133 deps = [
134 ":uart",
135 "//aos/testing:googletest",
136 ],
137)
138
139cc_test(
Brian Silverman246cb222019-02-02 16:38:18 -0800140 name = "spi_test",
141 srcs = [
142 "spi_test.cc",
143 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800144 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman246cb222019-02-02 16:38:18 -0800145 deps = [
146 ":spi",
147 "//aos/testing:googletest",
148 ],
149)
Brian Silverman41709732019-02-09 20:53:08 -0800150
151cc_library(
152 name = "cobs",
153 hdrs = [
154 "cobs.h",
155 ],
156 deps = [
Austin Schuhb72be802022-01-02 12:26:28 -0800157 "@com_google_absl//absl/types:span",
Brian Silverman41709732019-02-09 20:53:08 -0800158 ],
159)
160
161cc_test(
162 name = "cobs_test",
163 srcs = [
164 "cobs_test.cc",
165 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800166 target_compatible_with = ["@platforms//os:linux"],
Brian Silverman41709732019-02-09 20:53:08 -0800167 deps = [
168 ":cobs",
169 "//aos/testing:googletest",
170 "//aos/testing:test_logging",
Austin Schuhb72be802022-01-02 12:26:28 -0800171 "@com_google_absl//absl/types:span",
Brian Silverman41709732019-02-09 20:53:08 -0800172 ],
173)
Parker Schuh13696b32019-02-16 15:51:20 -0800174
175cc_library(
176 name = "serial",
Parker Schuh13696b32019-02-16 15:51:20 -0800177 srcs = ["serial.cc"],
Brian Silverman3240e102019-02-16 18:24:24 -0800178 hdrs = ["serial.h"],
Philipp Schraderdada1072020-11-24 11:34:46 -0800179 target_compatible_with = ["@platforms//os:linux"],
Parker Schuh7c42f0d2019-02-17 14:02:33 -0800180 visibility = ["//visibility:public"],
Parker Schuh13696b32019-02-16 15:51:20 -0800181 deps = [
Brian Silverman3240e102019-02-16 18:24:24 -0800182 "//aos/logging",
Parker Schuh13696b32019-02-16 15:51:20 -0800183 ],
184)
Brian Silverman3240e102019-02-16 18:24:24 -0800185
186cc_binary(
187 name = "teensy.elf",
188 srcs = [
189 "teensy.cc",
190 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800191 target_compatible_with = ["//tools/platforms/hardware:cortex_m4f"],
Brian Silverman3240e102019-02-16 18:24:24 -0800192 deps = [
Philipp Schraderdada1072020-11-24 11:34:46 -0800193 ":cobs",
194 ":spi",
195 ":uart",
Austin Schuha2503a72020-12-15 20:57:57 -0800196 "//aos/time",
Brian Silverman3240e102019-02-16 18:24:24 -0800197 "//motors:util",
198 "//motors/core",
199 "//motors/peripheral:configuration",
Brian Silvermand7d01102019-02-24 16:11:21 -0800200 "//motors/peripheral:spi",
Brian Silverman3240e102019-02-16 18:24:24 -0800201 "//motors/peripheral:uart",
202 "//motors/print:usb",
Brian Silvermana498bbb2019-03-03 17:18:04 -0800203 "//y2019/vision:constants",
Austin Schuhb72be802022-01-02 12:26:28 -0800204 "@com_google_absl//absl/types:span",
Brian Silverman3240e102019-02-16 18:24:24 -0800205 ],
206)
207
208hex_from_elf(
209 name = "teensy",
Philipp Schraderdada1072020-11-24 11:34:46 -0800210 target_compatible_with = ["//tools/platforms/hardware:cortex_m4f"],
Brian Silverman3240e102019-02-16 18:24:24 -0800211)