blob: 4aa2a104f9c6cbcd2ad6ab1b540f6796e8798004 [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 Silverman2df84412013-12-10 14:00:40 -080041 struct {
42 // If the current gyro_angle has been not updated because of a bad
43 // reading from the sensor.
44 uint8_t old_gyro_reading : 1;
Brian Silverman18b01642013-12-13 21:12:25 -080045 // If the gyro is still initializing.
46 // If this is 1, then all of the other gyro data is invalid.
47 uint8_t uninitialized_gyro : 1;
48 // If the gyro is still zeroing.
49 // If this is 1, then all of the other gyro data is invalid.
50 uint8_t zeroing_gyro : 1;
Brian Silverman2df84412013-12-10 14:00:40 -080051 // If we're not going to get any more good gyro_angles.
52 uint8_t bad_gyro : 1;
53 };
54 };
55 struct {
56 uint64_t header1, header2;
57 };
58 };
59
60 // We are 64-bit aligned at this point.
61
62 union {
Brian Silverman57621112014-01-01 16:08:24 -080063 // This is for the test code that basically just sends all of the values
64 // over to make sure that everything is working.
Brian Silverman2df84412013-12-10 14:00:40 -080065 struct {
Brian Silverman1b6fbd02013-12-12 18:08:47 -080066 int32_t encoders[8];
Brian Silverman2df84412013-12-10 14:00:40 -080067
Brian Silverman1b6fbd02013-12-12 18:08:47 -080068 uint16_t analogs[8];
Brian Silverman2df84412013-12-10 14:00:40 -080069
Brian Silverman1b6fbd02013-12-12 18:08:47 -080070 uint32_t digitals;
Brian Silverman57621112014-01-01 16:08:24 -080071
72 int32_t posedge_value, negedge_value;
73 uint8_t posedge_count, negedge_count;
Brian Silverman96944812013-12-28 22:33:08 -080074 } test;
Brian Silverman7d16c572014-01-03 20:27:57 -080075
76 // This is for the comp and practice robots.
77 struct {
Brian Silverman5b433df2014-02-17 11:57:37 -080078 SingleClawPosition top_claw, bottom_claw;
79
Brian Silverman7d16c572014-01-03 20:27:57 -080080 int32_t left_drive;
81 int32_t right_drive;
Brian Silverman5b433df2014-02-17 11:57:37 -080082
83 // The length of the pulse from the ultrasonic sensor in 100kHZ ticks.
84 uint32_t ultrasonic_pulse_length;
85
Brian Silvermanfac5c292014-02-17 15:26:57 -080086 int32_t shooter_position, pusher_distal_posedge_position,
87 pusher_proximal_posedge_position;
Brian Silverman5b433df2014-02-17 11:57:37 -080088
Austin Schuh809c2562014-03-02 11:50:19 -080089 uint16_t low_left_drive_hall;
90 uint16_t high_left_drive_hall;
91 uint16_t low_right_drive_hall;
92 uint16_t high_right_drive_hall;
Brian Silverman7d16c572014-01-03 20:27:57 -080093
Brian Silverman78670262014-01-17 23:40:47 -080094 uint16_t battery_voltage;
Brian Silverman7d16c572014-01-03 20:27:57 -080095
Brian Silvermanfac5c292014-02-17 15:26:57 -080096 HallEffectEdges pusher_distal, pusher_proximal;
Brian Silverman7d16c572014-01-03 20:27:57 -080097
98 struct {
Brian Silverman5b433df2014-02-17 11:57:37 -080099 uint8_t plunger : 1;
100 uint8_t pusher_distal : 1;
101 uint8_t pusher_proximal : 1;
102 uint8_t latch : 1;
103 } bools;
Brian Silverman7d16c572014-01-03 20:27:57 -0800104 } main;
Brian Silverman2df84412013-12-10 14:00:40 -0800105 };
106} __attribute__((aligned(8)));
107#pragma pack(pop)
108
109// The number of bytes that we actually send (so it stays consistent) (including
110// the byte-stuffing overhead and the CRC on the end).
Brian Silverman1662a0e2013-12-19 17:50:01 -0800111// This will always be a multiple of 4.
Brian Silverman803b7a52014-01-01 13:21:18 -0800112#define DATA_STRUCT_SEND_SIZE 148
Brian Silverman2df84412013-12-10 14:00:40 -0800113
114#ifdef __cplusplus
115#define STATIC_ASSERT(cond, msg) static_assert(cond, #msg)
116#endif
117// 4 bytes of 0s at the beginning, 4 bytes of byte-stuffing overhead, and 4
118// bytes of CRC on the end.
119STATIC_ASSERT(
120 (sizeof(struct DATA_STRUCT_NAME) + 8 + 4) <= DATA_STRUCT_SEND_SIZE,
121 The_sensor_data_structure_is_too_big);
122// The byte-stuffing and CRC both work in chunks of 4 bytes, so it has to be a
123// multiple of that in size.
124STATIC_ASSERT((sizeof(struct DATA_STRUCT_NAME) % 4) == 0,
125 The_sensor_data_structure_is_not_a_multiple_of_4_bytes);
126#ifdef __cplusplus
127#undef STATIC_ASSERT
128#endif