blob: 6d747bbbc8730a099bb47e04d0825e62549bc75c [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
Brian Silverman0bca3ba2014-03-26 14:07:55 -070085 // The length of the pulse from the ultrasonic sensor in 100KHz ticks.
Brian Silverman5b433df2014-02-17 11:57:37 -080086 uint32_t ultrasonic_pulse_length;
87
Brian Silverman0bca3ba2014-03-26 14:07:55 -070088 // The length of the pulse from the sidecar PWM output in 10MHz ticks.
89 uint32_t output_check_pulse_length;
90
Brian Silvermanfac5c292014-02-17 15:26:57 -080091 int32_t shooter_position, pusher_distal_posedge_position,
92 pusher_proximal_posedge_position;
Brian Silverman5b433df2014-02-17 11:57:37 -080093
Austin Schuh809c2562014-03-02 11:50:19 -080094 uint16_t low_left_drive_hall;
95 uint16_t high_left_drive_hall;
96 uint16_t low_right_drive_hall;
97 uint16_t high_right_drive_hall;
Brian Silverman7d16c572014-01-03 20:27:57 -080098
Brian Silverman56658322014-03-22 16:57:22 -070099 uint16_t battery_voltage_high, battery_voltage_low;
Brian Silverman7d16c572014-01-03 20:27:57 -0800100
Brian Silvermanfac5c292014-02-17 15:26:57 -0800101 HallEffectEdges pusher_distal, pusher_proximal;
Brian Silverman7d16c572014-01-03 20:27:57 -0800102
103 struct {
Brian Silverman5b433df2014-02-17 11:57:37 -0800104 uint8_t plunger : 1;
105 uint8_t pusher_distal : 1;
106 uint8_t pusher_proximal : 1;
107 uint8_t latch : 1;
108 } bools;
Brian Silverman7d16c572014-01-03 20:27:57 -0800109 } main;
Brian Silverman2df84412013-12-10 14:00:40 -0800110 };
111} __attribute__((aligned(8)));
112#pragma pack(pop)
113
114// The number of bytes that we actually send (so it stays consistent) (including
115// the byte-stuffing overhead and the CRC on the end).
Brian Silverman1662a0e2013-12-19 17:50:01 -0800116// This will always be a multiple of 4.
Brian Silverman803b7a52014-01-01 13:21:18 -0800117#define DATA_STRUCT_SEND_SIZE 148
Brian Silverman2df84412013-12-10 14:00:40 -0800118
119#ifdef __cplusplus
120#define STATIC_ASSERT(cond, msg) static_assert(cond, #msg)
121#endif
122// 4 bytes of 0s at the beginning, 4 bytes of byte-stuffing overhead, and 4
123// bytes of CRC on the end.
124STATIC_ASSERT(
125 (sizeof(struct DATA_STRUCT_NAME) + 8 + 4) <= DATA_STRUCT_SEND_SIZE,
126 The_sensor_data_structure_is_too_big);
127// The byte-stuffing and CRC both work in chunks of 4 bytes, so it has to be a
128// multiple of that in size.
129STATIC_ASSERT((sizeof(struct DATA_STRUCT_NAME) % 4) == 0,
130 The_sensor_data_structure_is_not_a_multiple_of_4_bytes);
131#ifdef __cplusplus
132#undef STATIC_ASSERT
133#endif