Search by Tags

CANLib-SJ1000 API

 
Article updated at 28 Oct 2017

Attention: this is a legacy library and thus not supported by Toradex anymore. We recommend that you use the new libraries for all Toradex modules. Please see the Toradex CE Libraries and Code Samples for up-to-date information.

Library to interface with a SJA1000 Stand-alone CAN Controller.

Data Structures

struct  _CAN_MESSAGE_EXT

Macros

#define  STANDARD  0x00
#define  EXTENDED  0x01
#define  CAN_VER_MAJ  3
Version Info.
#define  CAN_VER_MIN  3
#define  CAN_VER_BUILD  1

Functions

void  CANGetLibVersion (DWORD *pVerMaj, DWORD *pVerMin, DWORD *pBuild)
DWORD  InitSJA1000 (DWORD device, DWORD base, DWORD interruptGPIO, DWORD waterMark, DWORD bufferSize)
void  DeInitSJA1000 (DWORD device)
void  CANReInitialise (DWORD device)
BOOL  CanWriteDescriptor (DWORD device, DWORD descr, DWORD mask)
DWORD  CanReadDescriptor (DWORD device)
DWORD  CanReadMask (DWORD device)
BOOL  CanReset (DWORD device)
BOOL  CanSetBaudrate (DWORD device, DWORD baud)
BOOL  CanTransmitMessage (DWORD device, CAN_MESSAGE_EXT *msg)
DWORD  CANReceiveMessages (DWORD device, CAN_MESSAGE_EXT *msg, DWORD numberOfMsg, DWORD timeout)
DWORD  GetCanStatus (DWORD device)
void  PrintMessage (CAN_MESSAGE_EXT *msg)

Macro Definition Documentation

#define CAN_VER_BUILD   1
#define CAN_VER_MAJ   3

Version Info.

#define CAN_VER_MIN   3
#define EXTENDED   0x01
#define STANDARD   0x00

Typedef Documentation

Structure for extended frame types (29 Bit adress-range). Set "frametype" to "STANDARD" or "EXTENDED". The RTR (Remote-Frame) flag and data length code are now in seperate variables for better hardware independence !


Function Documentation

void CANGetLibVersion ( DWORD *  pVerMaj,
DWORD *  pVerMin,
DWORD *  pBuild
)

Returns the library version.

Parameters:
[out] VersionMajor Returns the major version number. Set this parameter to NULL if not required.
[out] VersionMinor Returns the minor version number. Set this parameter to NULL if not required.
[out] Build Returns the build number. Set this parameter to NULL if not required.
Return values:
NA
DWORD CanReadDescriptor ( DWORD  device )

Read the Acceptance Code

Parameters:
[in] device CAN Device ID
Return values:
Acceptance Code
DWORD CanReadMask ( DWORD  device )

Read the Mask

Parameters:
[in] device CAN Device ID
Return values:
Mask
DWORD CANReceiveMessages ( DWORD  device,
CAN_MESSAGE_EXT msg,
DWORD  numberOfMsg,
DWORD  timeout
)

Receive CAN messages

Parameters:
[in] device CAN Device ID
[out] msg pointer to CAN_MESSAGE_EXT array sufficient to hold numberOfMsg messages
[in] numberOfMsg Number of messages to wait for
[in] timeout Timeout value in milliseconds, use INFINITE to wait forever
Return values:
Number messages received, 0 = timeout
void CANReInitialise ( DWORD  device )

Reinitialise the CAN Controller/n Clears any unserviced interrupts.

Parameters:
[in] device CAN Device ID
Return values:
NA
BOOL CanReset ( DWORD  device )

Reset the CanChip and clear all buffers

Parameters:
[in] device CAN Device ID
Return values:
TRUE,: Success, FALSE: Error
BOOL CanSetBaudrate ( DWORD  device,
DWORD  baud
)

Set the Baudrate./n 1000, 800, 500, 250, 125, 100, 50, 20, 10 kBaud./n All other settings set the baud to 125 kBaud

Parameters:
[in] device CAN Device ID
[in] baud Baudrate
Return values:
TRUE,: Success, FALSE: Error
BOOL CanTransmitMessage ( DWORD  device,
CAN_MESSAGE_EXT msg
)

Send a CAN Message

Parameters:
[in] device CAN Device ID
[in] msg Pointer to a CAN message structure
Return values:
TRUE,: Success, FALSE: Error
BOOL CanWriteDescriptor ( DWORD  device,
DWORD  descr,
DWORD  mask
)

Write the Acceptance Code and Mask Registers./n Library is running in dual mode (AFM =0)./n For more information see the SJA1000 documentation.

Parameters:
[in] device CAN Device ID
[in] descr 32 bit acceptance code
[in] mask 32 bit acceptance mask
Return values:
TRUE,: Success, FALSE: Error
void DeInitSJA1000 ( DWORD  device )

Release CAN Controller

Parameters:
[in] device CAN Device ID
Return values:
NA
DWORD GetCanStatus ( DWORD  device )

Return the CAN Status

Parameters:
[in] device CAN Device ID
Return values:
0 = OK/n Test with CAN_ERROR and CAN_OVERRUN_HW Constants
DWORD InitSJA1000 ( DWORD  device,
DWORD  base,
DWORD  interruptGPIO,
DWORD  waterMark,
DWORD  bufferSize
)

Initialise CAN Controller

Parameters:
[in] device CAN Device ID
[in] base SJA1000 Chip Base Address
[in] interruptGPIO GPIO Number of the interrupt from the SJA1000
[in] waterMark Number of messages received before the library signals reception of messages.
[in] bufferSize Size of the receive buffer in CAN_MESSAGE_EXT messages
Return values:
0 = Success
1 = SoC not supported
-1 = Could not create ISR_CoM struct
-2 = Could not map Chip Base Address
-4 = Could not create Mutex
-5 = Could not enter reset mode
-6 = Could not enter normal mode
-7 = Could not create receive buffer
-8 = Could not create Interrupt Service Thread
-9 = Could not initialise GPIO
void PrintMessage ( CAN_MESSAGE_EXT msg )

Print the contents of the supplied CAN_MESSAGE_EXT message

Parameters:
[in] msg Pointer to a CAN_MESSAGE_EXT instance
Return values:
NA