AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
PCBUSB.h
1/* -- $HeadURL: https://svn.uv-software.net/MacCAN/PCANUSB/Library/trunk/drv/pcan_api.h $ --
2 *
3 * project : CAN - Controller Area Network
4 *
5 * purpose : PCAN Application Programming Interface
6 *
7 * copyright : (C) 2012-2023 by UV Software, Berlin
8 *
9 * compiler : Apple clang version 14.0.0 (clang-1400.0.29.202)
10 *
11 * export : TPCANStatus CAN_Initialize(TPCANHandle Channel, TPCANBaudrate Btr0Btr1, TPCANType HwType, DWORD IOPort, WORD Interrupt);
12 * TPCANStatus CAN_Uninitialize(TPCANHandle Channel);
13 * TPCANStatus CAN_Reset(TPCANHandle Channel);
14 * TPCANStatus CAN_GetStatus(TPCANHandle Channel);
15 * TPCANStatus CAN_Read(TPCANHandle Channel, TPCANMsg* MessageBuffer, TPCANTimestamp* TimestampBuffer);
16 * TPCANStatus CAN_Write(TPCANHandle Channel, TPCANMsg* MessageBuffer);
17 * TPCANStatus CAN_FilterMessages(TPCANHandle Channel, DWORD FromID, DWORD ToID, TPCANMode Mode);
18 * TPCANStatus CAN_GetValue(TPCANHandle Channel, TPCANParameter Parameter, void* Buffer, DWORD BufferLength);
19 * TPCANStatus CAN_SetValue(TPCANHandle Channel, TPCANParameter Parameter, void* Buffer, DWORD BufferLength);
20 * TPCANStatus CAN_GetErrorText(TPCANStatus Error, WORD Language, LPSTR Buffer);
21 * *** CAN FD capable devices ***
22 * TPCANStatus CAN_InitializeFD(TPCANHandle Channel, TPCANBitrateFD BitrateFD);
23 * TPCANStatus CAN_ReadFD(TPCANHandle Channel, TPCANMsgFD* MessageBuffer, TPCANTimestampFD* TimestampBuffer);
24 * TPCANStatus CAN_WriteFD(TPCANHandle Channel, TPCANMsgFD* MessageBuffer);
25 *
26 * includes : (none)
27 *
28 * author : Uwe Vogt, UV Software
29 *
30 * e-mail : [email protected]
31 *
32 *
33 * ----------- description --------------------------------------------
34 *
35 * PCAN API - PEAK CAN Application Programming Interface
36 *
37 * This Application Programming Interface (API) is an almost compatible
38 * implementation of the PEAK PCANBasic DLL on macOS (x86_64 and arm64).
39 *
40 * Supported CAN Interfaces:
41 * - PCAN-USB
42 * - PCAN-USB FD
43 * Up to 8 devices are supported.
44 *
45 * Version of PCAN API:
46 * - Based on PEAK's version of 2022-07-06
47 */
48// clang-format off
50
51#ifndef PCAN_API_H_INCLUDED
52#define PCAN_API_H_INCLUDED
53
54/* ----------- includes -----------------------------------------------
55 */
56
57#ifdef __APPLE__
58#include <MacTypes.h> // To map Windows integer types
59#endif
60
61/* ----------- defines ------------------------------------------------
62 */
63
64#ifdef __APPLE__
65#ifndef BYTE
66#define BYTE UInt8
67#endif
68#ifndef WORD
69#define WORD UInt16
70#endif
71#ifndef DWORD
72#define DWORD UInt32
73#endif
74#ifndef UINT64
75#define UINT64 UInt64
76#endif
77#ifndef LPSTR
78#define LPSTR char*
79#endif
80#define __T(s) s
81#endif
82
83/* Defined and supported PCAN channels
84 */
85#define PCAN_NONEBUS 0x00U
86
87#define PCAN_USBBUS1 0x51U
88#define PCAN_USBBUS2 0x52U
89#define PCAN_USBBUS3 0x53U
90#define PCAN_USBBUS4 0x54U
91#define PCAN_USBBUS5 0x55U
92#define PCAN_USBBUS6 0x56U
93#define PCAN_USBBUS7 0x57U
94#define PCAN_USBBUS8 0x58U
95#ifndef __APPLE__
96#define PCAN_USBBUS9 0x509U
97#define PCAN_USBBUS10 0x50AU
98#define PCAN_USBBUS11 0x50BU
99#define PCAN_USBBUS12 0x50CU
100#define PCAN_USBBUS13 0x50DU
101#define PCAN_USBBUS14 0x50EU
102#define PCAN_USBBUS15 0x50FU
103#define PCAN_USBBUS16 0x510U
104#endif
105
106
107/* PCAN error and status codes
108 */
109#define PCAN_ERROR_OK 0x00000U
110#define PCAN_ERROR_XMTFULL 0x00001U
111#define PCAN_ERROR_OVERRUN 0x00002U
112#define PCAN_ERROR_BUSLIGHT 0x00004U
113#define PCAN_ERROR_BUSHEAVY 0x00008U
114#define PCAN_ERROR_BUSWARNING PCAN_ERROR_BUSHEAVY
115#define PCAN_ERROR_BUSPASSIVE 0x40000U
116#define PCAN_ERROR_BUSOFF 0x00010U
117#define PCAN_ERROR_ANYBUSERR (PCAN_ERROR_BUSWARNING | PCAN_ERROR_BUSLIGHT | PCAN_ERROR_BUSHEAVY | PCAN_ERROR_BUSOFF | PCAN_ERROR_BUSPASSIVE)
118#define PCAN_ERROR_QRCVEMPTY 0x00020U
119#define PCAN_ERROR_QOVERRUN 0x00040U
120#define PCAN_ERROR_QXMTFULL 0x00080U
121#define PCAN_ERROR_REGTEST 0x00100U
122#define PCAN_ERROR_NODRIVER 0x00200U
123#define PCAN_ERROR_HWINUSE 0x00400U
124#define PCAN_ERROR_NETINUSE 0x00800U
125#define PCAN_ERROR_ILLHW 0x01400U
126#define PCAN_ERROR_ILLNET 0x01800U
127#define PCAN_ERROR_ILLCLIENT 0x01C00U
128#define PCAN_ERROR_ILLHANDLE (PCAN_ERROR_ILLHW | PCAN_ERROR_ILLNET | PCAN_ERROR_ILLCLIENT)
129#define PCAN_ERROR_RESOURCE 0x02000U
130#define PCAN_ERROR_ILLPARAMTYPE 0x04000U
131#define PCAN_ERROR_ILLPARAMVAL 0x08000U
132#define PCAN_ERROR_UNKNOWN 0x10000U
133#define PCAN_ERROR_ILLDATA 0x20000U
134#define PCAN_ERROR_ILLMODE 0x80000U
135#define PCAN_ERROR_CAUTION 0x2000000U
136#define PCAN_ERROR_INITIALIZE 0x4000000U
137#define PCAN_ERROR_ILLOPERATION 0x8000000U
138
139/* PCAN devices
140 */
141#define PCAN_NONE 0x00U
142#define PCAN_PEAKCAN 0x01U
143#define PCAN_ISA 0x02U
144#define PCAN_DNG 0x03U
145#define PCAN_PCI 0x04U
146#define PCAN_USB 0x05U
147#define PCAN_PCC 0x06U
148#define PCAN_VIRTUAL 0x07U
149#define PCAN_LAN 0x08U
150
151/* PCAN parameters
152 */
153#define PCAN_DEVICE_ID 0x01U
154#define PCAN_5VOLTS_POWER 0x02U
155#define PCAN_RECEIVE_EVENT 0x03U
156#define PCAN_MESSAGE_FILTER 0x04U
157#define PCAN_API_VERSION 0x05U
158#define PCAN_CHANNEL_VERSION 0x06U
159#define PCAN_BUSOFF_AUTORESET 0x07U
160#define PCAN_LISTEN_ONLY 0x08U
161#define PCAN_LOG_LOCATION 0x09U
162#define PCAN_LOG_STATUS 0x0AU
163#define PCAN_LOG_CONFIGURE 0x0BU
164#define PCAN_LOG_TEXT 0x0CU
165#define PCAN_CHANNEL_CONDITION 0x0DU
166#define PCAN_HARDWARE_NAME 0x0EU
167#define PCAN_RECEIVE_STATUS 0x0FU
168#define PCAN_CONTROLLER_NUMBER 0x10U
169#define PCAN_TRACE_LOCATION 0x11U
170#define PCAN_TRACE_STATUS 0x12U
171#define PCAN_TRACE_SIZE 0x13U
172#define PCAN_TRACE_CONFIGURE 0x14U
173#define PCAN_CHANNEL_IDENTIFYING 0x15U
174#define PCAN_CHANNEL_FEATURES 0x16U
175#define PCAN_BITRATE_ADAPTING 0x17U
176#define PCAN_BITRATE_INFO 0x18U
177#define PCAN_BITRATE_INFO_FD 0x19U
178#define PCAN_BUSSPEED_NOMINAL 0x1AU
179#define PCAN_BUSSPEED_DATA 0x1BU
180#define PCAN_IP_ADDRESS 0x1CU
181#define PCAN_LAN_SERVICE_STATUS 0x1DU
182#define PCAN_ALLOW_STATUS_FRAMES 0x1EU
183#define PCAN_ALLOW_RTR_FRAMES 0x1FU
184#define PCAN_ALLOW_ERROR_FRAMES 0x20U
185#define PCAN_INTERFRAME_DELAY 0x21U
186#define PCAN_ACCEPTANCE_FILTER_11BIT 0x22U
187#define PCAN_ACCEPTANCE_FILTER_29BIT 0x23U
188#define PCAN_IO_DIGITAL_CONFIGURATION 0x24U
189#define PCAN_IO_DIGITAL_VALUE 0x25U
190#define PCAN_IO_DIGITAL_SET 0x26U
191#define PCAN_IO_DIGITAL_CLEAR 0x27U
192#define PCAN_IO_ANALOG_VALUE 0x28U
193#define PCAN_FIRMWARE_VERSION 0x29U
194#define PCAN_ATTACHED_CHANNELS_COUNT 0x2AU
195#define PCAN_ATTACHED_CHANNELS 0x2BU
196#define PCAN_ALLOW_ECHO_FRAMES 0x2CU
197#define PCAN_DEVICE_PART_NUMBER 0x2DU
198#define PCAN_EXT_BTR0BTR1 0x80U
199#define PCAN_EXT_TX_COUNTER 0x81U
200#define PCAN_EXT_RX_COUNTER 0x82U
201#define PCAN_EXT_ERR_COUNTER 0x83U
202#define PCAN_EXT_RX_QUE_OVERRUN 0x84U
203#define PCAN_EXT_HARDWARE_VERSION 0x85U
204#define PCAN_EXT_SOFTWARE_VERSION 0x86U
205#define PCAN_EXT_RECEIVE_CALLBACK 0x87U
206#define PCAN_EXT_LOG_USB 0x8FU
207
208/* DEPRECATED parameters
209 */
210#define PCAN_DEVICE_NUMBER PCAN_DEVICE_ID
211
212/* PCAN parameter values
213 */
214#define PCAN_PARAMETER_OFF 0x00U
215#define PCAN_PARAMETER_ON 0x01U
216#define PCAN_FILTER_CLOSE 0x00U
217#define PCAN_FILTER_OPEN 0x01U
218#define PCAN_FILTER_CUSTOM 0x02U
219#define PCAN_CHANNEL_UNAVAILABLE 0x00U
220#define PCAN_CHANNEL_AVAILABLE 0x01U
221#define PCAN_CHANNEL_OCCUPIED 0x02U
222#define PCAN_CHANNEL_PCANVIEW (PCAN_CHANNEL_AVAILABLE | PCAN_CHANNEL_OCCUPIED)
223
224#define LOG_FUNCTION_DEFAULT 0x00U
225#define LOG_FUNCTION_ENTRY 0x01U
226#define LOG_FUNCTION_PARAMETERS 0x02U
227#define LOG_FUNCTION_LEAVE 0x04U
228#define LOG_FUNCTION_WRITE 0x08U
229#define LOG_FUNCTION_READ 0x10U
230#define LOG_FUNCTION_ALL 0xFFFFU
231
232#define TRACE_FILE_SINGLE 0x00U
233#define TRACE_FILE_SEGMENTED 0x01U
234#define TRACE_FILE_DATE 0x02U
235#define TRACE_FILE_TIME 0x04U
236#define TRACE_FILE_OVERWRITE 0x80U
237
238#define FEATURE_FD_CAPABLE 0x01U
239#define FEATURE_DELAY_CAPABLE 0x02U
240#define FEATURE_IO_CAPABLE 0x04U
241
242#define SERVICE_STATUS_STOPPED 0x01U
243#define SERVICE_STATUS_RUNNING 0x04U
244
245/* Other constants
246 */
247#define MAX_LENGTH_HARDWARE_NAME 33
248#define MAX_LENGTH_VERSION_STRING 256
249
250/* PCAN message types
251 */
252#define PCAN_MESSAGE_STANDARD 0x00U
253#define PCAN_MESSAGE_RTR 0x01U
254#define PCAN_MESSAGE_EXTENDED 0x02U
255#define PCAN_MESSAGE_FD 0x04U
256#define PCAN_MESSAGE_BRS 0x08U
257#define PCAN_MESSAGE_ESI 0x10U
258#define PCAN_MESSAGE_ECHO 0x20U
259#define PCAN_MESSAGE_ERRFRAME 0x40U
260#define PCAN_MESSAGE_STATUS 0x80U
261
262/* LookUp Parameters
263 */
264#define LOOKUP_DEVICE_TYPE __T("devicetype")
265#define LOOKUP_DEVICE_ID __T("deviceid")
266#define LOOKUP_CONTROLLER_NUMBER __T("controllernumber")
267#define LOOKUP_IP_ADDRESS __T("ipaddress")
268
269/* Frame Type / Initialization Mode
270 */
271#define PCAN_MODE_STANDARD PCAN_MESSAGE_STANDARD
272#define PCAN_MODE_EXTENDED PCAN_MESSAGE_EXTENDED
273
274/* Baud rate codes = BTR0/BTR1 register values for the CAN controller.
275 * You can define your own Baud rate with the BTROBTR1 register.
276 * Take a look at www.peak-system.com for their free software "BAUDTOOL"
277 * to calculate the BTROBTR1 register for every bit rate and sample point.
278 */
279#define PCAN_BAUD_1M 0x0014U
280#define PCAN_BAUD_800K 0x0016U
281#define PCAN_BAUD_500K 0x001CU
282#define PCAN_BAUD_250K 0x011CU
283#define PCAN_BAUD_125K 0x031CU
284#define PCAN_BAUD_100K 0x432FU
285#define PCAN_BAUD_95K 0xC34EU
286#define PCAN_BAUD_83K 0x852BU
287#define PCAN_BAUD_50K 0x472FU
288#define PCAN_BAUD_47K 0x1414U
289#define PCAN_BAUD_33K 0x8B2FU
290#define PCAN_BAUD_20K 0x532FU
291#define PCAN_BAUD_10K 0x672FU
292#define PCAN_BAUD_5K 0x7F7FU
293
294/* Represents the configuration for a CAN bit rate
295 * Note:
296 * * Each parameter and its value must be separated with a '='.
297 * * Each pair of parameter/value must be separated using ','.
298 *
299 * Example:
300 * f_clock=80000000,nom_brp=10,nom_tseg1=5,nom_tseg2=2,nom_sjw=1,data_brp=4,data_tseg1=7,data_tseg2=2,data_sjw=1
301 */
302#define PCAN_BR_CLOCK __T("f_clock")
303#define PCAN_BR_CLOCK_MHZ __T("f_clock_mhz")
304#define PCAN_BR_NOM_BRP __T("nom_brp")
305#define PCAN_BR_NOM_TSEG1 __T("nom_tseg1")
306#define PCAN_BR_NOM_TSEG2 __T("nom_tseg2")
307#define PCAN_BR_NOM_SJW __T("nom_sjw")
308#define PCAN_BR_NOM_SAMPLE __T("nom_sam")
309#define PCAN_BR_DATA_BRP __T("data_brp")
310#define PCAN_BR_DATA_TSEG1 __T("data_tseg1")
311#define PCAN_BR_DATA_TSEG2 __T("data_tseg2")
312#define PCAN_BR_DATA_SJW __T("data_sjw")
313#define PCAN_BR_DATA_SAMPLE __T("data_ssp_offset")
314
315/* ----------- types --------------------------------------------------
316 */
317
318#define TPCANHandle WORD
319#define TPCANStatus DWORD
320#define TPCANParameter BYTE
321#define TPCANDevice BYTE
322#define TPCANMessageType BYTE
323#define TPCANType BYTE
324#define TPCANMode BYTE
325#define TPCANBaudrate WORD
326#define TPCANBitrateFD LPSTR
327#define TPCANTimestampFD UINT64
328
331typedef struct tagTPCANMsg
332{
333 DWORD ID;
334 TPCANMessageType MSGTYPE;
335 BYTE LEN;
336 BYTE DATA[8];
337} TPCANMsg;
338
342typedef struct tagTPCANTimestamp
343{
344 DWORD millis;
345 WORD millis_overflow;
346 WORD micros;
347} TPCANTimestamp;
348
351typedef struct tagTPCANMsgFD
352{
353 DWORD ID;
354 TPCANMessageType MSGTYPE;
355 BYTE DLC;
356 BYTE DATA[64];
357} TPCANMsgFD;
358
361typedef struct tagTPCANChannelInformation
362{
363 TPCANHandle channel_handle;
364 TPCANDevice device_type;
365 BYTE controller_number;
366 DWORD device_features;
367 char device_name[MAX_LENGTH_HARDWARE_NAME];
368 DWORD device_id;
369 DWORD channel_condition;
370}TPCANChannelInformation;
371
372
373/* ----------- variables ----------------------------------------------
374 */
375
376
377/* ----------- prototypes ---------------------------------------------
378 */
379
380#ifdef __cplusplus
381extern "C" {
382#define _DEF_ARG =0
383#else
384#define _DEF_ARG
385#endif
386
397TPCANStatus CAN_Initialize(
398 TPCANHandle Channel,
399 TPCANBaudrate Btr0Btr1,
400 TPCANType HwType _DEF_ARG,
401 DWORD IOPort _DEF_ARG,
402 WORD Interrupt _DEF_ARG);
403
423TPCANStatus CAN_InitializeFD(
424 TPCANHandle Channel,
425 TPCANBitrateFD BitrateFD);
426
435TPCANStatus CAN_Uninitialize(
436 TPCANHandle Channel);
437
446TPCANStatus CAN_Reset(
447 TPCANHandle Channel);
448
455TPCANStatus CAN_GetStatus(
456 TPCANHandle Channel);
457
467TPCANStatus CAN_Read(
468 TPCANHandle Channel,
469 TPCANMsg* MessageBuffer,
470 TPCANTimestamp* TimestampBuffer);
471
481TPCANStatus CAN_ReadFD(
482 TPCANHandle Channel,
483 TPCANMsgFD* MessageBuffer,
484 TPCANTimestampFD* TimestampBuffer);
485
493TPCANStatus CAN_Write(
494 TPCANHandle Channel,
495 TPCANMsg* MessageBuffer);
496
504TPCANStatus CAN_WriteFD(
505 TPCANHandle Channel,
506 TPCANMsgFD* MessageBuffer);
507
520TPCANStatus CAN_FilterMessages(
521 TPCANHandle Channel,
522 DWORD FromID,
523 DWORD ToID,
524 TPCANMode Mode);
525
538TPCANStatus CAN_GetValue(
539 TPCANHandle Channel,
540 TPCANParameter Parameter,
541 void* Buffer,
542 DWORD BufferLength);
543
544
557TPCANStatus CAN_SetValue(
558 TPCANHandle Channel,
559 TPCANParameter Parameter,
560 void* Buffer,
561 DWORD BufferLength);
562
574TPCANStatus CAN_GetErrorText(
575 TPCANStatus Error,
576 WORD Language,
577 LPSTR Buffer);
578
587TPCANStatus CAN_LookUpChannel(
588 LPSTR Parameters,
589 TPCANHandle* FoundChannel);
590
591#ifdef __cplusplus
592}
593#endif
594#endif /* PCAN_API_H_INCLUDED */
595
596/* ----------------------------------------------------------------------
597 * Uwe Vogt, UV Software, Chausseestrasse 33 A, 10115 Berlin, Germany
598 * Tel.: +49-30-46799872, Fax: +49-30-46799873, Mobile: +49-170-3801903
599 * E-Mail: [email protected], Homepage: http://www.uv-software.de/
600 */
601// clang-format on