blob: b381202fae9142732271bd0b2ed6fe985a262180 [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;
Brian Silverman7d16c572014-01-03 20:27:57 -080065 uint16_t left_drive_hall;
66 uint16_t right_drive_hall;
67
Brian Silverman78670262014-01-17 23:40:47 -080068 uint16_t battery_voltage;
Brian Silverman7d16c572014-01-03 20:27:57 -080069
Brian Silverman78670262014-01-17 23:40:47 -080070 // The length of the pulse from the ultrasonic sensor in 100kHZ ticks.
71 uint32_t ultrasonic_pulse_length;
Brian Silverman7d16c572014-01-03 20:27:57 -080072
73 struct {
Brian Silverman7d16c572014-01-03 20:27:57 -080074 };
75 } main;
Brian Silverman2df84412013-12-10 14:00:40 -080076 };
77} __attribute__((aligned(8)));
78#pragma pack(pop)
79
80// The number of bytes that we actually send (so it stays consistent) (including
81// the byte-stuffing overhead and the CRC on the end).
Brian Silverman1662a0e2013-12-19 17:50:01 -080082// This will always be a multiple of 4.
Brian Silverman803b7a52014-01-01 13:21:18 -080083#define DATA_STRUCT_SEND_SIZE 148
Brian Silverman2df84412013-12-10 14:00:40 -080084
85#ifdef __cplusplus
86#define STATIC_ASSERT(cond, msg) static_assert(cond, #msg)
87#endif
88// 4 bytes of 0s at the beginning, 4 bytes of byte-stuffing overhead, and 4
89// bytes of CRC on the end.
90STATIC_ASSERT(
91 (sizeof(struct DATA_STRUCT_NAME) + 8 + 4) <= DATA_STRUCT_SEND_SIZE,
92 The_sensor_data_structure_is_too_big);
93// The byte-stuffing and CRC both work in chunks of 4 bytes, so it has to be a
94// multiple of that in size.
95STATIC_ASSERT((sizeof(struct DATA_STRUCT_NAME) % 4) == 0,
96 The_sensor_data_structure_is_not_a_multiple_of_4_bytes);
97#ifdef __cplusplus
98#undef STATIC_ASSERT
99#endif