linlib.h
Go to the documentation of this file.
1 /*
2  * Copyright 2023 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 
84 #include <stddef.h>
85 
89 typedef int LinHandle;
90 
94 #define linINVALID_HANDLE ((LinHandle)(-1))
95 
96 typedef unsigned char BYTE;
97 typedef unsigned int DWORD;
98 typedef unsigned int BOOL;
99 
109 typedef enum {
110  linOK = 0,
112 
119 
126 
132 
138 
139 
160 } LinStatus;
164 // sizeof(LinMessageInfo) should be 68 for correct alignment
165 
180 typedef struct {
191  unsigned long timestamp;
192 
197  unsigned long synchBreakLength;
198 
203  unsigned long frameLength;
204 
209  unsigned long bitrate;
210 
215  unsigned char checkSum;
216 
221  unsigned char idPar;
222 
223  unsigned short z;
224 
231  unsigned long synchEdgeTime[4];
232 
239  unsigned long byteTime[8];
241 
242 
243 
252 #define LIN_TX 1
253 #define LIN_RX 2
254 #define LIN_WAKEUP_FRAME 4
255 #define LIN_NODATA 8
256 #define LIN_CSUM_ERROR 16
257 #define LIN_PARITY_ERROR 32
258 #define LIN_SYNCH_ERROR 64
259 #define LIN_BIT_ERROR 128
260 
282 #define linCHANNELDATA_CARD_FIRMWARE_REV 9
283 
289 #define LINERROR(f) ((f) & (LIN_NODATA | LIN_CSUM_ERROR | LIN_SYNCH_ERROR | LIN_BIT_ERROR))
290 
291 
292 // Define LINLIBAPI unless it's done already.
293 // (linlib.c provides its own definition of LINLIBAPI before including this file.)
294 //
295 #define LINLIBAPI
296 
297 #ifdef __cplusplus
298 extern "C" {
299 #endif
300 
310 
317 void LINLIBAPI linUnloadLibrary(void);
318 
319 
355 LinStatus LINLIBAPI linGetTransceiverData(int channel, unsigned char eanNo[8],
356  unsigned char serNo[8], int *ttype);
357 
378 LinHandle LINLIBAPI linOpenChannel(int channel, int flags);
379 
380 
389 #define LIN_MASTER 1
390 #define LIN_SLAVE 2
391 
406 LinStatus LINLIBAPI linClose(LinHandle h);
407 
408 
423 LinStatus LINLIBAPI linGetVersion(int *major, int *minor, int *build);
424 
425 
462  unsigned char *bootVerMajor,
463  unsigned char *bootVerMinor,
464  unsigned char *bootVerBuild,
465  unsigned char *appVerMajor,
466  unsigned char *appVerMinor,
467  unsigned char *appVerBuild);
468 
469 
470 
491 LinStatus LINLIBAPI linGetChannelData(int channel, int item, void *buffer, size_t bufsize);
492 
509 LinStatus LINLIBAPI linSetBitrate(LinHandle h, unsigned int bps);
510 
526 
541 
554 unsigned long LINLIBAPI linReadTimer(LinHandle h);
555 
577 LinStatus LINLIBAPI linWriteMessage(LinHandle h, unsigned int id, const void *msg,
578  unsigned int dlc);
579 
595 LinStatus LINLIBAPI linRequestMessage(LinHandle h, unsigned int id);
596 
623 LinStatus LINLIBAPI linReadMessage(LinHandle h, unsigned int *id, void *msg,
624  unsigned int *dlc, unsigned int *flags,
625  LinMessageInfo *msgInfo);
626 
656 LinStatus LINLIBAPI linReadMessageWait(LinHandle h, unsigned int *id, void *msg,
657  unsigned int *dlc, unsigned int *flags,
658  LinMessageInfo *msgInfo, unsigned long timeout);
659 
679 LinStatus LINLIBAPI linUpdateMessage(LinHandle h, unsigned int id, const void *msg,
680  unsigned int dlc);
681 
682 
707  unsigned int cFlags, unsigned int delay);
708 
717 #define LIN_MSG_DISTURB_CSUM 1
718 
722 #define LIN_MSG_DISTURB_PARITY 2
723 
734 #define LIN_MSG_USE_STANDARD_PARITY 0x04
735 
738 #define LIN_MSG_USE_ENHANCED_PARITY 0x08
739 
774 LinStatus LINLIBAPI linSetupLIN(LinHandle h, unsigned int lFlags, unsigned int bps);
775 
776 
789 #define LIN_ENHANCED_CHECKSUM 1
790 
796 #define LIN_VARIABLE_DLC 2
797 
819 LinStatus LINLIBAPI linWriteWakeup(LinHandle h, unsigned int count,
820  unsigned int interval);
821 
822 
835 LinStatus LINLIBAPI linClearMessage(LinHandle h, unsigned int id);
836 
879 LinStatus LINLIBAPI linWriteSync(LinHandle h, unsigned long timeout);
880 
893 
942 #ifdef __cplusplus
943 }
944 #endif
945 
946 #endif // __LINLIB_H
unsigned long frameLength
Definition: linlib.h:203
unsigned int DWORD
Definition: linlib.h:97
Library not initialized.
Definition: linlib.h:145
LinStatus
Definition: linlib.h:109
LinStatus linGetTransceiverData(int channel, unsigned char eanNo[8], unsigned char serNo[8], int *ttype)
DeviceIOControl failed.
Definition: linlib.h:152
LinStatus linGetChannelData(int channel, int item, void *buffer, size_t bufsize)
LinStatus linSetBitrate(LinHandle h, unsigned int bps)
Definition: linlib.h:118
LinStatus linGetVersion(int *major, int *minor, int *build)
unsigned short z
Dummy for alignment.
Definition: linlib.h:223
LinStatus linBusOff(LinHandle h)
LinStatus linReadMessageWait(LinHandle h, unsigned int *id, void *msg, unsigned int *dlc, unsigned int *flags, LinMessageInfo *msgInfo, unsigned long timeout)
LinStatus linGetCanHandle(LinHandle h, unsigned int *canHandle)
LinStatus linSetupIllegalMessage(LinHandle h, unsigned int id, unsigned int cFlags, unsigned int delay)
Internal error in the driver.
Definition: linlib.h:148
The LIN interface response wasn&#39;t the expected one.
Definition: linlib.h:150
void linInitializeLibrary(void)
Internal error in the driver.
Definition: linlib.h:155
The requested feature or function is not implemented in the device you are trying to use it on...
Definition: linlib.h:159
LinStatus linUpdateMessage(LinHandle h, unsigned int id, const void *msg, unsigned int dlc)
LinStatus linGetFirmwareVersion(LinHandle h, unsigned char *bootVerMajor, unsigned char *bootVerMinor, unsigned char *bootVerBuild, unsigned char *appVerMajor, unsigned char *appVerMinor, unsigned char *appVerBuild)
int LinHandle
Definition: linlib.h:89
Timeout occurred.
Definition: linlib.h:144
LinStatus linWriteWakeup(LinHandle h, unsigned int count, unsigned int interval)
unsigned long bitrate
Definition: linlib.h:209
unsigned int BOOL
Definition: linlib.h:98
LinStatus linSetupLIN(LinHandle h, unsigned int lFlags, unsigned int bps)
unsigned char BYTE
Definition: linlib.h:96
Definition: linlib.h:125
The card was removed or not inserted.
Definition: linlib.h:153
The license is not valid.
Definition: linlib.h:154
Function not supported in this version.
Definition: linlib.h:158
unsigned char idPar
Definition: linlib.h:221
CAN driver type not supported.
Definition: linlib.h:151
Out of memory.
Definition: linlib.h:142
Access denied.
Definition: linlib.h:156
LinStatus linReadMessage(LinHandle h, unsigned int *id, void *msg, unsigned int *dlc, unsigned int *flags, LinMessageInfo *msgInfo)
No channels avaliable.
Definition: linlib.h:143
LinStatus linWriteMessage(LinHandle h, unsigned int id, const void *msg, unsigned int dlc)
unsigned long timestamp
Definition: linlib.h:191
Error in parameter.
Definition: linlib.h:140
OK - no error.
Definition: linlib.h:110
LinStatus linRequestMessage(LinHandle h, unsigned int id)
Handle is invalid.
Definition: linlib.h:147
LinStatus linWriteSync(LinHandle h, unsigned long timeout)
There was an error response from the LIN interface.
Definition: linlib.h:149
Specified hardware not found. This error is reported when the LIN transceiver isn&#39;t powered up...
Definition: linlib.h:141
unsigned char checkSum
Definition: linlib.h:215
unsigned long linReadTimer(LinHandle h)
#define LINLIBAPI
Definition: linlib.h:295
LinHandle linOpenChannel(int channel, int flags)
Definition: linlib.h:131
unsigned long synchBreakLength
Definition: linlib.h:197
Definition: linlib.h:137
No messages available.
Definition: linlib.h:111
Function not supported in this version.
Definition: linlib.h:157
int canHandle
Definition: canlib.h:166
void linUnloadLibrary(void)
LinStatus linClearMessage(LinHandle h, unsigned int id)
LinStatus linBusOn(LinHandle h)
Definition: linlib.h:180
Can&#39;t get handle.
Definition: linlib.h:146