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 HANDLE;
97 typedef unsigned int BOOL;
98 
108 typedef enum {
109  linOK = 0,
134 } LinStatus;
138 // sizeof(LinMessageInfo) should be 68 for correct alignment
139 
154 typedef struct {
165  unsigned long timestamp;
166 
171  unsigned long synchBreakLength;
172 
177  unsigned long frameLength;
178 
183  unsigned long bitrate;
184 
189  unsigned char checkSum;
190 
195  unsigned char idPar;
196 
197  unsigned short z;
198 
203  unsigned long synchEdgeTime[4];
204 
209  unsigned long byteTime[8];
211 
212 
213 
222 #define LIN_TX 1
223 #define LIN_RX 2
224 #define LIN_WAKEUP_FRAME 4
225 #define LIN_NODATA 8
226 #define LIN_CSUM_ERROR 16
227 #define LIN_PARITY_ERROR 32
228 #define LIN_SYNCH_ERROR 64
229 #define LIN_BIT_ERROR 128
230 
253 #define linCHANNELDATA_CARD_FIRMWARE_REV 9
254 
260 #define LINERROR(f) ((f) & (LIN_NODATA | LIN_CSUM_ERROR | LIN_SYNCH_ERROR | LIN_BIT_ERROR))
261 
262 
263 // Define LINLIBAPI unless it's done already.
264 // (linlib.c provides its own definition of LINLIBAPI before including this file.)
265 //
266 #define LINLIBAPI
267 
268 #ifdef __cplusplus
269 extern "C" {
270 #endif
271 
281 
288 void LINLIBAPI linUnloadLibrary(void);
289 
290 
326 LinStatus LINLIBAPI linGetTransceiverData(int channel, unsigned char eanNo[8],
327  unsigned char serNo[8], int *ttype);
328 
351 LinHandle LINLIBAPI linOpenChannel(int channel, int flags);
352 
353 
358 #define LIN_MASTER 1
359 #define LIN_SLAVE 2
360 
375 LinStatus LINLIBAPI linClose(LinHandle h);
376 
412  unsigned char *bootVerMajor,
413  unsigned char *bootVerMinor,
414  unsigned char *bootVerBuild,
415  unsigned char *appVerMajor,
416  unsigned char *appVerMinor,
417  unsigned char *appVerBuild);
418 
419 
420 
442 LinStatus LINLIBAPI linGetChannelData(int channel, int item, void *buffer, size_t bufsize);
443 
459 LinStatus LINLIBAPI linSetBitrate(LinHandle h, unsigned int bps);
460 
475 
489 
502 unsigned long LINLIBAPI linReadTimer(LinHandle h);
503 
524 LinStatus LINLIBAPI linWriteMessage(LinHandle h, unsigned int id, const void *msg,
525  unsigned int dlc);
526 
540 LinStatus LINLIBAPI linRequestMessage(LinHandle h, unsigned int id);
541 
568 LinStatus LINLIBAPI linReadMessage(LinHandle h, unsigned int *id, void *msg,
569  unsigned int *dlc, unsigned int *flags,
570  LinMessageInfo *msgInfo);
571 
601 LinStatus LINLIBAPI linReadMessageWait(LinHandle h, unsigned int *id, void *msg,
602  unsigned int *dlc, unsigned int *flags,
603  LinMessageInfo *msgInfo, unsigned long timeout);
604 
623 LinStatus LINLIBAPI linUpdateMessage(LinHandle h, unsigned int id, const void *msg,
624  unsigned int dlc);
625 
626 
651  unsigned int cFlags, unsigned int delay);
652 
661 #define LIN_MSG_DISTURB_CSUM 1
662 
666 #define LIN_MSG_DISTURB_PARITY 2
667 
678 #define LIN_MSG_USE_STANDARD_PARITY 0x04
679 
682 #define LIN_MSG_USE_ENHANCED_PARITY 0x08
683 
717 LinStatus LINLIBAPI linSetupLIN(LinHandle h, unsigned int lFlags, unsigned int bps);
718 
719 
732 #define LIN_ENHANCED_CHECKSUM 1
733 
739 #define LIN_VARIABLE_DLC 2
740 
759 LinStatus LINLIBAPI linWriteWakeup(LinHandle h, unsigned int count,
760  unsigned int interval);
761 
762 
775 LinStatus LINLIBAPI linClearMessage(LinHandle h, unsigned int id);
776 
819 LinStatus LINLIBAPI linWriteSync(LinHandle h, unsigned long timeout);
820 
833 
859 #ifdef __cplusplus
860 }
861 #endif
862 
863 #endif // __LINLIB_H
LinStatus linWriteWakeup(LinHandle h, unsigned int count, unsigned int interval)
Definition: linlib.h:154
LinStatus linRequestMessage(LinHandle h, unsigned int id)
LinStatus linSetBitrate(LinHandle h, unsigned int bps)
Definition: linlib.h:113
LinHandle linOpenChannel(int channel, int flags)
LinStatus linClearMessage(LinHandle h, unsigned int id)
unsigned int BOOL
Definition: linlib.h:97
The LIN interface response wasn&#39;t the expected one.
Definition: linlib.h:125
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:183
Definition: linlib.h:123
LinStatus
Definition: linlib.h:108
The card was removed or not inserted.
Definition: linlib.h:128
int canHandle
Definition: canlib.h:138
CAN driver type not supported.
Definition: linlib.h:126
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:124
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:116
Error in parameter.
Definition: linlib.h:115
No channels avaliable.
Definition: linlib.h:118
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:121
Function not supported in this version.
Definition: linlib.h:132
unsigned int DWORD
Definition: linlib.h:95
Definition: linlib.h:114
Handle is invalid.
Definition: linlib.h:122
Library not initialized.
Definition: linlib.h:120
LinStatus linWriteSync(LinHandle h, unsigned long timeout)
Definition: linlib.h:112
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:127
LinStatus linGetCanHandle(LinHandle h, unsigned int *canHandle)
#define LINLIBAPI
Definition: linlib.h:266
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:130
Timeout occurred.
Definition: linlib.h:119
No messages available.
Definition: linlib.h:110
Out of memory.
Definition: linlib.h:117
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:111
Function not supported in this version.
Definition: linlib.h:133
Access denied.
Definition: linlib.h:131
unsigned long frameLength
Definition: linlib.h:177
OK - no error.
Definition: linlib.h:109
The license is not valid.
Definition: linlib.h:129
LinStatus linBusOff(LinHandle h)
unsigned long synchBreakLength
Definition: linlib.h:171
unsigned char BYTE
Definition: linlib.h:94
unsigned long timestamp
Definition: linlib.h:165
unsigned short z
Dummy for alignment.
Definition: linlib.h:197
void linInitializeLibrary(void)
unsigned char checkSum
Definition: linlib.h:189
unsigned int HANDLE
Definition: linlib.h:96
unsigned char idPar
Definition: linlib.h:195