UsbCanMessages.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2015-2018, Dataspeed Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Dataspeed Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
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 // Throw compiler errors on bad message sizes
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  * Common Structures and Unions
00057  ******************************************************************************/
00058 typedef struct PACK_ATTRIB {
00059     uint16_t major;
00060     uint16_t minor;
00061     uint16_t build;
00062 } Version; // 6 bytes
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; // 16 bytes
00082 static inline void testCommonSizes() {
00083     BUILD_ASSERT(sizeof(Version) == 6);
00084     BUILD_ASSERT(sizeof(MessageBuffer) == 16);
00085 }
00086 /******************************************************************************/
00087 
00088 
00089 /*******************************************************************************
00090  * Configuration Interface
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  * Data Stream
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


dataspeed_can_usb
Author(s): Kevin Hallenbeck
autogenerated on Thu Jun 6 2019 21:16:43