blob: 0e0d3bda4fd39e58f4f5f0956a50c1f115a56890 [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 ]),
40 tools = [
41 "//third_party/pycrc:pycrc_main",
42 ],
43)
44
45cc_library(
Brian Silverman0a5e7db2019-02-17 13:45:27 -080046 name = "jevois_crc",
Brian Silverman246cb222019-02-02 16:38:18 -080047 srcs = [
Brian Silverman0a5e7db2019-02-17 13:45:27 -080048 "jevois_crc.c",
Brian Silverman246cb222019-02-02 16:38:18 -080049 ],
50 hdrs = [
Brian Silverman0a5e7db2019-02-17 13:45:27 -080051 "jevois_crc.h",
Brian Silverman246cb222019-02-02 16:38:18 -080052 ],
53 deps = [
54 "//third_party/GSL",
55 ],
56)
57
Brian Silverman1c0612e2019-01-26 17:26:08 -080058cc_library(
59 name = "structures",
60 hdrs = [
61 "structures.h",
62 ],
63 visibility = ["//visibility:public"],
64 deps = [
65 "//aos/containers:sized_array",
Brian Silvermana3688802019-02-16 19:31:26 -080066 "//aos/time",
Brian Silverman1c0612e2019-01-26 17:26:08 -080067 "//third_party/eigen",
68 ],
69)
Brian Silverman246cb222019-02-02 16:38:18 -080070
71cc_library(
72 name = "spi",
73 srcs = [
74 "spi.cc",
75 ],
76 hdrs = [
77 "spi.h",
78 ],
79 deps = [
Brian Silverman0a5e7db2019-02-17 13:45:27 -080080 ":jevois_crc",
Brian Silverman246cb222019-02-02 16:38:18 -080081 ":structures",
Brian Silverman2eb89762019-02-17 15:16:37 -080082 "//aos/logging",
Brian Silverman246cb222019-02-02 16:38:18 -080083 "//aos/util:bitpacking",
84 "//third_party/GSL",
85 "//third_party/optional",
86 ],
87)
88
Brian Silvermanbfbbe872019-02-10 18:00:57 -080089cc_library(
90 name = "uart",
91 srcs = [
92 "uart.cc",
93 ],
94 hdrs = [
95 "uart.h",
96 ],
97 deps = [
Brian Silverman2eb89762019-02-17 15:16:37 -080098 ":cobs",
99 ":jevois_crc",
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800100 ":structures",
101 "//aos/containers:sized_array",
Brian Silverman2eb89762019-02-17 15:16:37 -0800102 "//aos/logging",
103 "//aos/util:bitpacking",
104 "//third_party/GSL",
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800105 "//third_party/optional",
106 ],
107)
108
Brian Silverman246cb222019-02-02 16:38:18 -0800109cc_test(
Brian Silverman2eb89762019-02-17 15:16:37 -0800110 name = "uart_test",
111 srcs = [
112 "uart_test.cc",
113 ],
114 deps = [
115 ":uart",
116 "//aos/testing:googletest",
117 ],
118)
119
120cc_test(
Brian Silverman246cb222019-02-02 16:38:18 -0800121 name = "spi_test",
122 srcs = [
123 "spi_test.cc",
124 ],
125 deps = [
126 ":spi",
127 "//aos/testing:googletest",
128 ],
129)
Brian Silverman41709732019-02-09 20:53:08 -0800130
131cc_library(
132 name = "cobs",
133 hdrs = [
134 "cobs.h",
135 ],
136 deps = [
137 "//aos/logging",
138 "//third_party/GSL",
139 ],
140)
141
142cc_test(
143 name = "cobs_test",
144 srcs = [
145 "cobs_test.cc",
146 ],
147 deps = [
148 ":cobs",
149 "//aos/testing:googletest",
150 "//aos/testing:test_logging",
151 "//third_party/GSL",
152 ],
153)
Parker Schuh13696b32019-02-16 15:51:20 -0800154
155cc_library(
156 name = "serial",
Parker Schuh13696b32019-02-16 15:51:20 -0800157 srcs = ["serial.cc"],
Brian Silverman3240e102019-02-16 18:24:24 -0800158 hdrs = ["serial.h"],
Parker Schuh7c42f0d2019-02-17 14:02:33 -0800159 visibility = ["//visibility:public"],
Parker Schuh13696b32019-02-16 15:51:20 -0800160 deps = [
Brian Silverman3240e102019-02-16 18:24:24 -0800161 "//aos/logging",
Parker Schuh13696b32019-02-16 15:51:20 -0800162 ],
163)
Brian Silverman3240e102019-02-16 18:24:24 -0800164
165cc_binary(
166 name = "teensy.elf",
167 srcs = [
168 "teensy.cc",
169 ],
170 restricted_to = ["//tools:cortex-m4f"],
171 deps = [
172 "//aos/time:time_mcu",
173 "//motors:util",
174 "//motors/core",
175 "//motors/peripheral:configuration",
176 "//motors/peripheral:uart",
177 "//motors/print:usb",
178 ],
179)
180
181hex_from_elf(
182 name = "teensy",
183 restricted_to = ["//tools:cortex-m4f"],
184)