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,
110 
117 
124 
130 
136 
137 
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];
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 
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 
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 
518 
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 
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 
877 
904 #ifdef __cplusplus
905 }
906 #endif
907 
908 #endif // __LINLIB_H
LinStatus linWriteWakeup(LinHandle h, unsigned int count, unsigned int interval)
Definition: linlib.h:178
LinStatus linRequestMessage(LinHandle h, unsigned int id)
LinStatus linSetBitrate(LinHandle h, unsigned int bps)
Definition: linlib.h:129
LinHandle linOpenChannel(int channel, int flags)
LinStatus linClearMessage(LinHandle h, unsigned int id)
unsigned int BOOL
Definition: linlib.h:96
The LIN interface response wasn&#39;t the expected one.
Definition: linlib.h:148
LinStatus linGetFirmwareVersion(LinHandle h, unsigned char *bootVerMajor, unsigned char *bootVerMinor, unsigned char *bootVerBuild, unsigned char *appVerMajor, unsigned char *appVerMinor, unsigned char *appVerBuild)
unsigned long bitrate
Definition: linlib.h:207
Internal error in the driver.
Definition: linlib.h:146
LinStatus
Definition: linlib.h:107
The card was removed or not inserted.
Definition: linlib.h:151
int canHandle
Definition: canlib.h:138
CAN driver type not supported.
Definition: linlib.h:149
LinStatus linUpdateMessage(LinHandle h, unsigned int id, const void *msg, unsigned int dlc)
LinStatus linGetChannelData(int channel, int item, void *buffer, size_t bufsize)
There was an error response from the LIN interface.
Definition: linlib.h:147
LinStatus linGetTransceiverData(int channel, unsigned char eanNo[8], unsigned char serNo[8], int *ttype)
Specified hardware not found. This error is reported when the LIN transceiver isn&#39;t powered up...
Definition: linlib.h:139
Error in parameter.
Definition: linlib.h:138
No channels avaliable.
Definition: linlib.h:141
LinStatus linBusOn(LinHandle h)
LinStatus linWriteMessage(LinHandle h, unsigned int id, const void *msg, unsigned int dlc)
Can&#39;t get handle.
Definition: linlib.h:144
The requested feature or function is not implemented in the device you are trying to use it on...
Definition: linlib.h:157
Function not supported in this version.
Definition: linlib.h:155
unsigned int DWORD
Definition: linlib.h:95
Definition: linlib.h:135
Handle is invalid.
Definition: linlib.h:145
Library not initialized.
Definition: linlib.h:143
LinStatus linWriteSync(LinHandle h, unsigned long timeout)
Definition: linlib.h:123
void linUnloadLibrary(void)
LinStatus linReadMessage(LinHandle h, unsigned int *id, void *msg, unsigned int *dlc, unsigned int *flags, LinMessageInfo *msgInfo)
DeviceIOControl failed.
Definition: linlib.h:150
LinStatus linGetCanHandle(LinHandle h, unsigned int *canHandle)
#define LINLIBAPI
Definition: linlib.h:289
LinStatus linReadMessageWait(LinHandle h, unsigned int *id, void *msg, unsigned int *dlc, unsigned int *flags, LinMessageInfo *msgInfo, unsigned long timeout)
Internal error in the driver.
Definition: linlib.h:153
Timeout occurred.
Definition: linlib.h:142
No messages available.
Definition: linlib.h:109
Out of memory.
Definition: linlib.h:140
LinStatus linSetupIllegalMessage(LinHandle h, unsigned int id, unsigned int cFlags, unsigned int delay)
unsigned long linReadTimer(LinHandle h)
LinStatus linSetupLIN(LinHandle h, unsigned int lFlags, unsigned int bps)
int LinHandle
Definition: linlib.h:87
Definition: linlib.h:116
Function not supported in this version.
Definition: linlib.h:156
Access denied.
Definition: linlib.h:154
unsigned long frameLength
Definition: linlib.h:201
OK - no error.
Definition: linlib.h:108
The license is not valid.
Definition: linlib.h:152
LinStatus linBusOff(LinHandle h)
unsigned long synchBreakLength
Definition: linlib.h:195
unsigned char BYTE
Definition: linlib.h:94
unsigned long timestamp
Definition: linlib.h:189
unsigned short z
Dummy for alignment.
Definition: linlib.h:221
void linInitializeLibrary(void)
LinStatus linGetVersion(int *major, int *minor, int *build)
unsigned char checkSum
Definition: linlib.h:213
unsigned char idPar
Definition: linlib.h:219