Project

General

Profile

Support Request #1269 ยป canfd_types.h

hidden, 2017-10-19 11:26

 
1
/**
2
 *
3
 * tCANFDData structure
4
 *
5
 * @file
6
 * Copyright © Audi Electronic Venture GmbH. All rights reserved
7
 *
8
 * $Author: EWEIRAE $
9
 * $Date: 2015-11-01 14:30:25 +0200 (Mi, 08 Jul 2015) $
10
 * $Revision: 37491 $
11
 *
12
 * @remarks
13
 *
14
 */
15
#ifndef _CANFD_TYPES_HEADER_
16
#define _CANFD_TYPES_HEADER_
17

    
18
#include "can_types.h"
19

    
20
namespace adtf_devicetb
21
{
22

    
23
/// object identifier for the raw can fd media sample with the default class implementation
24
/// adtf_devicetb::cMediaSampleCanFD
25
#define OID_ADTF_MEDIA_SAMPLE_CANFD       "adtf.sample.canfd_message"
26

    
27
/// object identifier for the raw can fd media type (see class adtf_devicetb::IMediaTypeCANFD).
28
#define OID_ADTF_MEDIA_TYPE_CANFD         "adtf.type.canfd"
29
/// interface identifier for the can fd media type (see interface adtf_devicetb::IMediaTypeCANFD).
30
#define IID_ADTF_MEDIA_TYPE_CANFD         "iid.type_canfd"
31

    
32
/// sub type for new can fd data (major Type is MEDIA_TYPE_CAN   0x0200) 
33
#define MEDIA_SUBTYPE_CANFD_DATA          0x0004
34

    
35
/**
36
 * The ADTF Default CANFD Media Type description of adtf_devicetb::tADTFMediaTypeCANFD structure in 
37
 * DDL Version 1.0+.
38
 * @see ADTF_MEDIA_DESC_MEDIATYPE_CANFD
39
 */
40
#define ADTF_MEDIA_DESC_MEDIATYPE_CANFD_DDL1      "<structs>" \
41
                                                ADTF_MEDIA_DESC_MEDIA_TYPEINFO_DDL1 \
42
                                                "  <struct name=\"" OID_ADTF_MEDIA_TYPE_CANFD "\" version=\"1\" alignment=\"1\">" \
43
                                                "    <element type=\"tMediaTypeInfo\"    name=\"sMediatype\"    bytepos=\"0\" arraysize=\"1\" byteorder=\"LE\" alignment=\"1\"/>" \
44
                                                "    <element type=\"tChar\"             name=\"strChannelID\"   bytepos=\"12\" arraysize=\"256\" byteorder=\"LE\" alignment=\"1\"/>" \
45
                                                "  </struct>" \
46
                                                "</structs>"
47

    
48
/**
49
 * The ADTF Default CAN FD Media Type description.
50
 * @see ADTF_MEDIA_DESC_MEDIATYPE_CANFD_DDL1
51
 */
52
#define ADTF_MEDIA_DESC_MEDIATYPE_CANFD           ADTF_MEDIA_DESC_MEDIATYPE_CANFD_DDL1
53

    
54
/**
55
 * This Macro is the type name of the adtf_devicetb::tCANFDData to describe media samples 
56
 * submitted on a pin (adtf::IPin). 
57
 * Set these description on the Media Type (adtf::IMediaTypeDescription of the IMediatype set on pin).
58
 */
59
#define ADTF_MEDIA_DESC_CANFDDATA                 "tCANFDData"
60

    
61
/**
62
 * This Macro defines the description of a adtf_devicetb::tCANFDData structure 
63
 * used within CAN FD MediaSamples of type OID_ADTF_MEDIA_SAMPLE_CANFD
64
 * used for ADTF_MEDIA_DESC_CANFDMESSAGE_DESCRIPTION in Version 1.0+.
65
 */
66
#define ADTF_MEDIA_DESC_CANFDDATA_DESCRIPTION_DDL1    "<struct name=\"" ADTF_MEDIA_DESC_CANFDDATA "\" alignment=\"1\" version=\"1\">" \
67
                                                    "    <element type=\"tUInt8\"   name=\"ui8Tag\"       bytepos=\"0\"  arraysize=\"1\" byteorder=\"LE\" alignment=\"1\"/>" \
68
                                                    "    <element type=\"tUInt8\"   name=\"ui8Channel\"   bytepos=\"1\"  arraysize=\"1\" byteorder=\"LE\" alignment=\"1\"/>" \
69
                                                    "    <element type=\"tUInt64\"  name=\"tmTimeStamp\"  bytepos=\"2\"  arraysize=\"1\" byteorder=\"LE\" alignment=\"1\"/>" \
70
                                                    "    <element type=\"tUInt32\"  name=\"ui32Id\"       bytepos=\"10\" arraysize=\"1\" byteorder=\"LE\" alignment=\"1\"/>" \
71
                                                    "    <element type=\"tUInt8\"   name=\"ui8Length\"    bytepos=\"14\" arraysize=\"1\" byteorder=\"LE\" alignment=\"1\"/>" \
72
                                                    "    <element type=\"tUInt8\"   name=\"ui8Reserved\"  bytepos=\"15\" arraysize=\"1\" byteorder=\"LE\" alignment=\"1\"/>" \
73
                                                    "    <element type=\"tUInt16\"  name=\"ui16Flags\"    bytepos=\"16\" arraysize=\"1\" byteorder=\"LE\" alignment=\"1\"/>" \
74
                                                    "    <element type=\"tUInt16\"  name=\"ui16Reserved\" bytepos=\"18\" arraysize=\"1\" byteorder=\"LE\" alignment=\"1\"/>" \
75
                                                    "    <element type=\"tUInt32\"  name=\"ui32Reserved\" bytepos=\"20\" arraysize=\"1\" byteorder=\"LE\" alignment=\"1\"/>" \
76
                                                    "    <element type=\"tUInt8\"   name=\"aui8Data\"     bytepos=\"24\" arraysize=\"64\" byteorder=\"LE\" alignment=\"1\"/>" \
77
                                                    "</struct>"
78

    
79

    
80
/**
81
 * This Macro defines the description of a adtf_devicetb::tCANFDData structure 
82
 * used within CAN MediaSamples of type OID_ADTF_MEDIA_SAMPLE_CANFD
83
 * used for ADTF_MEDIA_DESC_CANFDMESSAGE_DESCRIPTION in Version 2.0.
84
 */
85
#define ADTF_MEDIA_DESC_CANFDDATA_ENUM_DDL2 "<enums>" \
86
                                            "<enum name=\"eMessageTag\" type=\"tUInt8\">" \
87
                                                "<element name=\"MT_Data\" value=\"0\" />" \
88
                                                "<element name=\"MT_Status\" value=\"1\" />" \
89
                                            "</enum>" \
90
                                            "<enum name=\"eDataFlags\" type=\"tUInt16\">" \
91
                                                "<element name=\"DF_ERROR_FRAME\" value=\"1\" />" \
92
                                                "<element name=\"DF_NONE\" value=\"0\" />" \
93
                                                "<element name=\"DF_REMOTE_FRAME\" value=\"2\" />" \
94
                                                "<element name=\"DF_TX_COMPLETED\" value=\"4\" />" \
95
                                                "<element name=\"DF_FLEXIBLE_DATARATE\" value=\"8\" />" \
96
                                            "</enum>" \
97
                                        "</enums>"
98

    
99
#define ADTF_MEDIA_DESC_CANFDDATA_DESCRIPTION_DDL2    "<?xml version=\"1.0\" encoding=\"iso-8859-1\" standalone=\"no\"?>"\
100
                                                    "<adtf:ddl xmlns:adtf=\"adtf\">"\
101
                                                    ADTF_MEDIA_DESC_CANFDDATA_ENUM_DDL2 \
102
                                                    "<structs>"\
103
                                                    "<struct name=\"" ADTF_MEDIA_DESC_CANFDDATA "\" alignment=\"1\" version=\"1\">" \
104
                                                    "    <element type=\"eMessageTag\"   name=\"ui8Tag\"       bytepos=\"0\"  arraysize=\"1\" byteorder=\"LE\" alignment=\"1\"/>" \
105
                                                    "    <element type=\"tUInt8\"   name=\"ui8Channel\"   bytepos=\"1\"  arraysize=\"1\" byteorder=\"LE\" alignment=\"1\"/>" \
106
                                                    "    <element type=\"tUInt64\"  name=\"tmTimeStamp\"  bytepos=\"2\"  arraysize=\"1\" byteorder=\"LE\" alignment=\"1\"/>" \
107
                                                    "    <element type=\"tUInt32\"  name=\"ui32Id\"       bytepos=\"10\" arraysize=\"1\" byteorder=\"LE\" alignment=\"1\"/>" \
108
                                                    "    <element type=\"tUInt8\"   name=\"ui8Length\"    bytepos=\"14\" arraysize=\"1\" byteorder=\"LE\" alignment=\"1\"/>" \
109
                                                    "    <element type=\"tUInt8\"   name=\"ui8Reserved\"  bytepos=\"15\" arraysize=\"1\" byteorder=\"LE\" alignment=\"1\"/>" \
110
                                                    "    <element type=\"eDataFlags\"  name=\"ui16Flags\"    bytepos=\"16\" arraysize=\"1\" byteorder=\"LE\" alignment=\"1\"/>" \
111
                                                    "    <element type=\"tUInt16\"  name=\"ui16Reserved\" bytepos=\"18\" arraysize=\"1\" byteorder=\"LE\" alignment=\"1\"/>" \
112
                                                    "    <element type=\"tUInt32\"  name=\"ui32Reserved\" bytepos=\"20\" arraysize=\"1\" byteorder=\"LE\" alignment=\"1\"/>" \
113
                                                    "    <element type=\"tUInt8\"   name=\"aui8Data\"     bytepos=\"24\" arraysize=\"64\" byteorder=\"LE\" alignment=\"1\"/>" \
114
                                                    "</struct>"\
115
                                                    "</structs>"\
116
                                                    "</adtf:ddl>"
117

    
118
/**
119
 * This Macro defines the description of a adtf_devicetb::tCANFDData structure 
120
 * used within ADTF adtf::cMediaSampleCanFD.
121
 * @see ADTF_MEDIA_DESC_CANFDMESSAGE_DESCRIPTION_DDL2.
122
 */
123
#define ADTF_MEDIA_DESC_CANFDDATA_DESCRIPTION     ADTF_MEDIA_DESC_CANFDDATA_DESCRIPTION_DDL2
124

    
125

    
126
#pragma pack(push, 1)
127

    
128

    
129
/**
130
 * The Default structure that describe the ADTF CAN FD Type cMediaTypeCANFD.
131
 * The Media Description of this structure is defined within Macro ADTF_MEDIA_DESC_MEDIATYPE_CANFD.
132
 */
133
struct tADTFMediaTypeCANFD
134
{
135
    /// Default media type
136
    adtf::tMediaTypeInfo    sMediatype;
137
    /// Symbolic name of the channel
138
    tChar                   strChannelID[256];
139
};
140

    
141

    
142
/**
143
 * The CAN FD Type Interface extends the default adtf media type 
144
 * to add CAN FD specific data descriptions.
145
 * <table>
146
 * <tr> <td> Interface Identifier (IID) </td> <td> IID_ADTF_MEDIA_TYPE_CANFD </td> </tr>
147
 * </table>
148
 */
149
class IMediaTypeCANFD : virtual public adtf::IMediaType
150
{
151
public:
152
    /**
153
     *  Set the symbolic name of the channel
154
     *  @param      strChannelID  [in]   New symbolic name
155
     *  @result     Standard Result Code
156
     */
157
    virtual tResult SetChannelID(const char* strChannelID) = 0;
158

    
159
    /**
160
     *  Returns the current symbolic name of the channel
161
     *  @result     Pointer to symbolic name
162
     */
163
    virtual const tChar* GetChannelID() const = 0;
164
};
165

    
166
/**
167
 *  The CAN FD data structure is used by CAN FD MediaSamples of type OID_ADTF_MEDIA_SAMPLE_CANFD
168
 *  use following code within your filter: 
169
 * \code
170
 *
171
 * //...
172
 * cObjectPtr<IMediaSample> pCANFDSample;
173
 * RETURN_IF_FAILED(AllocMediaSample((tVoid**)&pCANFDSample, OID_ADTF_MEDIA_SAMPLE_CANFD, IID_ADTF_MEDIA_SAMPLE));
174
 * adtf_devicetb::tCANFDData sCANFDMessage; 
175
 *
176
 * //... fill your CAN message with the data 
177
 * 
178
 * RETURN_IF_FAILED(pCANFDSample->Update(_clock->GetStreamTime(), &sCANFDMessage, sizeof(tCANFDData), 0));
179
 *
180
 * //...
181
 *
182
 * 
183
 * \endcode
184
 *
185
 */
186
 struct tCANFDData
187
{
188
    /**
189
     *  This enum specifies the different kinds of messages
190
     *  that may be contained in the union
191
     */
192
    enum eMessageTag
193
    {
194
        MT_Data = 0,        //!< Data
195
        MT_Status = 1,      //!< Status
196
    };
197

    
198
    /**
199
     *  CAN FD message flags
200
     */
201
    enum eDataFlags
202
    {
203
        DF_NONE = 0                        //!< Standard flags
204
        , DF_ERROR_FRAME = 1             //!< Indicates an error frame
205
        , DF_REMOTE_FRAME = 2            //!< Indicates a remote frame
206
        , DF_TX_COMPLETED = 4             //!< Notification for successful message transmission
207
        , DF_EXTENDED_DATA_LENGTH = 8    //!< Indicates FlexibleData-Rate (FDF Flexible Datarate Format Indicator)
208
        , DF_CAN_FD_FORMAT_IDENTIFIER = DF_EXTENDED_DATA_LENGTH //!< same as Extended Data Length
209
        , DF_BAUD_RATE_SWITCH = 16      //!< Indicates that the Message uses Flexible Datarate
210
        , DF_SET_CAN_FD_AND_BRS = DF_CAN_FD_FORMAT_IDENTIFIER | DF_BAUD_RATE_SWITCH //!< Helper to Set Extended Data Length and Baud Rate Switch at once
211
        , DF_ERROR_STATE_INDICATOR = 32 //!< EDI Bit Indicates an Error-active state at the CAN FD Node        
212
    };
213

    
214
    /**
215
     *  CAN FD bus state flags. 
216
     */
217
    enum eBusStatus
218
    {
219
        BS_OFFLINE = 1,         //!< Bus is offline
220
        BS_ERROR_PASSIVE = 2,   //!< One of the error counters has reached the error level.
221
        BS_ERROR_WARNING = 4,   //!< One of the error counters has reached the warning level.
222
        BS_ERROR_ACTIVE = 8     //!< Bus is online
223
    };
224

    
225
    /**
226
     *  CAN FD message id masks. These masks should be used to check for extended or standard messages
227
     *  and to get the correct identifier from ui32Id in tData.
228
     */
229
    enum eMsgId
230
    {
231
        MSG_IDMASK_BASE         = 0x000007FF   //!< Message IDs for base frame format use 11 bit identifiers
232
        , MSG_IDMASK_EXTENDED   = 0x1FFFFFFF   //!< Message IDs for extended frame format use 29 bit identifiers
233
        , MSG_EXTENDED_FLAG     = 0x80000000   //!< Extended CAN messages are marked by bit 31
234
    };
235

    
236
    /**
237
     *  CAN FD message header structure
238
     */
239
    struct tMessageHeader
240
    {
241
        tUInt8      ui8Tag;             //!< Type of contained message (see eMessageTag)
242
        tUInt8      ui8Channel;         //!< Channel that received this message
243
        tTimeStamp  tmTimeStamp;        //!< Hardware timestamp in micro seconds 
244
    };
245

    
246
    /**
247
     *  CAN FD message data structure
248
     */
249
    struct tData
250
    {
251
        tUInt32     ui32Id;             //!< id of can message. For extended CAN messages bit 31 is set. Use the members of the enum eMsgId to get the identifier and check for extended messages.
252
        tUInt8      ui8Length;          //!< length of data [0..8,12,16,20,24,32,48,64] @attention DLC on Physical layer is coded differently
253
        tUInt8      ui8Reserved;        //!< reserved, should be zero
254
        tUInt16     ui16Flags;          //!< Flags @see eDataFlags
255
        tUInt16     ui16Reserved;       //!< reserved, should be zero
256
        tUInt32     ui32Reserved;       //!< reserved, should be zero
257
        tUInt8      aui8Data[64];       //!< data field
258
    };
259

    
260
    /**
261
     *  CAN FD bus status structure
262
     */
263
    struct tStatus
264
    {
265
        tUInt32     ui32BitRate;        //!< Arbitration or nominal CAN FD bus bitrate
266
        tUInt32     ui32RxBitCount;     //!< Count of received bits
267
        tUInt32     ui32TxBitCount;     //!< Count of transmitted bits
268
        tUInt16     ui16RxErrorCounter; //!< Error counter for the receive section of the CAN controller.
269
        tUInt16     ui16TxErrorCounter; //!< Error counter for the transmit section of the CAN controller.
270
        tUInt8      ui8BusStatus;       //!< Flags @see eBusStatus
271
        tUInt8      ui8Reserved;        //!< reserved, should be zero
272
        tUInt32     ui32DataBitRate;    //!< alternate Bitrate used for Data in CAN FD messages with BRS flag set.
273
        tUInt8        aui8Reserved[56];   //!< reserved, should be Zero
274
    };
275

    
276
    tMessageHeader  sHeader;            //!< CAN message header structure
277

    
278
    union
279
    {
280
        tData   sData;                  //!< used when ui8Tag == MT_Data
281
        tStatus sStatus;                //!< used when ui8Tag == MT_Status
282
    };
283
};
284

    
285
#pragma pack(pop)
286

    
287
} //adtf_devicetb
288

    
289
//*************************************************************************************************
290
#endif // _CANFD_TYPES_HEADER_
    (1-1/1)