Kvaser Linux CANLIB
|
Data Structures | |
struct | canNotifyData |
Typedefs | |
typedef struct canNotifyData | canNotifyData |
Functions | |
canStatus | canClose (const CanHandle hnd) |
canStatus | canBusOn (const CanHandle hnd) |
canStatus | canBusOff (const CanHandle hnd) |
canStatus | canSetBusParams (const CanHandle hnd, long freq, unsigned int tseg1, unsigned int tseg2, unsigned int sjw, unsigned int noSamp, unsigned int syncmode) |
canStatus | canGetBusParams (const CanHandle hnd, long *freq, unsigned int *tseg1, unsigned int *tseg2, unsigned int *sjw, unsigned int *noSamp, unsigned int *syncmode) |
canStatus | canSetBusOutputControl (const CanHandle hnd, const unsigned int drivertype) |
canStatus | canGetBusOutputControl (const CanHandle hnd, unsigned int *drivertype) |
canStatus | canAccept (const CanHandle hnd, const long envelope, const unsigned int flag) |
canStatus | canReadStatus (const CanHandle hnd, unsigned long *const flags) |
canStatus | canReadErrorCounters (const CanHandle hnd, unsigned int *txErr, unsigned int *rxErr, unsigned int *ovErr) |
canStatus | canWrite (const CanHandle hnd, long id, void *msg, unsigned int dlc, unsigned int flag) |
canStatus | canWriteSync (const CanHandle hnd, unsigned long timeout) |
canStatus | canRead (const CanHandle hnd, long *id, void *msg, unsigned int *dlc, unsigned int *flag, unsigned long *time) |
canStatus | canReadWait (const CanHandle hnd, long *id, void *msg, unsigned int *dlc, unsigned int *flag, unsigned long *time, unsigned long timeout) |
canStatus | canReadSync (const CanHandle hnd, unsigned long timeout) |
canStatus | canSetNotify (const CanHandle hnd, void(*callback)(canNotifyData *), unsigned int notifyFlags, void *tag) |
canStatus | canGetRawHandle (const CanHandle hnd, void *pvFd) |
canStatus | canTranslateBaud (long *const freq, unsigned int *const tseg1, unsigned int *const tseg2, unsigned int *const sjw, unsigned int *const nosamp, unsigned int *const syncMode) |
canStatus | canReadTimer (const CanHandle hnd, unsigned long *time) |
CanHandle | canOpenChannel (int channel, int flags) |
canStatus | canSetBusParamsC200 (const CanHandle hnd, BYTE btr0, BYTE btr1) |
canStatus | canResetBus (const CanHandle hnd) |
canStatus | canWriteWait (const CanHandle hnd, long id, void *msg, unsigned int dlc, unsigned int flag, unsigned long timeout) |
canStatus | canFlushReceiveQueue (const CanHandle hnd) |
canStatus | canFlushTransmitQueue (const CanHandle hnd) |
typedef struct canNotifyData canNotifyData |
This routine sets the message acceptance filters on a CAN channel.
On some boards the acceptance filtering is done by the CAN hardware; on other boards (typically those with an embedded CPU,) the acceptance filtering is done by software. canAccept() behaves in the same way for all boards, however.
canSetAcceptanceFilter() and canAccept() both serve the same purpose but the former can set the code and mask in just one call.
If you want to remove a filter, call canAccept() with the mask set to 0.
[in] | hnd | An open handle to a CAN circuit. |
[in] | envelope | The mask or code to set. |
[in] | flag | Any of canFILTER_SET_CODE_STD, canFILTER_SET_MASK_STD, canFILTER_SET_CODE_EXT or canFILTER_SET_MASK_EXT |
Takes the specified channel off-bus.
[in] | hnd | An open handle to a CAN channel. |
Takes the specified channel on-bus.
If you are using multiple handles to the same physical channel, for example if you are writing a threaded application, you must call canBusOn() once for each handle. The same applies to canBusOff() - the physical channel will not go off bus until the last handle to the channel goes off bus.
[in] | hnd | An open handle to a CAN channel. |
Closes the channel associated with the handle. If no other threads are using the CAN circuit, it is taken off bus. The handle can not be used for further references to the channel, so any variable containing it should be zeroed.
canClose() will almost always return canOK; the specified handle is closed on an best-effort basis.
[in] | hnd | An open handle to a CAN channel. |
This function removes all received messages from the handle's receive queue. Other handles open to the same channel are not affcted by this operation. That is, only the messages belonging to the handle you are passing to canFlushReceiveQueue are discarded.
[in] | hnd | A handle to an open circuit. |
This function removes all messages pending transmission from the transmit queue of the circuit.
[in] | hnd | A handle to an open circuit. |
This function retrieves the current CAN controller driver type. This corresponds loosely to the bus output control register in the CAN controller, hence the name of this function. CANLIB does not allow for direct manipulation of the bus output control register; instead, symbolic constants are used to select the desired driver type.
[in] | hnd | An open handle to a CAN circuit. |
[in] | drivertype | A pointer to an unsigned int which receives the current driver type. The driver type can be either canDRIVER_NORMAL or canDRIVER_SILENT. |
canStatus canGetBusParams | ( | const CanHandle | hnd, |
long * | freq, | ||
unsigned int * | tseg1, | ||
unsigned int * | tseg2, | ||
unsigned int * | sjw, | ||
unsigned int * | noSamp, | ||
unsigned int * | syncmode | ||
) |
This function retrieves the current bus parameters for the specified channel.
The anatomy of a CAN bit is discussed in detail at Kvaser's web site at www.kvaser.com.
[in] | hnd | An open handle to a CAN controller. |
[out] | freq | Bit rate (bits per second). |
[out] | tseg1 | Time segment 1, that is, the number of quanta from (but not including) the Sync Segment to the sampling point. |
[out] | tseg2 | Time segment 2, that is, the number of quanta from the sampling point to the end of the bit. |
[out] | sjw | The Synchronization Jump Width; can be 1,2,3, or 4. |
[out] | noSamp | The number of sampling points; can be 1 or 3. |
[out] | syncmode | Unsupported, always read as zero. |
Returns raw handle/file descriptor for use in system calls.
[in] | hnd | CanHandle |
[out] | pvFd | Pointer to raw can data. |
CanHandle canOpenChannel | ( | int | channel, |
int | flags | ||
) |
Opens a CAN channel (circuit) and returns a handle which is used in subsequent calls to CANLIB.
Channel numbering is dependent on the installed hardware. The first channel always has number 0.
For example,
If you are using multiple threads, note that the returned handle is usable only in the context of the thread that created it. That is, you must call canOpenChannel() in each of the threads in your application that uses the CAN bus. You can open the same channel from multiple threads, but you must call canOpenChannel() once per thread.
If you are using the same channel via multiple handles, note that the default behaviour is that the different handles will "hear" each other just as if each handle referred to a channel of its own. If you open, say, channel 0 from thread A and thread B and then send a message from thread A, it will be "received" by thread B. This behaviour can be changed using canIOCTL_SET_LOCAL_TXECHO.
[in] | channel | The number of the channel. Channel numbering is hardware dependent. |
[in] | flags | A combination of canOPEN_xxx flags |
canStatus canRead | ( | const CanHandle | hnd, |
long * | id, | ||
void * | msg, | ||
unsigned int * | dlc, | ||
unsigned int * | flag, | ||
unsigned long * | time | ||
) |
Reads a message from the receive buffer. If no message is available, the function returns immediately with return code canERR_NOMSG.
If you are using the same channel via multiple handles, note that the default behaviour is that the different handles will "hear" each other just as if each handle referred to a channel of its own. If you open, say, channel 0 from thread A and thread B and then send a message from thread A, it will be "received" by thread B. This behaviour can be changed using canIOCTL_SET_LOCAL_TXECHO.
It is allowed to pass NULL
as the value of id, msg, dlc, flag, and time.
[in] | hnd | A handle to an open circuit. |
[out] | id | Pointer to a buffer which receives the CAN identifier. This buffer will only get the identifier. To determine whether this identifier was standard (11-bit) or extended (29-bit), and/or whether it was remote or not, or if it was an error frame, examine the contents of the flag argument. |
[out] | msg | Pointer to the buffer which receives the message data. This buffer must be large enough (i.e. 8 bytes.) Only the message data is copied; the rest of the buffer is left as-is. |
[out] | dlc | Pointer to a buffer which receives the message length. |
[out] | flag | Pointer to a buffer which receives the message flags, which is a combination of the canMSG_xxx and canMSGERR_xxx values. |
[out] | time | Pointer to a buffer which receives the message time stamp. |
canStatus canReadErrorCounters | ( | const CanHandle | hnd, |
unsigned int * | txErr, | ||
unsigned int * | rxErr, | ||
unsigned int * | ovErr | ||
) |
Reads the error counters of the CAN controller.
canReadErrorCounters() returns the latest known values of the error counters in the specified circuit. If the error counters change values precisely when canReadErrorCounters() is called, it may not be reflected in the returned result.
It is allowed to pass NULL
as the value of the txErr, rxErr, and ovErr parameters.
Use canIoCtl() to clear the counters.
[in] | hnd | A handle to an open circuit. |
[out] | txErr | A pointer to a DWORD which receives the transmit error counter. |
[out] | rxErr | A pointer to a DWORD which receives the receive error counter. |
[out] | ovErr | A pointer to a DWORD which receives the number of overrun errors. |
Returns the status for the specified circuit. flags points to a longword which receives a combination of the canSTAT_xxx flags.
[in] | hnd | A handle to an open circuit. |
[out] | flags | Pointer to a DWORD which receives the status flags; this is a combination of any of the canSTAT_xxx. |
Waits until the receive buffer contains at least one message or a timeout occurs.
If you are using the same channel via multiple handles, note that the default behaviour is that the different handles will "hear" each other just as if each handle referred to a channel of its own. If you open, say, channel 0 from thread A and thread B and then send a message from thread A, it will be "received" by thread B. This behaviour can be changed using canIOCTL_SET_LOCAL_TXECHO.
[in] | hnd | A handle to an open circuit. |
[in] | timeout | The timeout in milliseconds. 0xFFFFFFFF gives an infinite timeout. |
Reads the current time from the clock used to timestamp the messages for the indicated circuit.
This API may return canERR_INVHANDLE and/or canERR_NOTINITIALIZED! This happens if hnd is invalid, or if the library was not initialized.
[in] | hnd | A handle to an open circuit. |
[out] | time | The current time, with the prevailing time resolution. |
canStatus canReadWait | ( | const CanHandle | hnd, |
long * | id, | ||
void * | msg, | ||
unsigned int * | dlc, | ||
unsigned int * | flag, | ||
unsigned long * | time, | ||
unsigned long | timeout | ||
) |
Reads a message from the receive buffer. If no message is available, the function waits until a message arrives or a timeout occurs.
If you are using the same channel via multiple handles, note that the default behaviour is that the different handles will "hear" each other just as if each handle referred to a channel of its own. If you open, say, channel 0 from thread A and thread B and then send a message from thread A, it will be "received" by thread B. This behaviour can be changed using canIOCTL_SET_LOCAL_TXECHO.
It is allowed to pass NULL
as the value of id, msg, dlc, flag, and time.
[in] | hnd | A handle to an open circuit. |
[out] | id | Pointer to a buffer which receives the CAN identifier. This buffer will only get the identifier. To determine whether this identifier was standard (11-bit) or extended (29-bit), and/or whether it was remote or not, or if it was an error frame, examine the contents of the flag argument. |
[out] | msg | Pointer to the buffer which receives the message data. This buffer must be large enough (i.e. 8 bytes.). |
[out] | dlc | Pointer to a buffer which receives the message length. |
[out] | flag | Pointer to a buffer which receives the message flags, which is a combination of the canMSG_xxx and canMSGERR_xxx values. |
[out] | time | Pointer to a buffer which receives the message time stamp. |
[in] | timeout | If no message is immediately available, this parameter gives the number of milliseconds to wait for a message before returning. 0xFFFFFFFF gives an infinite timeout. |
This function tries to reset a CAN bus controller by taking the channel off bus and then on bus again (if it was on bus before the call to canResetBus().)
This function will affect the hardware (and cause a real reset of the CAN chip) only if hnd is the only handle open on the channel. If there are other open handles, this operation will not affect the hardware.
[in] | hnd | A handle to an open circuit. |
This function sets the driver type for a CAN controller. This corresponds loosely to the bus output control register in the CAN controller, hence the name of this function. CANLIB does not allow for direct manipulation of the bus output control register; instead, symbolic constants are used to select the desired driver type.
[in] | hnd | A handle to an open circuit. |
[out] | drivertype | Can driver type, canDRIVER_xxx) |
canStatus canSetBusParams | ( | const CanHandle | hnd, |
long | freq, | ||
unsigned int | tseg1, | ||
unsigned int | tseg2, | ||
unsigned int | sjw, | ||
unsigned int | noSamp, | ||
unsigned int | syncmode | ||
) |
This function sets the bus timing parameters for the specified CAN controller.
The library provides default values for tseg1, tseg2, sjw and noSamp when freq is specified to one of the pre-defined constants, canBITRATE_xxx.
If freq is any other value, no default values are supplied by the library.
If you are using multiple handles to the same physical channel, for example if you are writing a threaded application, you must call canBusOff() once for each handle. The same applies to canBusOn() - the physical channel will not go off bus until the last handle to the channel goes off bus.
[in] | hnd | An open handle to a CAN controller. |
[in] | freq | Bit rate (measured in bits per second); or one of the predefined constants canBITRATE_xxx, which are described below. |
[in] | tseg1 | Time segment 1, that is, the number of quanta from (but not including) the Sync Segment to the sampling point. |
[in] | tseg2 | Time segment 2, that is, the number of quanta from the sampling point to the end of the bit. |
[in] | sjw | The Synchronization Jump Width; can be 1,2,3, or 4. |
[in] | noSamp | The number of sampling points; can be 1 or 3. |
[in] | syncmode | Unsupported and ignored. |
This function sets the bus timing parameters using the same convention as the 82c200 CAN controller (which is the same as many other CAN controllers, for example, the 82527.)
To calculate the bit timing parameters, you can use the bit timing calculator that is included with CANLIB SDK. Look in the BIN directory.
82c200 Bit Timing
1
: 3 samples, 0
: 1 samples [in] | hnd | A handle to an open CAN circuit. |
[in] | btr0 | The desired bit timing, formatted as the contents of the BTR0 register in the 82c200. |
[in] | btr1 | The desired bit timing, formatted as the contents of the BTR1 register in the 82c200. |
canStatus canSetNotify | ( | const CanHandle | hnd, |
void(*)(canNotifyData *) | callback, | ||
unsigned int | notifyFlags, | ||
void * | tag | ||
) |
This function associates a callback function with the CAN circuit.
[in] | hnd | A handle to an open CAN circuit. |
[in] | callback | Handle to callback routine. |
[in] | notifyFlags | The events specified with canNOTIFY_xxx, for which callback should be called. |
[in] | tag | Pointer to user defined data. Passed to callback in the canNotifyData struct. |
canStatus canTranslateBaud | ( | long *const | freq, |
unsigned int *const | tseg1, | ||
unsigned int *const | tseg2, | ||
unsigned int *const | sjw, | ||
unsigned int *const | nosamp, | ||
unsigned int *const | syncMode | ||
) |
This function translates the canBITRATE_xxx constants to their corresponding bus parameter values. At return, this freq contains the actual bit rate (in bits per second). TSeg1 is the number of quanta (less one) in a bit before the sampling point. TSeg2 is the number of quanta after the sampling point.
[in] | freq | A pointer to a DWORD which contains the canBITRATE_xxx constant to translate |
[in] | tseg1 | A pointer to a buffer which receives the Time segment 1, that is, the number of quanta from (but not including) the Sync Segment to the sampling point. |
[in] | tseg2 | A pointer to a buffer which receives the Time segment 2, that is, the number of quanta from the sampling point to the end of the bit. |
[in] | sjw | A pointer to a buffer which receives the Synchronization Jump Width; can be 1,2,3, or 4. |
[in] | nosamp | A pointer to a buffer which receives the number of sampling points; can be 1 or 3. |
[in] | syncMode | Unsupported, always read as zero. |
canStatus canWrite | ( | const CanHandle | hnd, |
long | id, | ||
void * | msg, | ||
unsigned int | dlc, | ||
unsigned int | flag | ||
) |
This function sends a CAN message. The call returns immediately after queuing the message to the driver.
If you are using the same channel via multiple handles, note that the default behaviour is that the different handles will "hear" each other just as if each handle referred to a channel of its own. If you open, say, channel 0 from thread A and thread B and then send a message from thread A, it will be "received" by thread B. This behaviour can be changed using canIOCTL_SET_LOCAL_TXECHO.
[in] | hnd | A handle to an open CAN circuit. |
[in] | id | The identifier of the CAN message to send. |
[in] | msg | A pointer to the message data, or NULL . |
[in] | dlc | The length of the message. Can be at most 8. |
[in] | flag | A combination of message flags, canMSG_xxx. Use this parameter to send extended (29-bit) frames and/or remote frames. Use canMSG_EXT and/or canMSG_RTR for this purpose. |
Waits until all CAN messages for the specified handle are sent, or the timeout period expires.
[in] | hnd | A handle to an open CAN circuit. |
[in] | timeout | The timeout in milliseconds. 0xFFFFFFFF gives an infinite timeout. |
canStatus canWriteWait | ( | const CanHandle | hnd, |
long | id, | ||
void * | msg, | ||
unsigned int | dlc, | ||
unsigned int | flag, | ||
unsigned long | timeout | ||
) |
This function sends a CAN message. It returns when the message is sent, or the timeout expires.
This is a convenience function that combines canWrite() and canWriteSync().
If you are using the same channel via multiple handles, note that the default behaviour is that the different handles will "hear" each other just as if each handle referred to a channel of its own. If you open, say, channel 0 from thread A and thread B and then send a message from thread A, it will be "received" by thread B. This behaviour can be changed using canIOCTL_SET_LOCAL_TXECHO.
[in] | hnd | A handle to an open CAN circuit. |
[in] | id | The identifier of the CAN message to send. |
[in] | msg | A pointer to the message data, or NULL . |
[in] | dlc | The length of the message. Can be at most 8. |
[in] | flag | A combination of message flags, canMSG_xxx. Use this parameter to send extended (29-bit) frames and/or remote frames. Use canMSG_EXT and/or canMSG_RTR for this purpose. |
[in] | timeout | The timeout, in milliseconds. 0xFFFFFFFF gives an infinite timeout. |