Brian Silverman | 2df8441 | 2013-12-10 14:00:40 -0800 | [diff] [blame] | 1 | // 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. |
| 7 | // In the cape code, fill_packet.h #includes this file. |
| 8 | // In the fitpc code, frc971/input/gyro_board_data.h #includes this file. |
| 9 | |
| 10 | #pragma pack(push, 1) |
| 11 | // Be careful with declaration order in here. ARM doesn't like unaligned |
| 12 | // accesses! |
| 13 | struct DATA_STRUCT_NAME { |
| 14 | int64_t gyro_angle; |
| 15 | |
| 16 | union { |
| 17 | struct { |
Brian Silverman | ffeef3f | 2013-12-22 14:06:23 -0800 | [diff] [blame] | 18 | // In 10us since the cape last reset. |
Brian Silverman | 2df8441 | 2013-12-10 14:00:40 -0800 | [diff] [blame] | 19 | uint64_t timestamp; |
| 20 | |
Brian Silverman | 1b6fbd0 | 2013-12-12 18:08:47 -0800 | [diff] [blame] | 21 | // The CRC32 (same algorithm as the checksum for the packet) of the whole |
| 22 | // contents of flash for the main code (aka what's in the .hex file). |
| 23 | uint32_t flash_checksum; |
| 24 | |
Brian Silverman | 2df8441 | 2013-12-10 14:00:40 -0800 | [diff] [blame] | 25 | struct { |
| 26 | // If the current gyro_angle has been not updated because of a bad |
| 27 | // reading from the sensor. |
| 28 | uint8_t old_gyro_reading : 1; |
Brian Silverman | 18b0164 | 2013-12-13 21:12:25 -0800 | [diff] [blame] | 29 | // If the gyro is still initializing. |
| 30 | // If this is 1, then all of the other gyro data is invalid. |
| 31 | uint8_t uninitialized_gyro : 1; |
| 32 | // If the gyro is still zeroing. |
| 33 | // If this is 1, then all of the other gyro data is invalid. |
| 34 | uint8_t zeroing_gyro : 1; |
Brian Silverman | 2df8441 | 2013-12-10 14:00:40 -0800 | [diff] [blame] | 35 | // If we're not going to get any more good gyro_angles. |
| 36 | uint8_t bad_gyro : 1; |
| 37 | }; |
| 38 | }; |
| 39 | struct { |
| 40 | uint64_t header1, header2; |
| 41 | }; |
| 42 | }; |
| 43 | |
| 44 | // We are 64-bit aligned at this point. |
| 45 | |
| 46 | union { |
| 47 | struct { |
Brian Silverman | 1b6fbd0 | 2013-12-12 18:08:47 -0800 | [diff] [blame] | 48 | int32_t encoders[8]; |
Brian Silverman | 2df8441 | 2013-12-10 14:00:40 -0800 | [diff] [blame] | 49 | |
Brian Silverman | 1b6fbd0 | 2013-12-12 18:08:47 -0800 | [diff] [blame] | 50 | uint16_t analogs[8]; |
Brian Silverman | 2df8441 | 2013-12-10 14:00:40 -0800 | [diff] [blame] | 51 | |
Brian Silverman | 1b6fbd0 | 2013-12-12 18:08:47 -0800 | [diff] [blame] | 52 | uint32_t digitals; |
Brian Silverman | 9694481 | 2013-12-28 22:33:08 -0800 | [diff] [blame^] | 53 | } test; |
Brian Silverman | 2df8441 | 2013-12-10 14:00:40 -0800 | [diff] [blame] | 54 | |
| 55 | struct { |
Brian Silverman | 2df8441 | 2013-12-10 14:00:40 -0800 | [diff] [blame] | 56 | } bot3; |
| 57 | }; |
| 58 | } __attribute__((aligned(8))); |
| 59 | #pragma pack(pop) |
| 60 | |
| 61 | // The number of bytes that we actually send (so it stays consistent) (including |
| 62 | // the byte-stuffing overhead and the CRC on the end). |
Brian Silverman | 1662a0e | 2013-12-19 17:50:01 -0800 | [diff] [blame] | 63 | // This will always be a multiple of 4. |
Brian Silverman | 2df8441 | 2013-12-10 14:00:40 -0800 | [diff] [blame] | 64 | #define DATA_STRUCT_SEND_SIZE 200 |
| 65 | |
| 66 | #ifdef __cplusplus |
| 67 | #define STATIC_ASSERT(cond, msg) static_assert(cond, #msg) |
| 68 | #endif |
| 69 | // 4 bytes of 0s at the beginning, 4 bytes of byte-stuffing overhead, and 4 |
| 70 | // bytes of CRC on the end. |
| 71 | STATIC_ASSERT( |
| 72 | (sizeof(struct DATA_STRUCT_NAME) + 8 + 4) <= DATA_STRUCT_SEND_SIZE, |
| 73 | The_sensor_data_structure_is_too_big); |
| 74 | // The byte-stuffing and CRC both work in chunks of 4 bytes, so it has to be a |
| 75 | // multiple of that in size. |
| 76 | STATIC_ASSERT((sizeof(struct DATA_STRUCT_NAME) % 4) == 0, |
| 77 | The_sensor_data_structure_is_not_a_multiple_of_4_bytes); |
| 78 | #ifdef __cplusplus |
| 79 | #undef STATIC_ASSERT |
| 80 | #endif |