blob: 9304e8e3ab90dd101a32bafed27179004d2b03c2 [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 ],
Brian Silvermance4825f2019-02-17 18:28:39 -080079 visibility = ["//visibility:public"],
Brian Silverman246cb222019-02-02 16:38:18 -080080 deps = [
Brian Silverman0a5e7db2019-02-17 13:45:27 -080081 ":jevois_crc",
Brian Silverman246cb222019-02-02 16:38:18 -080082 ":structures",
Brian Silverman2eb89762019-02-17 15:16:37 -080083 "//aos/logging",
Brian Silverman246cb222019-02-02 16:38:18 -080084 "//aos/util:bitpacking",
85 "//third_party/GSL",
86 "//third_party/optional",
87 ],
88)
89
Brian Silvermanbfbbe872019-02-10 18:00:57 -080090cc_library(
91 name = "uart",
92 srcs = [
93 "uart.cc",
94 ],
95 hdrs = [
96 "uart.h",
97 ],
Brian Silvermance4825f2019-02-17 18:28:39 -080098 visibility = ["//visibility:public"],
Brian Silvermanbfbbe872019-02-10 18:00:57 -080099 deps = [
Brian Silverman2eb89762019-02-17 15:16:37 -0800100 ":cobs",
101 ":jevois_crc",
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800102 ":structures",
103 "//aos/containers:sized_array",
Brian Silverman2eb89762019-02-17 15:16:37 -0800104 "//aos/logging",
105 "//aos/util:bitpacking",
106 "//third_party/GSL",
Brian Silvermanbfbbe872019-02-10 18:00:57 -0800107 "//third_party/optional",
108 ],
109)
110
Brian Silverman246cb222019-02-02 16:38:18 -0800111cc_test(
Brian Silverman2eb89762019-02-17 15:16:37 -0800112 name = "uart_test",
113 srcs = [
114 "uart_test.cc",
115 ],
116 deps = [
117 ":uart",
118 "//aos/testing:googletest",
119 ],
120)
121
122cc_test(
Brian Silverman246cb222019-02-02 16:38:18 -0800123 name = "spi_test",
124 srcs = [
125 "spi_test.cc",
126 ],
127 deps = [
128 ":spi",
129 "//aos/testing:googletest",
130 ],
131)
Brian Silverman41709732019-02-09 20:53:08 -0800132
133cc_library(
134 name = "cobs",
135 hdrs = [
136 "cobs.h",
137 ],
138 deps = [
139 "//aos/logging",
140 "//third_party/GSL",
141 ],
142)
143
144cc_test(
145 name = "cobs_test",
146 srcs = [
147 "cobs_test.cc",
148 ],
149 deps = [
150 ":cobs",
151 "//aos/testing:googletest",
152 "//aos/testing:test_logging",
153 "//third_party/GSL",
154 ],
155)
Parker Schuh13696b32019-02-16 15:51:20 -0800156
157cc_library(
158 name = "serial",
Parker Schuh13696b32019-02-16 15:51:20 -0800159 srcs = ["serial.cc"],
Brian Silverman3240e102019-02-16 18:24:24 -0800160 hdrs = ["serial.h"],
Parker Schuh7c42f0d2019-02-17 14:02:33 -0800161 visibility = ["//visibility:public"],
Parker Schuh13696b32019-02-16 15:51:20 -0800162 deps = [
Brian Silverman3240e102019-02-16 18:24:24 -0800163 "//aos/logging",
Parker Schuh13696b32019-02-16 15:51:20 -0800164 ],
165)
Brian Silverman3240e102019-02-16 18:24:24 -0800166
167cc_binary(
168 name = "teensy.elf",
169 srcs = [
170 "teensy.cc",
171 ],
172 restricted_to = ["//tools:cortex-m4f"],
173 deps = [
174 "//aos/time:time_mcu",
175 "//motors:util",
176 "//motors/core",
177 "//motors/peripheral:configuration",
178 "//motors/peripheral:uart",
179 "//motors/print:usb",
180 ],
181)
182
183hex_from_elf(
184 name = "teensy",
185 restricted_to = ["//tools:cortex-m4f"],
186)