blob: 9e5ee6cd3cdd6333c43591751559c398cbe05ce4 [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.
Brian Silverman924e3992014-01-03 14:05:04 -08007// In the cape code, bbb_cape/src/cape/fill_packet.h #includes this file.
8// In the prime code, bbb_cape/src/bbb/data_struct.h #includes this file.
Brian Silverman2df84412013-12-10 14:00:40 -08009
10#pragma pack(push, 1)
11// Be careful with declaration order in here. ARM doesn't like unaligned
Brian Silverman7d16c572014-01-03 20:27:57 -080012// accesses and this structure is packed, so messing the order up will cause the
13// compiler to generate very inefficient code to access fields.
Brian Silverman2df84412013-12-10 14:00:40 -080014struct DATA_STRUCT_NAME {
15 int64_t gyro_angle;
16
17 union {
18 struct {
Brian Silvermanffeef3f2013-12-22 14:06:23 -080019 // In 10us since the cape last reset.
Brian Silverman2df84412013-12-10 14:00:40 -080020 uint64_t timestamp;
21
Brian Silverman1b6fbd02013-12-12 18:08:47 -080022 // The CRC32 (same algorithm as the checksum for the packet) of the whole
23 // contents of flash for the main code (aka what's in the .hex file).
24 uint32_t flash_checksum;
25
Brian Silverman2df84412013-12-10 14:00:40 -080026 struct {
27 // If the current gyro_angle has been not updated because of a bad
28 // reading from the sensor.
29 uint8_t old_gyro_reading : 1;
Brian Silverman18b01642013-12-13 21:12:25 -080030 // If the gyro is still initializing.
31 // If this is 1, then all of the other gyro data is invalid.
32 uint8_t uninitialized_gyro : 1;
33 // If the gyro is still zeroing.
34 // If this is 1, then all of the other gyro data is invalid.
35 uint8_t zeroing_gyro : 1;
Brian Silverman2df84412013-12-10 14:00:40 -080036 // If we're not going to get any more good gyro_angles.
37 uint8_t bad_gyro : 1;
38 };
39 };
40 struct {
41 uint64_t header1, header2;
42 };
43 };
44
45 // We are 64-bit aligned at this point.
46
47 union {
Brian Silverman57621112014-01-01 16:08:24 -080048 // This is for the test code that basically just sends all of the values
49 // over to make sure that everything is working.
Brian Silverman2df84412013-12-10 14:00:40 -080050 struct {
Brian Silverman1b6fbd02013-12-12 18:08:47 -080051 int32_t encoders[8];
Brian Silverman2df84412013-12-10 14:00:40 -080052
Brian Silverman1b6fbd02013-12-12 18:08:47 -080053 uint16_t analogs[8];
Brian Silverman2df84412013-12-10 14:00:40 -080054
Brian Silverman1b6fbd02013-12-12 18:08:47 -080055 uint32_t digitals;
Brian Silverman57621112014-01-01 16:08:24 -080056
57 int32_t posedge_value, negedge_value;
58 uint8_t posedge_count, negedge_count;
Brian Silverman96944812013-12-28 22:33:08 -080059 } test;
Brian Silverman7d16c572014-01-03 20:27:57 -080060
61 // This is for the comp and practice robots.
62 struct {
63 int32_t left_drive;
64 int32_t right_drive;
65 int32_t shooter_angle;
66 int32_t shooter;
67 int32_t indexer;
68 int32_t wrist;
69
70 int32_t capture_top_rise;
71 int32_t capture_top_fall;
72 int32_t capture_bottom_fall_delay;
73 int32_t capture_wrist_rise;
74 int32_t capture_shooter_angle_rise;
75
76 uint16_t battery_voltage;
77 uint16_t left_drive_hall;
78 uint16_t right_drive_hall;
79
80 int8_t top_rise_count;
81
82 int8_t top_fall_count;
83
84 int8_t bottom_rise_count;
85
86 int8_t bottom_fall_delay_count;
87 int8_t bottom_fall_count;
88
89 int8_t wrist_rise_count;
90
91 int8_t shooter_angle_rise_count;
92
93 struct {
94 uint8_t wrist_hall_effect : 1;
95 uint8_t angle_adjust_bottom_hall_effect : 1;
96 uint8_t top_disc : 1;
97 uint8_t bottom_disc : 1;
98 uint8_t loader_top : 1;
99 uint8_t loader_bottom : 1;
100 };
101 } main;
Brian Silverman2df84412013-12-10 14:00:40 -0800102 };
103} __attribute__((aligned(8)));
104#pragma pack(pop)
105
106// The number of bytes that we actually send (so it stays consistent) (including
107// the byte-stuffing overhead and the CRC on the end).
Brian Silverman1662a0e2013-12-19 17:50:01 -0800108// This will always be a multiple of 4.
Brian Silverman803b7a52014-01-01 13:21:18 -0800109#define DATA_STRUCT_SEND_SIZE 148
Brian Silverman2df84412013-12-10 14:00:40 -0800110
111#ifdef __cplusplus
112#define STATIC_ASSERT(cond, msg) static_assert(cond, #msg)
113#endif
114// 4 bytes of 0s at the beginning, 4 bytes of byte-stuffing overhead, and 4
115// bytes of CRC on the end.
116STATIC_ASSERT(
117 (sizeof(struct DATA_STRUCT_NAME) + 8 + 4) <= DATA_STRUCT_SEND_SIZE,
118 The_sensor_data_structure_is_too_big);
119// The byte-stuffing and CRC both work in chunks of 4 bytes, so it has to be a
120// multiple of that in size.
121STATIC_ASSERT((sizeof(struct DATA_STRUCT_NAME) % 4) == 0,
122 The_sensor_data_structure_is_not_a_multiple_of_4_bytes);
123#ifdef __cplusplus
124#undef STATIC_ASSERT
125#endif