Brian Silverman | 246cb22 | 2019-02-02 16:38:18 -0800 | [diff] [blame^] | 1 | spi_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 | |
| 21 | genrule( |
| 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 | |
| 42 | cc_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 Silverman | 1c0612e | 2019-01-26 17:26:08 -0800 | [diff] [blame] | 55 | cc_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 Silverman | 246cb22 | 2019-02-02 16:38:18 -0800 | [diff] [blame^] | 66 | |
| 67 | cc_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 | |
| 84 | cc_test( |
| 85 | name = "spi_test", |
| 86 | srcs = [ |
| 87 | "spi_test.cc", |
| 88 | ], |
| 89 | deps = [ |
| 90 | ":spi", |
| 91 | "//aos/testing:googletest", |
| 92 | ], |
| 93 | ) |