UsbCanMessages.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2015-2020, Dataspeed Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Dataspeed Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 #ifndef _USB_CAN_MESSAGES_H
36 #define _USB_CAN_MESSAGES_H
37 #include <stdint.h>
38 
39 #if defined(__linux__) || defined(_WIN32)
40  #define PACK_ATTRIB
41  #pragma pack(push, 1)
42 #else
43  #define PACK_ATTRIB __attribute__ ((packed))
44 #endif
45 
46 // Throw compiler errors on bad message sizes
47 #define BUILD_ASSERT(cond) do { (void) sizeof(char [1 - 2*!(cond)]); } while(0)
48 
49 #define COMMS_VERSION 1
50 
51 #define USB_VID 0x6923
52 #define USB_PID 0x0112
53 #define USB_MI 0
54 
55 /*******************************************************************************
56  * Common Structures and Unions
57  ******************************************************************************/
58 typedef struct PACK_ATTRIB {
59  uint16_t major;
60  uint16_t minor;
61  uint16_t build;
62 } Version; // 6 bytes
63 typedef union PACK_ATTRIB {
64  struct PACK_ATTRIB {
65  union PACK_ATTRIB {
66  struct PACK_ATTRIB {
67  uint32_t id :29;
68  uint32_t extended :1;
69  uint32_t channel :2;
70  uint32_t stamp :28;
71  uint32_t dlc :4;
72  };
73  uint32_t headerWord[2];
74  };
75  union PACK_ATTRIB {
76  uint8_t data[8];
77  uint32_t dataWord[2];
78  };
79  };
80  uint32_t messageWord[4];
81 } MessageBuffer; // 16 bytes
82 static inline void testCommonSizes() {
83  BUILD_ASSERT(sizeof(Version) == 6);
84  BUILD_ASSERT(sizeof(MessageBuffer) == 16);
85 }
86 /******************************************************************************/
87 
88 
89 /*******************************************************************************
90  * Configuration Interface
91  ******************************************************************************/
92 #define CONFIGURATION_ENDPOINT 1
93 enum {
95  USB_ID_REBOOT = 0x01,
96  USB_ID_RESET = 0x08,
104 };
105 enum {
108 };
109 typedef union PACK_ATTRIB {
110  uint8_t msg_id;
111  struct PACK_ATTRIB {
112  uint8_t msg_id;
113  uint8_t hw_rev;
114  uint16_t comms;
117  uint32_t serial_number;
118  uint8_t mac_addr[6];
119  } version;
120  struct PACK_ATTRIB {
121  uint8_t msg_id;
122  uint8_t channel;
123  uint8_t mode;
124  uint8_t dummy;
125  uint32_t bitrate;
126  } bus_cfg;
127  struct PACK_ATTRIB {
128  uint8_t msg_id;
129  uint8_t channel;
130  uint8_t success;
131  uint8_t :8;
132  uint32_t mask;
133  uint32_t match;
134  } filter;
135  struct PACK_ATTRIB {
136  uint8_t msg_id;
137  uint8_t num_channels;
138  } num_channels;
139  struct PACK_ATTRIB {
140  uint8_t msg_id;
141  uint8_t dummy8;
142  uint16_t dummy16;
143  uint32_t stamp;
144  } time;
145  struct PACK_ATTRIB {
146  uint8_t msg_id;
147  uint8_t clear;
148  uint16_t dummy16;
149  uint32_t rx_drops[4];
150  uint32_t tx_drops[4];
151  uint8_t rx_errors[4];
152  uint8_t tx_errors[4];
153  } stats;
154 } ConfigPacket;
155 static inline void testConfigurationInterfaceSizes() {
156  BUILD_ASSERT(sizeof(ConfigPacket) <= 64);
157 }
158 /******************************************************************************/
159 
160 
161 /*******************************************************************************
162  * Data Stream
163  ******************************************************************************/
164 #define STREAM_ENDPOINT 2
165 typedef struct PACK_ATTRIB {
167 } StreamPacket;
168 static inline void testDataStreamSizes() {
169  BUILD_ASSERT(sizeof(StreamPacket) <= 64);
170 }
171 /******************************************************************************/
172 
173 #undef BUILD_ASSERT
174 #undef PACK_ATTRIB
175 #if defined(__linux__) || defined (_WIN32)
176  #pragma pack(pop) // Undo packing
177 #endif
178 
179 #endif // _USB_CAN_MESSAGES_H
#define BUILD_ASSERT(cond)
struct PACK_ATTRIB::PACK_ATTRIB bus_cfg
uint32_t messageWord[4]
struct PACK_ATTRIB::PACK_ATTRIB stats
struct PACK_ATTRIB::PACK_ATTRIB num_channels
union PACK_ATTRIB ConfigPacket
MessageBuffer msg[4]
struct PACK_ATTRIB::PACK_ATTRIB time
uint16_t major
uint16_t minor
static void testDataStreamSizes()
uint16_t build
struct PACK_ATTRIB Version
struct PACK_ATTRIB::PACK_ATTRIB version
uint8_t msg_id
struct PACK_ATTRIB StreamPacket
static void testConfigurationInterfaceSizes()
union PACK_ATTRIB MessageBuffer
struct PACK_ATTRIB::PACK_ATTRIB filter
static void testCommonSizes()


dataspeed_can_usb
Author(s): Kevin Hallenbeck
autogenerated on Thu Jul 9 2020 03:42:00