blob: b944d98403c2f3dd514b7ec3e77e20d045d1345c [file] [log] [blame]
Brian Silverman246cb222019-02-02 16:38:18 -08001spi_crc_args = [
2 "$(location //third_party/pycrc:pycrc_main)",
3 "--width=16",
4 # This is the recommendation from
5 # http://users.ece.cmu.edu/~koopman/roses/dsn04/koopman04_crc_poly_embedded.pdf
6 # for messages of 242 - 2048 bits, which covers what we want.
7 # That's an analysis from an exhaustive search of all polynomials for
8 # various CRCs to find the best ones. This is 0xBAAD, converted from the
9 # weird format used there to the standard one used by pycrc.
10 "--poly=0x755b",
11 "--reflect-in=False",
12 "--xor-in=0xffff",
13 "--reflect-out=False",
14 "--xor-out=0xffff",
15 "--std=C99",
16 "--algorithm=table-driven",
17 "--symbol-prefix=jevois_spi_crc_",
18 "--crc-type=uint16_t",
19]
20
21genrule(
22 name = "gen_spi_crc",
23 outs = [
24 "spi_crc.h",
25 "spi_crc.c",
26 ],
27 cmd = " && ".join([
28 " ".join(spi_crc_args + [
29 "--generate=h",
30 "--output=$(location spi_crc.h)",
31 ]),
32 " ".join(spi_crc_args + [
33 "--generate=c",
34 "--output=$(location spi_crc.c)",
35 ]),
36 ]),
37 tools = [
38 "//third_party/pycrc:pycrc_main",
39 ],
40)
41
42cc_library(
43 name = "spi_crc",
44 srcs = [
45 "spi_crc.c",
46 ],
47 hdrs = [
48 "spi_crc.h",
49 ],
50 deps = [
51 "//third_party/GSL",
52 ],
53)
54
Brian Silverman1c0612e2019-01-26 17:26:08 -080055cc_library(
56 name = "structures",
57 hdrs = [
58 "structures.h",
59 ],
60 visibility = ["//visibility:public"],
61 deps = [
62 "//aos/containers:sized_array",
63 "//third_party/eigen",
64 ],
65)
Brian Silverman246cb222019-02-02 16:38:18 -080066
67cc_library(
68 name = "spi",
69 srcs = [
70 "spi.cc",
71 ],
72 hdrs = [
73 "spi.h",
74 ],
75 deps = [
76 ":spi_crc",
77 ":structures",
78 "//aos/util:bitpacking",
79 "//third_party/GSL",
80 "//third_party/optional",
81 ],
82)
83
84cc_test(
85 name = "spi_test",
86 srcs = [
87 "spi_test.cc",
88 ],
89 deps = [
90 ":spi",
91 "//aos/testing:googletest",
92 ],
93)
Brian Silverman41709732019-02-09 20:53:08 -080094
95cc_library(
96 name = "cobs",
97 hdrs = [
98 "cobs.h",
99 ],
100 deps = [
101 "//aos/logging",
102 "//third_party/GSL",
103 ],
104)
105
106cc_test(
107 name = "cobs_test",
108 srcs = [
109 "cobs_test.cc",
110 ],
111 deps = [
112 ":cobs",
113 "//aos/testing:googletest",
114 "//aos/testing:test_logging",
115 "//third_party/GSL",
116 ],
117)