blob: 943e8c2549eb61dcd73af07186b0b4aae2f061d2 [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)
Brian Silverman5b433df2014-02-17 11:57:37 -080011typedef struct {
12 uint8_t posedges, negedges;
13} HallEffectEdges;
14typedef struct {
15 int32_t position, posedge_position, negedge_position;
16
17 HallEffectEdges front, calibration, back;
18
19 struct {
20 uint16_t front : 1;
21 uint16_t calibration : 1;
22 uint16_t back : 1;
23 } bools;
24} SingleClawPosition;
25
Brian Silverman2df84412013-12-10 14:00:40 -080026// Be careful with declaration order in here. ARM doesn't like unaligned
Brian Silverman7d16c572014-01-03 20:27:57 -080027// accesses and this structure is packed, so messing the order up will cause the
28// compiler to generate very inefficient code to access fields.
Brian Silverman2df84412013-12-10 14:00:40 -080029struct DATA_STRUCT_NAME {
30 int64_t gyro_angle;
31
32 union {
33 struct {
Brian Silvermanffeef3f2013-12-22 14:06:23 -080034 // In 10us since the cape last reset.
Brian Silverman2df84412013-12-10 14:00:40 -080035 uint64_t timestamp;
36
Brian Silverman1b6fbd02013-12-12 18:08:47 -080037 // The CRC32 (same algorithm as the checksum for the packet) of the whole
38 // contents of flash for the main code (aka what's in the .hex file).
39 uint32_t flash_checksum;
40
Brian Silvermanf482b4c2014-03-17 19:44:20 -070041 uint8_t analog_errors;
42
Brian Silverman2df84412013-12-10 14:00:40 -080043 struct {
44 // If the current gyro_angle has been not updated because of a bad
45 // reading from the sensor.
46 uint8_t old_gyro_reading : 1;
Brian Silverman18b01642013-12-13 21:12:25 -080047 // If the gyro is still initializing.
48 // If this is 1, then all of the other gyro data is invalid.
49 uint8_t uninitialized_gyro : 1;
50 // If the gyro is still zeroing.
51 // If this is 1, then all of the other gyro data is invalid.
52 uint8_t zeroing_gyro : 1;
Brian Silverman2df84412013-12-10 14:00:40 -080053 // If we're not going to get any more good gyro_angles.
54 uint8_t bad_gyro : 1;
55 };
56 };
57 struct {
58 uint64_t header1, header2;
59 };
60 };
61
62 // We are 64-bit aligned at this point.
63
64 union {
Brian Silverman57621112014-01-01 16:08:24 -080065 // This is for the test code that basically just sends all of the values
66 // over to make sure that everything is working.
Brian Silverman2df84412013-12-10 14:00:40 -080067 struct {
Brian Silverman1b6fbd02013-12-12 18:08:47 -080068 int32_t encoders[8];
Brian Silverman2df84412013-12-10 14:00:40 -080069
Brian Silverman1b6fbd02013-12-12 18:08:47 -080070 uint16_t analogs[8];
Brian Silverman2df84412013-12-10 14:00:40 -080071
Brian Silverman1b6fbd02013-12-12 18:08:47 -080072 uint32_t digitals;
Brian Silverman57621112014-01-01 16:08:24 -080073
74 int32_t posedge_value, negedge_value;
75 uint8_t posedge_count, negedge_count;
Brian Silverman96944812013-12-28 22:33:08 -080076 } test;
Brian Silverman7d16c572014-01-03 20:27:57 -080077
78 // This is for the comp and practice robots.
79 struct {
Brian Silverman5b433df2014-02-17 11:57:37 -080080 SingleClawPosition top_claw, bottom_claw;
81
Brian Silverman7d16c572014-01-03 20:27:57 -080082 int32_t left_drive;
83 int32_t right_drive;
Brian Silverman5b433df2014-02-17 11:57:37 -080084
85 // The length of the pulse from the ultrasonic sensor in 100kHZ ticks.
86 uint32_t ultrasonic_pulse_length;
87
Brian Silvermanfac5c292014-02-17 15:26:57 -080088 int32_t shooter_position, pusher_distal_posedge_position,
89 pusher_proximal_posedge_position;
Brian Silverman5b433df2014-02-17 11:57:37 -080090
Austin Schuh809c2562014-03-02 11:50:19 -080091 uint16_t low_left_drive_hall;
92 uint16_t high_left_drive_hall;
93 uint16_t low_right_drive_hall;
94 uint16_t high_right_drive_hall;
Brian Silverman7d16c572014-01-03 20:27:57 -080095
Brian Silverman78670262014-01-17 23:40:47 -080096 uint16_t battery_voltage;
Brian Silverman7d16c572014-01-03 20:27:57 -080097
Brian Silvermanfac5c292014-02-17 15:26:57 -080098 HallEffectEdges pusher_distal, pusher_proximal;
Brian Silverman7d16c572014-01-03 20:27:57 -080099
100 struct {
Brian Silverman5b433df2014-02-17 11:57:37 -0800101 uint8_t plunger : 1;
102 uint8_t pusher_distal : 1;
103 uint8_t pusher_proximal : 1;
104 uint8_t latch : 1;
105 } bools;
Brian Silverman7d16c572014-01-03 20:27:57 -0800106 } main;
Brian Silverman2df84412013-12-10 14:00:40 -0800107 };
108} __attribute__((aligned(8)));
109#pragma pack(pop)
110
111// The number of bytes that we actually send (so it stays consistent) (including
112// the byte-stuffing overhead and the CRC on the end).
Brian Silverman1662a0e2013-12-19 17:50:01 -0800113// This will always be a multiple of 4.
Brian Silverman803b7a52014-01-01 13:21:18 -0800114#define DATA_STRUCT_SEND_SIZE 148
Brian Silverman2df84412013-12-10 14:00:40 -0800115
116#ifdef __cplusplus
117#define STATIC_ASSERT(cond, msg) static_assert(cond, #msg)
118#endif
119// 4 bytes of 0s at the beginning, 4 bytes of byte-stuffing overhead, and 4
120// bytes of CRC on the end.
121STATIC_ASSERT(
122 (sizeof(struct DATA_STRUCT_NAME) + 8 + 4) <= DATA_STRUCT_SEND_SIZE,
123 The_sensor_data_structure_is_too_big);
124// The byte-stuffing and CRC both work in chunks of 4 bytes, so it has to be a
125// multiple of that in size.
126STATIC_ASSERT((sizeof(struct DATA_STRUCT_NAME) % 4) == 0,
127 The_sensor_data_structure_is_not_a_multiple_of_4_bytes);
128#ifdef __cplusplus
129#undef STATIC_ASSERT
130#endif