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. |
Brian Silverman | 924e399 | 2014-01-03 14:05:04 -0800 | [diff] [blame] | 7 | // 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 Silverman | 2df8441 | 2013-12-10 14:00:40 -0800 | [diff] [blame] | 9 | |
| 10 | #pragma pack(push, 1) |
Brian Silverman | 5b433df | 2014-02-17 11:57:37 -0800 | [diff] [blame] | 11 | typedef struct { |
| 12 | uint8_t posedges, negedges; |
| 13 | } HallEffectEdges; |
| 14 | typedef 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 Silverman | 2df8441 | 2013-12-10 14:00:40 -0800 | [diff] [blame] | 26 | // Be careful with declaration order in here. ARM doesn't like unaligned |
Brian Silverman | 7d16c57 | 2014-01-03 20:27:57 -0800 | [diff] [blame] | 27 | // 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 Silverman | 2df8441 | 2013-12-10 14:00:40 -0800 | [diff] [blame] | 29 | struct DATA_STRUCT_NAME { |
| 30 | int64_t gyro_angle; |
| 31 | |
| 32 | union { |
| 33 | struct { |
Brian Silverman | ffeef3f | 2013-12-22 14:06:23 -0800 | [diff] [blame] | 34 | // In 10us since the cape last reset. |
Brian Silverman | 2df8441 | 2013-12-10 14:00:40 -0800 | [diff] [blame] | 35 | uint64_t timestamp; |
| 36 | |
Brian Silverman | 1b6fbd0 | 2013-12-12 18:08:47 -0800 | [diff] [blame] | 37 | // 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 Silverman | f482b4c | 2014-03-17 19:44:20 -0700 | [diff] [blame] | 41 | uint8_t analog_errors; |
| 42 | |
Brian Silverman | 2df8441 | 2013-12-10 14:00:40 -0800 | [diff] [blame] | 43 | 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 Silverman | 18b0164 | 2013-12-13 21:12:25 -0800 | [diff] [blame] | 47 | // 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 Silverman | 2df8441 | 2013-12-10 14:00:40 -0800 | [diff] [blame] | 53 | // 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 Silverman | 5762111 | 2014-01-01 16:08:24 -0800 | [diff] [blame] | 65 | // This is for the test code that basically just sends all of the values |
| 66 | // over to make sure that everything is working. |
Brian Silverman | 2df8441 | 2013-12-10 14:00:40 -0800 | [diff] [blame] | 67 | struct { |
Brian Silverman | 1b6fbd0 | 2013-12-12 18:08:47 -0800 | [diff] [blame] | 68 | int32_t encoders[8]; |
Brian Silverman | 2df8441 | 2013-12-10 14:00:40 -0800 | [diff] [blame] | 69 | |
Brian Silverman | 1b6fbd0 | 2013-12-12 18:08:47 -0800 | [diff] [blame] | 70 | uint16_t analogs[8]; |
Brian Silverman | 2df8441 | 2013-12-10 14:00:40 -0800 | [diff] [blame] | 71 | |
Brian Silverman | 1b6fbd0 | 2013-12-12 18:08:47 -0800 | [diff] [blame] | 72 | uint32_t digitals; |
Brian Silverman | 5762111 | 2014-01-01 16:08:24 -0800 | [diff] [blame] | 73 | |
| 74 | int32_t posedge_value, negedge_value; |
| 75 | uint8_t posedge_count, negedge_count; |
Brian Silverman | 9694481 | 2013-12-28 22:33:08 -0800 | [diff] [blame] | 76 | } test; |
Brian Silverman | 7d16c57 | 2014-01-03 20:27:57 -0800 | [diff] [blame] | 77 | |
| 78 | // This is for the comp and practice robots. |
| 79 | struct { |
Brian Silverman | 5b433df | 2014-02-17 11:57:37 -0800 | [diff] [blame] | 80 | SingleClawPosition top_claw, bottom_claw; |
| 81 | |
Brian Silverman | 7d16c57 | 2014-01-03 20:27:57 -0800 | [diff] [blame] | 82 | int32_t left_drive; |
| 83 | int32_t right_drive; |
Brian Silverman | 5b433df | 2014-02-17 11:57:37 -0800 | [diff] [blame] | 84 | |
| 85 | // The length of the pulse from the ultrasonic sensor in 100kHZ ticks. |
| 86 | uint32_t ultrasonic_pulse_length; |
| 87 | |
Brian Silverman | fac5c29 | 2014-02-17 15:26:57 -0800 | [diff] [blame] | 88 | int32_t shooter_position, pusher_distal_posedge_position, |
| 89 | pusher_proximal_posedge_position; |
Brian Silverman | 5b433df | 2014-02-17 11:57:37 -0800 | [diff] [blame] | 90 | |
Austin Schuh | 809c256 | 2014-03-02 11:50:19 -0800 | [diff] [blame] | 91 | 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 Silverman | 7d16c57 | 2014-01-03 20:27:57 -0800 | [diff] [blame] | 95 | |
Brian Silverman | 5665832 | 2014-03-22 16:57:22 -0700 | [diff] [blame^] | 96 | uint16_t battery_voltage_high, battery_voltage_low; |
Brian Silverman | 7d16c57 | 2014-01-03 20:27:57 -0800 | [diff] [blame] | 97 | |
Brian Silverman | fac5c29 | 2014-02-17 15:26:57 -0800 | [diff] [blame] | 98 | HallEffectEdges pusher_distal, pusher_proximal; |
Brian Silverman | 7d16c57 | 2014-01-03 20:27:57 -0800 | [diff] [blame] | 99 | |
| 100 | struct { |
Brian Silverman | 5b433df | 2014-02-17 11:57:37 -0800 | [diff] [blame] | 101 | uint8_t plunger : 1; |
| 102 | uint8_t pusher_distal : 1; |
| 103 | uint8_t pusher_proximal : 1; |
| 104 | uint8_t latch : 1; |
| 105 | } bools; |
Brian Silverman | 7d16c57 | 2014-01-03 20:27:57 -0800 | [diff] [blame] | 106 | } main; |
Brian Silverman | 2df8441 | 2013-12-10 14:00:40 -0800 | [diff] [blame] | 107 | }; |
| 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 Silverman | 1662a0e | 2013-12-19 17:50:01 -0800 | [diff] [blame] | 113 | // This will always be a multiple of 4. |
Brian Silverman | 803b7a5 | 2014-01-01 13:21:18 -0800 | [diff] [blame] | 114 | #define DATA_STRUCT_SEND_SIZE 148 |
Brian Silverman | 2df8441 | 2013-12-10 14:00:40 -0800 | [diff] [blame] | 115 | |
| 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. |
| 121 | STATIC_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. |
| 126 | STATIC_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 |