SEPIA
Software documentation for the APEX SEPIA receivers
PCANBasic.h
1 // Copyright (C) 1999-2010 PEAK-System Technik GmbH, Darmstadt
2 // PCANBasic.h
3 //
4 // ~~~~~~~~~~~~
5 //
6 // PCAN-Basic API
7 //
8 // ~~~~~~~~~~~~
9 //
10 // ------------------------------------------------------------------
11 // Author : Keneth Wagner
12 // Last change: 21.01.2010 Wagner
13 //
14 // Language: ANSI-C
15 // ------------------------------------------------------------------
16 //
17 // more Info at http://www.peak-system.com
18 //
19 #ifndef __PCANBASICH__
20 #define __PCANBASICH__
21 
22 #ifdef linux
23 #define __stdcall
24 #endif
25 
27 // Value definitions
29 
30 // Currently defined and supported PCAN channels
31 //
32 #define PCAN_NONEBUS 0x00 // Undefined/default value for a PCAN bus
33 
34 #define PCAN_ISABUS1 0x21 // PCAN-ISA interface, channel 1
35 #define PCAN_ISABUS2 0x22 // PCAN-ISA interface, channel 2
36 #define PCAN_ISABUS3 0x23 // PCAN-ISA interface, channel 3
37 #define PCAN_ISABUS4 0x24 // PCAN-ISA interface, channel 4
38 #define PCAN_ISABUS5 0x25 // PCAN-ISA interface, channel 5
39 #define PCAN_ISABUS6 0x26 // PCAN-ISA interface, channel 6
40 #define PCAN_ISABUS7 0x27 // PCAN-ISA interface, channel 7
41 #define PCAN_ISABUS8 0x28 // PCAN-ISA interface, channel 8
42 
43 #define PCAN_DNGBUS1 0x31 // PCAN-Dongle/LPT interface, channel 1
44 
45 #define PCAN_PCIBUS1 0x41 // PCAN-PCI interface, channel 1
46 #define PCAN_PCIBUS2 0x42 // PCAN-PCI interface, channel 2
47 #define PCAN_PCIBUS3 0x43 // PCAN-PCI interface, channel 3
48 #define PCAN_PCIBUS4 0x44 // PCAN-PCI interface, channel 4
49 #define PCAN_PCIBUS5 0x45 // PCAN-PCI interface, channel 5
50 #define PCAN_PCIBUS6 0x46 // PCAN-PCI interface, channel 6
51 #define PCAN_PCIBUS7 0x47 // PCAN-PCI interface, channel 7
52 #define PCAN_PCIBUS8 0x48 // PCAN-PCI interface, channel 8
53 
54 #define PCAN_USBBUS1 0x51 // PCAN-USB interface, channel 1
55 #define PCAN_USBBUS2 0x52 // PCAN-USB interface, channel 2
56 #define PCAN_USBBUS3 0x53 // PCAN-USB interface, channel 3
57 #define PCAN_USBBUS4 0x54 // PCAN-USB interface, channel 4
58 #define PCAN_USBBUS5 0x55 // PCAN-USB interface, channel 5
59 #define PCAN_USBBUS6 0x56 // PCAN-USB interface, channel 6
60 #define PCAN_USBBUS7 0x57 // PCAN-USB interface, channel 7
61 #define PCAN_USBBUS8 0x58 // PCAN-USB interface, channel 8
62 
63 #define PCAN_PCCBUS1 0x61 // PCAN-PC Card interface, channel 1
64 #define PCAN_PCCBUS2 0x62 // PCAN-PC Card interface, channel 2
65 
66 // Represent the PCAN error and status codes
67 //
68 #define PCAN_ERROR_OK 0x00000 // No error
69 #define PCAN_ERROR_XMTFULL 0x00001 // Transmit buffer in CAN controller is full
70 #define PCAN_ERROR_OVERRUN 0x00002 // CAN controller was read too late
71 #define PCAN_ERROR_BUSLIGHT 0x00004 // Bus error: an error counter reached the 'light' limit
72 #define PCAN_ERROR_BUSHEAVY 0x00008 // Bus error: an error counter reached the 'heavy' limit
73 #define PCAN_ERROR_BUSOFF 0x00010 // Bus error: the CAN controller is in bus-off state
74 #define PCAN_ERROR_ANYBUSERR (PCAN_ERROR_BUSLIGHT | PCAN_ERROR_BUSHEAVY | PCAN_ERROR_BUSOFF)
75 #define PCAN_ERROR_QRCVEMPTY 0x00020 // Receive queue is empty
76 #define PCAN_ERROR_QOVERRUN 0x00040 // Receive queue was read too late
77 #define PCAN_ERROR_QXMTFULL 0x00080 // Transmit queue is full
78 #define PCAN_ERROR_REGTEST 0x00100 // Test of the CAN controller hardware registers failed (no hardware found)
79 #define PCAN_ERROR_NODRIVER 0x00200 // Driver not loaded
80 #define PCAN_ERROR_HWINUSE 0x00400 // Hardware already in use by a Net
81 #define PCAN_ERROR_NETINUSE 0x00800 // A Client is already connected to the Net
82 // mod
83 #define PCAN_ERROR_ILLHW 0x01000 // Hardware handle is invalid
84 #define PCAN_ERROR_ILLNET 0x01400 // Net handle is invalid
85 #define PCAN_ERROR_ILLCLIENT 0x01800 // Client handle is invalid
86 // mod
87 #define PCAN_ERROR_ILLHANDLE (PCAN_ERROR_ILLHW | PCAN_ERROR_ILLNET | PCAN_ERROR_ILLCLIENT)
88 #define PCAN_ERROR_RESOURCE 0x02000 // Resource (FIFO, Client, timeout) cannot be created
89 #define PCAN_ERROR_ILLPARAMTYPE 0x04000 // Invalid parameter
90 #define PCAN_ERROR_ILLPARAMVAL 0x08000 // Invalid parameter value
91 #define PCAN_ERROR_UNKNOWN 0x10000 // Unknow error
92 #define PCAN_ERROR_INITIALIZE 0x40000 // Channel is not initialized
93 
94 // PCAN devices
95 //
96 #define PCAN_NONE 0x00 // Undefined, unknown or not selected PCAN device value
97 #define PCAN_PEAKCAN 0x01 // PCAN Non-Plug&Play devices. NOT USED WITHIN PCAN-Basic API
98 #define PCAN_ISA 0x02 // PCAN-ISA, PCAN-PC/104, and PCAN-PC/104-Plus
99 #define PCAN_DNG 0x03 // PCAN-Dongle
100 #define PCAN_PCI 0x04 // PCAN-PCI, PCAN-cPCI, PCAN-miniPCI, and PCAN-PCI Express
101 #define PCAN_USB 0x05 // PCAN-USB and PCAN-USB Pro
102 #define PCAN_PCC 0x06 // PCAN-PC Card
103 
104 // PCAN parameters
105 //
106 #define PCAN_DEVICE_NUMBER 0x01 // PCAN-USB device number parameter
107 #define PCAN_5VOLTS_POWER 0x02 // PCAN-PC Card 5-Volt power parameter
108 #define PCAN_RECEIVE_EVENT 0x03 // PCAN receive event handler parameter
109 #define PCAN_MESSAGE_FILTER 0x04 // PCAN message filter parameter
110 #define PCAN_API_VERSION 0x05 // PCAN-Basic API version parameter
111 #define PCAN_CHANNEL_VERSION 0x06 // PCAN device channel version parameter
112 #define PCAN_BUSOFF_AUTORESET 0x07 // PCAN Reset-On-Busoff parameter
113 #define PCAN_LISTEN_ONLY 0x08 // PCAN Listen-Only parameter
114 #define PCAN_LOG_LOCATION 0x09 // Directory path for trace files
115 #define PCAN_LOG_STATUS 0x0A // Debug-Trace activation status
116 #define PCAN_LOG_CONFIGURE 0x0B // Configuration of the debugged information (LOG_FUNCTION_***)
117 #define PCAN_LOG_TEXT 0x0C // Custom insertion of text into the log file
118 #define PCAN_CHANNEL_CONDITION 0x0D // Availability status of a PCAN-Channel
119 
120 // PCAN parameter values
121 //
122 #define PCAN_PARAMETER_OFF 0x00 // The PCAN parameter is not set (inactive)
123 #define PCAN_PARAMETER_ON 0x01 // The PCAN parameter is set (active)
124 #define PCAN_FILTER_CLOSE 0x00 // The PCAN filter is closed. No messages will be received
125 #define PCAN_FILTER_OPEN 0x01 // The PCAN filter is fully opened. All messages will be received
126 #define PCAN_FILTER_CUSTOM 0x02 // The PCAN filter is custom configured.
127 #define PCAN_CHANNEL_ILLEGAL 0x00 // The PCAN-Channel handle is illegal
128 #define PCAN_CHANNEL_AVAILABLE 0x01 // The PCAN-Channel handle is valid to connect/initialize
129 #define PCAN_CHANNEL_OCCUPIED 0x02 // The PCAN-Channel handle is valid, but is already being used
130 #define PCAN_CHANNEL_UNOCCUPIED 0x03 // The PCAN-Channel handle is valid and ready for use (Plug & Play hardware only)
131 
132 #define LOG_FUNCTION_DEFAULT 0x00 // Logs system exceptions / errors
133 #define LOG_FUNCTION_ENTRY 0x01 // Logs the entries to the PCAN-Basic API functions
134 #define LOG_FUNCTION_PARAMETERS 0x02 // Logs the parameters passed to the PCAN-Basic API functions
135 #define LOG_FUNCTION_LEAVE 0x04 // Logs the exits from the PCAN-Basic API functions
136 #define LOG_FUNCTION_WRITE 0x08 // Logs the CAN messages passed to the CAN_Write function
137 #define LOG_FUNCTION_READ 0x10 // Logs the CAN messages received within the CAN_Read function
138 
139 
140 // PCAN message types
141 //
142 #define PCAN_MESSAGE_STANDARD 0x00 // The PCAN message is a CAN Standard Frame (11-bit identifier)
143 #define PCAN_MESSAGE_RTR 0x01 // The PCAN message is a CAN Remote-Transfer-Request Frame
144 #define PCAN_MESSAGE_EXTENDED 0x02 // The PCAN message is a CAN Extended Frame (29-bit identifier)
145 #define PCAN_MESSAGE_STATUS 0x80 // The PCAN message represents a PCAN status message
146 
147 // Frame Type / Initialization Mode
148 //
149 #define PCAN_MODE_STANDARD PCAN_MESSAGE_STANDARD
150 #define PCAN_MODE_EXTENDED PCAN_MESSAGE_EXTENDED
151 
152 // Baud rate codes = BTR0/BTR1 register values for the CAN controller.
153 // You can define your own Baud rate with the BTROBTR1 register.
154 // Take a look at www.peak-system.com for our free software "BAUDTOOL"
155 // to calculate the BTROBTR1 register for every baudrate and sample point.
156 //
157 #define PCAN_BAUD_1M 0x0014 // 1 MBit/s
158 #define PCAN_BAUD_500K 0x001C // 500 kBit/s
159 #define PCAN_BAUD_250K 0x011C // 250 kBit/s
160 #define PCAN_BAUD_125K 0x031C // 125 kBit/s
161 #define PCAN_BAUD_100K 0x432F // 100 kBit/s
162 #define PCAN_BAUD_50K 0x472F // 50 kBit/s
163 #define PCAN_BAUD_20K 0x532F // 20 kBit/s
164 #define PCAN_BAUD_10K 0x672F // 10 kBit/s
165 #define PCAN_BAUD_5K 0x7F7F // 5 kBit/s
166 
167 #define PCAN_TYPE_ISA 0x01 // PCAN-ISA 82C200
168 #define PCAN_TYPE_ISA_SJA 0x09 // PCAN-ISA SJA1000
169 #define PCAN_TYPE_ISA_PHYTEC 0x04 // PHYTEC ISA
170 #define PCAN_TYPE_DNG 0x02 // PCAN-Dongle 82C200
171 #define PCAN_TYPE_DNG_EPP 0x03 // PCAN-Dongle EPP 82C200
172 #define PCAN_TYPE_DNG_SJA 0x05 // PCAN-Dongle SJA1000
173 #define PCAN_TYPE_DNG_SJA_EPP 0x06 // PCAN-Dongle EPP SJA1000
174 
176 // Type definitions
178 
179 
180 #define TPCANHandle BYTE // Represents a PCAN hardware channel handle
181 #define TPCANStatus DWORD // Represents a PCAN status/error code
182 #define TPCANParameter BYTE // Represents a PCAN parameter to be read or set
183 #define TPCANDevice BYTE // Represents a PCAN device
184 #define TPCANMessageType BYTE // Represents the type of a PCAN message
185 #define TPCANType BYTE // Represents the type of PCAN hardware to be initialized
186 #define TPCANMode BYTE // Represents a PCAN filter mode
187 #define TPCANBaudrate WORD // Represents a PCAN Baud rate register value
188 
190 // Structure definitions
192 
193 // Represents a PCAN message
194 //
195 typedef struct tagTPCANMsg
196 {
197  DWORD ID; // 11/29-bit message identifier
198  TPCANMessageType MSGTYPE; // Type of the message
199  BYTE LEN; // Data Length Code of the message (0..8)
200  BYTE DATA[8]; // Data of the message (DATA[0]..DATA[7])
201 } TPCANMsg;
202 
203 // Represents a timestamp of a received PCAN message
204 // Total Microseconds = micros + 1000 * millis + 0xFFFFFFFF * 1000 * millis_overflow
205 //
206 typedef struct tagTPCANTimestamp
207 {
208  DWORD millis; // Base-value: milliseconds: 0.. 2^32-1
209  WORD millis_overflow; // Roll-arounds of millis
210  WORD micros; // Microseconds: 0..999
211 } TPCANTimestamp;
212 
213 #ifdef __cplusplus
214 extern "C" {
215 #endif
216 
218 // PCAN-Basic API function declarations
220 
221 
231 TPCANStatus __stdcall CAN_Initialize(
232  TPCANHandle Channel,
233  TPCANBaudrate Btr0Btr1,
234  TPCANType HwType,
235  DWORD IOPort,
236  WORD Interrupt);
237 
238 
246 TPCANStatus __stdcall CAN_Uninitialize(
247  TPCANHandle Channel);
248 
249 
258 TPCANStatus __stdcall CAN_Reset(
259  TPCANHandle Channel);
260 
261 
267 TPCANStatus __stdcall CAN_GetStatus(
268  TPCANHandle Channel);
269 
270 
280 TPCANStatus __stdcall CAN_Read(
281  TPCANHandle Channel,
282  TPCANMsg* MessageBuffer,
283  TPCANTimestamp* TimestampBuffer);
284 
285 
292 TPCANStatus __stdcall CAN_Write(
293  TPCANHandle Channel,
294  TPCANMsg* MessageBuffer);
295 
296 
309 TPCANStatus __stdcall CAN_FilterMessages(
310  TPCANHandle Channel,
311  DWORD FromID,
312  DWORD ToID,
313  TPCANMode Mode);
314 
315 
327 TPCANStatus __stdcall CAN_GetValue(
328  TPCANHandle Channel,
329  TPCANParameter Parameter,
330  void* Buffer,
331  DWORD BufferLength);
332 
333 
345 TPCANStatus __stdcall CAN_SetValue(
346  TPCANHandle Channel,
347  TPCANParameter Parameter,
348  void* Buffer,
349  DWORD BufferLength);
350 
351 
363 TPCANStatus __stdcall CAN_GetErrorText(
364  TPCANStatus Error,
365  WORD Language,
366  LPSTR Buffer);
367 
368 #ifdef __cplusplus
369 }
370 #endif
371 
372 #endif