AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
Usbcan32.h
1/****************************************************************************
2
3 (c) SYS TEC electronic AG, D-08468 Heinsdorfergrund, Am Windrad 2
4 www.systec-electronic.com
5
6 Project: USB-CANmodul
7
8 Description: Standard header file for the USBCAN32.DLL
9
10 -------------------------------------------------------------------------
11
12 $RCSfile:$
13
14 $Author: R.Dietzsch $
15
16 $Revision: 1.1 $ $Date: 2003/03/18 $
17
18 $State: $
19
20 Build Environment:
21 MSVC 5.0 and MSVC 6.0
22
23 -------------------------------------------------------------------------
24
25 Revision History:
26
27 2003/03/17 r.d.: Parameter m_dwSerialNr in tUcanHardwareInfo included.
28 2003/03/18 r.d.: New Function UcanInitCanEx() for additional init parameters.
29 UcanGetVersion() returns standard version format.
30 2005/10/12 r.d.: Several new functions included for Multiport CAN-to-USB 3004006
31 2006/06/06 r.d.: - Support of USB-CANmodul1 "Basic" 3204000 or USB-CANmodul2 "Advanced" 3204002
32 - New member variable m_dwProductCode in struct tUcanHardwareInfoEx to find out the hardware type.
33 - New member variables m_wNrOfRxBufferEntries and m_wNrOfTxBufferEntries in struct tUcanInitCanParam to change number of buffer entries.
34
35****************************************************************************/
36
37// clang-format off
39
40// Protection against mutliple including
41#ifndef __USBCAN32_H__
42#define __USBCAN32_H__
43
44
45// allow access to functions for C++ applications as well
46#ifdef __cplusplus
47extern "C"
48{
49#endif
50
51#if defined (WIN32) || defined (LINUX) || defined (__linux__)
52
53 // obsolate define
54 #ifndef STDCALL
55 #define STDCALL __stdcall
56 #endif
57
58 // new define
59 #ifndef PUBLIC
60 #define PUBLIC __stdcall
61 #endif
62
63#else
64
65 // obsolate define
66 #ifndef STDCALL
67 #define STDCALL far pascal
68 #endif
69
70 // new define
71 #ifndef PUBLIC
72 #define PUBLIC far pascal
73 #endif
74
75#endif
76
77#if !defined (_TCHAR_DEFINED)
78 #if defined (__linux__)
79 #define _TCHAR_DEFINED
80 #ifdef UNICODE
81 typedef wchar_t _TCHAR;
82 #define _T(x) L##x
83 #else
84 typedef char _TCHAR;
85 #define _T(x) x
86 #endif
87 #else
88 #include <tchar.h>
89 #endif
90#endif
91
92
93//---------------------------------------------------------------------------
94// macro definition
95//---------------------------------------------------------------------------
96
97// Filter calculation:
98
99// Extended Frame:
100// 33222222 22221111 11111100 00000000 \ (Bits 0-31 of AMR and ACR)
101// 10987654 32109876 54321098 76543210 /
102// -------- -------- -------- ----- > 29-Bit ID
103// - > RTR-Bit > GW-002 only
104// .-- > unused
105
106// Standard Frame:
107// 33222222 22221111 11111100 00000000 \ (Bits 0-31 of AMR and ACR)
108// 10987654 32109876 54321098 76543210 /
109// -------- --- > 11-Bit ID
110// - > RTR-Bit > GW-002 only
111// .---- ........ ........ > unused
112// -------- > Data byte 0 \ GW-002 only
113// -------- > Data byte 1 /
114
115// Macros for calculation of vallues for acceptance filter
116#define USBCAN_SET_AMR(extended, can_id, rtr) \
117 (extended) ? ((((DWORD)can_id)<<3 )|((rtr)?0x000004:0)|0x00003) : \
118 ((((DWORD)can_id)<<21)|((rtr)?0x100000:0)|0xfffff)
119#define USBCAN_SET_ACR(extended, can_id, rtr) \
120 (extended) ? ((((DWORD)can_id)<<3 )|((rtr)?0x000004:0)) : \
121 ((((DWORD)can_id)<<21)|((rtr)?0x100000:0))
122
123
124//---------------------------------------------------------------------------
125//
126// Macro: USBCAN_CALCULATE_AMR(), USBCAN_CALCULATE_ACR()
127//
128// Description: macros are calculating AMR and ACR using CAN-ID as parameter
129//
130// NOTE: This macros only are working if both from-id and
131// to-id results a successive order of bits.
132// Example:
133// from-id: 0x000 to-id: 0x01F --> macros are working
134// from-id: 0x400 to-id: 0x4FF --> macros are working
135// from-id: 0x101 to-id: 0x202 --> macros are NOT working
136//
137// A received CAN messages (with CAN-ID = RxID) will be accepted if the following
138// condition is fulfilled:
139// ((~(RxID ^ ACR) | AMR) == 0xFFFFFFFF)
140//
141// Parameters: extended = [IN] if TRUE parameters from_id and to_id contains 29-bit CAN-ID
142// from_id = [IN] first CAN-ID which should be received
143// to_id = [IN] last CAN-ID which should be received
144// rtr_only = [IN] if TRUE only RTR-Messages should be received, and rtr_too will be ignored
145// rtr_too = [IN] if TRUE CAN data frames and RTR-Messages should be received
146//
147// NOTE: The parameters rtr_only and rtr_too will be ignored with all the modules of
148// 3rd adn 4th generation.
149//
150// Return: DWORD = AMR or ACR
151//
152//---------------------------------------------------------------------------
153
154#define USBCAN_CALCULATE_AMR(extended,from_id,to_id,rtr_only,rtr_too) \
155 (extended) ? ((((DWORD)(from_id)^(to_id))<<3 )|((rtr_too&!rtr_only)?0x000004:0)|0x00003) : \
156 ((((DWORD)(from_id)^(to_id))<<21)|((rtr_too&!rtr_only)?0x100000:0)|0xfffff)
157#define USBCAN_CALCULATE_ACR(extended,from_id,to_id,rtr_only,rtr_too) \
158 (extended) ? ((((DWORD)(from_id)&(to_id))<<3 )|((rtr_only)?0x000004:0)) : \
159 ((((DWORD)(from_id)&(to_id))<<21)|((rtr_only)?0x100000:0))
160
161
162//---------------------------------------------------------------------------
163//
164// Macro: USBCAN_MAJOR_VER(), USBCAN_MINOR_VER(), USBCAN_RELEASE_VER()
165//
166// Description: macros to convert the version iformation from functions UcanGetVersionEx() and UcanGetFwVersion()
167//
168// Parameters: ver = [IN] extended version information as unsigned long (32 bit)
169//
170// Return: major, minor or release version
171//
172//---------------------------------------------------------------------------
173
174#define USBCAN_MAJOR_VER(ver) ( (ver) & 0x000000FF)
175#define USBCAN_MINOR_VER(ver) (((ver) & 0x0000FF00) >> 8)
176#define USBCAN_RELEASE_VER(ver) (((ver) & 0xFFFF0000) >> 16)
177
178
179//---------------------------------------------------------------------------
180// const defines
181//---------------------------------------------------------------------------
182
183#if !defined (_WIN32_WCE)
184
185 // maximum number of modules, that are supported (can not be changed!)
186 #define USBCAN_MAX_MODULES 64
187
188 // maximum number of applications, that can make use of this DLL (can not be changed!)
189 #define USBCAN_MAX_INSTANCES 64
190
191#else
192
193 // maximum number of modules, that are supported (can not be changed!)
194 #define USBCAN_MAX_MODULES 9
195
196 // maximum number of applications, that can make use of this DLL (can not be changed!)
197 #define USBCAN_MAX_INSTANCES 9
198
199#endif
200
201// With the function UcanInitHardware() or UcanInitHardwareEx() the module is used, which
202// is detected first. This define should only be used, in case only one module is connected
203// to the computer.
204#define USBCAN_ANY_MODULE 255
205
206// no valid USB-CAN Handle
207#define USBCAN_INVALID_HANDLE 0xff
208
209// pre-defined baudrate values for GW-001 and GW-002 (use function UcanInitCan() or UcanSetBaudrate())
210// fCAN = 8MHz
211// --- bit rate values for 1st and 2nd generation (G1/G2) of USB-CANmodul ---
212#define USBCAN_BAUD_1MBit 0x0014 // = 1000 kBit/s
213#define USBCAN_BAUD_800kBit 0x0016 // = 800 kBit/s
214#define USBCAN_BAUD_500kBit 0x001c // = 500 kBit/s
215#define USBCAN_BAUD_250kBit 0x011c // = 250 kBit/s
216#define USBCAN_BAUD_125kBit 0x031c // = 125 kBit/s
217#define USBCAN_BAUD_100kBit 0x432f // = 100 kBit/s
218#define USBCAN_BAUD_50kBit 0x472f // = 50 kBit/s
219#define USBCAN_BAUD_20kBit 0x532f // = 20 kBit/s
220#define USBCAN_BAUD_10kBit 0x672f // = 10 kBit/s
221//
222// other bitrates:
223// - 83,33 bit/sec, sample point 83,33% = 0x6f03
224// - 307,69 bit/sec, sample point 84,62% = 0x1901
225
226#define USBCAN_BAUD_USE_BTREX 0x0000 // uses predefined extended values of baudrate for
227 // Multiport 3004006, USB-CANmodul1 3204000 or USB-CANmodul2 3204002
228 // (do not use for GW-001/002)
229#define USBCAN_BAUD_AUTO 0xFFFF // automatic baudrate detection (not implemented in this version)
230
231// pre-defined baudrate values for Multiport 3004006, USB-CANmodul1 3204000 or USB-CANmodul2 3204002 (use function UcanInitCanEx or UcanSetBaudrateEx)
232// fCAN = 48MHz (for 10kBit/sec fCAN = 24MHz)
233// --- bit rate values for 3rd generation (G3) of USB-CANmodul ---
234#define USBCAN_BAUDEX_1MBit 0x00020354 // = 1000 kBit/s Sample Point: 68,75%
235#define USBCAN_BAUDEX_800kBit 0x00030254 // = 800 kBit/s Sample Point: 66,67%
236#define USBCAN_BAUDEX_500kBit 0x00050354 // = 500 kBit/s Sample Point: 68,75%
237#define USBCAN_BAUDEX_250kBit 0x000B0354 // = 250 kBit/s Sample Point: 68,75%
238#define USBCAN_BAUDEX_125kBit 0x00170354 // = 125 kBit/s Sample Point: 68,75%
239#define USBCAN_BAUDEX_100kBit 0x00171466 // = 100 kBit/s Sample Point: 65,00%
240#define USBCAN_BAUDEX_50kBit 0x002F1466 // = 50 kBit/s Sample Point: 65,00%
241#define USBCAN_BAUDEX_20kBit 0x00771466 // = 20 kBit/s Sample Point: 65,00%
242#define USBCAN_BAUDEX_10kBit 0x80771466 // = 10 kBit/s Sample Point: 65,00% (CLK = 1, see L-487 since version 15)
243
244// pre-defined baudrate values for Multiport 3004006, USB-CANmodul1 3204000 or USB-CANmodul2 3204002 (use function UcanInitCanEx or UcanSetBaudrateEx)
245// fCAN = 48MHz (for 10kBit/sec fCAN = 24MHz)
246// --- bit rate values for 3rd generation (G3) of USB-CANmodul ---
247#define USBCAN_BAUDEX_SP2_1MBit 0x00020741 // = 1000 kBit/s Sample Point: 87,50%
248#define USBCAN_BAUDEX_SP2_800kBit 0x00030731 // = 800 kBit/s Sample Point: 86,67%
249#define USBCAN_BAUDEX_SP2_500kBit 0x00050741 // = 500 kBit/s Sample Point: 87,50%
250#define USBCAN_BAUDEX_SP2_250kBit 0x000B0741 // = 250 kBit/s Sample Point: 87,50%
251#define USBCAN_BAUDEX_SP2_125kBit 0x00170741 // = 125 kBit/s Sample Point: 87,50%
252#define USBCAN_BAUDEX_SP2_100kBit 0x001D1741 // = 100 kBit/s Sample Point: 87,50%
253#define USBCAN_BAUDEX_SP2_50kBit 0x003B1741 // = 50 kBit/s Sample Point: 87,50%
254#define USBCAN_BAUDEX_SP2_20kBit 0x00771772 // = 20 kBit/s Sample Point: 85,00%
255#define USBCAN_BAUDEX_SP2_10kBit 0x80771772 // = 10 kBit/s Sample Point: 85,00% (CLK = 1, see L-487 since version 15)
256//
257// other bitrates:
258// - 33,333 kBit/sec, sample point 88,89% = 0x004F1671
259// - 83,333 kBit/sec, sample point 88,89% = 0x001F1671
260// - 307,692 kBit/sec, sample point 84,62% = 0x000B0441
261// - 615,384 kBit/sec, sample point 84,62% = 0x00050441
262// - 666,667 kBit/sec, sample point 88,89% = 0x00030671
263
264// pre-defined baudrate values for 4th generation of USB-CANmodul series (use function UcanInitCanEx or UcanSetBaudrateEx)
265// fCAN = 24MHz (used when 25% higher performance is deactivated)
266// --- bit rate values for 4th generation (G4) of USB-CANmodul ---
267#define USBCAN_BAUDEX_G4_1MBit 0x40180001 // = 1000 kBit/s Sample Point: 83,33%
268#define USBCAN_BAUDEX_G4_800kBit 0x401B0001 // = 800 kBit/s Sample Point: 86,67%
269#define USBCAN_BAUDEX_G4_500kBit 0x401C0002 // = 500 kBit/s Sample Point: 87,50%
270#define USBCAN_BAUDEX_G4_250kBit 0x401C0005 // = 250 kBit/s Sample Point: 87,50%
271#define USBCAN_BAUDEX_G4_125kBit 0x401C000B // = 125 kBit/s Sample Point: 87,50%
272#define USBCAN_BAUDEX_G4_100kBit 0x412F000B // = 100 kBit/s Sample Point: 85,00%
273#define USBCAN_BAUDEX_G4_50kBit 0x412F0017 // = 50 kBit/s Sample Point: 85,00%
274#define USBCAN_BAUDEX_G4_20kBit 0x412F003B // = 20 kBit/s Sample Point: 85,00%
275#define USBCAN_BAUDEX_G4_10kBit 0x412F0077 // = 10 kBit/s Sample Point: 85,00%
276//
277// other bitrates:
278// - 33,333 kBit/sec, sample point 85,00% = 0x412F0023
279// - 83,333 kBit/sec, sample point 88,9% = 0x411E000F
280// - 307,692 kBit/sec, sample point 84,62% = 0x40190005
281// - 615,384 kBit/sec, sample point 84,62% = 0x40190002
282// - 666,667 kBit/sec, sample point 83,33% = 0x402D0001
283//
284// fCAN = 30MHz (used when 25% higher performance is activated)
285// --- bit rate values for 4th generation (G4) of USB-CANmodul ---
286#define USBCAN_BAUDEX_G4X_1MBit 0xC01B0001 // = 1000 kBit/s Sample Point: 86,67%
287//#define USBCAN_BAUDEX_G4X_800kBit /* not supported */ // = 800 kBit/s
288#define USBCAN_BAUDEX_G4X_500kBit 0xC02F0002 // = 500 kBit/s Sample Point: 85,00%
289#define USBCAN_BAUDEX_G4X_250kBit 0xC02F0005 // = 250 kBit/s Sample Point: 85,00%
290#define USBCAN_BAUDEX_G4X_125kBit 0xC02F000B // = 125 kBit/s Sample Point: 85,00%
291#define USBCAN_BAUDEX_G4X_100kBit 0xC12F000E // = 100 kBit/s Sample Point: 85,00%
292#define USBCAN_BAUDEX_G4X_50kBit 0xC12F001D // = 50 kBit/s Sample Point: 85,00%
293#define USBCAN_BAUDEX_G4X_20kBit 0xC12F004A // = 20 kBit/s Sample Point: 85,00%
294#define USBCAN_BAUDEX_G4X_10kBit 0xC12F0095 // = 10 kBit/s Sample Point: 85,00%
295//
296// other bitrates:
297// - 33,333 kBit/sec, sample point 85,00% = 0xC02F002C
298// - 83,333 kBit/sec, sample point 85,00% = 0xC02F0011
299// - 307,692 kBit/sec, not supported
300// - 615,384 kBit/sec, not supported
301// - 666,667 kBit/sec, sample point 86,67% = 0xC01B0002
302
303#define USBCAN_BAUDEX_USE_BTR01 0x00000000 // uses predefined values of BTR0/BTR1 for GW-001/002
304#define USBCAN_BAUDEX_AUTO 0xFFFFFFFF // automatic baudrate detection (not implemented in this version)
305
306// Frame format for a CAN message (bit oriented)
307#define USBCAN_MSG_FF_STD 0x00 // Standard Frame (11-Bit-ID)
308#define USBCAN_MSG_FF_ECHO 0x20 // Tx echo (message received from UcanReadCanMsg.. was previously sent by UcanWriteCanMsg..)
309#define USBCAN_MSG_FF_RTR 0x40 // Remote Transmition Request Frame
310#define USBCAN_MSG_FF_EXT 0x80 // Extended Frame (29-Bit-ID)
311
312// Function return codes (encoding)
313#define USBCAN_SUCCESSFUL 0x00 // no error
314#define USBCAN_ERR 0x01 // error in library; function has not been executed
315#define USBCAN_ERRCMD 0x40 // error in module; function has not been executed
316#define USBCAN_WARNING 0x80 // Warning; function has been executed anyway
317#define USBCAN_RESERVED 0xc0 // reserved return codes (up to 255)
318
319// Error messages, that can occur in the library
320#define USBCAN_ERR_RESOURCE 0x01 // could not created a resource (memory, Handle, ...)
321#define USBCAN_ERR_MAXMODULES 0x02 // the maximum number of open modules is exceeded
322#define USBCAN_ERR_HWINUSE 0x03 // a module is already in use
323#define USBCAN_ERR_ILLVERSION 0x04 // the software versions of the module and library are incompatible
324#define USBCAN_ERR_ILLHW 0x05 // the module with the corresponding device number is not connected
325#define USBCAN_ERR_ILLHANDLE 0x06 // wrong USB-CAN-Handle handed over to the function
326#define USBCAN_ERR_ILLPARAM 0x07 // wrong parameter handed over to the function
327#define USBCAN_ERR_BUSY 0x08 // instruction can not be processed at this time
328#define USBCAN_ERR_TIMEOUT 0x09 // no answer from the module
329#define USBCAN_ERR_IOFAILED 0x0a // a request for the driver failed
330#define USBCAN_ERR_DLL_TXFULL 0x0b // the message did not fit into the transmission queue
331#define USBCAN_ERR_MAXINSTANCES 0x0c // maximum number of applications is reached
332#define USBCAN_ERR_CANNOTINIT 0x0d // CAN-interface is not yet initialized
333#define USBCAN_ERR_DISCONNECT 0x0e // USB-CANmodul was disconnected
334#define USBCAN_ERR_DISCONECT USBCAN_ERR_DISCONNECT // renamed (still defined for compatibility reason)
335#define USBCAN_ERR_NOHWCLASS 0x0f // the needed device class does not exist
336#define USBCAN_ERR_ILLCHANNEL 0x10 // illegal CAN channel for GW-001/GW-002
337#define USBCAN_ERR_RESERVED1 0x11
338#define USBCAN_ERR_ILLHWTYPE 0x12 // the API function can not be used with this hardware
339#define USBCAN_ERR_SERVER_TIMEOUT 0x13 // the command server does not send an reply of an command
340
341// Error messages, that the module returns during the command sequence
342#define USBCAN_ERRCMD_NOTEQU 0x40 // the received response does not match with the transmitted command
343#define USBCAN_ERRCMD_REGTST 0x41 // no access to the CAN controler possible
344#define USBCAN_ERRCMD_ILLCMD 0x42 // the module could not interpret the command
345#define USBCAN_ERRCMD_EEPROM 0x43 // error while reading the EEPROM occured
346#define USBCAN_ERRCMD_RESERVED1 0x44
347#define USBCAN_ERRCMD_RESERVED2 0x45
348#define USBCAN_ERRCMD_RESERVED3 0x46
349#define USBCAN_ERRCMD_ILLBDR 0x47 // illegal baudrate values for Multiport 3004006, USB-CANmodul1 3204000 or USB-CANmodul2 3204002 in BTR0/BTR1
350#define USBCAN_ERRCMD_NOTINIT 0x48 // CAN channel was not initialized
351#define USBCAN_ERRCMD_ALREADYINIT 0x49 // CAN channel was already initialized
352#define USBCAN_ERRCMD_ILLSUBCMD 0x4A // illegal sub-command specified
353#define USBCAN_ERRCMD_ILLIDX 0x4B // illegal index specified (e.g. index for cyclic CAN message)
354#define USBCAN_ERRCMD_RUNNING 0x4C // cyclic CAN message(s) can not be defined because transmission of cyclic CAN messages is already running
355
356// Warning messages, that can occur in library
357// NOTE: These messages are only warnings. The function has been executed anyway.
358#define USBCAN_WARN_NODATA 0x80 // no CAN messages received
359#define USBCAN_WARN_SYS_RXOVERRUN 0x81 // overrun in the receive queue of the driver (but this CAN message is successfuly read)
360#define USBCAN_WARN_DLL_RXOVERRUN 0x82 // overrun in the receive queue of the library (but this CAN message is successfuly read)
361#define USBCAN_WARN_RESERVED1 0x83
362#define USBCAN_WARN_RESERVED2 0x84
363#define USBCAN_WARN_FW_TXOVERRUN 0x85 // overrun in the transmit queue of the firmware (but this CAN message was successfully stored in buffer)
364#define USBCAN_WARN_FW_RXOVERRUN 0x86 // overrun in the receive queue of the firmware (but this CAN message was successfully read)
365#define USBCAN_WARN_FW_TXMSGLOST 0x87 // (not implemented yet)
366#define USBCAN_WARN_NULL_PTR 0x90 // pointer to address is NULL (function will not work correctly)
367#define USBCAN_WARN_TXLIMIT 0x91 // function UcanWriteCanMsgEx() was called for sending more CAN messages than one
368 // But not all of them could be sent because the buffer is full.
369// // Variable pointed by pdwCount_p received the number of succeddfully sent CAN messages.
370#define USBCAN_WARN_BUSY 0x92 // function cannot be processed because the DLL is busy
371#define USBCAN_WARN_CONFIG 0x93 // function not processed because configuration
372
373// system errors
374//#define USBCAN_ERR_ABORT 0xC0
375//#define USBCAN_ERR_DATA 0xC1
376
377// macros to check the error code
378#define USBCAN_CHECK_VALID_RXCANMSG(ret) \
379 ((ret == USBCAN_SUCCESSFUL) || (ret > USBCAN_WARNING)) // checks if function UcanReadCanMsg..() returns a valid CAN message
380
381#define USBCAN_CHECK_TX_OK(ret) \
382 ((ret == USBCAN_SUCCESSFUL) || (ret > USBCAN_WARNING)) // checks if function UcanWriteCanMsg..() successfuly wrote CAN message(s)
383 // While using UcanWriteCanMsgEx() the number of sent CAN messages can be less than
384 // the numer of CAN messages which shold be sent. (see also USBCAN_WARN_TXLIMIT)
385#define USBCAN_CHECK_TX_SUCCESS(ret) \
386 (ret == USBCAN_SUCCESSFUL) // checks if function UcanWriteCanMsgEx() successfuly wrote all CAN message(s)
387
388#define USBCAN_CHECK_TX_NOTALL(ret) \
389 (ret == USBCAN_WARN_TXLIMIT) // checks if function UcanWriteCanMsgEx() did not sent all CAN messages
390
391#define USBCAN_CHECK_WARNING(ret) \
392 (ret >= USBCAN_WARNING) // checks if any function returns a warning
393
394#define USBCAN_CHECK_ERROR(ret) \
395 ((ret != USBCAN_SUCCESSFUL) && (ret < USBCAN_WARNING)) // checks if any function returns an error
396
397#define USBCAN_CHECK_ERROR_CMD(ret) \
398 ((ret >= USBCAN_ERRCMD) && (ret < USBCAN_WARNING)) // checks if any function returns an error from firmware in USB-CANmodul
399
400
401// The Callback function is called, if certain events did occur.
402// These Defines specify the event.
403#define USBCAN_EVENT_INITHW 0 // the USB-CANmodul has been initialized
404#define USBCAN_EVENT_INITCAN 1 // the CAN interface has been initialized
405#define USBCAN_EVENT_RECIEVE 2 // a new CAN message has been received (for compatibility reason)
406#define USBCAN_EVENT_RECEIVE 2 // a new CAN message has been received
407#define USBCAN_EVENT_STATUS 3 // the error state in the module has changed
408#define USBCAN_EVENT_DEINITCAN 4 // the CAN interface has been deinitialized (UcanDeinitCan() was called)
409#define USBCAN_EVENT_DEINITHW 5 // the USB-CANmodul has been deinitialized (UcanDeinitHardware() was called)
410#define USBCAN_EVENT_CONNECT 6 // a new USB-CANmodul has been connected
411#define USBCAN_EVENT_DISCONNECT 7 // a USB-CANmodul has been disconnected
412#define USBCAN_EVENT_FATALDISCON 8 // a USB-CANmodul has been disconnected during operation
413#define USBCAN_EVENT_USBBUS_ERROR 16 // An USB bus error has occurred (e.g. STALL or XACT)
414#define USBCAN_EVENT_RECONNECT 17 // The USB-CANmodul was automatically reconnected
415#define USBCAN_EVENT_RESERVED1 0x80
416
417// CAN status flags (is returned with function UcanGetStatus() or UcanGetStatusEx() )
418#define USBCAN_CANERR_OK 0x0000 // no error
419#define USBCAN_CANERR_XMTFULL 0x0001 // Tx-buffer of the CAN controller is full
420#define USBCAN_CANERR_OVERRUN 0x0002 // Rx-buffer of the CAN controller is full
421#define USBCAN_CANERR_BUSLIGHT 0x0004 // Bus error: Error Limit 1 exceeded (refer to SJA1000 manual)
422#define USBCAN_CANERR_BUSHEAVY 0x0008 // Bus error: Error Limit 2 exceeded (refer to SJA1000 manual)
423#define USBCAN_CANERR_BUSOFF 0x0010 // Bus error: CAN controllerhas gone into Bus-Off state
424#define USBCAN_CANERR_QRCVEMPTY 0x0020 // RcvQueue is empty
425#define USBCAN_CANERR_QOVERRUN 0x0040 // RcvQueue overrun
426#define USBCAN_CANERR_QXMTFULL 0x0080 // transmit queue is full
427#define USBCAN_CANERR_REGTEST 0x0100 // Register test of the SJA1000 failed
428#define USBCAN_CANERR_MEMTEST 0x0200 // Memory test failed
429#define USBCAN_CANERR_TXMSGLOST 0x0400 // transmit CAN message was automatically deleted by firmware
430 // (because transmit timeout run over)
431
432// USB error messages (is returned with UcanGetStatus..() )
433#define USBCAN_USBERR_OK 0x0000 // no error
434#define USBCAN_USBERR_STATUS_TIMEOUT 0x2000 // restet because status timeout (device reconnected via USB)
435#define USBCAN_USBERR_WATCHDOG_TIMEOUT 0x4000 // restet because watchdog timeout (device reconnected via USB)
436
437// ABR and ACR for mode "receive all CAN messages"
438#define USBCAN_AMR_ALL (DWORD) 0xffffffff
439#define USBCAN_ACR_ALL (DWORD) 0x00000000
440
441#define USBCAN_OCR_DEFAULT 0x1A // default OCR for standard GW-002
442#define USBCAN_OCR_RS485_ISOLATED 0x1E // OCR for RS485 interface and galvanic isolation
443#define USBCAN_OCR_RS485_NOT_ISOLATED 0x0A // OCR for RS485 interface without galvanic isolation
444#define USBCAN_DEFAULT_BUFFER_ENTRIES 4096
445
446// definitions for CAN channels
447#define USBCAN_CHANNEL_CH0 0
448#define USBCAN_CHANNEL_CH1 1
449#define USBCAN_CHANNEL_ANY 255 // only available for functions UcanCallbackFktEx, UcanReadCanMsgEx
450#define USBCAN_CHANNEL_ALL 254 // reserved for futer use
451#define USBCAN_CHANNEL_NO 253 // reserved for futer use
452#define USBCAN_CHANNEL_CAN1 USBCAN_CHANNEL_CH0 // differences between software and label at hardware
453#define USBCAN_CHANNEL_CAN2 USBCAN_CHANNEL_CH1 // differences between software and label at hardware
454#define USBCAN_CHANNEL_LIN USBCAN_CHANNEL_CH1 // reserved for futer use
455
456// definitions for function UcanResetCanEx() (for compatibility reason these bits are inverted)
457#define USBCAN_RESET_ALL 0x00000000 // reset everything
458#define USBCAN_RESET_NO_STATUS 0x00000001 // no CAN status reset (only supported in new devices - not GW-001/002)
459#define USBCAN_RESET_NO_CANCTRL 0x00000002 // no CAN controller reset
460#define USBCAN_RESET_NO_TXCOUNTER 0x00000004 // no TX message counter reset
461#define USBCAN_RESET_NO_RXCOUNTER 0x00000008 // no RX message counter reset
462#define USBCAN_RESET_NO_TXBUFFER_CH 0x00000010 // no TX message buffer reset at channel level
463#define USBCAN_RESET_NO_TXBUFFER_DLL 0x00000020 // no TX message buffer reset at USBCAN32.DLL level
464#define USBCAN_RESET_NO_TXBUFFER_FW 0x00000080 // no TX message buffer reset at firmware level
465#define USBCAN_RESET_NO_RXBUFFER_CH 0x00000100 // no RX message buffer reset at channel level
466#define USBCAN_RESET_NO_RXBUFFER_DLL 0x00000200 // no RX message buffer reset at USBCAN32.DLL level
467#define USBCAN_RESET_NO_RXBUFFER_SYS 0x00000400 // no RX message buffer reset at kernel driver level
468#define USBCAN_RESET_NO_RXBUFFER_FW 0x00000800 // no RX message buffer reset at firmware level
469#define USBCAN_RESET_FIRMWARE 0xFFFFFFFF // buffers, counters and CANCRTL will be reseted indirectly during firmware reset
470 // (means automatically disconnect from USB port in 500ms)
471
472// combinations of flags for UcanResetCanEx()
473// NOTE: for combinations use OR (example: USBCAN_RESET_NO_COUNTER_ALL | USBCAN_RESET_NO_BUFFER_ALL)
474#define USBCAN_RESET_NO_COUNTER_ALL (USBCAN_RESET_NO_TXCOUNTER | USBCAN_RESET_NO_RXCOUNTER)
475#define USBCAN_RESET_NO_TXBUFFER_COMM (USBCAN_RESET_NO_TXBUFFER_DLL | 0x00000040 | USBCAN_RESET_NO_TXBUFFER_FW)
476#define USBCAN_RESET_NO_RXBUFFER_COMM (USBCAN_RESET_NO_RXBUFFER_DLL | USBCAN_RESET_NO_RXBUFFER_SYS | USBCAN_RESET_NO_RXBUFFER_FW)
477#define USBCAN_RESET_NO_TXBUFFER_ALL (USBCAN_RESET_NO_TXBUFFER_CH | USBCAN_RESET_NO_TXBUFFER_COMM)
478#define USBCAN_RESET_NO_RXBUFFER_ALL (USBCAN_RESET_NO_RXBUFFER_CH | USBCAN_RESET_NO_RXBUFFER_COMM)
479#define USBCAN_RESET_NO_BUFFER_COMM (USBCAN_RESET_NO_TXBUFFER_COMM | USBCAN_RESET_NO_RXBUFFER_COMM)
480#define USBCAN_RESET_NO_BUFFER_ALL (USBCAN_RESET_NO_TXBUFFER_ALL | USBCAN_RESET_NO_RXBUFFER_ALL)
481// NOTE: for combinations use AND instead of OR (example: USBCAN_RESET_ONLY_RX_BUFF & USBCAN_RESET_ONLY_STATUS)
482#define USBCAN_RESET_ONLY_STATUS (0x0000FFFF & ~(USBCAN_RESET_NO_STATUS))
483#define USBCAN_RESET_ONLY_CANCTRL (0x0000FFFF & ~(USBCAN_RESET_NO_CANCTRL))
484#define USBCAN_RESET_ONLY_TXBUFFER_FW (0x0000FFFF & ~(USBCAN_RESET_NO_TXBUFFER_FW))
485#define USBCAN_RESET_ONLY_RXBUFFER_FW (0x0000FFFF & ~(USBCAN_RESET_NO_RXBUFFER_FW))
486#define USBCAN_RESET_ONLY_RXCHANNEL_BUFF (0x0000FFFF & ~(USBCAN_RESET_NO_RXBUFFER_CH))
487#define USBCAN_RESET_ONLY_TXCHANNEL_BUFF (0x0000FFFF & ~(USBCAN_RESET_NO_TXBUFFER_CH))
488#define USBCAN_RESET_ONLY_RX_BUFF (0x0000FFFF & ~(USBCAN_RESET_NO_RXBUFFER_ALL | USBCAN_RESET_NO_RXCOUNTER))
489#define USBCAN_RESET_ONLY_RX_BUFF_GW002 (0x0000FFFF & ~(USBCAN_RESET_NO_RXBUFFER_ALL | USBCAN_RESET_NO_RXCOUNTER | USBCAN_RESET_NO_TXBUFFER_FW))
490#define USBCAN_RESET_ONLY_TX_BUFF (0x0000FFFF & ~(USBCAN_RESET_NO_TXBUFFER_ALL | USBCAN_RESET_NO_TXCOUNTER))
491#define USBCAN_RESET_ONLY_ALL_BUFF (USBCAN_RESET_ONLY_RX_BUFF & USBCAN_RESET_ONLY_TX_BUFF)
492#define USBCAN_RESET_ONLY_ALL_COUNTER (0x0000FFFF & ~(USBCAN_RESET_NO_COUNTER_ALL))
493
494
495// Meaning of suffixes of defines USBCAN_RESET_NO_..BUFFER_.. (used for function UcanResetCanEx() to reset buffers or not)
496//
497// CAN- Firmware- Kernel- USBCAN32.DLL USBCAN32.DLL
498// Controller: Buffer Buffer Buffer Channel-Buffer
499//----------------------------------------------------------------------------------------------------------------------------
500// Suffix: .._FW .._SYS .._DLL .._CH
501// .._COMM = {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
502// .._ALL = {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
503//--------------RX buffers----------------------------------------------------------------------------------------------------
504// devices:
505//
506// GW-001: +-----+ +---------+
507// GW-002: | CH0 | ||||||||||| +--------------------+
508// sysWORXX: +-----+ -----> +---------+ +---------+ +---------+ --> +---------+ --> | UcanReadCanMsg..() |
509// ||||||||||| --> ||||||||||| --> ||||||||||| | |
510// ....... -----> +---------+ +---------+ +---------+ --> +---------+ --> | UcanReadCanMsgEx() |
511// sysWORXX: . CH1 . ||||||||||| +--------------------+
512// ....... +---------+
513//
514// Nr. of messages in buffer: 768 4096 4096 (tUcanInitCanParam.m_wNrOfRxBufferEntries)
515//--------------TX buffers----------------------------------------------------------------------------------------------------
516// devices:
517//
518// GW-001: +-----+
519// GW-002: | CH0 | +--------------------+
520// sysWORXX: +-----+ <----- +---------+ +---------+ <------------------ | UcanWriteCanMsg..()|
521// ||||||||||| <------------------ ||||||||||| | |
522// ....... <----- +---------+ +---------+ <------------------ | UcanWriteCanMsgEx()|
523// sysWORXX: . CH1 . +--------------------+
524// .......
525//
526// Nr. of messages in buffer: 768 (tUcanInitCanParam.m_wNrOfRxBufferEntries)
527//----------------------------------------------------------------------------------------------------------------------------
528//
529// NOTE:
530// If Rx-Buffers of Firmware, Kernel-Mode Driver and/or Rx-Buffer of DLL (suffix .._DLL) will be reseted,
531// then CAN messages of both CAN-Channels (CH0 and CH1) may be deleted (lost for application).
532//
533// If UcanResetCanEx() is called with dwResetFlags_p = USBCAN_RESET_NO_RXBUFFER_COMM (for example), then
534// only Rx-Buffer of CAN-Channel 0 or 1 will be deleted (as defined in parameter bChannel_p).
535
536// definitions for product code in structure tUcanHardwareInfoEx
537#define USBCAN_PRODCODE_MASK_DID 0xFFFF0000L
538#define USBCAN_PRODCODE_MASK_MFU 0x00008000L
539#define USBCAN_PRODCODE_PID_TWO_CHA 0x00000001L
540#define USBCAN_PRODCODE_PID_TERM 0x00000001L
541#define USBCAN_PRODCODE_PID_RBUSER 0x00000001L
542#define USBCAN_PRODCODE_PID_RBCAN 0x00000001L
543#define USBCAN_PRODCODE_PID_G4 0x00000020L
544#define USBCAN_PRODCODE_PID_RESVD 0x00000040L
545#define USBCAN_PRODCODE_MASK_PID 0x00007FFFL
546#define USBCAN_PRODCODE_MASK_PIDG3 (USBCAN_PRODCODE_MASK_PID & ~USBCAN_PRODCODE_PID_RESVD)
547#define USBCAN_PRODCODE_MASK_PIDG4 (USBCAN_PRODCODE_MASK_PID & ~USBCAN_PRODCODE_PID_RESVD)
548
549#define USBCAN_PRODCODE_PID_GW001 0x00001100L // order code GW-001 "USB-CANmodul" outdated
550#define USBCAN_PRODCODE_PID_GW002 0x00001102L // order code GW-002 "USB-CANmodul" outdated
551#define USBCAN_PRODCODE_PID_MULTIPORT 0x00001103L // order code 3004006/3404000/3404001 "Multiport CAN-to-USB"
552#define USBCAN_PRODCODE_PID_BASIC 0x00001104L // order code 3204000/3204001 "USB-CANmodul1"
553#define USBCAN_PRODCODE_PID_ADVANCED 0x00001105L // order code 3204002/3204003 "USB-CANmodul2"
554#define USBCAN_PRODCODE_PID_USBCAN8 0x00001107L // order code 3404000 "USB-CANmodul8"
555#define USBCAN_PRODCODE_PID_USBCAN16 0x00001109L // order code 3404001 "USB-CANmodul16"
556#define USBCAN_PRODCODE_PID_RESERVED3 0x00001110L
557#define USBCAN_PRODCODE_PID_ADVANCED_G4 0x00001121L // order code ------- "USB-CANmodul2" 4th generation
558#define USBCAN_PRODCODE_PID_BASIC_G4 0x00001122L // order code 3204000 "USB-CANmodul1" 4th generation
559#define USBCAN_PRODCODE_PID_USBCAN8_G4 0x00001123L // order code 3404000 "USB-CANmodul8"
560#define USBCAN_PRODCODE_PID_USBCAN16_G4 0x00001125L // order code 3404001 "USB-CANmodul16"
561#define USBCAN_PRODCODE_PID_RESERVED1 0x00001144L
562#define USBCAN_PRODCODE_PID_RESERVED2 0x00001145L
563#define USBCAN_PRODCODE_PID_RESERVED4 0x00001162L
564
565
566//---------------------------------------------------------------------------
567//
568// Macro: USBCAN_CHECK_SUPPORT_CYCLIC_MSG()
569// USBCAN_CHECK_SUPPORT_TWO_CHANNEL()
570// USBCAN_CHECK_SUPPORT_TERM_RESISTOR()
571// USBCAN_CHECK_SUPPORT_USER_PORT()
572// USBCAN_CHECK_SUPPORT_RBUSER_PORT()
573// USBCAN_CHECK_SUPPORT_RBCAN_PORT()
574// USBCAN_CHECK_IS_SYSWORXX()
575// USBCAN_CHECK_SUPPORT_UCANNET()
576//
577// Description: macros to check if an USB-CANmodul does support different features
578//
579// Parameters: pHwInfoEx = [IN] pointer to the extended hardware information structure
580// (returned by UcanGetHardwareInfoEx2()
581//
582// Return: BOOL = TRUE if hardware does support the feature
583//
584//---------------------------------------------------------------------------
585
586// checks if the module is a sysWORXX USB-CANmodul
587#define USBCAN_CHECK_IS_SYSWORXX(pHwInfoEx) \
588 (((pHwInfoEx)->m_dwProductCode & USBCAN_PRODCODE_MASK_PID) >= USBCAN_PRODCODE_PID_MULTIPORT) && \
589 (((pHwInfoEx)->m_dwProductCode & USBCAN_PRODCODE_MASK_PID) != USBCAN_PRODCODE_PID_RESERVED3)
590
591// checks if the module is a USB-CANmodul G4
592#define USBCAN_CHECK_IS_G4(pHwInfoEx) \
593 (((pHwInfoEx)->m_dwProductCode & USBCAN_PRODCODE_PID_G4) != 0)
594
595// checks if the module is a USB-CANmodul G3
596#define USBCAN_CHECK_IS_G3(pHwInfoEx) \
597 (USBCAN_CHECK_IS_SYSWORXX(pHwInfoEx) && !USBCAN_CHECK_IS_G4(pHwInfoEx))
598
599// checks if the module is a USB-CANmodul G2 (GW-002)
600#define USBCAN_CHECK_IS_G2(pHwInfoEx) \
601 ((pHwInfoEx)->m_dwProductCode & USBCAN_PRODCODE_MASK_PID) == USBCAN_PRODCODE_PID_GW002)
602
603// checks if the module is a USB-CANmodul G1 (GW-001)
604#define USBCAN_CHECK_IS_G1(pHwInfoEx) \
605 ((pHwInfoEx)->m_dwProductCode & USBCAN_PRODCODE_MASK_PID) == USBCAN_PRODCODE_PID_GW001)
606
607// checks if the module supports automatically transmission of cyclic CAN messages
608#define USBCAN_CHECK_SUPPORT_CYCLIC_MSG(pHwInfoEx) \
609 (USBCAN_CHECK_IS_SYSWORXX(pHwInfoEx) && \
610 (USBCAN_MAJOR_VER((pHwInfoEx)->m_dwFwVersionEx) > 3) || ( \
611 (USBCAN_MAJOR_VER((pHwInfoEx)->m_dwFwVersionEx) == 3) && \
612 (USBCAN_MINOR_VER((pHwInfoEx)->m_dwFwVersionEx) >= 6) ) )
613
614// checks if the module supports two CAN channels (at logical device)
615#define USBCAN_CHECK_SUPPORT_TWO_CHANNEL(pHwInfoEx) \
616 ((((pHwInfoEx)->m_dwProductCode & USBCAN_PRODCODE_MASK_PID) >= USBCAN_PRODCODE_PID_MULTIPORT) && \
617 (((pHwInfoEx)->m_dwProductCode & USBCAN_PRODCODE_PID_TWO_CHA) != 0) )
618
619// checks if the module supports a termination resistor
620#define USBCAN_CHECK_SUPPORT_TERM_RESISTOR(pHwInfoEx) \
621 ((((pHwInfoEx)->m_dwProductCode & USBCAN_PRODCODE_PID_TERM) != 0))
622
623// checks if the module supports a user I/O port
624#define USBCAN_CHECK_SUPPORT_USER_PORT(pHwInfoEx) \
625 ((((pHwInfoEx)->m_dwProductCode & USBCAN_PRODCODE_MASK_PID) != USBCAN_PRODCODE_PID_GW001) && \
626 (((pHwInfoEx)->m_dwProductCode & USBCAN_PRODCODE_MASK_PID) != USBCAN_PRODCODE_PID_BASIC) && \
627 (((pHwInfoEx)->m_dwProductCode & USBCAN_PRODCODE_MASK_PID) != USBCAN_PRODCODE_PID_RESERVED3) && \
628 (((pHwInfoEx)->m_dwProductCode & USBCAN_PRODCODE_MASK_PID) != USBCAN_PRODCODE_PID_BASIC_G4) && \
629 (((pHwInfoEx)->m_dwProductCode & USBCAN_PRODCODE_MASK_PID) != USBCAN_PRODCODE_PID_RESERVED1) && \
630 (((pHwInfoEx)->m_dwProductCode & USBCAN_PRODCODE_MASK_PID) != USBCAN_PRODCODE_PID_RESERVED4) && \
631 ( (USBCAN_MAJOR_VER ((pHwInfoEx)->m_dwFwVersionEx) > 2) || \
632 ((USBCAN_MAJOR_VER ((pHwInfoEx)->m_dwFwVersionEx) == 2) && \
633 (USBCAN_MINOR_VER ((pHwInfoEx)->m_dwFwVersionEx) >= 16)) ) )
634
635// checks if the module supports a user I/O port including read back feature
636#define USBCAN_CHECK_SUPPORT_RBUSER_PORT(pHwInfoEx) \
637 ((((pHwInfoEx)->m_dwProductCode & USBCAN_PRODCODE_PID_RBUSER) != 0))
638
639// checks if the module supports a CAN I/O port including read back feature
640#define USBCAN_CHECK_SUPPORT_RBCAN_PORT(pHwInfoEx) \
641 ((((pHwInfoEx)->m_dwProductCode & USBCAN_PRODCODE_PID_RBCAN) != 0))
642
643// checks if the module supports the usage of USB-CANnetwork driver
644#define USBCAN_CHECK_SUPPORT_UCANNET(pHwInfoEx) \
645 (USBCAN_CHECK_IS_SYSWORXX(pHwInfoEx) && \
646 (USBCAN_MAJOR_VER((pHwInfoEx)->m_dwFwVersionEx) > 3) || ( \
647 (USBCAN_MAJOR_VER((pHwInfoEx)->m_dwFwVersionEx) == 3) && \
648 (USBCAN_MINOR_VER((pHwInfoEx)->m_dwFwVersionEx) >= 8) ) )
649
650
651//---------------------------------------------------------------------------
652// definitions for cyclic CAN messages
653#define USBCAN_MAX_CYCLIC_CANMSG 16
654
655// stopps the transmission of cyclic CAN messages (use instead of USBCAN_CYCLIC_FLAG_START)
656#define USBCAN_CYCLIC_FLAG_STOPP 0x00000000L
657
658// the following flags can be cobined
659#define USBCAN_CYCLIC_FLAG_START 0x80000000L // global enable of transmission of cyclic CAN messages
660#define USBCAN_CYCLIC_FLAG_SEQUMODE 0x40000000L // list of cyclcic CAN messages will be processed in
661 // sequential mode (otherwise in parallel mode)
662#define USBCAN_CYCLIC_FLAG_NOECHO 0x00010000L // each sent CAN message of the list will be sent back
663 // to the host
664
665// each CAN message from the list can be enabled or disabled separatly
666#define USBCAN_CYCLIC_FLAG_LOCK_0 0x00000001L // if some of these bits are set, then the according
667#define USBCAN_CYCLIC_FLAG_LOCK_1 0x00000002L // CAN message from the list is disabled
668#define USBCAN_CYCLIC_FLAG_LOCK_2 0x00000004L
669#define USBCAN_CYCLIC_FLAG_LOCK_3 0x00000008L
670#define USBCAN_CYCLIC_FLAG_LOCK_4 0x00000010L
671#define USBCAN_CYCLIC_FLAG_LOCK_5 0x00000020L
672#define USBCAN_CYCLIC_FLAG_LOCK_6 0x00000040L
673#define USBCAN_CYCLIC_FLAG_LOCK_7 0x00000080L
674#define USBCAN_CYCLIC_FLAG_LOCK_8 0x00000100L
675#define USBCAN_CYCLIC_FLAG_LOCK_9 0x00000200L
676#define USBCAN_CYCLIC_FLAG_LOCK_10 0x00000400L
677#define USBCAN_CYCLIC_FLAG_LOCK_11 0x00000800L
678#define USBCAN_CYCLIC_FLAG_LOCK_12 0x00001000L
679#define USBCAN_CYCLIC_FLAG_LOCK_13 0x00002000L
680#define USBCAN_CYCLIC_FLAG_LOCK_14 0x00004000L
681#define USBCAN_CYCLIC_FLAG_LOCK_15 0x00008000L
682
683//---------------------------------------------------------------------------
684// definitions for function UcanGetMsgPending()
685#define USBCAN_PENDING_FLAG_RX_DLL 0x00000001L // returns number of pending RX CAN messages in USBCAN32.DLL
686#define USBCAN_PENDING_FLAG_RX_SYS 0x00000002L // (not implemented yet) returns number of pending RX CAN messages in USBCAN.SYS or UCANNET.SYS
687#define USBCAN_PENDING_FLAG_RX_FW 0x00000004L // returns number of pending RX CAN messages in firmware
688#define USBCAN_PENDING_FLAG_TX_DLL 0x00000010L // returns number of pending TX CAN messages in USBCAN32.DLL
689#define USBCAN_PENDING_FLAG_TX_SYS 0x00000020L // place holder - there is no TX buffer in USBCAN.SYS or UCANNET.SYS
690#define USBCAN_PENDING_FLAG_TX_FW 0x00000040L // returns number of pending TX CAN messages in firmware
691// These bits can be combined. In these case the function UcanGetMsgPending() returns the summary of the counters.
692
693#define USBCAN_PENDING_FLAG_RX_ALL (USBCAN_PENDING_FLAG_RX_DLL | USBCAN_PENDING_FLAG_RX_SYS | USBCAN_PENDING_FLAG_RX_FW)
694#define USBCAN_PENDING_FLAG_TX_ALL (USBCAN_PENDING_FLAG_TX_DLL | USBCAN_PENDING_FLAG_TX_SYS | USBCAN_PENDING_FLAG_TX_FW)
695#define USBCAN_PENDING_FLAG_ALL (USBCAN_PENDING_FLAG_RX_ALL | USBCAN_PENDING_FLAG_TX_ALL)
696
697#define USBCAN_HWEX_FLAG_UCANNET 0x00000001L // if enabled, then the USB-CANmodul is configured for UCANNET.SYS driver
698#define USBCAN_HWEX_FLAG_HWCTRL 0x00000002L // if enabled, then application hat exclusive hw control
699#define USBCAN_HWEX_FLAG_USBBUS_ERROR 0x00000004L // if enabled, then USB bus error occured (e.g. STALL or XACT)
700#define USBCAN_HWEX_FLAG_USBBUS_AUTO 0x00000100L // if enabled, then the DLL processes a reconnect automatically
701
702
703//---------------------------------------------------------------------------
704// types
705//---------------------------------------------------------------------------
706
707// set structure alignement to 1 byte
708#if !defined (_WIN32_WCE)
709#pragma pack(push,1)
710#endif
711
712// Typedef for the USB-CAN Handle
713#ifndef UCHANDLE_DEFINED
714 #define UCHANDLE_DEFINED
715 typedef BYTE tUcanHandle;
716#endif
717
718// for further use
719#define UCANRET BYTE
720#define UCANBYTE BYTE
721#define UCANWORD WORD
722#define UCANDWORD DWORD
723
724typedef BYTE tUcanMode; // definitions of CAN modes
725
726#define kUcanModeNormal 0x00 // normal mode (send and reciceive)
727#define kUcanModeListenOnly 0x01 // listen only mode (only reciceive)
728#define kUcanModeTxEcho 0x02 // CAN messages which was sent will be received at UcanReadCanMsg..
729#define kUcanModeRxOrderCh 0x04 // reserved (not implemented in this version)
730#define kUcanModeHighResTimer 0x08 // high resolution time stamps in received CAN messages (only avaylable with STM derivates)
731#define kUcanModeReserved 0x10 // only used for SocketCAN
732
733
734// version types for function UcanGetVersionEx()
735typedef DWORD tUcanVersionType;
736
737#define kVerTypeUserLib 0x00000001L // version of the library
738#define kVerTypeUserDll 0x00000001L // version of USBCAN32.DLL (for Win2k, WinXP or higher) USBCANCE.DLL (for WinCE)
739#define kVerTypeSysDrv 0x00000002L // version of USBCAN.SYS (for Win2k, WinXP or higher) USBCANDRV.DLL (for WinCE)
740#define kVerTypeFirmware 0x00000003L // reserved (not supported, use function UcanGetFwVersion)
741#define kVerTypeNetDrv 0x00000004L // version of UCANNET.SYS (not supported for WinCE)
742#define kVerTypeSysLd 0x00000005L // version of USBCANLD.SYS (not supported for WinCE) (loader for USB-CANmodul GW-001)
743#define kVerTypeSysL2 0x00000006L // version of USBCANL2.SYS (loader for USB-CANmodul GW-002)
744#define kVerTypeSysL3 0x00000007L // version of USBCANL3.SYS (not supported for WinCE) (loader for Multiport CAN-to-USB 340400x or 3004006)
745#define kVerTypeSysL4 0x00000008L // version of USBCANL4.SYS (loader for USB-CANmodul1 3204000 or 3204001)
746#define kVerTypeSysL5 0x00000009L // version of USBCANL5.SYS (loader for USB-CANmodul1 3204002 or 3204003)
747#define kVerTypeCpl 0x0000000AL // version of USBCANCP.CPL (not supported for WinCE)
748#define kVerTypeSysL21 0x0000000BL // version of USBCANL21.SYS (loader for USB-CANmodul2 G4)
749#define kVerTypeSysL22 0x0000000CL // version of USBCANL22.SYS (loader for USB-CANmodul1 G4)
750#define kVerTypeSysL23 0x0000000DL // version of USBCANL23.SYS (loader for USB-CANmodul8/16 G4)
751#define kVerTypeSysLex 0x0000000EL // version of USBCANLEX.SYS (loader for all USB-CANmodul types of G4)
752
753
754// Typedef for the Callback function
755typedef void (PUBLIC *tCallbackFkt) (tUcanHandle UcanHandle_p, BYTE bEvent_p);
756typedef void (PUBLIC *tCallbackFktEx) (tUcanHandle UcanHandle_p, DWORD dwEvent_p, BYTE bChannel_p, void* pArg_p);
757
758// Typedef for the Connection-Control function
759typedef void (PUBLIC *tConnectControlFkt) (BYTE bEvent_p, DWORD dwParam_p);
760typedef void (PUBLIC *tConnectControlFktEx) (DWORD dwEvent_p, DWORD dwParam_p, void* pArg_p);
761
762// Structure for the CAN message (suitable for CAN messages according to spec. CAN2.0B)
763typedef struct _tCanMsgStruct
764{
765 DWORD m_dwID; // CAN Identifier
766 BYTE m_bFF; // CAN Frame format (BIT7=1: 29BitID / BIT6=1: RTR-Frame / BIT5=1: Tx echo)
767 BYTE m_bDLC; // CAN Data Length Code
768 BYTE m_bData[8]; // CAN Data
769 DWORD m_dwTime; // Time in ms
770
771 // NOTE:
772 //
773 // Value of m_dwTime only is valid for received CAN messages. It is ignored for
774 // CAN messages to send.
775 //
776 // Value m_dwTime will be received from Hardware. Thus it is
777 // important to know that only 24 bits of the value are valid.
778 // It means that the timer value will be reset to zero each
779 // 2^24 milliseconds = 4,66 hours. If you need to calculate
780 // a time difference you should use the macro USBCAN_CALC_TIMEDIFF().
781 //
782 // Since driver version V4.11 the time stamp parameter is corrected to 32 bits.
783 // ( but the marco USBCAN_CALC_TIMEDIFF() does work too in this version )
784
785} tCanMsgStruct;
786
787//#define USBCAN_CALC_TIMEDIFF(old_time,new_time) \
788// ((new_time) >= (old_time)) ? \
789// ((new_time) - (old_time)) : \
790// -1* ((old_time) - (new_time))
791#define USBCAN_CALC_TIMEDIFF(old_time,new_time) ((new_time) - (old_time))
792
793// Structure with the stati (Function: UcanGetStatus() or UcanGetStatusEx() )
794typedef struct _tStatusStruct
795{
796 WORD m_wCanStatus; // current CAN status
797 WORD m_wUsbStatus; // current USB status
798
799} tStatusStruct;
800
801// Structure with init parameters for function UcanInitCanEx() and UcanInitCanEx2()
802typedef struct _tUcanInitCanParam
803{
804 DWORD m_dwSize; // [IN] size of this structure
805 BYTE m_bMode; // [IN] slecets the mode of CAN controller (see kUcanMode...)
806
807 // Baudrate Registers for GW-001 or GW-002
808 BYTE m_bBTR0; // [IN] Bus Timing Register 0 (SJA1000 - use high byte USBCAN_BAUD_...)
809 BYTE m_bBTR1; // [IN] Bus Timing Register 1 (SJA1000 - use low byte USBCAN_BAUD_...)
810
811 BYTE m_bOCR; // [IN] Output Controll Register of SJA1000 (should be 0x1A)
812 DWORD m_dwAMR; // [IN] Acceptance Mask Register (SJA1000)
813 DWORD m_dwACR; // [IN] Acceptance Code Register (SJA1000)
814
815 // since version V3.00 - is ignored from function UcanInitCanEx() and until m_dwSize < 20
816 DWORD m_dwBaudrate; // [IN] Baudrate Register for Multiport 3004006, USB-CANmodul1 3204000 or USB-CANmodul2 3204002
817 // (use USBCAN_BAUDEX_...)
818
819 // since version V3.05 - is ignored unltil m_dwSize < 24
820 WORD m_wNrOfRxBufferEntries; // [IN] number of receive buffer entries (default is 4096)
821 WORD m_wNrOfTxBufferEntries; // [IN] number of transmit buffer entries (default is 4096)
822
823} tUcanInitCanParam;
824
825// Structure with the hardware properties of a USB-CANmodul (Function: UcanGetHardwareInf())
826typedef struct _tUcanHardwareInfo
827{
828 BYTE m_bDeviceNr; // [OUT] device number of the USB-CANmodul
829 tUcanHandle m_UcanHandle; // [OUT] USB-CAN-Handle assigned by the library
830 DWORD m_dwReserved; // [OUT] reserved
831
832 // values only for CAN channel 0
833 BYTE m_bBTR0; // [OUT] Bus Timing Register 0 (SJA1000)
834 BYTE m_bBTR1; // [OUT] Bus Timing Register 1 (SJA1000)
835 BYTE m_bOCR; // [OUT] Output Control Register (SJA1000)
836 DWORD m_dwAMR; // [OUT] Acceptance Mask Register (SJA1000)
837 DWORD m_dwACR; // [OUT] Acceptance Code Register (SJA1000)
838
839 // new values since 17.03.03 Version V2.16
840 BYTE m_bMode; // [OUT] mode of CAN controller (see kUcanMode...)
841 DWORD m_dwSerialNr; // [OUT] serial number from USB-CANmodul
842
843} tUcanHardwareInfo;
844
845typedef struct _tUcanHardwareInfoEx
846{
847 DWORD m_dwSize; // [IN] size of this structure
848 tUcanHandle m_UcanHandle; // [OUT] USB-CAN-Handle assigned by the DLL
849 BYTE m_bDeviceNr; // [OUT] device number of the USB-CANmodul
850 DWORD m_dwSerialNr; // [OUT] serial number from USB-CANmodul
851 DWORD m_dwFwVersionEx; // [OUT] version of firmware
852 DWORD m_dwProductCode; // [OUT] product code (for differentiate between different hardware modules)
853 // see constants USBCAN_PRODCODE_...
854
855 DWORD m_adwUniqueId[4]; // [OUT] unique ID (available since V5.01) !!! m_dwSize must be >= USBCAN_HWINFO_SIZE_V2
856 DWORD m_dwFlags; // [OUT] additional flags
857}
858tUcanHardwareInfoEx;
859#define USBCAN_HWINFO_SIZE_V1 0x12 // size without m_adwDeviceId[]
860#define USBCAN_HWINFO_SIZE_V2 0x22 // size with m_adwDeviceId[]
861#define USBCAN_HWINFO_SIZE_V3 0x26 // size with m_adwDeviceId[] and m_dwFlags
862
863typedef struct _tUcanHardwareInitInfo
864{
865 DWORD m_dwSize; // [IN] size of this structure
866 BOOL m_fDoInitialize; // [IN] specifies if the found module should be initialized by the DLL
867 tUcanHandle* m_pUcanHandle; // [IN] pointer to variable receiving the USB-CAN-Handle
868 tCallbackFktEx m_fpCallbackFktEx; // [IN] pointer to callback function
869 void* m_pCallbackArg; // [IN] pointer to user defined parameter for callback function
870 BOOL m_fTryNext; // [IN] specifies if a further module should be found
871}
872tUcanHardwareInitInfo;
873
874typedef void (PUBLIC *tUcanEnumCallback) (
875 DWORD dwIndex_p, // [IN] gives a sequential number of the enumerated module
876 BOOL fIsUsed_p, // [IN] set to TRUE if the module is used by another application
877 tUcanHardwareInfoEx* pHwInfoEx_p, // [IN] pointer to the hardware info structure identifying the enumerated module
878 tUcanHardwareInitInfo* pInitInfo_p, // [IN] pointer to an init structure for initializing the module
879 void* pArg_p); // [IN] user argument which was overhand with UcanEnumerateHardware()
880
881typedef struct _tUcanChannelInfo
882{
883 DWORD m_dwSize; // [IN] size of this structure
884 BYTE m_bMode; // [OUT] slecets the mode of CAN controller (see kUcanMode...)
885 BYTE m_bBTR0; // [OUT] Bus Timing Register 0 (SJA1000 - use high byte USBCAN_BAUD_...)
886 BYTE m_bBTR1; // [OUT] Bus Timing Register 1 (SJA1000 - use low byte USBCAN_BAUD_...)
887 BYTE m_bOCR; // [OUT] Output Controll Register of SJA1000 (should be 0x1A)
888 DWORD m_dwAMR; // [OUT] Acceptance Mask Register (SJA1000)
889 DWORD m_dwACR; // [OUT] Acceptance Code Register (SJA1000)
890 DWORD m_dwBaudrate; // [OUT] Baudrate Register for Multiport 3004006, USB-CANmodul1 3204000 or USB-CANmodul2 3204002 (use USBCAN_BAUDEX_...)
891 BOOL m_fCanIsInit; // [OUT] is TRUE if CAN interface was initialized, otherwise FALSE
892 WORD m_wCanStatus; // [OUT] CAN status (same as received from function UcanGetStatus..())
893
894} tUcanChannelInfo;
895
896// structure with transfered packet information
897typedef struct _tUcanMsgCountInfo
898{
899 WORD m_wSentMsgCount; // counter of sent CAN messages
900 WORD m_wRecvdMsgCount; // counter of received CAN messages
901
902} tUcanMsgCountInfo;
903
904typedef struct _tUcanMsgCountInfoEx
905{
906 DWORD m_dwSentMsgCount; // counter of sent CAN messages
907 DWORD m_dwRecvdMsgCount; // counter of received CAN messages
908
909} tUcanMsgCountInfoEx;
910
911typedef struct _tUcanRtcStatus
912{
913 DWORD m_dwSize; // [IN] size of this structure
914 BYTE m_bSeconds; // [OUT]
915 BYTE m_bMinutes; // [OUT]
916 BYTE m_bHours; // [OUT]
917 BYTE m_bDays; // [OUT]
918 BYTE m_bWeekdays; // [OUT]
919 BYTE m_bMonthsCentury; // [OUT]
920 BYTE m_bYears; // [OUT]
921}
922tUcanRtcStatus;
923
924typedef struct _tUcanSdCardStatus
925{
926 DWORD m_dwSize; // [IN] size of this structure
927 DWORD m_dwFlags; // [OUT] (SD card set or not set)
928 DWORD m_dwTotalSize; // [OUT] (in 1024 bytes)
929 DWORD m_dwFreeSize; // [OUT] (in 1024 bytes)
930}
931tUcanSdCardStatus;
932
933#if !defined (_WIN32_WCE)
934#pragma pack(pop)
935#endif
936
937
938//---------------------------------------------------------------------------
939// function prototypes
940//---------------------------------------------------------------------------
941
942
943//---------------------------------------------------------------------------
944//
945// Function: UcanSetDebugMode()
946//
947// Description: sets a new debug mode
948//
949// Parameters: dwDbgLevel_p = debug level (bit format)
950// pszFilePathName_p = file path to debug log file
951// dwFlags_p = 0x00000000 no file append mode
952// 0x00000001 file append mode
953//
954// Return: BOOL = FALSE if logfile not created otherwise TRUE
955//
956//---------------------------------------------------------------------------
957
958BOOL PUBLIC UcanSetDebugMode (DWORD dwDbgLevel_p, _TCHAR* pszFilePathName_p, DWORD dwFlags_p);
959
960
961//---------------------------------------------------------------------------
962//
963// Function: UcanGetVersion()
964//
965// Description: returns software version of USBCAN32.DLL
966//
967// NOTE: This function is obsolete. Pleas use UcanGetVersionEx() instead of.
968//
969// Parameters: none
970//
971// Returns: software version
972// format: Bits 0-7: least significant version number (binary)
973// Bits 8-15: most significant version number (binary)
974// Bits 16-30: reserved
975// Bit 31: 1 = customer specific version
976//
977//---------------------------------------------------------------------------
978
979DWORD PUBLIC UcanGetVersion (void);
980
981
982//---------------------------------------------------------------------------
983//
984// Function: UcanGetVersionEx()
985//
986// Description: returns software version of different software modules
987//
988// Parameters: VerType_p = [IN] which version should be returned
989// kVerTypeUserDll returnes Version of USBCAN32.DLL
990// (see tUcanVersionType for more information)
991//
992// Returns: software version
993//
994// format: Bit 0-7: Version (use USBCAN_MAJOR_VER() )
995// Bit 8-15: Revision (use USBCAN_MINOR_VER() )
996// Bit 16-31: Release (use USBCAN_RELEASE_VER() )
997//
998// NOTE: If returned version is zero, then value of VerType_p
999// is unknown or not supported or the file version could not be read.
1000//
1001//---------------------------------------------------------------------------
1002
1003DWORD PUBLIC UcanGetVersionEx (tUcanVersionType VerType_p);
1004
1005
1006//---------------------------------------------------------------------------
1007//
1008// Function: UcanGetFwVersion()
1009//
1010// Description: returns version of the firmware within USB-CANmodul
1011//
1012// Parameters: UcanHandle_p = [IN] USBCAN handle
1013//
1014// Return: DWORD = version in extended format (see UcanGetVersionEx)
1015//
1016//---------------------------------------------------------------------------
1017
1018DWORD PUBLIC UcanGetFwVersion (tUcanHandle UcanHandle_p);
1019
1020
1021//---------------------------------------------------------------------------
1022//
1023// Function: UcanInitHwConnectControl(), UcanInitHwConnectControlEx
1024//
1025// Description: Initializes the Hardware-Connection-Control function
1026//
1027// Parameters: fpConnectControlFkt_p = [IN] address to Hardware-Connection-Control function
1028//
1029// fpConnectControlFktEx_p = [IN] address of the new Hardware-Connection-Control function
1030// NULL: no Callback function is used
1031// pCallbackArg_p = [IN] additional user defined parameter for callback function
1032//
1033// NOTE: Do not set function pointer of type tConnectControlFkt to fpConnectControlFktEx_p and
1034// do not set function pointer of type tConnectControlFktEx to fpConnectControlFkt_p !
1035//
1036// Return: result of the function (see USBCAN_ERR_...)
1037//
1038//---------------------------------------------------------------------------
1039
1040UCANRET PUBLIC UcanInitHwConnectControl (tConnectControlFkt fpConnectControlFkt_p);
1041UCANRET PUBLIC UcanInitHwConnectControlEx (tConnectControlFktEx fpConnectControlFktEx_p, void* pCallbackArg_p);
1042
1043
1044//---------------------------------------------------------------------------
1045//
1046// Function: UcanDeinitHwConnectControl()
1047//
1048// Description: Deinitializes the Hardware-Connection-Control function
1049//
1050// Parameters: none
1051//
1052// Return: result of the function (see USBCAN_ERR_...)
1053//
1054//---------------------------------------------------------------------------
1055
1056UCANRET PUBLIC UcanDeinitHwConnectControl (void);
1057
1058
1059//---------------------------------------------------------------------------
1060//
1061// Function: UcanEnumerateHardware()
1062//
1063// Description: Enumerates connected USB-CANmoduls
1064//
1065// Parameters: fpCallback_p = [IN] callback handler which is called for each found module
1066// pCallbackArg_p = [IN] user argument which is overhand to the callback handler with each call
1067// fEnumUsedDevs_p = [IN] if set to TRUE modules are enumerated too which are used by other applications
1068// bDeviceNrLow_p = [IN] lower value of the device number which should be enumerated
1069// bDeviceNrHigh_p = [IN] higher value of the device number which should be enumerated
1070// dwSerialNrLow_p = [IN] lower value of the serial number which should be enumerated
1071// dwSerialNrHigh_p = [IN] higher value of the serial number which should be enumerated
1072// dwProductCodeLow_p = [IN] lower value of the product code which should be enumerated
1073// dwProductCodeHigh_p = [IN] higher value of the product code which should be enumerated
1074//
1075// Return: DWORD = number of enumerated modules
1076//
1077//---------------------------------------------------------------------------
1078
1079DWORD PUBLIC UcanEnumerateHardware (tUcanEnumCallback fpCallback_p, void* pCallbackArg_p,
1080 BOOL fEnumUsedDevs_p, // if TRUE used modules are enumerated too
1081 BYTE bDeviceNrLow_p, BYTE bDeviceNrHigh_p, // filter parameter for device number
1082 DWORD dwSerialNrLow_p, DWORD dwSerialNrHigh_p, // filter parameter for serial number
1083 DWORD dwProductCodeLow_p, DWORD dwProductCodeHigh_p); // filter parameter for product code
1084
1085
1086//---------------------------------------------------------------------------
1087//
1088// Function: UcanInitHardware(), UcanInitHardwareEx(), UcanInitHardwareEx2()
1089//
1090// Description: Initializes a USB-CANmodul with the device number X or serial number Y
1091//
1092// Parameters: pUcanHandle_p = [OUT] address pointing to the variable for the USB-CAN-Handle
1093// should not be NULL!
1094// bDeviceNr_p = [IN] device number of the USB-CANmodul
1095// valid values: 0 through 254
1096// USBCAN_ANY_MODULE: the first module that is found will be used
1097// dwSerialNr_p = [IN] serial number of the USB-CANmodul
1098// fpCallbackFkt_p = [IN] address of the Callback function
1099// NULL: no Callback function is used
1100// fpCallbackFktEx_p = [IN] address of the new callback function
1101// NULL: no Callback function is used
1102// pCallbackArg_p = [IN] additional user defined parameter for callback function
1103//
1104// NOTE: Do not set function pointer of type tCallbackFkt to fpCallbackFktEx_p and
1105// do not set function pointer of type tCallbackFktEx to fpCallbackFkt_p !
1106//
1107// Return: result of the function (see USBCAN_ERR_...)
1108//
1109//---------------------------------------------------------------------------
1110
1111UCANRET PUBLIC UcanInitHardware (tUcanHandle* pUcanHandle_p, BYTE bDeviceNr_p, tCallbackFkt fpCallbackFkt_p);
1112UCANRET PUBLIC UcanInitHardwareEx (tUcanHandle* pUcanHandle_p, BYTE bDeviceNr_p, tCallbackFktEx fpCallbackFktEx_p, void* pCallbackArg_p);
1113UCANRET PUBLIC UcanInitHardwareEx2 (tUcanHandle* pUcanHandle_p, DWORD dwSerialNr_p, tCallbackFktEx fpCallbackFktEx_p, void* pCallbackArg_p);
1114
1115
1116//---------------------------------------------------------------------------
1117//
1118// Function: UcanSetDeviceNr()
1119//
1120// Description: Sets a new device number to the USB-CANmodul.
1121//
1122// Parameters: UcanHandle_p = [IN] USB-CAN-Handle
1123// Handle, which is returned by the function UcanInitHardware..()
1124// bDeviceNr_p = [IN] new device nr
1125//
1126// Return: result of the function (see USBCAN_ERR_...)
1127//
1128//---------------------------------------------------------------------------
1129
1130UCANRET PUBLIC UcanSetDeviceNr (tUcanHandle UcanHandle_p, BYTE bDeviceNr_p);
1131
1132
1133//---------------------------------------------------------------------------
1134//
1135// Function: UcanGetModuleTime()
1136//
1137// Description: Returns the current time stamp of USB-CANmodul.
1138// NOTE: Some milliseconds are pased if function returnes.
1139//
1140// Parameters: UcanHandle_p = [IN] USB-CAN-Handle
1141// Handle, which is returned by the function UcanInitHardware..()
1142// pdwTime_p = [OUT] pointer to DWORD receiving time stamp
1143// can not be NULL
1144//
1145// Return: result of the function (see USBCAN_ERR_...)
1146//
1147//---------------------------------------------------------------------------
1148
1149UCANRET PUBLIC UcanGetModuleTime (tUcanHandle UcanHandle_p, DWORD* pdwTime_p);
1150
1151
1152//---------------------------------------------------------------------------
1153//
1154// Function: UcanGetHardwareInfo(), UcanGetHardwareInfoEx2()
1155//
1156// Description: Returns the hardware information of an initialized USB-CANmodul
1157//
1158// Parameters: UcanHandle_p = [IN] USB-CAN-Handle
1159// Handle, which is returned by the function UcanInitHardware..()
1160// pHwInfo_p = [OUT] pointer to hardware info structure
1161// can not be NULL
1162//
1163// pCanInfoCh0_p = [OUT] pointer to CAN channel 0 info structure
1164// pCanInfoCh1_p = [OUT] pointer to CAN channel 1 info structure
1165// pCanInfoCh0_p and pCanInfoCh1_p can be NULL
1166//
1167// Return: result of the function (see USBCAN_ERR_...)
1168//
1169//---------------------------------------------------------------------------
1170
1171UCANRET PUBLIC UcanGetHardwareInfo (tUcanHandle UcanHandle_p, tUcanHardwareInfo* pHwInfo_p);
1172UCANRET PUBLIC UcanGetHardwareInfoEx2 (tUcanHandle UcanHandle_p, tUcanHardwareInfoEx* pHwInfo_p, tUcanChannelInfo* pCanInfoCh0_p, tUcanChannelInfo* pCanInfoCh1_p);
1173
1174
1175//---------------------------------------------------------------------------
1176//
1177// Function: UcanInitCan(), UcanInitCanEx(), UcanInitCanEx2()
1178//
1179// Description: Initializes the CAN interface on the USB-CANmodul
1180//
1181// Parameters: UcanHandle_p = [IN] USB-CAN-Handle
1182// Handle, which is returned by the function UcanInitHardware..()
1183// bBTR0_p = [IN] Baudrate Register 0 (SJA1000)
1184// bBTR1_p = [IN] Baudrate Register 1 (SJA1000)
1185// dwAMR_p = [IN] Acceptance Filter Mask (SJA1000)
1186// dwACR_p = [IN] Acceptance Filter Code (SJA1000)
1187//
1188// pInitCanParam_p = [IN] pointer to init parameter structure
1189// bChannel_p = [IN] CAN channel (USBCAN_CHANNEL_CH0 or USBCAN_CHANNEL_CH1)
1190//
1191// Return: result of the function (see USBCAN_ERR_...)
1192//
1193//---------------------------------------------------------------------------
1194
1195UCANRET PUBLIC UcanInitCan (tUcanHandle UcanHandle_p, BYTE bBTR0_p, BYTE bBTR1_p, DWORD dwAMR_p, DWORD dwACR_p);
1196UCANRET PUBLIC UcanInitCanEx (tUcanHandle UcanHandle_p, tUcanInitCanParam* pInitCanParam_p);
1197UCANRET PUBLIC UcanInitCanEx2 (tUcanHandle UcanHandle_p, BYTE bChannel_p, tUcanInitCanParam* pInitCanParam_p);
1198
1199
1200//---------------------------------------------------------------------------
1201//
1202// Function: UcanSetBaudrate(), UcanSetBaudrateEx()
1203//
1204// Description: Modifies the baudrate settings of the USB-CANmodul
1205//
1206// Parameters: UcanHandle_p = [IN] USB-CAN-Handle
1207// Handle, which is returned by the function UcanInitHardware..()
1208// bBTR0_p = [IN] Baudrate Register 0 (GW-001/002 - Multiport 3004006,
1209// USB-CANmodul1 3204000 or USB-CANmodul2 3204002 only standard values)
1210// bBTR1_p = [IN] Baudrate Register 1 (GW-001/002 - Multiport 3004006,
1211// USB-CANmodul1 3204000 or USB-CANmodul2 3204002 only standard values)
1212//
1213// bChannel_p = [IN] CAN channel (USBCAN_CHANNEL_CH0 or USBCAN_CHANNEL_CH1)
1214// dwBaudrate_p = [IN] Baudrate Register of Multiport 3004006, USB-CANmodul1 3204000 or USB-CANmodul2 3204002
1215//
1216// Return: result of the function (see USBCAN_ERR_...)
1217//
1218//---------------------------------------------------------------------------
1219
1220UCANRET PUBLIC UcanSetBaudrate (tUcanHandle UcanHandle_p, BYTE bBTR0_p, BYTE bBTR1_p);
1221UCANRET PUBLIC UcanSetBaudrateEx (tUcanHandle UcanHandle_p, BYTE bChannel_p, BYTE bBTR0_p, BYTE bBTR1_p, DWORD dwBaudrate_p);
1222
1223
1224//---------------------------------------------------------------------------
1225//
1226// Function: UcanSetAcceptance(), UcanSetAcceptanceEx()
1227//
1228// Description: Modifies the Acceptance Filter settings of the USB-CANmodul
1229//
1230// Parameters: UcanHandle_p = [IN] USB-CAN-Handle
1231// Handle, which is returned by the function UcanInitHardware..()
1232// dwAMR_p = [IN] Acceptance Filter Mask (SJA1000)
1233// dwACR_p = [IN] Acceptance Filter Code (SJA1000)
1234//
1235// bChannel_p = [IN] CAN channel (USBCAN_CHANNEL_CH0 or USBCAN_CHANNEL_CH1)
1236//
1237// Return: result of the function (see USBCAN_ERR_...)
1238//
1239//---------------------------------------------------------------------------
1240
1241UCANRET PUBLIC UcanSetAcceptance (tUcanHandle UcanHandle_p, DWORD dwAMR_p, DWORD dwACR_p);
1242UCANRET PUBLIC UcanSetAcceptanceEx (tUcanHandle UcanHandle_p, BYTE bChannel_p, DWORD dwAMR_p, DWORD dwACR_p);
1243
1244
1245//---------------------------------------------------------------------------
1246//
1247// Function: UcanResetCan(), UcanResetCanEx()
1248//
1249// Description: Resets the CAN interface (Hardware-Reset, empty buffer, ...)
1250//
1251// Parameters: UcanHandle_p = [IN] USB-CAN-Handle
1252// Handle, which is returned by the function UcanInitHardware..()
1253//
1254// bChannel_p = [IN] CAN channel (USBCAN_CHANNEL_CH0 or USBCAN_CHANNEL_CH1)
1255// dwResetFlags_p = [IN] flags defines what should be reseted
1256// (see USBCAN_RESET_...)
1257//
1258// Return: result of the function (see USBCAN_ERR_...)
1259//
1260//---------------------------------------------------------------------------
1261
1262UCANRET PUBLIC UcanResetCan (tUcanHandle UcanHandle_p);
1263UCANRET PUBLIC UcanResetCanEx (tUcanHandle UcanHandle_p, BYTE bChannel_p, DWORD dwResetFlags_p);
1264
1265
1266//---------------------------------------------------------------------------
1267//
1268// Function: UcanReadCanMsg(), UcanReadCanMsgEx()
1269//
1270// Description: Reads one or more CAN messages
1271//
1272// Parameters: UcanHandle_p = [IN] USB-CAN-Handle
1273// Handle, which is returned by the function UcanInitHardware..()
1274// pCanMsg_p = [OUT] pointer to the CAN message structure
1275//
1276// pbChannel_p = [IN/OUT] pointer CAN channel (USBCAN_CHANNEL_CH0 or USBCAN_CHANNEL_CH1, USBCAN_CHANNEL_ANY)
1277// pointer must not be NULL
1278// if INPUT is USBCAN_CHANNEL_ANY the OUTPUT will be the read CAN channel
1279// pdwCount_p = [IN/OUT] pointer to number of received CAN messages
1280// if NULL only one CAN message will be read
1281// INPUT: *pdwCount_p contains max number of CAN messages which should be read
1282// OUTPUT: *pdwCount_p contains real number of CAN messages was read
1283//
1284// Return: result of the function (see USBCAN_ERR_...)
1285//
1286//---------------------------------------------------------------------------
1287
1288UCANRET PUBLIC UcanReadCanMsg (tUcanHandle UcanHandle_p, tCanMsgStruct* pCanMsg_p);
1289UCANRET PUBLIC UcanReadCanMsgEx (tUcanHandle UcanHandle_p, BYTE* pbChannel_p, tCanMsgStruct* pCanMsg_p, DWORD* pdwCount_p);
1290
1291
1292//---------------------------------------------------------------------------
1293//
1294// Function: UcanWriteCanMsg(), UcanWriteCanMsgEx()
1295//
1296// Description: Sends one or more CAN messages
1297//
1298// Parameters: UcanHandle_p = [IN] USB-CAN-Handle
1299// Handle, which is returned by the function UcanInitHardware..()
1300// pCanMsg_p = [IN] pointer to the CAN message structure
1301//
1302// bChannel_p = [IN] CAN channel (USBCAN_CHANNEL_CH0 or USBCAN_CHANNEL_CH1)
1303// pdwCount_p = [IN/OUT] pointer to number of CAN messages to write
1304// if NULL only one CAN message will be written
1305// INPUT: *pdwCount_p contains number of CAN messages which should be written
1306// OUTPUT: *pdwCount_p contains real number of CAN messages was written
1307//
1308// Return: result of the function (see USBCAN_ERR_...)
1309//
1310//---------------------------------------------------------------------------
1311
1312UCANRET PUBLIC UcanWriteCanMsg (tUcanHandle UcanHandle_p, tCanMsgStruct* pCanMsg_p);
1313UCANRET PUBLIC UcanWriteCanMsgEx (tUcanHandle UcanHandle_p, BYTE bChannel_p, tCanMsgStruct* pCanMsg_p, DWORD* pdwCount_p);
1314
1315
1316//---------------------------------------------------------------------------
1317//
1318// Function: UcanGetStatus(), UcanGetStatusEx()
1319//
1320// Description: Returns the state of the USB-CANmodul
1321//
1322// Parameters: UcanHandle_p = [IN] USB-CAN-Handle
1323// Handle, which is returned by the function UcanInitHardware..()
1324// pStatus_p = [OUT] pointer to Status structure
1325//
1326// bChannel_p = [IN] CAN channel (USBCAN_CHANNEL_CH0 or USBCAN_CHANNEL_CH1)
1327//
1328// Return: result of the function (see USBCAN_ERR_...)
1329//
1330//---------------------------------------------------------------------------
1331
1332UCANRET PUBLIC UcanGetStatus (tUcanHandle UcanHandle_p, tStatusStruct* pStatus_p);
1333UCANRET PUBLIC UcanGetStatusEx (tUcanHandle UcanHandle_p, BYTE bChannel_p, tStatusStruct* pStatus_p);
1334
1335
1336//---------------------------------------------------------------------------
1337//
1338// Function: UcanGetMsgCountInfo(), UcanGetMsgCountInfoEx()
1339//
1340// Description: Reads the packet information from USB-CANmodul (counter of
1341// received and sent CAN messages).
1342//
1343// Parameters: UcanHandle_p = [IN] USB-CAN-Handle
1344// Handle, which is returned by the function UcanInitHardware..()
1345// pMsgCountInfo_p = [OUT] pointer to message counter information structure
1346//
1347// bChannel_p = [IN] CAN channel (USBCAN_CHANNEL_CH0 or USBCAN_CHANNEL_CH1)
1348//
1349// Return: result of the function (see USBCAN_ERR_...)
1350//
1351//---------------------------------------------------------------------------
1352
1353UCANRET PUBLIC UcanGetMsgCountInfo (tUcanHandle UcanHandle_p, tUcanMsgCountInfo* pMsgCountInfo_p);
1354UCANRET PUBLIC UcanGetMsgCountInfoEx (tUcanHandle UcanHandle_p, BYTE bChannel_p, tUcanMsgCountInfo* pMsgCountInfo_p);
1355UCANRET PUBLIC UcanGetMsgCountInfoEx2 (tUcanHandle UcanHandle_p, BYTE bChannel_p, tUcanMsgCountInfoEx* pMsgCountInfo_p);
1356
1357
1358//---------------------------------------------------------------------------
1359//
1360// Function: UcanDeinitCan(), UcanDeinitCanEx()
1361//
1362// Description: Shuts down the CAN interface on the USB-CANmodul
1363//
1364// Parameters: UcanHandle_p = [IN] USB-CAN-Handle
1365// Handle, which is returned by the function UcanInitHardware..()
1366//
1367// bChannel_p = [IN] CAN channel (USBCAN_CHANNEL_CH0 or USBCAN_CHANNEL_CH1)
1368//
1369// Return: result of the function (see USBCAN_ERR_...)
1370//
1371//---------------------------------------------------------------------------
1372
1373UCANRET PUBLIC UcanDeinitCan (tUcanHandle UcanHandle_p);
1374UCANRET PUBLIC UcanDeinitCanEx (tUcanHandle UcanHandle_p, BYTE bChannel_p);
1375
1376
1377//---------------------------------------------------------------------------
1378//
1379// Function: UcanDeinitHardware()
1380//
1381// Description: Deinitializes a USB-CANmodul
1382//
1383// Parameters: UcanHandle_p = [IN] USB-CAN-Handle
1384// Handle, which is returned by the function UcanInitHardware..()
1385//
1386// Return: result of the function (see USBCAN_ERR_...)
1387//
1388//---------------------------------------------------------------------------
1389
1390UCANRET PUBLIC UcanDeinitHardware (tUcanHandle UcanHandle_p);
1391
1392
1393//---------------------------------------------------------------------------
1394//
1395// Callback functions
1396//
1397//---------------------------------------------------------------------------
1398
1399//---------------------------------------------------------------------------
1400//
1401// Function: UcanCallbackFkt(), UcanCallbackFktEx()
1402//
1403// Description: Is called from the USBCAN32.DLL if a working event occured.
1404//
1405// Parameters: UcanHandle_p = [IN] USB-CAN-Handle
1406// Handle, which is returned by the function UcanInitHardware..()
1407// bEvent_p/dwEvent_p = [IN] event
1408// USBCAN_EVENT_INITHW
1409// USBCAN_EVENT_INITCAN
1410// USBCAN_EVENT_RECEIVE
1411// USBCAN_EVENT_STATUS
1412// USBCAN_EVENT_DEINITCAN
1413// USBCAN_EVENT_DEINITHW
1414//
1415// bChannel_p = [IN] CAN channel (USBCAN_CHANNEL_CH0 or USBCAN_CHANNEL_CH1, USBCAN_CHANNEL_ANY)
1416// pArg_p = [IN] additional parameter
1417// Parameter which was defined with UcanInitHardwareEx()
1418//
1419// Returns: none
1420//
1421//---------------------------------------------------------------------------
1422
1423void PUBLIC UcanCallbackFkt (tUcanHandle UcanHandle_p, BYTE bEvent_p);
1424void PUBLIC UcanCallbackFktEx (tUcanHandle UcanHandle_p, DWORD dwEvent_p, BYTE bChannel_p, void* pArg_p);
1425
1426
1427//---------------------------------------------------------------------------
1428//
1429// Function: UcanConnectControlFkt(), UcanConnectControlFktEx()
1430//
1431// Description: Is called from the USBCAN32.DLL if a plug & play event occured.
1432//
1433// Parameters: bEvent_p/dwEvent_p = [IN] event
1434// USBCAN_EVENT_CONNECT
1435// USBCAN_EVENT_DISCONNECT
1436// USBCAN_EVENT_FATALDISCON
1437// dwParam_p = [IN] additional parameter (depends on bEvent_p)
1438// USBCAN_EVENT_CONNECT: always 0
1439// USBCAN_EVENT_DISCONNECT. always 0
1440// USBCAN_EVENT_FATALDISCON: USB-CAN-Handle of the disconnected module
1441//
1442// pArg_p = [IN] additional parameter
1443// Parameter which was defined with UcanInitHardwareEx()
1444//
1445// Returns: none
1446//
1447//---------------------------------------------------------------------------
1448
1449void PUBLIC UcanConnectControlFkt (BYTE bEvent_p, DWORD dwParam_p);
1450void PUBLIC UcanConnectControlFktEx (DWORD dwEvent_p, DWORD dwParam_p, void* pArg_p);
1451
1452
1453//---------------------------------------------------------------------------
1454//
1455// automatic transmission of cyclic CAN messages by the device firmware
1456//
1457// Only available for Multiport CAN-to-USB, USB-CANmodulX
1458// (NOT for GW-001 and GW-002 !!!).
1459//
1460//---------------------------------------------------------------------------
1461
1462//---------------------------------------------------------------------------
1463//
1464// Function: UcanDefineCyclicCanMsg()
1465//
1466// Description: defines a list of CAN messages for automatic transmission
1467// NOTE: when this function is called an older list will be deleted
1468//
1469// Parameters: UcanHandle_p = [IN] USB-CAN-Handle
1470// Handle, which is returned by the function UcanInitHardware..()
1471// bChannel_p = [IN] CAN channel (USBCAN_CHANNEL_CH0 or USBCAN_CHANNEL_CH1)
1472// pCanMsgList_p = [IN] pointer to the CAN message list (must be an array)
1473// dwCount_p = [IN] number of CAN messages within the list
1474// if zero an older list will only be deleted
1475//
1476// Return: result of the function (see USBCAN_ERR_...)
1477//
1478//---------------------------------------------------------------------------
1479
1480UCANRET PUBLIC UcanDefineCyclicCanMsg (tUcanHandle UcanHandle_p,
1481 BYTE bChannel_p, tCanMsgStruct* pCanMsgList_p, DWORD dwCount_p);
1482
1483
1484//---------------------------------------------------------------------------
1485//
1486// Function: UcanReadCyclicCanMsg()
1487//
1488// Description: reads the list of CAN messages for automatically sending back
1489//
1490// Parameters: UcanHandle_p = [IN] USB-CAN-Handle
1491// Handle, which is returned by the function UcanInitHardware..()
1492// bChannel_p = [IN] CAN channel (USBCAN_CHANNEL_CH0 or USBCAN_CHANNEL_CH1)
1493// pCanMsgList_p = [OUT] pointer to receive the CAN message list (must be an array)
1494// pdwCount_p = [OUT] pointer to a 32 bit variables for receiving the number of
1495// CAN messages within the list
1496//
1497// Return: result of the function (see USBCAN_ERR_...)
1498//
1499//---------------------------------------------------------------------------
1500
1501UCANRET PUBLIC UcanReadCyclicCanMsg (tUcanHandle UcanHandle_p,
1502 BYTE bChannel_p, tCanMsgStruct* pCanMsgList_p, DWORD* pdwCount_p);
1503
1504
1505//---------------------------------------------------------------------------
1506//
1507// Function: UcanEnableCyclicCanMsg()
1508//
1509// Description: enables or disables the automatically sending
1510//
1511// Parameters: UcanHandle_p = [IN] USB-CAN-Handle
1512// Handle, which is returned by the function UcanInitHardware..()
1513// bChannel_p = [IN] CAN channel (USBCAN_CHANNEL_CH0 or USBCAN_CHANNEL_CH1)
1514// dwFlags_p = [IN] this flags specifies which CAN messages should be
1515// activated, specifies the processing mode oth the list
1516// (sequential or parallel), enables or disables the TxEcho
1517// for this CAN messages
1518// (see constants USBCAN_CYCLIC_FLAG_...)
1519//
1520// Return: result of the function (see USBCAN_ERR_...)
1521//
1522//---------------------------------------------------------------------------
1523
1524UCANRET PUBLIC UcanEnableCyclicCanMsg (tUcanHandle UcanHandle_p,
1525 BYTE bChannel_p, DWORD dwFlags_p);
1526
1527
1528// for the future:
1529//UCANRET PUBLIC UcanSaveCyclicCanMsg (tUcanHandle UcanHandle_p,
1530// BYTE bChannel_p, tUcanInitCanParam* pInitCanParam_p, DWORD dwFlags_p);
1531
1532
1533//---------------------------------------------------------------------------
1534//
1535// Function: UcanGetMsgPending()
1536//
1537// Description: returns the number of pending CAN messages
1538//
1539// Parameters: UcanHandle_p = [IN] USB-CAN-Handle
1540// Handle, which is returned by the function UcanInitHardware..()
1541// bChannel_p = [IN] CAN channel (USBCAN_CHANNEL_CH0, USBCAN_CHANNEL_CH1 or USBCAN_CHANNEL_ANY)
1542// If USBCAN_CHANNEL_ANY is set then the number of borth channels will be
1543// added as long as they are initialized.
1544// dwFlags_p = [IN] this flags specifies which buffers shoulb be checked
1545// (see constants USBCAN_PENDING_FLAG_...)
1546// pdwPendingCount_p = [OUT] pointer to a 32 bit variable which receives the number of pending messages
1547//
1548// Return: result of the function (see USBCAN_ERR_...)
1549//
1550//---------------------------------------------------------------------------
1551
1552UCANRET PUBLIC UcanGetMsgPending (tUcanHandle UcanHandle_p,
1553 BYTE bChannel_p, DWORD dwFlags_p, DWORD* pdwPendingCount_p);
1554
1555
1556
1557//---------------------------------------------------------------------------
1558//
1559// Function: UcanGetCanErrorCounter()
1560//
1561// Description: reads the current value of the error counters within the CAN controller
1562//
1563// Only available for Multiport CAN-to-USB, USB-CANmodulX
1564// (NOT for GW-001 and GW-002 !!!).
1565//
1566// Parameters: UcanHandle_p = [IN] USB-CAN-Handle
1567// Handle, which is returned by the function UcanInitHardware..()
1568// bChannel_p = [IN] CAN channel (USBCAN_CHANNEL_CH0 or USBCAN_CHANNEL_CH1)
1569// pdwTxErrorCounter_p = [OUT] pointer to a 32 bit variable which receives the TX error counter
1570// pdwRxErrorCounter_p = [OUT] pointer to a 32 bit variable which receives the RX error counter
1571//
1572// Return: result of the function (see USBCAN_ERR_...)
1573//
1574//---------------------------------------------------------------------------
1575
1576UCANRET PUBLIC UcanGetCanErrorCounter (tUcanHandle UcanHandle_p,
1577 BYTE bChannel_p, DWORD* pdwTxErrorCounter_p, DWORD* pdwRxErrorCounter_p);
1578
1579
1580//---------------------------------------------------------------------------
1581//
1582// Function: UcanSetTxTimeout()
1583//
1584// Description: sets the transmission timeout
1585//
1586// Note: When a transmission timeout is set the firmware tries to send
1587// a message within this timeout. If it could not be sent the firmware sets
1588// the "auto delete" state. Within this state all transmit CAN messages for
1589// this channel will be deleted automatically for not blocking the other
1590// channel. When firmware does delete a transmit CAN message then a new
1591// error status will be set: USBCAN_CANERR_TXMSGLOST (red LED is blinking).
1592//
1593// This function can also be used for USB-CANmodul2, 8 or 16 (multiport).
1594//
1595// Parameters: UcanHandle_p = [IN] USB-CAN-Handle
1596// bChannel_p = [IN] CAN channel (USBCAN_CHANNEL_CH0 or USBCAN_CHANNEL_CH1)
1597// dwTxTimeout_p = [IN] transmit timeout in milleseconds
1598// (value 0 swithes off the "auto delete" featuere = default setting)
1599//
1600// Return: result of the function (see USBCAN_ERR_...)
1601//
1602//---------------------------------------------------------------------------
1603
1604UCANRET PUBLIC UcanSetTxTimeout (tUcanHandle UcanHandle_p,
1605 BYTE bChannel_p, DWORD dwTxTimeout_p);
1606
1607
1608// future functions
1609UCANRET PUBLIC UcanGetRtcStatus (tUcanHandle UcanHandle_p, tUcanRtcStatus* pRtcStatus_p);
1610UCANRET PUBLIC UcanGetSdCardStatus (tUcanHandle UcanHandle_p, tUcanSdCardStatus* pSdCardStatus_p);
1611
1612
1613#ifdef __cplusplus
1614} // von extern "C"
1615#endif
1616
1617
1618#endif //__USBCAN32_H__
1619
1621// clang-format on