Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef _USB_CAN_MESSAGES_H
00036 #define _USB_CAN_MESSAGES_H
00037 #include <stdint.h>
00038
00039 #if defined(__linux__) || defined(_WIN32)
00040 #define PACK_ATTRIB
00041 #pragma pack(push, 1)
00042 #else
00043 #define PACK_ATTRIB __attribute__ ((packed))
00044 #endif
00045
00046
00047 #define BUILD_ASSERT(cond) do { (void) sizeof(char [1 - 2*!(cond)]); } while(0)
00048
00049 #define COMMS_VERSION 1
00050
00051 #define USB_VID 0x6923
00052 #define USB_PID 0x0112
00053 #define USB_MI 0
00054
00055
00056
00057
00058 typedef struct PACK_ATTRIB {
00059 uint16_t major;
00060 uint16_t minor;
00061 uint16_t build;
00062 } Version;
00063 typedef union PACK_ATTRIB {
00064 struct PACK_ATTRIB {
00065 union PACK_ATTRIB {
00066 struct PACK_ATTRIB {
00067 uint32_t id :29;
00068 uint32_t extended :1;
00069 uint32_t channel :2;
00070 uint32_t stamp :28;
00071 uint32_t dlc :4;
00072 };
00073 uint32_t headerWord[2];
00074 };
00075 union PACK_ATTRIB {
00076 uint8_t data[8];
00077 uint32_t dataWord[2];
00078 };
00079 };
00080 uint32_t messageWord[4];
00081 } MessageBuffer;
00082 static inline void testCommonSizes() {
00083 BUILD_ASSERT(sizeof(Version) == 6);
00084 BUILD_ASSERT(sizeof(MessageBuffer) == 16);
00085 }
00086
00087
00088
00089
00090
00091
00092 #define CONFIGURATION_ENDPOINT 1
00093 enum {
00094 USB_ID_VERSION = 0x00,
00095 USB_ID_REBOOT = 0x01,
00096 USB_ID_RESET = 0x08,
00097 USB_ID_SET_BUS_CFG = 0x10,
00098 USB_ID_GET_BUS_CFG = 0x11,
00099 USB_ID_SET_FILTER = 0x12,
00100 USB_ID_GET_FILTER = 0x13,
00101 USB_ID_NUM_CHANNELS = 0x40,
00102 USB_ID_GET_TIME = 0x41,
00103 USB_ID_GET_STATS = 0x42,
00104 };
00105 enum {
00106 MODE_NORMAL = 0,
00107 MODE_LISTEN_ONLY = 1,
00108 };
00109 typedef union PACK_ATTRIB {
00110 uint8_t msg_id;
00111 struct PACK_ATTRIB {
00112 uint8_t msg_id;
00113 uint8_t hw_rev;
00114 uint16_t comms;
00115 Version firmware;
00116 Version bootloader;
00117 uint32_t serial_number;
00118 uint8_t mac_addr[6];
00119 } version;
00120 struct PACK_ATTRIB {
00121 uint8_t msg_id;
00122 uint8_t channel;
00123 uint8_t mode;
00124 uint8_t dummy;
00125 uint32_t bitrate;
00126 } bus_cfg;
00127 struct PACK_ATTRIB {
00128 uint8_t msg_id;
00129 uint8_t channel;
00130 uint8_t success;
00131 uint8_t :8;
00132 uint32_t mask;
00133 uint32_t match;
00134 } filter;
00135 struct PACK_ATTRIB {
00136 uint8_t msg_id;
00137 uint8_t num_channels;
00138 } num_channels;
00139 struct PACK_ATTRIB {
00140 uint8_t msg_id;
00141 uint8_t dummy8;
00142 uint16_t dummy16;
00143 uint32_t stamp;
00144 } time;
00145 struct PACK_ATTRIB {
00146 uint8_t msg_id;
00147 uint8_t clear;
00148 uint16_t dummy16;
00149 uint32_t rx_drops[4];
00150 uint32_t tx_drops[4];
00151 uint8_t rx_errors[4];
00152 uint8_t tx_errors[4];
00153 } stats;
00154 } ConfigPacket;
00155 static inline void testConfigurationInterfaceSizes() {
00156 BUILD_ASSERT(sizeof(ConfigPacket) <= 64);
00157 }
00158
00159
00160
00161
00162
00163
00164 #define STREAM_ENDPOINT 2
00165 typedef struct PACK_ATTRIB {
00166 MessageBuffer msg[4];
00167 } StreamPacket;
00168 static inline void testDataStreamSizes() {
00169 BUILD_ASSERT(sizeof(StreamPacket) <= 64);
00170 }
00171
00172
00173 #undef BUILD_ASSERT
00174 #undef PACK_ATTRIB
00175 #if defined(__linux__) || defined (_WIN32)
00176 #pragma pack(pop) // Undo packing
00177 #endif
00178
00179 #endif // _USB_CAN_MESSAGES_H