linlib.h
Go to the documentation of this file.
1 /*
2 * Copyright 2017 by Kvaser AB, Molndal, Sweden
3 * http://www.kvaser.com
4 *
5 * This software is dual licensed under the following two licenses:
6 * BSD-new and GPLv2. You may use either one. See the included
7 * COPYING file for details.
8 *
9 * License: BSD-new
10 * ==============================================================================
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * * Neither the name of the <organization> nor the
19 * names of its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
30 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 *
35 * License: GPLv2
36 * ==============================================================================
37 * This program is free software; you can redistribute it and/or modify
38 * it under the terms of the GNU General Public License as published by
39 * the Free Software Foundation; either version 2 of the License, or
40 * (at your option) any later version.
41 *
42 * This program is distributed in the hope that it will be useful,
43 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 * GNU General Public License for more details.
46 *
47 * You should have received a copy of the GNU General Public License
48 * along with this program; if not, write to the Free Software
49 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
50 *
51 *
52 * IMPORTANT NOTICE:
53 * ==============================================================================
54 * This source code is made available for free, as an open license, by Kvaser AB,
55 * for use with its applications. Kvaser AB does not accept any liability
56 * whatsoever for any third party patent or other immaterial property rights
57 * violations that may result from any usage of this source code, regardless of
58 * the combination of source code and various applications that it can be used
59 * in, or with.
60 *
61 * -----------------------------------------------------------------------------
62 */
63
81 #ifndef __LINLIB_H
82 #define __LINLIB_H
83
87 typedef int LinHandle;
88
92 #define linINVALID_HANDLE ((LinHandle)(-1))
93
94 typedef unsigned char BYTE;
95 typedef unsigned int DWORD;
96 typedef unsigned int BOOL;
97
107 typedef enum {
108 linOK = 0,
109 linERR_NOMSG = -1,
110
116 linERR_NOTRUNNING = -3,
117
123 linERR_RUNNING = -4,
124
129 linERR_MASTERONLY = -5,
130
135 linERR_SLAVEONLY = -6,
136
137
138 linERR_PARAM = -7,
139 linERR_NOTFOUND = -8,
140 linERR_NOMEM = -9,
141 linERR_NOCHANNELS = -10,
142 linERR_TIMEOUT = -11,
143 linERR_NOTINITIALIZED = -12,
144 linERR_NOHANDLES = -13,
145 linERR_INVHANDLE = -14,
146 linERR_CANERROR = -15,
147 linERR_ERRRESP = -16,
148 linERR_WRONGRESP = -17,
149 linERR_DRIVER = -18,
150 linERR_DRIVERFAILED = -19,
151 linERR_NOCARD = -20,
152 linERR_LICENSE = -21,
153 linERR_INTERNAL = -22,
154 linERR_NO_ACCESS = -23,
155 linERR_VERSION = -24,
156 linERR_NO_REF_POWER = -25,
157 linERR_NOT_IMPLEMENTED = -26
158 } LinStatus;
162 // sizeof(LinMessageInfo) should be 68 for correct alignment
163
178 typedef struct {
189 unsigned long timestamp;
190
195 unsigned long synchBreakLength;
196
201 unsigned long frameLength;
202
207 unsigned long bitrate;
208
213 unsigned char checkSum;
214
219 unsigned char idPar;
220
221 unsigned short z;
222
227 unsigned long synchEdgeTime[4];
228
233 unsigned long byteTime[8];
234 } LinMessageInfo;
235
236
237
246 #define LIN_TX 1
247 #define LIN_RX 2
248 #define LIN_WAKEUP_FRAME 4
249 #define LIN_NODATA 8
250 #define LIN_CSUM_ERROR 16
251 #define LIN_PARITY_ERROR 32
252 #define LIN_SYNCH_ERROR 64
253 #define LIN_BIT_ERROR 128
254
276 #define linCHANNELDATA_CARD_FIRMWARE_REV 9
277
283 #define LINERROR(f) ((f) & (LIN_NODATA | LIN_CSUM_ERROR | LIN_SYNCH_ERROR | LIN_BIT_ERROR))
284
285
286 // Define LINLIBAPI unless it's done already.
287 // (linlib.c provides its own definition of LINLIBAPI before including this file.)
288 //
289 #define LINLIBAPI
290
291 #ifdef __cplusplus
292 extern "C" {
293 #endif
294
303 void LINLIBAPI linInitializeLibrary(void);
304
311 void LINLIBAPI linUnloadLibrary(void);
312
313
349 LinStatus LINLIBAPI linGetTransceiverData(int channel, unsigned char eanNo[8],
350 unsigned char serNo[8], int *ttype);
351
372 LinHandle LINLIBAPI linOpenChannel(int channel, int flags);
373
374
383 #define LIN_MASTER 1
384 #define LIN_SLAVE 2
385
400 LinStatus LINLIBAPI linClose(LinHandle h);
401
402
417 LinStatus LINLIBAPI linGetVersion(int *major, int *minor, int *build);
418
419
454 LinStatus LINLIBAPI linGetFirmwareVersion(LinHandle h,
455 unsigned char *bootVerMajor,
456 unsigned char *bootVerMinor,
457 unsigned char *bootVerBuild,
458 unsigned char *appVerMajor,
459 unsigned char *appVerMinor,
460 unsigned char *appVerBuild);
461
462
463
484 LinStatus LINLIBAPI linGetChannelData(int channel, int item, void *buffer, size_t bufsize);
485
501 LinStatus LINLIBAPI linSetBitrate(LinHandle h, unsigned int bps);
502
517 LinStatus LINLIBAPI linBusOn(LinHandle h);
518
532 LinStatus LINLIBAPI linBusOff(LinHandle h);
533
546 unsigned long LINLIBAPI linReadTimer(LinHandle h);
547
568 LinStatus LINLIBAPI linWriteMessage(LinHandle h, unsigned int id, const void *msg,
569 unsigned int dlc);
570
584 LinStatus LINLIBAPI linRequestMessage(LinHandle h, unsigned int id);
585
612 LinStatus LINLIBAPI linReadMessage(LinHandle h, unsigned int *id, void *msg,
613 unsigned int *dlc, unsigned int *flags,
614 LinMessageInfo *msgInfo);
615
645 LinStatus LINLIBAPI linReadMessageWait(LinHandle h, unsigned int *id, void *msg,
646 unsigned int *dlc, unsigned int *flags,
647 LinMessageInfo *msgInfo, unsigned long timeout);
648
667 LinStatus LINLIBAPI linUpdateMessage(LinHandle h, unsigned int id, const void *msg,
668 unsigned int dlc);
669
670
694 LinStatus LINLIBAPI linSetupIllegalMessage(LinHandle h, unsigned int id,
695 unsigned int cFlags, unsigned int delay);
696
705 #define LIN_MSG_DISTURB_CSUM 1
706
710 #define LIN_MSG_DISTURB_PARITY 2
711
722 #define LIN_MSG_USE_STANDARD_PARITY 0x04
723
726 #define LIN_MSG_USE_ENHANCED_PARITY 0x08
727
761 LinStatus LINLIBAPI linSetupLIN(LinHandle h, unsigned int lFlags, unsigned int bps);
762
763
776 #define LIN_ENHANCED_CHECKSUM 1
777
783 #define LIN_VARIABLE_DLC 2
784
803 LinStatus LINLIBAPI linWriteWakeup(LinHandle h, unsigned int count,
804 unsigned int interval);
805
806
819 LinStatus LINLIBAPI linClearMessage(LinHandle h, unsigned int id);
820
863 LinStatus LINLIBAPI linWriteSync(LinHandle h, unsigned long timeout);
864
876 LinStatus LINLIBAPI linGetCanHandle(LinHandle h, unsigned int *canHandle);
877
904 #ifdef __cplusplus
905 }
906 #endif
907
908 #endif // __LINLIB_H
linWriteWakeup
LinStatus linWriteWakeup(LinHandle h, unsigned int count, unsigned int interval)
LinMessageInfo
Definition: linlib.h:178
linRequestMessage
LinStatus linRequestMessage(LinHandle h, unsigned int id)
linSetBitrate
LinStatus linSetBitrate(LinHandle h, unsigned int bps)
linERR_MASTERONLY
Definition: linlib.h:129
linOpenChannel
LinHandle linOpenChannel(int channel, int flags)
linClearMessage
LinStatus linClearMessage(LinHandle h, unsigned int id)
BOOL
unsigned int BOOL
Definition: linlib.h:96
linERR_WRONGRESP
The LIN interface response wasn&#39;t the expected one.
Definition: linlib.h:148
linGetFirmwareVersion
LinStatus linGetFirmwareVersion(LinHandle h, unsigned char *bootVerMajor, unsigned char *bootVerMinor, unsigned char *bootVerBuild, unsigned char *appVerMajor, unsigned char *appVerMinor, unsigned char *appVerBuild)
LinMessageInfo::bitrate
unsigned long bitrate
Definition: linlib.h:207
linERR_CANERROR
Internal error in the driver.
Definition: linlib.h:146
LinStatus
LinStatus
Definition: linlib.h:107
linERR_NOCARD
The card was removed or not inserted.
Definition: linlib.h:151
canHandle
int canHandle
Definition: canlib.h:148
linERR_DRIVER
CAN driver type not supported.
Definition: linlib.h:149
linUpdateMessage
LinStatus linUpdateMessage(LinHandle h, unsigned int id, const void *msg, unsigned int dlc)
linGetChannelData
LinStatus linGetChannelData(int channel, int item, void *buffer, size_t bufsize)
linERR_ERRRESP
There was an error response from the LIN interface.
Definition: linlib.h:147
linGetTransceiverData
LinStatus linGetTransceiverData(int channel, unsigned char eanNo[8], unsigned char serNo[8], int *ttype)
linERR_NOTFOUND
Specified hardware not found. This error is reported when the LIN transceiver isn&#39;t powered up...
Definition: linlib.h:139
linERR_PARAM
Error in parameter.
Definition: linlib.h:138
linERR_NOCHANNELS
No channels avaliable.
Definition: linlib.h:141
linBusOn
LinStatus linBusOn(LinHandle h)
linWriteMessage
LinStatus linWriteMessage(LinHandle h, unsigned int id, const void *msg, unsigned int dlc)
linERR_NOHANDLES
Can&#39;t get handle.
Definition: linlib.h:144
linERR_NOT_IMPLEMENTED
The requested feature or function is not implemented in the device you are trying to use it on...
Definition: linlib.h:157
linERR_VERSION
Function not supported in this version.
Definition: linlib.h:155
DWORD
unsigned int DWORD
Definition: linlib.h:95
linERR_SLAVEONLY
Definition: linlib.h:135
linERR_INVHANDLE
Handle is invalid.
Definition: linlib.h:145
linERR_NOTINITIALIZED
Library not initialized.
Definition: linlib.h:143
linWriteSync
LinStatus linWriteSync(LinHandle h, unsigned long timeout)
linERR_RUNNING
Definition: linlib.h:123
linUnloadLibrary
void linUnloadLibrary(void)
linReadMessage
LinStatus linReadMessage(LinHandle h, unsigned int *id, void *msg, unsigned int *dlc, unsigned int *flags, LinMessageInfo *msgInfo)
linERR_DRIVERFAILED
DeviceIOControl failed.
Definition: linlib.h:150
linGetCanHandle
LinStatus linGetCanHandle(LinHandle h, unsigned int *canHandle)
LINLIBAPI
#define LINLIBAPI
Definition: linlib.h:289
linReadMessageWait
LinStatus linReadMessageWait(LinHandle h, unsigned int *id, void *msg, unsigned int *dlc, unsigned int *flags, LinMessageInfo *msgInfo, unsigned long timeout)
linERR_INTERNAL
Internal error in the driver.
Definition: linlib.h:153
linERR_TIMEOUT
Timeout occurred.
Definition: linlib.h:142
linERR_NOMSG
No messages available.
Definition: linlib.h:109
linERR_NOMEM
Out of memory.
Definition: linlib.h:140
linSetupIllegalMessage
LinStatus linSetupIllegalMessage(LinHandle h, unsigned int id, unsigned int cFlags, unsigned int delay)
linReadTimer
unsigned long linReadTimer(LinHandle h)
linSetupLIN
LinStatus linSetupLIN(LinHandle h, unsigned int lFlags, unsigned int bps)
LinHandle
int LinHandle
Definition: linlib.h:87
linERR_NOTRUNNING
Definition: linlib.h:116
linERR_NO_REF_POWER
Function not supported in this version.
Definition: linlib.h:156
linERR_NO_ACCESS
Access denied.
Definition: linlib.h:154
LinMessageInfo::frameLength
unsigned long frameLength
Definition: linlib.h:201
linOK
OK - no error.
Definition: linlib.h:108
linERR_LICENSE
The license is not valid.
Definition: linlib.h:152
linBusOff
LinStatus linBusOff(LinHandle h)
LinMessageInfo::synchBreakLength
unsigned long synchBreakLength
Definition: linlib.h:195
BYTE
unsigned char BYTE
Definition: linlib.h:94
LinMessageInfo::timestamp
unsigned long timestamp
Definition: linlib.h:189
LinMessageInfo::z
unsigned short z
Dummy for alignment.
Definition: linlib.h:221
linInitializeLibrary
void linInitializeLibrary(void)
linGetVersion
LinStatus linGetVersion(int *major, int *minor, int *build)
LinMessageInfo::checkSum
unsigned char checkSum
Definition: linlib.h:213
LinMessageInfo::idPar
unsigned char idPar
Definition: linlib.h:219