source: pacpussensors/trunk/CanGateway/driver/kvaser/linux/linlib.h@ 107

Last change on this file since 107 was 97, checked in by DHERBOMEZ Gérald, 9 years ago

add include files for kvaser

File size: 28.1 KB
Line 
1/**
2 * \section LICENSE
3 * <pre style="white-space: pre-wrap">
4 * This software is dual licensed under the following two licenses:
5 * BSD-new and GPLv2. You may use either one. See the included
6 * COPYING file for details.
7 *
8 * License: BSD-new
9 * ===============================================================================
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * * Neither the name of the <organization> nor the
18 * names of its contributors may be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 *
33 * License: GPLv2
34 * ===============================================================================
35 * This program is free software; you can redistribute it and/or
36 * modify it under the terms of the GNU General Public License
37 * as published by the Free Software Foundation; either version 2
38 * of the License, or (at your option) any later version.
39 *
40 * This program is distributed in the hope that it will be useful,
41 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 * GNU General Public License for more details.
44 *
45 * You should have received a copy of the GNU General Public License
46 * along with this program; if not, write to the Free Software
47 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
48 *
49 * ---------------------------------------------------------------------------
50 * </pre>
51 *
52 * \section DESCRIPTION
53 *
54 * Definitions for the LINlib API.
55 *
56 * \file linlib.h
57 * \author Kvaser AB
58 */
59
60#ifndef __LINLIB_H
61#define __LINLIB_H
62
63/**
64 * \defgroup LIN LIN
65 * @{
66 */
67
68 /**
69 * LIN handle
70 */
71typedef int LinHandle;
72
73/**
74 * Invalid LIN handle
75 */
76#define linINVALID_HANDLE ((LinHandle)(-1))
77
78#if !WIN32
79# define CompilerAssert(exp) extern char _CompilerAssert[(exp) ? 1 : -1]
80#endif
81
82
83/**
84 * \name Return codes from the LINlib functions
85 * \anchor linERR_xxx
86 * @{
87 */
88typedef enum {
89 linOK = 0, ///< OK - no error
90 linERR_NOMSG = -1, ///< No messages available
91 linERR_NOTRUNNING = -3,
92 linERR_RUNNING = -4,
93 linERR_MASTERONLY = -5,
94 linERR_SLAVEONLY = -6,
95 linERR_PARAM = -7, ///< Error in parameter
96 linERR_NOTFOUND = -8, ///< Specified hardware not found. This error is reported when the LIN transceiver isn't powered up
97 linERR_NOMEM = -9, ///< Out of memory
98 linERR_NOCHANNELS = -10, ///< No channels avaliable
99 linERR_TIMEOUT = -11, ///< Timeout occurred
100 linERR_NOTINITIALIZED = -12, ///< Library not initialized
101 linERR_NOHANDLES = -13, ///< Can't get handle
102 linERR_INVHANDLE = -14, ///< Handle is invalid
103 linERR_CANERROR = -15,
104 linERR_ERRRESP = -16, ///< There was an error response from the LIN interface
105 linERR_WRONGRESP = -17, ///< The LIN interface response wasn't the expected one
106 linERR_DRIVER = -18, ///< CAN driver type not supported
107 linERR_DRIVERFAILED = -19, ///< DeviceIOControl failed; use the Win32 GetLastError API to get the real (WIn32) error code.
108 linERR_NOCARD = -20, ///< The card was removed or not inserted
109 linERR_LICENSE = -21, ///< The license is not valid
110 linERR_INTERNAL = -22, ///< Internal error in the driver
111 linERR_NO_ACCESS = -23, ///< Access denied
112 linERR_VERSION = -24 ///< Function not supported in this version
113} LinStatus;
114/** @} */
115
116
117// sizeof(LinMessageInfo) should be 68 for correct alignment
118#if WIN32
119#include <pshpack1.h>
120#endif
121
122/**
123 * In certain LIN bus API calls, the following structure is used to provide more
124 * information about the LIN messages.
125 *
126 * \note The precision of the timing data given in us (microseconds) can be less
127 * than one microsecond; for low bitrates the lowest bits might always be zero.
128 *
129 * \note The min and max values listed inside [] of the message timing values
130 * can be calculated from the LIN specification by using the shortest (0 bytes)
131 * or longest (8 bytes) messages at the lowest or highest allowed bitrate.
132 *
133 * \note The LIN interface will accept messages that are a bit out-of-bounds as
134 * well.
135 */
136typedef struct {
137 /**
138 * Kvaser DRV Lin timestamp - Timestamp in milliseconds of the falling edge of
139 * the synch break of the message. Uses the canlib CAN timer.
140 *
141 * Kvaser LIN Leaf timestamp - Timestamp in milliseconds of the falling edge
142 * of the synch break of the message. Uses the canlib CAN timer.
143 *
144 * \note All Kvaser Leaf with Kvaser MagiSync&tm; are synchronized
145 * (also with CAN channels).
146 */
147 unsigned long timestamp;
148
149 /**
150 * Length of the synch break in microseconds.
151 * [650 .. 13000], [400 .. 8000] for a wakeup signal.
152 */
153 unsigned long synchBreakLength;
154
155 /**
156 * The total frame length in microseconds; from the synch break to the
157 * end of the crc. [2200 .. 173600]
158 */
159 unsigned long frameLength;
160
161 /**
162 * The bitrate of the message in bits per seconds.
163 * Range [1000 .. 20000] (plus some margin)
164 */
165 unsigned long bitrate;
166
167 /**
168 * The checksum as read from the LIN bus. Might not
169 * match the data in case of \ref LIN_CSUM_ERROR.
170 */
171 unsigned char checkSum;
172
173 /**
174 * The id with parity of the message as read from the
175 * LIN bus. Might be invalid in case of \ref LIN_PARITY_ERROR.
176 */
177 unsigned char idPar;
178
179 unsigned short z; ///< Dummy for alignment
180
181 /**
182 * Time in microseconds of the falling edges in the
183 * synch byte relative the falling edge of the start bit.
184 */
185 unsigned long synchEdgeTime[4];
186
187 /**
188 * Start time in microseconds of each data byte. In case of 8-byte messages,
189 * the crc time isn't included (but can be deduced from frameLength).
190 */
191 unsigned long byteTime[8];
192} LinMessageInfo;
193
194#if WIN32
195#include <poppack.h>
196#endif
197
198
199/**
200 * \name LIN message flags
201 * \anchor LIN_xxx
202 * The following flags can be returned from \ref linReadMessage() and
203 * \ref linReadMessageWait().
204 *
205 * @{
206 */
207#define LIN_TX 1 ///< The message was something we transmitted on the bus
208#define LIN_RX 2 ///< The message was something we received from the bus
209#define LIN_WAKEUP_FRAME 4 ///< A wake up frame was received. Id/msg/dlc are undefined
210#define LIN_NODATA 8 ///< No data, only a header
211#define LIN_CSUM_ERROR 16 ///< Checksum error
212#define LIN_PARITY_ERROR 32 ///< ID parity error
213#define LIN_SYNCH_ERROR 64 ///< A synch error
214#define LIN_BIT_ERROR 128 ///< Bit error when transmitting
215/** @} */
216
217/**
218 * Macro for determining if a flag field contains a LIN error flag bit.
219 */
220#define LINERROR(f) ((f) & (LIN_NODATA | LIN_CSUM_ERROR | LIN_SYNCH_ERROR | LIN_BIT_ERROR))
221
222
223// Define LINLIBAPI unless it's done already.
224// (linlib.c provides its own definition of LINLIBAPI before including this file.)
225//
226#if WIN32
227#ifndef LINLIBAPI
228# if defined(__BORLANDC__)
229# define LINLIBAPI __stdcall
230# elif defined(_MSC_VER) || defined(__MWERKS__) || defined(__GNUC__)
231# define LINLIBAPI __stdcall
232# endif
233#endif
234#else
235#define LINLIBAPI
236#endif
237
238#ifdef __cplusplus
239extern "C" {
240#endif
241
242/**
243 * This function initializes the LIN library and must be called before any other
244 * LIN function is called. If this function isn't called, subsequent calls to
245 * the other LIN functions will return \ref linERR_NOTINITIALIZED.
246 *
247 * \sa \ref linOpenChannel()
248 */
249void LINLIBAPI linInitializeLibrary(void);
250
251
252/**
253 * Retrieves the transceiver information for a CAN channel. The application
254 * typically uses this call to find out whether a particular CAN channel has a
255 * LIN interface connected to it.
256 * For a Kvaser LIN Leaf it retrieves the transceiver type and device information.
257 *
258 * This function call will open the CAN channel, but no CAN messages are
259 * transmitted on it. In other words, it's risk-free to use even if no LIN
260 * interface is connected, or if the channel is connected to a CAN system.
261 *
262 * \note Attempts to use the channel for LIN communication will be meaningful
263 * only if \ref linGetTransceiverData() stores \ref canTRANSCEIVER_TYPE_LIN in \a ttype.
264 *
265 * \note A LIN interface need not be powered for this call to succeed.
266 *
267 * \note The information may not always be accurate. Especially after changing
268 * transceiver on a running LAPcan card, you should go on bus and off bus again
269 * to be sure the transceiver information is updated.
270 *
271 * \param[in] channel The number of a CAN channel for which the transceiver
272 * data will be retrieved.
273 * \param[out] eanNo A pointer to an array of 8 bytes where the EAN number of
274 * the LIN interface will be stored.
275 * \param[out] serNo A pointer to an array of 8 bytes where the serial number
276 * of the LIN interface will be stored.
277 * \param[out] ttype A pointer to an integer where the transceiver type will
278 * be stored.
279 *
280 * \return \ref linOK (zero) if success
281 * \return \ref linERR_xxx (negative) if failure
282 *
283 * \sa \ref linGetFirmwareVersion()
284 */
285LinStatus LINLIBAPI linGetTransceiverData(int channel, unsigned char eanNo[8],
286 unsigned char serNo[8], int *ttype);
287
288/**
289 * Open a channel to a LIN interface.
290 *
291 * \note For DRV Lin: The cable must be powered and connected to a LAPcan channel.
292 *
293 * \note For Kvaser LIN Leaf: The Leaf must be powered from the LIN side.
294 *
295 * \param[in] channel The number of the channel. Channel numbering is hardware
296 * dependent.
297 * This is the same channel number as used by \ref canOpenChannel().
298 * \param[in] flags Either one of the following values: \ref LIN_MASTER or
299 * \ref LIN_SLAVE.
300 *
301 * \return If the call succeeds, a handle to the opened channel is returned.
302 * The handle is an integer greater than or equal to zero.
303 *
304 * \return If the call fails, the return value is a negative integer indicating
305 * an error code. See \ref linERR_xxx for a list of possible error codes.
306 *
307 * \sa \ref linClose()
308 */
309LinHandle LINLIBAPI linOpenChannel(int channel, int flags);
310
311
312/**
313 * \name Flags for linOpenChannel()
314 * @{
315 */
316#define LIN_MASTER 1 ///< The LIN interface will be a LIN master
317#define LIN_SLAVE 2 ///< The LIN interface will be a LIN slave
318/** @} */
319
320
321/**
322 * Closes an open handle to a LIN channel. The handle becomes invalid and can
323 * not be used in subsequent calls to the LIN functions.
324 *
325 * \param[in] h A handle to an open LIN channel.
326 *
327 * \return \ref linOK (zero) if success
328 * \return \ref linERR_xxx (negative) if failure
329 *
330 * \sa \ref linOpenChannel()
331 */
332LinStatus LINLIBAPI linClose(LinHandle h);
333
334/**
335 * This function retrieves the firmware version from the LIN interface.
336 *
337 *
338 * \note The version numbers aren't valid until \ref linBusOn() has been called.
339 *
340 * \note The firmware in the LIN interface is divided into two parts, the boot
341 * code and the application. The boot code is used only when reprogramming
342 * (reflashing) the LIN interface. The application handles all LIN communication.
343 *
344 * \note Version numbers are, since the precambric era, divided into a major
345 * version number, a minor version number and a build number. These are usually
346 * written like, for example, 3.2.12. Here the major number is 3, the minor
347 * number 2 and the build number 12.
348 *
349 * \param[in] h A handle to an open LIN channel.
350 * \param[out] bootVerMajor A pointer to a byte where the major version number
351 * of the boot code is stored.
352 * \param[out] bootVerMinor A pointer to a byte where the minor version number
353 * of the boot code is stored.
354 * \param[out] bootVerBuild A pointer to a byte where the build number of the
355 * boot code is stored.
356 * \param[out] appVerMajor A pointer to a byte where the major version number
357 * of the application code is stored.
358 * \param[out] appVerMinor A pointer to a byte where the minor version number
359 * of the application code is stored.
360 * \param[out] appVerBuild A pointer to a byte where the build number of the application is stored.
361 *
362 * \return \ref linOK (zero) if success
363 * \return \ref linERR_xxx (negative) if failure
364 */
365LinStatus LINLIBAPI linGetFirmwareVersion(LinHandle h,
366 unsigned char *bootVerMajor,
367 unsigned char *bootVerMinor,
368 unsigned char *bootVerBuild,
369 unsigned char *appVerMajor,
370 unsigned char *appVerMinor,
371 unsigned char *appVerBuild);
372
373/**
374 * This function sets the bit rate for a master, or the initial bit rate for a
375 * slave. The LIN interface should not be on-bus when this function is called.
376 *
377 * \note The LIN Interface should not be on bus.
378 *
379 * \note Supported bit rates are 1000 - 20000 bits per second.
380 *
381 * \param[in] h A handle to an open LIN channel.
382 * \param[in] bps Bit rate in bits per second.
383 *
384 * \return \ref linOK (zero) if success
385 * \return \ref linERR_xxx (negative) if failure
386 */
387LinStatus LINLIBAPI linSetBitrate(LinHandle h, unsigned int bps);
388
389/**
390 * This function activates the LIN interface.
391 *
392 * \note It will be reset, so any setups done earlier will be lost.
393 *
394 * \param[in] h A handle to an open LIN channel.
395 *
396 * \return \ref linOK (zero) if success
397 * \return \ref linERR_xxx (negative) if failure
398 *
399 * \sa \ref linBusOff()
400 */
401LinStatus LINLIBAPI linBusOn(LinHandle h);
402
403/**
404 * This function deactivates the LIN interface. It will not participate further
405 * in the LIN bus traffic.
406 *
407 * \param[in] h A handle to an open LIN channel.
408 *
409 * \return \ref linOK (zero) if success
410 * \return \ref linERR_xxx (negative) if failure
411 *
412 * \sa \ref linBusOn()
413 */
414LinStatus LINLIBAPI linBusOff(LinHandle h);
415
416/**
417 * Return the current timer value (used for timestamps)
418 *
419 * \note For convenience, this call returns the timer value instead of passing
420 * it in a parameter. This means that if the call fails, it will still return
421 * a value (which then is the error code, type casted to a long unsigned
422 * integer - e.g. 0xFFFFFFF2 for \ref linERR_INVHANDLE. Watch out.
423 *
424 * \param[in] h A handle to an open LIN channel.
425 * \return If the call succeeds, the present timer value is returned.
426 */
427unsigned long LINLIBAPI linReadTimer(LinHandle h);
428
429/**
430 * Write a LIN message.
431 * It is advisable to wait until the message is echoed by \ref linReadMessage()
432 * before transmitting a new message, or in case of a schedule table being used,
433 * transmit the next message when the previous one is known to be complete.
434 *
435 * \note Only available in master mode.
436 *
437 * \param[in] h A handle to an open LIN channel.
438 * \param[in] id The identifier of the LIN message.
439 * \param[in] msg A pointer to a buffer containing the data of the LIN
440 * message.
441 * \param[in] dlc The length of the LIN message.
442 *
443 * \return \ref linOK (zero) if success
444 * \return \ref linERR_xxx (negative) if failure
445 *
446 * \sa \ref linWriteSync()
447 */
448LinStatus LINLIBAPI linWriteMessage(LinHandle h, unsigned int id, const void *msg,
449 unsigned int dlc);
450
451/**
452 * This function writes a LIN message header to the LIN bus. A slave in the
453 * system is then expected to fill in the header with data.
454 *
455 * \note This call is only available in master mode.
456 *
457 * \param[in] h A handle to an open LIN channel.
458 * \param[in] id The identifier of the LIN message.
459 *
460 * \return \ref linOK (zero) if success
461 * \return \ref linERR_xxx (negative) if failure
462 */
463LinStatus LINLIBAPI linRequestMessage(LinHandle h, unsigned int id);
464
465/**
466 * Read a message from the LIN interface. If a message is available for
467 * reception, \ref linOK is returned. This is a non-blocking call. If no message
468 * is available in the LIN interface, an error code is returned.
469 *
470 * \note This call will also return echoes of what the LIN interface is
471 * transmitting with \ref linWriteMessage. In other words, the LIN interface can hear
472 * itself.
473 *
474 * \param[in] h A handle to an open LIN channel.
475 * \param[out] id A pointer to an integer where the identifier of the
476 * received LIN message will be stored.
477 * \param[out] msg A pointer to a buffer where the data of the LIN message
478 * will be stored.
479 * \param[out] dlc A pointer to an integer where the length of the received
480 * LIN message will be stored.
481 * \param[out] flags A combination of zero or more of the \ref LIN_xxx flags.
482 * \param[out] msgInfo A pointer to a \ref LinMessageInfo struct where data about the
483 * received LIN message will be stored.
484 *
485 * \return \ref linOK (zero) if success
486 * \return \ref linERR_xxx (negative) if failure
487 *
488 * \sa \ref linReadMessageWait()
489 */
490LinStatus LINLIBAPI linReadMessage(LinHandle h, unsigned int *id, void *msg,
491 unsigned int *dlc, unsigned int *flags,
492 LinMessageInfo *msgInfo);
493
494/**
495 * Read a message from the LIN interface. If a message is available for
496 * reception, \ref linOK is returned. This is a blocking call. It waits until a
497 * message is received in the LIN interface, or the specified timeout period
498 * elapses.
499 *
500 * \note This call will also return echoes of what the LIN interface is
501 * transmitting with \ref linWriteMessage(). In other words, the LIN interface can
502 * hear itself.
503 *
504 * \param[in] h A handle to an open LIN channel.
505 * \param[in] timeout The maximum number of milliseconds to wait for a message
506 * to be received by the LIN interface.
507 * \param[out] id A pointer to an integer where the identifier of the
508 * received LIN message will be stored.
509 * \param[out] msg A pointer to a buffer where the data of the LIN message
510 * will be stored.
511 * \param[out] dlc A pointer to an integer where the length of the received
512 * LIN message will be stored.
513 * \param[out] flags A combination of zero or more of the \ref LIN_xxx flags.
514 * \param[out] msgInfo A pointer to a \ref LinMessageInfo struct where data about the
515 * received LIN message will be stored.
516 *
517 * \return \ref linOK (zero) if success
518 * \return \ref linERR_xxx (negative) if failure
519 *
520 * \sa \ref linReadMessage()
521 */
522LinStatus LINLIBAPI linReadMessageWait(LinHandle h, unsigned int *id, void *msg,
523 unsigned int *dlc, unsigned int *flags,
524 LinMessageInfo *msgInfo, unsigned long timeout);
525
526/**
527 * This function updates a message buffer in a slave. The contents of the
528 * message buffer will be used the next time the slave is polled for the
529 * specified LIN message id.
530 *
531 * \note The LIN Interface must be on bus.
532 *
533 * \param[in] h A handle to an open LIN channel.
534 * \param[in] id The identifier of the LIN message.
535 * \param[in] msg A pointer to a buffer containing the data of the LIN message.
536 * \param[in] dlc The length of the LIN message.
537 *
538 * \return \ref linOK (zero) if success
539 * \return \ref linERR_xxx (negative) if failure
540 *
541 * \sa \ref linClearMessage()
542 */
543LinStatus LINLIBAPI linUpdateMessage(LinHandle h, unsigned int id, const void *msg,
544 unsigned int dlc);
545
546
547/**
548 * Using this function, it is possible to use the LIN interface to create
549 * corrupted LIN messages. You call the function once for each LIN identifier
550 * that should be affected.
551 *
552 * To return to normal mode, either restart the LIN interface (by going off bus
553 * and on the bus again) or call the function with delay and \a cFlags set to zero.
554 *
555 * \note The LIN Interface must be on bus for this command to work.
556 * \note It is supported in firmware version 2.4.1 and later.
557 *
558 * \param[in] h A handle to an open LIN channel.
559 * \param[in] id The identifier of the LIN message.
560 * \param[in] cFlags One or more of the \ref LIN_MSG_DISTURB_xxx flags.
561 * \param[in] delay The delay parameter will result in a delay of this many
562 * bittimes after the header and before the first data byte.
563 *
564 * \return \ref linOK (zero) if success
565 * \return \ref linERR_xxx (negative) if failure
566 *
567 * \sa \ref linSetupLIN()
568 */
569LinStatus LINLIBAPI linSetupIllegalMessage(LinHandle h, unsigned int id,
570 unsigned int cFlags, unsigned int delay);
571
572/**
573 * \name LIN illegal message flags
574 * \anchor LIN_MSG_DISTURB_xxx
575 * @{
576 */
577/**
578 * The checksum of transmitted messages will be inverted (and consequently illegal.)
579 */
580#define LIN_MSG_DISTURB_CSUM 1
581/**
582 * The two parity bits will be inverted (and consequently illegal.)
583 * Used only in master mode.
584 */
585#define LIN_MSG_DISTURB_PARITY 2
586/** @} */
587
588
589/**
590 * \name LIN message parity
591 * \anchor LIN_MSG_USE_xxx
592 * @{
593 */
594/**
595 * Use enhanced (2.x) parity for the specified msg
596 */
597#define LIN_MSG_USE_STANDARD_PARITY 0x04
598/**
599 * Use standard (1.x) parity for the specified msg
600 */
601#define LIN_MSG_USE_ENHANCED_PARITY 0x08
602/** @} */
603
604/**
605 * This function changes various settings on a LIN Interface that is on bus.
606 * When going on bus, the bit rate and the flag values listed below are set to
607 * the default value (either as hard-coded in the firmware, or as stored in the
608 * non-volatile memory of the LIN Interface).
609 *
610 * With this function, you can do one or more of the following things:
611 * - Select checksum according to LIN 2.0
612 * - Turn variable message length off. The message length then will depend on
613 * the message ID.
614 *
615 * In master mode it is also possible to change the bit rate without going off
616 * bus first.
617 *
618 * \note The LIN Interface must be on bus for this command to work.
619 * \note It is supported in firmware version 2.5.1 and later.
620 * \note For LIN 2.0 compliance, you must specify both \ref LIN_ENHANCED_CHECKSUM
621 * and \ref LIN_VARIABLE_DLC.
622 *
623 * \param[in] h A handle to an open LIN channel.
624 * \param[in] lFlags One or more of the following flags:
625 * \ref LIN_ENHANCED_CHECKSUM, \ref LIN_VARIABLE_DLC
626 * \param bps Specifies the bit rate in bits per second. This parameter
627 * can be used only in master mode. The bit rate is set
628 * without going off bus.
629 *
630 * \return \ref linOK (zero) if success
631 * \return \ref linERR_xxx (negative) if failure
632 *
633 * \sa \ref linSetupIllegalMessage()
634 */
635LinStatus LINLIBAPI linSetupLIN(LinHandle h, unsigned int lFlags, unsigned int bps);
636
637
638/**
639 * \name LIN setup
640 * @{
641 */
642/**
643 * When specified, the LIN interface will use the "enhanced" checksum according
644 * to LIN 2.0. Note that (as per the LIN 2.0 spec) the enhanced checksum is not
645 * used on the diagnostic frames even if the \ref LIN_ENHANCED_CHECKSUM setting
646 * is in effect.
647 *
648 * The default value is OFF.
649 */
650#define LIN_ENHANCED_CHECKSUM 1
651/**
652 * When specified, turns variable message length on, so the the message length
653 * will depend on the message ID.
654 *
655 * The default value is ON.
656 */
657#define LIN_VARIABLE_DLC 2
658/** @} */
659
660/**
661 * Write a wakeup frame.
662 *
663 * If count is zero, one single wakeup frame is transmitted. If count > 1,
664 * several wakeup frames are transmitted spaced with 'interval' bittimes.
665 * The LIN interface will interrupt the sequence when a LIN message or another
666 * command is received. The stream of wakeups will be recived as incoming
667 * messages with the LIN_RX flag bit set.
668 *
669 * \param[in] h A handle to an open LIN channel.
670 * \param[in] count The number of wakeup frames to send.
671 * \param[in] interval The time, in bit times, between the wakeup frames.
672 *
673 * \return \ref linOK (zero) if success
674 * \return \ref linERR_xxx (negative) if failure
675 */
676LinStatus LINLIBAPI linWriteWakeup(LinHandle h, unsigned int count,
677 unsigned int interval);
678
679
680/**
681 * Clear a message buffer for a LIN slave. The message buffer will not answer
682 * next time it is polled.
683 *
684 * \param[in] h A handle to an open LIN channel.
685 * \param[in] id The LIN message id for which the corresponding buffer
686 * will be cleared.
687 *
688 * \return \ref linOK (zero) if success
689 * \return \ref linERR_xxx (negative) if failure
690 */
691LinStatus LINLIBAPI linClearMessage(LinHandle h, unsigned int id);
692
693/**
694 * Call this function to make sure all messages transmitted to the
695 * LIN Interface has been received by it.
696 *
697 * When messages are transmitted to the LIN Interface, they are queued by
698 * Windows before appearing on the CAN bus.
699 *
700 * The function returns \ref linOK if all writes are done, \ref linERR_TIMEOUT in
701 * case of timeout or possibly some other error code.
702 *
703 * If the LIN Interface is in master mode and a LIN message has been
704 * transmitted with \ref linWriteMessage(), this function will return when
705 * the LIN Interface has received the message. If another LIN messa ge is being
706 * received or transmitted, the message will not be transmitted on the
707 * LIN bus at once. And even if the LIN Interface is idle, the header of the new
708 * message will just have been started when \ref linWriteSync() retur ns.
709 *
710 * After calling \ref linUpdateMessage() and \ref linClearMessage() for a slave,
711 * this function is enough to know that the LIN Interface is updated.
712 *
713 * After \ref linWriteMessage(), it is advisable to wait until the message is
714 * echoed by \ref linReadMessage() before transmitting a new message, or in
715 * case of a schedule table being used, transmit the next message when
716 * the previous one is known to be complete.
717 *
718 * When, in master mode, a message should be transmitted after a poll
719 * (reception) is done, it might be necessary to call \ref linWriteMessage()
720 * before the result is received via \ref linReadMessage() as the LIN Interface waits
721 * up to the maximum frame length before knowing a received message is
722 * complete. A new message to transmit will force completion if the
723 * currently received one.
724 *
725 * \param[in] h A handle to an open LIN channel.
726 * \param[in] timeout The maximum number of milliseconds to wait for the queued
727 * messages to be transmitted by the LIN interface.
728 *
729 * \return \ref linOK (zero) if success
730 * \return \ref linERR_xxx (negative) if failure
731 *
732 * \sa \ref linWriteMessage()
733 */
734LinStatus LINLIBAPI linWriteSync(LinHandle h, unsigned long timeout);
735
736/**
737 * Return the CAN handle given an open LIN handle
738 *
739 * \param[in] h A handle to an open LIN channel.
740 * \param[out] canHandle A pointer to an integer where the CAN handle will be
741 * stored.
742 *
743 * \return \ref linOK (zero) if success
744 * \return \ref linERR_xxx (negative) if failure
745 */
746LinStatus LINLIBAPI linGetCanHandle(LinHandle h, unsigned int *canHandle);
747
748#ifdef __cplusplus
749}
750#endif
751
752/** @} */
753
754#endif // __LINLIB_H
Note: See TracBrowser for help on using the repository browser.