blob: 7cce3be726b455e48c6925aad58461ae4baa6ec6 [file] [log] [blame]
Brian Silverman2df84412013-12-10 14:00:40 -08001// This isn't really a header file. It's designed to be #included directly into
2// other code (possibly in a namespace or whatever), so it doesn't have include
3// guards.
4// This means that it can not #include anything else because it (sometimes) gets
5// #included inside a namespace.
6// <stdint.h> must be #included by the containing file.
7// In the cape code, fill_packet.h #includes this file.
8// In the fitpc code, frc971/input/gyro_board_data.h #includes this file.
9
10#pragma pack(push, 1)
11// Be careful with declaration order in here. ARM doesn't like unaligned
12// accesses!
13struct DATA_STRUCT_NAME {
14 int64_t gyro_angle;
15
16 union {
17 struct {
Brian Silvermanffeef3f2013-12-22 14:06:23 -080018 // In 10us since the cape last reset.
Brian Silverman2df84412013-12-10 14:00:40 -080019 uint64_t timestamp;
20
Brian Silverman1b6fbd02013-12-12 18:08:47 -080021 // The CRC32 (same algorithm as the checksum for the packet) of the whole
22 // contents of flash for the main code (aka what's in the .hex file).
23 uint32_t flash_checksum;
24
Brian Silverman2df84412013-12-10 14:00:40 -080025 struct {
26 // If the current gyro_angle has been not updated because of a bad
27 // reading from the sensor.
28 uint8_t old_gyro_reading : 1;
Brian Silverman18b01642013-12-13 21:12:25 -080029 // If the gyro is still initializing.
30 // If this is 1, then all of the other gyro data is invalid.
31 uint8_t uninitialized_gyro : 1;
32 // If the gyro is still zeroing.
33 // If this is 1, then all of the other gyro data is invalid.
34 uint8_t zeroing_gyro : 1;
Brian Silverman2df84412013-12-10 14:00:40 -080035 // If we're not going to get any more good gyro_angles.
36 uint8_t bad_gyro : 1;
37 };
38 };
39 struct {
40 uint64_t header1, header2;
41 };
42 };
43
44 // We are 64-bit aligned at this point.
45
46 union {
47 struct {
Brian Silverman1b6fbd02013-12-12 18:08:47 -080048 int32_t encoders[8];
Brian Silverman2df84412013-12-10 14:00:40 -080049
Brian Silverman1b6fbd02013-12-12 18:08:47 -080050 uint16_t analogs[8];
Brian Silverman2df84412013-12-10 14:00:40 -080051
Brian Silverman1b6fbd02013-12-12 18:08:47 -080052 uint32_t digitals;
Brian Silverman2df84412013-12-10 14:00:40 -080053 } main;
54
55 struct {
Brian Silverman2df84412013-12-10 14:00:40 -080056 } bot3;
57 };
58} __attribute__((aligned(8)));
59#pragma pack(pop)
60
61// The number of bytes that we actually send (so it stays consistent) (including
62// the byte-stuffing overhead and the CRC on the end).
Brian Silverman1662a0e2013-12-19 17:50:01 -080063// This will always be a multiple of 4.
Brian Silverman2df84412013-12-10 14:00:40 -080064#define DATA_STRUCT_SEND_SIZE 200
65
66#ifdef __cplusplus
67#define STATIC_ASSERT(cond, msg) static_assert(cond, #msg)
68#endif
69// 4 bytes of 0s at the beginning, 4 bytes of byte-stuffing overhead, and 4
70// bytes of CRC on the end.
71STATIC_ASSERT(
72 (sizeof(struct DATA_STRUCT_NAME) + 8 + 4) <= DATA_STRUCT_SEND_SIZE,
73 The_sensor_data_structure_is_too_big);
74// The byte-stuffing and CRC both work in chunks of 4 bytes, so it has to be a
75// multiple of that in size.
76STATIC_ASSERT((sizeof(struct DATA_STRUCT_NAME) % 4) == 0,
77 The_sensor_data_structure_is_not_a_multiple_of_4_bytes);
78#ifdef __cplusplus
79#undef STATIC_ASSERT
80#endif