libpcan.h
Go to the documentation of this file.
00001 #ifndef __LIBPCAN_H__
00002 #define __LIBPCAN_H__
00003 
00004 //****************************************************************************
00005 // Copyright (C) 2001-2007  PEAK System-Technik GmbH
00006 //
00007 // linux@peak-system.com
00008 // www.peak-system.com
00009 //
00010 // This library is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU Lesser General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2.1 of the License, or (at your option) any later version.
00014 
00015 // This library is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 // 
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 //
00024 // Maintainer(s): Klaus Hitschler (klaus.hitschler@gmx.de)
00025 // Contributions: Mudiaga Obada   (obada@vsi.cs.uni-frankfurt.de)
00026 //****************************************************************************
00027 
00028 //****************************************************************************
00029 //
00030 // libpcan.h
00031 // common header to access the functions within pcanlib.so.x.x,
00032 // originally created from Wilhelm Hoppe in pcan_pci.h
00033 //
00034 // $Id: libpcan.h 455 2007-02-11 22:19:11Z khitschler $
00035 //
00036 //****************************************************************************
00037 
00038 //****************************************************************************
00039 // INCLUDES
00040 #include <pcan.h>
00041 
00042 //****************************************************************************
00043 // compatibilty defines
00044 #if defined(LPSTR) || defined(HANDLE)
00045 #error "double define for LPSTR, HANDLE found"
00046 #endif
00047 
00048 #define LPSTR  char *
00049 #define HANDLE void *
00050 
00051 //****************************************************************************
00052 // for CAN_Open(...)
00053 
00054 //****************************************************************************
00055 // for CAN_Init(...)
00056 
00057 // parameter wBTR0BTR1
00058 // bitrate codes of BTR0/BTR1 registers
00059 #define CAN_BAUD_1M     0x0014  //   1 MBit/s
00060 #define CAN_BAUD_500K   0x001C  // 500 kBit/s
00061 #define CAN_BAUD_250K   0x011C  // 250 kBit/s
00062 #define CAN_BAUD_125K   0x031C  // 125 kBit/s
00063 #define CAN_BAUD_100K   0x432F  // 100 kBit/s
00064 #define CAN_BAUD_50K    0x472F  //  50 kBit/s
00065 #define CAN_BAUD_20K    0x532F  //  20 kBit/s
00066 #define CAN_BAUD_10K    0x672F  //  10 kBit/s
00067 #define CAN_BAUD_5K     0x7F7F  //   5 kBit/s
00068 
00069 // parameter nCANMsgType
00070 #define CAN_INIT_TYPE_EX                0x01    //Extended Frame
00071 #define CAN_INIT_TYPE_ST                0x00    //Standart Frame
00072 
00073 //****************************************************************************
00074 // error codes are defined in pcan.h
00075 #define CAN_ERR_ANYBUSERR (CAN_ERR_BUSLIGHT | CAN_ERR_BUSHEAVY | CAN_ERR_BUSOFF)
00076 
00077 //****************************************************************************
00078 // PROTOTYPES
00079 #ifdef __cplusplus
00080   extern "C"
00081 {
00082 #endif
00083 
00084 //****************************************************************************
00085 //  CAN_Open()
00086 //  creates a path to a CAN port
00087 //
00088 //  for PCAN-Dongle call:             CAN_Open(HW_DONGLE_.., DWORD dwPort, WORD wIrq);
00089 //  for PCAN-ISA or PCAN-PC/104 call: CAN_Open(HW_ISA_SJA, DWORD dwPort, WORD wIrq);
00090 //  for PCAN-PCI call:                CAN_Open(HW_PCI, int nPort); .. enumerate nPort 1..8.
00091 //
00092 //  if ((dwPort == 0) && (wIrq == 0)) CAN_Open() takes the 1st default ISA or DONGLE port.
00093 //  if (nPort == 0) CAN_Open() takes the 1st default PCI port.
00094 //  returns NULL when open failes.
00095 //
00096 //  The first CAN_Open() to a CAN hardware initializes the hardware to default
00097 //  parameter 500 kbit/sec and acceptance of extended frames.
00098 //
00099 HANDLE CAN_Open(WORD wHardwareType, ...);
00100 
00101 //****************************************************************************
00102 //  CAN_Init()
00103 //  initializes the CAN hardware with the BTR0 + BTR1 constant "CAN_BAUD_...".
00104 //  nCANMsgType must be filled with "CAN_INIT_TYPE_..".
00105 //  The default initialisation, e.g. CAN_Init is not called,
00106 //  is 500 kbit/sec and extended frames.
00107 //
00108 DWORD CAN_Init(HANDLE hHandle, WORD wBTR0BTR1, int nCANMsgType);
00109 
00110 //****************************************************************************
00111 //  CAN_Close()
00112 //  closes the path to the CAN hardware.
00113 //  The last close on the hardware put the chip into passive state.
00114 DWORD CAN_Close(HANDLE hHandle);
00115 
00116 //****************************************************************************
00117 //  CAN_Status()
00118 //  request the current (stored) status of the CAN hardware. After the read the
00119 //  stored status is reset.
00120 //  If the status is negative a system error is returned (e.g. -EBADF).
00121 DWORD CAN_Status(HANDLE hHandle);
00122 
00123 //****************************************************************************
00124 //  CAN_Write()
00125 //  writes a message to the CAN bus. If the write queue is full the current
00126 //  write blocks until either a message is sent or a error occured.
00127 //
00128 DWORD CAN_Write(HANDLE hHandle, TPCANMsg* pMsgBuff);
00129 
00130 //****************************************************************************
00131 //  LINUX_CAN_Write_Timeout()
00132 //  writes a message to the CAN bus. If the (software) message buffer is full
00133 //  the current write request blocks until a write slot gets empty 
00134 //  or a timeout or a error occures.
00135 //  nMicroSeconds  > 0 -> Timeout in microseconds
00136 //  nMicroSeconds == 0 -> polling
00137 //  nMicroSeconds  < 0 -> blocking, same as CAN_Write()
00138 DWORD LINUX_CAN_Write_Timeout(HANDLE hHandle, TPCANMsg* pMsgBuff, int nMicroSeconds);
00139 
00140 //****************************************************************************
00141 //  CAN_Read()
00142 //  reads a message from the CAN bus. If there is no message to read the current
00143 //  request blocks until either a new message arrives or a error occures.
00144 DWORD CAN_Read(HANDLE hHandle, TPCANMsg* pMsgBuff);
00145 
00146 //****************************************************************************
00147 //  LINUX_CAN_Read()
00148 //  reads a message WITH TIMESTAMP from the CAN bus. If there is no message 
00149 //  to read the current request blocks until either a new message arrives 
00150 //  or a error occures.
00151 DWORD LINUX_CAN_Read(HANDLE hHandle, TPCANRdMsg* pMsgBuff);
00152 
00153 //****************************************************************************
00154 //  LINUX_CAN_Read_Timeout()
00155 //  reads a message WITH TIMESTAMP from the CAN bus. If there is no message 
00156 //  to read the current request blocks until either a new message arrives 
00157 //  or a timeout or a error occures.
00158 //  nMicroSeconds  > 0 -> Timeout in microseconds
00159 //  nMicroSeconds == 0 -> polling
00160 //  nMicroSeconds  < 0 -> blocking, same as LINUX_CAN_Read()
00161 DWORD LINUX_CAN_Read_Timeout(HANDLE hHandle, TPCANRdMsg* pMsgBuff, int nMicroSeconds);
00162 
00163 //***************************************************************************
00164 // CAN_ResetFilter() - removes all current Message Filters
00165 // Caution! Currently this operation influences all read paths
00166 //
00167 DWORD CAN_ResetFilter(HANDLE hHandle);
00168 
00169 //***************************************************************************
00170 // CAN_MsgFilter() - reduce received data in to FromID <= ID <= ToID
00171 // Type may be MSGTYPE_STANDARD or MSGTYPE_EXTENDED
00172 // This function can be called multiple to add more ranges.
00173 // Caution! Currently this operation influences all read paths
00174 //
00175 DWORD CAN_MsgFilter(HANDLE hHandle, DWORD FromID, DWORD ToID, int nCANMsgType);
00176 
00177 //***************************************************************************
00178 // LINUX_CAN_FileHandle() - return PCAN driver file handle for select(2)
00179 //
00180 int LINUX_CAN_FileHandle(HANDLE hHandle);
00181 
00182 //****************************************************************************
00183 //  LINUX_CAN_Extended_Status()
00184 //  get the same as CAN_Status() with additional informaton about pending reads or writes
00185 //
00186 //  There is a uncertainty of 1 message for "nPendingWrites" for a small amount 
00187 //  of time between the messages is put into the CAN sender and the telegram is
00188 //  successfuly sent or an error is thrown.
00189 DWORD LINUX_CAN_Extended_Status(HANDLE hHandle, int *nPendingReads, int *nPendingWrites);
00190 
00191 //****************************************************************************
00192 //  CAN_VersionInfo()
00193 //  returns a text string with driver version info.
00194 //
00195 DWORD CAN_VersionInfo(HANDLE hHandle, LPSTR lpszTextBuff);
00196 
00197 //****************************************************************************
00198 //  nGetLastError()
00199 //  returns the last stored error (errno of the shared library). The returend
00200 //  error is independend of any path.
00201 //
00202 int nGetLastError(void);
00203 
00204 //****************************************************************************
00205 //  LINUX_CAN_Open() - another open, LINUX like
00206 //  creates a path to a CAN port
00207 //
00208 //  input: the path to the device node (e.g. /dev/pcan0)
00209 //  returns NULL when open failes
00210 //
00211 HANDLE LINUX_CAN_Open(const char *szDeviceName, int nFlag);
00212 
00213 //****************************************************************************
00214 //  LINUX_CAN_Statistics() - get statistics about this devices
00215 //
00216 DWORD LINUX_CAN_Statistics(HANDLE hHandle, TPDIAG *diag);
00217 
00218 //****************************************************************************
00219 //  LINUX_CAN_BTR0BTR1() - get the BTR0 and BTR1 from bitrate, LINUX like
00220 //
00221 //  input:  the handle to the device node
00222 //          the bitrate in bits / second, e.g. 500000 bits/sec
00223 //
00224 //  returns 0 if not possible
00225 //          BTR0BTR1 for the interface
00226 //
00227 WORD LINUX_CAN_BTR0BTR1(HANDLE hHandle, DWORD dwBitRate);
00228 
00229 #ifdef __cplusplus
00230 }
00231 #endif
00232 #endif // __LIBPCAN_H__


libpcan
Author(s): Florian Weisshardt
autogenerated on Fri Aug 28 2015 10:21:51