source: pacpussensors/trunk/CanGateway/driver/libpcan.h

Last change on this file was 1, checked in by DHERBOMEZ Gérald, 11 years ago

ajout des capteurs CanGateway et Alasca

File size: 9.3 KB
Line 
1#ifndef __LIBPCAN_H__
2#define __LIBPCAN_H__
3
4//****************************************************************************
5// Copyright (C) 2001-2007 PEAK System-Technik GmbH
6//
7// linux@peak-system.com
8// www.peak-system.com
9//
10// This library is free software; you can redistribute it and/or
11// modify it under the terms of the GNU Lesser General Public
12// License as published by the Free Software Foundation; either
13// version 2.1 of the License, or (at your option) any later version.
14
15// This library is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23//
24// Maintainer(s): Klaus Hitschler (klaus.hitschler@gmx.de)
25// Contributions: Mudiaga Obada (obada@vsi.cs.uni-frankfurt.de)
26//****************************************************************************
27
28//****************************************************************************
29//
30// libpcan.h
31// common header to access the functions within pcanlib.so.x.x,
32// originally created from Wilhelm Hoppe in pcan_pci.h
33//
34// $Id: libpcan.h 455 2007-02-11 22:19:11Z khitschler $
35//
36//****************************************************************************
37
38//****************************************************************************
39// INCLUDES
40#include "pcan.h"
41
42//****************************************************************************
43// compatibilty defines
44#if defined(LPSTR) || defined(HANDLE)
45#error "double define for LPSTR, HANDLE found"
46#endif
47
48#define LPSTR char *
49#define HANDLE void *
50
51//****************************************************************************
52// for CAN_Open(...)
53
54//****************************************************************************
55// for CAN_Init(...)
56
57// parameter wBTR0BTR1
58// bitrate codes of BTR0/BTR1 registers
59#define CAN_BAUD_1M 0x0014 // 1 MBit/s
60#define CAN_BAUD_500K 0x001C // 500 kBit/s
61#define CAN_BAUD_250K 0x011C // 250 kBit/s
62#define CAN_BAUD_125K 0x031C // 125 kBit/s
63#define CAN_BAUD_100K 0x432F // 100 kBit/s
64#define CAN_BAUD_50K 0x472F // 50 kBit/s
65#define CAN_BAUD_20K 0x532F // 20 kBit/s
66#define CAN_BAUD_10K 0x672F // 10 kBit/s
67#define CAN_BAUD_5K 0x7F7F // 5 kBit/s
68
69// parameter nCANMsgType
70#define CAN_INIT_TYPE_EX 0x01 //Extended Frame
71#define CAN_INIT_TYPE_ST 0x00 //Standart Frame
72
73//****************************************************************************
74// error codes are defined in pcan.h
75#define CAN_ERR_ANYBUSERR (CAN_ERR_BUSLIGHT | CAN_ERR_BUSHEAVY | CAN_ERR_BUSOFF)
76
77//****************************************************************************
78// PROTOTYPES
79#ifdef __cplusplus
80 extern "C"
81{
82#endif
83
84//****************************************************************************
85// CAN_Open()
86// creates a path to a CAN port
87//
88// for PCAN-Dongle call: CAN_Open(HW_DONGLE_.., DWORD dwPort, WORD wIrq);
89// for PCAN-ISA or PCAN-PC/104 call: CAN_Open(HW_ISA_SJA, DWORD dwPort, WORD wIrq);
90// for PCAN-PCI call: CAN_Open(HW_PCI, int nPort); .. enumerate nPort 1..8.
91//
92// if ((dwPort == 0) && (wIrq == 0)) CAN_Open() takes the 1st default ISA or DONGLE port.
93// if (nPort == 0) CAN_Open() takes the 1st default PCI port.
94// returns NULL when open failes.
95//
96// The first CAN_Open() to a CAN hardware initializes the hardware to default
97// parameter 500 kbit/sec and acceptance of extended frames.
98//
99HANDLE CAN_Open(WORD wHardwareType, ...);
100
101//****************************************************************************
102// CAN_Init()
103// initializes the CAN hardware with the BTR0 + BTR1 constant "CAN_BAUD_...".
104// nCANMsgType must be filled with "CAN_INIT_TYPE_..".
105// The default initialisation, e.g. CAN_Init is not called,
106// is 500 kbit/sec and extended frames.
107//
108DWORD CAN_Init(HANDLE hHandle, WORD wBTR0BTR1, int nCANMsgType);
109
110//****************************************************************************
111// CAN_Close()
112// closes the path to the CAN hardware.
113// The last close on the hardware put the chip into passive state.
114DWORD CAN_Close(HANDLE hHandle);
115
116//****************************************************************************
117// CAN_Status()
118// request the current (stored) status of the CAN hardware. After the read the
119// stored status is reset.
120// If the status is negative a system error is returned (e.g. -EBADF).
121DWORD CAN_Status(HANDLE hHandle);
122
123//****************************************************************************
124// CAN_Write()
125// writes a message to the CAN bus. If the write queue is full the current
126// write blocks until either a message is sent or a error occured.
127//
128DWORD CAN_Write(HANDLE hHandle, TPCANMsg* pMsgBuff);
129
130//****************************************************************************
131// LINUX_CAN_Write_Timeout()
132// writes a message to the CAN bus. If the (software) message buffer is full
133// the current write request blocks until a write slot gets empty
134// or a timeout or a error occures.
135// nMicroSeconds > 0 -> Timeout in microseconds
136// nMicroSeconds == 0 -> polling
137// nMicroSeconds < 0 -> blocking, same as CAN_Write()
138DWORD LINUX_CAN_Write_Timeout(HANDLE hHandle, TPCANMsg* pMsgBuff, int nMicroSeconds);
139
140//****************************************************************************
141// CAN_Read()
142// reads a message from the CAN bus. If there is no message to read the current
143// request blocks until either a new message arrives or a error occures.
144DWORD CAN_Read(HANDLE hHandle, TPCANMsg* pMsgBuff);
145
146//****************************************************************************
147// LINUX_CAN_Read()
148// reads a message WITH TIMESTAMP from the CAN bus. If there is no message
149// to read the current request blocks until either a new message arrives
150// or a error occures.
151DWORD LINUX_CAN_Read(HANDLE hHandle, TPCANRdMsg* pMsgBuff);
152
153//****************************************************************************
154// LINUX_CAN_Read_Timeout()
155// reads a message WITH TIMESTAMP from the CAN bus. If there is no message
156// to read the current request blocks until either a new message arrives
157// or a timeout or a error occures.
158// nMicroSeconds > 0 -> Timeout in microseconds
159// nMicroSeconds == 0 -> polling
160// nMicroSeconds < 0 -> blocking, same as LINUX_CAN_Read()
161DWORD LINUX_CAN_Read_Timeout(HANDLE hHandle, TPCANRdMsg* pMsgBuff, int nMicroSeconds);
162
163//***************************************************************************
164// CAN_ResetFilter() - removes all current Message Filters
165// Caution! Currently this operation influences all read paths
166//
167DWORD CAN_ResetFilter(HANDLE hHandle);
168
169//***************************************************************************
170// CAN_MsgFilter() - reduce received data in to FromID <= ID <= ToID
171// Type may be MSGTYPE_STANDARD or MSGTYPE_EXTENDED
172// This function can be called multiple to add more ranges.
173// Caution! Currently this operation influences all read paths
174//
175DWORD CAN_MsgFilter(HANDLE hHandle, DWORD FromID, DWORD ToID, int nCANMsgType);
176
177//***************************************************************************
178// LINUX_CAN_FileHandle() - return PCAN driver file handle for select(2)
179//
180int LINUX_CAN_FileHandle(HANDLE hHandle);
181
182//****************************************************************************
183// LINUX_CAN_Extended_Status()
184// get the same as CAN_Status() with additional informaton about pending reads or writes
185//
186// There is a uncertainty of 1 message for "nPendingWrites" for a small amount
187// of time between the messages is put into the CAN sender and the telegram is
188// successfuly sent or an error is thrown.
189DWORD LINUX_CAN_Extended_Status(HANDLE hHandle, int *nPendingReads, int *nPendingWrites);
190
191//****************************************************************************
192// CAN_VersionInfo()
193// returns a text string with driver version info.
194//
195DWORD CAN_VersionInfo(HANDLE hHandle, LPSTR lpszTextBuff);
196
197//****************************************************************************
198// nGetLastError()
199// returns the last stored error (errno of the shared library). The returend
200// error is independend of any path.
201//
202int nGetLastError(void);
203
204//****************************************************************************
205// LINUX_CAN_Open() - another open, LINUX like
206// creates a path to a CAN port
207//
208// input: the path to the device node (e.g. /dev/pcan0)
209// returns NULL when open failes
210//
211HANDLE LINUX_CAN_Open(const char *szDeviceName, int nFlag);
212
213//****************************************************************************
214// LINUX_CAN_Statistics() - get statistics about this devices
215//
216DWORD LINUX_CAN_Statistics(HANDLE hHandle, TPDIAG *diag);
217
218//****************************************************************************
219// LINUX_CAN_BTR0BTR1() - get the BTR0 and BTR1 from bitrate, LINUX like
220//
221// input: the handle to the device node
222// the bitrate in bits / second, e.g. 500000 bits/sec
223//
224// returns 0 if not possible
225// BTR0BTR1 for the interface
226//
227WORD LINUX_CAN_BTR0BTR1(HANDLE hHandle, DWORD dwBitRate);
228
229#ifdef __cplusplus
230}
231#endif
232#endif // __LIBPCAN_H__
Note: See TracBrowser for help on using the repository browser.