LIN related functions. More...
Functions | |
LinStatus | linGetTransceiverData (int channel, unsigned char eanNo[8], unsigned char serNo[8], int *ttype) |
LinHandle | linOpenChannel (int channel, int flags) |
LinStatus | linClose (LinHandle h) |
LinStatus | linSetBitrate (LinHandle h, unsigned int bps) |
LinStatus | linBusOn (LinHandle h) |
LinStatus | linBusOff (LinHandle h) |
LinStatus | linWriteMessage (LinHandle h, unsigned int id, const void *msg, unsigned int dlc) |
LinStatus | linRequestMessage (LinHandle h, unsigned int id) |
LinStatus | linReadMessage (LinHandle h, unsigned int *id, void *msg, unsigned int *dlc, unsigned int *flags, LinMessageInfo *msgInfo) |
LinStatus | linReadMessageWait (LinHandle h, unsigned int *id, void *msg, unsigned int *dlc, unsigned int *flags, LinMessageInfo *msgInfo, unsigned long timeout) |
LinStatus | linUpdateMessage (LinHandle h, unsigned int id, const void *msg, unsigned int dlc) |
LinStatus | linSetupIllegalMessage (LinHandle h, unsigned int id, unsigned int cFlags, unsigned int delay) |
LinStatus | linSetupLIN (LinHandle h, unsigned int lFlags, unsigned int bps) |
LinStatus | linWriteWakeup (LinHandle h, unsigned int count, unsigned int interval) |
LinStatus | linClearMessage (LinHandle h, unsigned int id) |
LinStatus | linWriteSync (LinHandle h, unsigned long timeout) |
LinStatus | linGetCanHandle (LinHandle h, unsigned int *canHandle) |
LIN related functions.
Takes the specified handle off-bus.
[in] | h | A handle to an open LIN channel. |
Takes the specified handle on-bus.
[in] | h | A handle to an open LIN channel. |
Clear a message buffer for a LIN slave. The message buffer will not answer next time it is polled.
[in] | h | A handle to an open LIN channel. |
[in] | id | The LIN message id for which the corresponding buffer will be cleared. |
Closes an open handle to a LIN channel. The handle becomes invalid and can not be used in subsequent calls to the LIN functions.
[in] | h | A handle to an open LIN channel. |
Return the CAN handle given an open LIN handle
[in] | h | A handle to an open LIN channel. |
[out] | canHandle | A pointer to an integer where the CAN handle will be stored. |
LinStatus linGetTransceiverData | ( | int | channel, |
unsigned char | eanNo[8], | ||
unsigned char | serNo[8], | ||
int * | ttype | ||
) |
Retrieves the transceiver information for a CAN channel. The application typically uses this call to find out whether a particular CAN channel has a LIN interface connected to it. For a Kvaser LIN Leaf it retrieves the transceiver type and device information.
This function call will open the CAN channel, but no CAN messages are transmitted on it. In other words, it's risk-free to use even if no LIN interface is connected, or if the channel is connected to a CAN system.
[in] | channel | The number of a CAN channel for which the transceiver data will be retrieved. |
[out] | eanNo | A pointer to an array of 8 bytes where the EAN number of the LIN interface will be stored. |
[out] | serNo | A pointer to an array of 8 bytes where the serial number of the LIN interface will be stored. |
[out] | ttype | A pointer to an integer where the transceiver type will be stored. |
LinHandle linOpenChannel | ( | int | channel, |
int | flags | ||
) |
Open a channel to a LIN interface.
[in] | channel | The number of the channel. Channel numbering is hardware dependent. This is the same channel number as used by canOpenChannel(). |
[in] | flags | Either one of the following values: LIN_MASTER or LIN_SLAVE. |
LinStatus linReadMessage | ( | LinHandle | h, |
unsigned int * | id, | ||
void * | msg, | ||
unsigned int * | dlc, | ||
unsigned int * | flags, | ||
LinMessageInfo * | msgInfo | ||
) |
Read a message from the LIN interface. If a message is available for reception, linOK is returned. This is a non-blocking call. If no message is available in the LIN interface, an error code is returned.
[in] | h | A handle to an open LIN channel. |
[out] | id | A pointer to an integer where the identifier of the received LIN message will be stored. |
[out] | msg | A pointer to a buffer where the data of the LIN message will be stored. |
[out] | dlc | A pointer to an integer where the length of the received LIN message will be stored. |
[out] | flags | A combination of zero or more of the LIN_xxx flags. |
[out] | msgInfo | A pointer to a LinMessageInfo struct where data about the received LIN message will be stored. |
LinStatus linReadMessageWait | ( | LinHandle | h, |
unsigned int * | id, | ||
void * | msg, | ||
unsigned int * | dlc, | ||
unsigned int * | flags, | ||
LinMessageInfo * | msgInfo, | ||
unsigned long | timeout | ||
) |
Read a message from the LIN interface. If a message is available for reception, linOK is returned. This is a blocking call. It waits until a message is received in the LIN interface, or the specified timeout period elapses.
[in] | h | A handle to an open LIN channel. |
[in] | timeout | The maximum number of milliseconds to wait for a message to be received by the LIN interface. |
[out] | id | A pointer to an integer where the identifier of the received LIN message will be stored. |
[out] | msg | A pointer to a buffer where the data of the LIN message will be stored. |
[out] | dlc | A pointer to an integer where the length of the received LIN message will be stored. |
[out] | flags | A combination of zero or more of the LIN_xxx flags. |
[out] | msgInfo | A pointer to a LinMessageInfo struct where data about the received LIN message will be stored. |
This function writes a LIN message header to the LIN bus. A slave in the system is then expected to fill in the header with data.
[in] | h | A handle to an open LIN channel. |
[in] | id | The identifier of the LIN message. |
This function sets the bit rate for a master, or the initial bit rate for a slave.
[in] | h | A handle to an open LIN channel. |
[in] | bps | Bit rate in bits per second. |
LinStatus linSetupIllegalMessage | ( | LinHandle | h, |
unsigned int | id, | ||
unsigned int | cFlags, | ||
unsigned int | delay | ||
) |
Using this function, it is possible to use the LIN interface to create corrupted LIN messages. You call the function once for each LIN identifier that should be affected.
To return to normal mode, either restart the LIN interface (by going off bus and on the bus again) or call the function with delay and cFlags set to zero.
[in] | h | A handle to an open LIN channel. |
[in] | id | The identifier of the LIN message. |
[in] | cFlags | One or more of the LIN_MSG_DISTURB_xxx or LIN_MSG_USE_xxx flags. |
[in] | delay | The delay parameter will result in a delay of this many bittimes after the header and before the first data byte. |
This function changes various settings on a handle that is on-bus. When going on-bus, the bit rate and the flag values listed below are set to the default value (either as hard-coded in the firmware, or as stored in the non-volatile memory of the LIN Interface).
With this function, you can do one or more of the following things:
In master mode it is also possible to change the bit rate without going off bus first.
[in] | h | A handle to an open LIN channel. |
[in] | lFlags | One or more of the following flags: LIN_ENHANCED_CHECKSUM, LIN_VARIABLE_DLC |
bps | Specifies the bit rate in bits per second. This parameter can be used only in master mode. The bit rate is set without going off bus. |
This function updates a message buffer in a slave. The contents of the message buffer will be used the next time the slave is polled for the specified LIN message id.
[in] | h | A handle to an open LIN channel. |
[in] | id | The identifier of the LIN message. |
[in] | msg | A pointer to a buffer containing the data of the LIN message. |
[in] | dlc | The length of the LIN message. |
Write a LIN message. It is advisable to wait until the message is echoed by linReadMessage() before transmitting a new message, or in case of a schedule table being used, transmit the next message when the previous one is known to be complete.
[in] | h | A handle to an open LIN channel. |
[in] | id | The identifier of the LIN message. |
[in] | msg | A pointer to a buffer containing the data of the LIN message. |
[in] | dlc | The length of the LIN message. |
Call this function to make sure all messages transmitted to the LIN Interface has been received by it.
When messages are transmitted to the LIN Interface, they are queued by the driver before appearing on the LIN bus.
The function returns linOK if all writes are done, linERR_TIMEOUT in case of timeout or possibly some other error code.
If the LIN Interface is in master mode and a LIN message has been transmitted with linWriteMessage(), this function will return when the LIN Interface has received the message. If another LIN message is being received or transmitted, the message will not be transmitted on the LIN bus at once. And even if the LIN Interface is idle, the header of the new message will just have been started when linWriteSync() returns.
After calling linUpdateMessage() and linClearMessage() for a slave, this function is enough to know that the LIN Interface is updated.
After linWriteMessage(), it is advisable to wait until the message is echoed by linReadMessage() before transmitting a new message, or in case of a schedule table being used, transmit the next message when the previous one is known to be complete.
When, in master mode, a message should be transmitted after a poll (reception) is done, it might be necessary to call linWriteMessage() before the result is received via linReadMessage() as the LIN Interface waits up to the maximum frame length before knowing a received message is complete. A new message to transmit will force completion if the currently received one.
[in] | h | A handle to an open LIN channel. |
[in] | timeout | The maximum number of milliseconds to wait for the queued messages to be transmitted by the LIN interface. |
Write a wakeup frame.
If count is zero, one single wakeup frame is transmitted. If count > 1, several wakeup frames are transmitted spaced with 'interval' bittimes. The LIN interface will interrupt the sequence when a LIN message or another command is received. The stream of wakeups will be recived as incoming messages with the LIN_RX flag bit set.
[in] | h | A handle to an open LIN channel. |
[in] | count | The number of wakeup frames to send. |
[in] | interval | The time, in bit times, between the wakeup frames. |