Software Drivers

xcan.h File Reference

#include "xstatus.h"
#include "xcan_l.h"

Classes

struct  XCan_Config
struct  XCan

Defines

#define XCAN_H
#define XCan_IsTxDone(InstancePtr)
#define XCan_IsTxFifoFull(InstancePtr)
#define XCan_IsHighPriorityBufFull(InstancePtr)
#define XCan_IsRxEmpty(InstancePtr)
#define XCan_IsAcceptFilterBusy(InstancePtr)
#define XCan_CreateIdValue(StandardId, SubRemoteTransReq, IdExtension, ExtendedId, RemoteTransReq)
#define XCan_CreateDlcValue(DataLengCode)   (((DataLengCode) << XCAN_DLCR_DLC_SHIFT) & XCAN_DLCR_DLC_MASK)
CAN operation modes



#define XCAN_MODE_CONFIG   0x00000001
#define XCAN_MODE_NORMAL   0x00000002
#define XCAN_MODE_LOOPBACK   0x00000004
#define XCAN_MODE_SLEEP   0x00000008
Callback identifiers used as parameters to XCan_SetHandler()



#define XCAN_HANDLER_SEND   1
#define XCAN_HANDLER_RECV   2
#define XCAN_HANDLER_ERROR   3
#define XCAN_HANDLER_EVENT   4

Typedefs

typedef void(* XCan_SendRecvHandler )(void *CallBackRef)
typedef void(* XCan_ErrorHandler )(void *CallBackRef, u32 ErrorMask)
typedef void(* XCan_EventHandler )(void *CallBackRef, u32 Mask)

Functions

int XCan_Initialize (XCan *InstancePtr, u16 DeviceId)
int XCan_VmInitialize (XCan *InstancePtr, u16 DeviceId, u32 VirtAddr)
void XCan_Reset (XCan *InstancePtr)
u8 XCan_GetMode (XCan *InstancePtr)
void XCan_EnterMode (XCan *InstancePtr, u8 OperationMode)
u32 XCan_GetStatus (XCan *InstancePtr)
void XCan_GetBusErrorCounter (XCan *InstancePtr, u8 *RxErrorCount, u8 *TxErrorCount)
u32 XCan_GetBusErrorStatus (XCan *InstancePtr)
void XCan_ClearBusErrorStatus (XCan *InstancePtr, u32 Mask)
int XCan_Send (XCan *InstancePtr, u32 *FramePtr)
int XCan_Recv (XCan *InstancePtr, u32 *FramePtr)
int XCan_SendHighPriority (XCan *InstancePtr, u32 *FramePtr)
void XCan_AcceptFilterEnable (XCan *InstancePtr, u32 FilterIndexes)
void XCan_AcceptFilterDisable (XCan *InstancePtr, u32 FilterIndexes)
u32 XCan_AcceptFilterGetEnabled (XCan *InstancePtr)
int XCan_AcceptFilterSet (XCan *InstancePtr, u32 FilterIndex, u32 MaskValue, u32 IdValue)
void XCan_AcceptFilterGet (XCan *InstancePtr, u32 FilterIndex, u32 *MaskValue, u32 *IdValue)
XCan_ConfigXCan_LookupConfig (u16 DeviceId)
XCan_ConfigXCan_GetConfig (unsigned int InstanceIndex)
int XCan_SetBaudRatePrescaler (XCan *InstancePtr, u8 Prescaler)
u8 XCan_GetBaudRatePrescaler (XCan *InstancePtr)
int XCan_SetBitTiming (XCan *InstancePtr, u8 SyncJumpWidth, u8 TimeSegment2, u8 TimeSegment1)
void XCan_GetBitTiming (XCan *InstancePtr, u8 *SyncJumpWidth, u8 *TimeSegment2, u8 *TimeSegment1)
int XCan_SelfTest (XCan *InstancePtr)
void XCan_InterruptEnable (XCan *InstancePtr, u32 Mask)
void XCan_InterruptDisable (XCan *InstancePtr, u32 Mask)
u32 XCan_InterruptGetEnabled (XCan *InstancePtr)
u32 XCan_InterruptGetStatus (XCan *InstancePtr)
void XCan_InterruptClear (XCan *InstancePtr, u32 Mask)
void XCan_IntrHandler (void *InstancePtr)
int XCan_SetHandler (XCan *InstancePtr, u32 HandlerType, void *CallBackFunc, void *CallBackRef)

Detailed Description


Define Documentation

#define XCan_CreateDlcValue ( DataLengCode   )     (((DataLengCode) << XCAN_DLCR_DLC_SHIFT) & XCAN_DLCR_DLC_MASK)

This macro calculates value for Data Length Code register given Data Length Code value.

Parameters:
DataLengCode indicates Data Length Code value.
Returns:
Value that can be assigned to Data Length Code register.
Note:
C-Style signature: u32 XCan_CreateDlcValue(u32 DataLengCode);

Read the CAN specification for meaning of Data Length Code.

#define XCan_CreateIdValue ( StandardId,
SubRemoteTransReq,
IdExtension,
ExtendedId,
RemoteTransReq   ) 
Value:
((((StandardId) << XCAN_IDR_ID1_SHIFT) & XCAN_IDR_ID1_MASK) | \
        (((SubRemoteTransReq) << XCAN_IDR_SRR_SHIFT) & XCAN_IDR_SRR_MASK) | \
        (((IdExtension) << XCAN_IDR_IDE_SHIFT) & XCAN_IDR_IDE_MASK) | \
        (((ExtendedId) << XCAN_IDR_ID2_SHIFT) & XCAN_IDR_ID2_MASK) | \
        ((RemoteTransReq) & XCAN_IDR_RTR_MASK))

This macro calculates CAN message identifier value given identifier field values.

Parameters:
StandardId contains Standard Message ID value.
SubRemoteTransReq contains Substitute Remote Transmission Request value.
IdExtension contains Identifier Extension value.
ExtendedId contains Extended Message ID value.
RemoteTransReq contains Remote Transmission Request value.
Returns:
Message Identifier value.
Note:
C-Style signature: u32 XCan_CreateIdValue(u32 StandardId, u32 SubRemoteTransReq, u32 IdExtension, u32 ExtendedId, u32 RemoteTransReq);

Read the CAN specification for meaning of each parameter.

#define XCAN_H
#define XCAN_HANDLER_ERROR   3

Handler type for error interrupt

#define XCAN_HANDLER_EVENT   4

Handler type for all other interrupts

#define XCAN_HANDLER_RECV   2

Handler type for frame reception interrupt

#define XCAN_HANDLER_SEND   1

Handler type for frame sending interrupt

#define XCan_IsAcceptFilterBusy ( InstancePtr   ) 
Value:
((XCan_ReadReg(((InstancePtr)->BaseAddress), XCAN_SR_OFFSET) & \
                XCAN_SR_ACFBSY_MASK) ? TRUE : FALSE)

This macro checks if the CAN device is ready for the driver to change Acceptance Filter Identifier Registers (AFIR) and Acceptance Filter Mask Registers (AFMR).

AFIR and AFMR for a filter are changeable only after the filter is disabled and this routine returns FALSE.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
Returns:
  • TRUE if the device is busy and NOT ready to accept writes to AFIR and AFMR.
  • FALSE if the device is ready to accept writes to AFIR and AFMR.
Note:
C-Style signature: int XCan_IsAcceptFilterBusy(XCan *InstancePtr);
#define XCan_IsHighPriorityBufFull ( InstancePtr   ) 
Value:
((XCan_ReadReg(((InstancePtr)->BaseAddress), XCAN_SR_OFFSET) & \
        XCAN_SR_TXBFLL_MASK) ? TRUE : FALSE)

This macro checks if the Transmission High Priority Buffer is full.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
Returns:
  • TRUE if TX High Priority Buffer is full.
  • FALSE if TX High Priority Buffer is not full.
Note:
C-Style signature: int XCan_IsHighPriorityBufFull(XCan *InstancePtr);
#define XCan_IsRxEmpty ( InstancePtr   ) 
Value:
((XCan_ReadReg(((InstancePtr)->BaseAddress), XCAN_ISR_OFFSET) & \
                XCAN_IXR_RXNEMP_MASK) ? FALSE : TRUE)

This macro checks if the receive FIFO is empty.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
Returns:
  • TRUE if RX FIFO is empty.
  • FALSE if RX FIFO is not empty.
Note:
C-Style signature: int XCan_IsRxEmpty(XCan *InstancePtr);
#define XCan_IsTxDone ( InstancePtr   ) 
Value:
((XCan_ReadReg(((InstancePtr)->BaseAddress), XCAN_ISR_OFFSET) & \
                XCAN_IXR_TXOK_MASK) ? TRUE : FALSE)

This macro checks if the transmission is complete.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
Returns:
  • TRUE if the transmission is done (completed).
  • FALSE if the transmission is not completed.
Note:
C-Style signature: int XCan_IsTxDone(XCan *InstancePtr);
#define XCan_IsTxFifoFull ( InstancePtr   ) 
Value:
((XCan_ReadReg(((InstancePtr)->BaseAddress), XCAN_SR_OFFSET) & \
                XCAN_SR_TXFLL_MASK) ? TRUE : FALSE)

This macro checks if the transmission FIFO is full.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
Returns:
  • TRUE if TX FIFO is full.
  • FALSE if TX FIFO is not full.
Note:
C-Style signature: int XCan_IsTxFifoFull(XCan *InstancePtr);
#define XCAN_MODE_CONFIG   0x00000001

Configuration mode

#define XCAN_MODE_LOOPBACK   0x00000004

Loop Back mode

#define XCAN_MODE_NORMAL   0x00000002

Normal mode

#define XCAN_MODE_SLEEP   0x00000008

Sleep mode


Typedef Documentation

typedef void(* XCan_ErrorHandler)(void *CallBackRef, u32 ErrorMask)

Callback type for error interrupt.

Parameters:
CallBackRef is a callback reference passed in by the upper layer when setting the callback functions, and passed back to the upper layer when the callback is invoked.
ErrorMask is a bit mask indicating the cause of the error. Its value equals 'OR'ing one or more XCAN_ESR_* values defined in xcan_l.h
typedef void(* XCan_EventHandler)(void *CallBackRef, u32 Mask)

Callback type for all kinds of interrupts except sending frame interrupt, receiving frame interrupt, and error interrupt.

Parameters:
CallBackRef is a callback reference passed in by the upper layer when setting the callback functions, and passed back to the upper layer when the callback is invoked.
Mask is a bit mask indicating the pending interrupts. Its value equals 'OR'ing one or more XCAN_IXR_* defined in xcan_l.h
typedef void(* XCan_SendRecvHandler)(void *CallBackRef)

Callback type for frame sending and reception interrupts.

Parameters:
CallBackRef is a callback reference passed in by the upper layer when setting the callback functions, and passed back to the upper layer when the callback is invoked.

Function Documentation

void XCan_AcceptFilterDisable ( XCan InstancePtr,
u32  FilterIndexes 
)

This routine disables individual acceptance filters. Up to 4 filters could be disabled. If all acceptance filters are disabled then all received frames are stored in the RX FIFO.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
FilterIndexes specifies which filter(s) to disable. Use any XCAN_AFR_UAF*_MASK to disable one filter, and "Or" multiple XCAN_AFR_UAF*_MASK values if multiple filters need to be disabled. Any filter not specified in this parameter will keep its previous enable/disable setting. If all acceptance filters are disabled then all received frames are stored in the RX FIFO.
Returns:
None.
Note:

Acceptance Filter Register is an optional register in Xilinx CAN device. If it is NOT existing in the device, this function should NOT be used. Calling this function in this case will cause an assertion failure.

void XCan_AcceptFilterEnable ( XCan InstancePtr,
u32  FilterIndexes 
)

This routine enables individual acceptance filters. Up to 4 filters could be enabled.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
FilterIndexes specifies which filter(s) to enable. Use any XCAN_AFR_UAF*_MASK to enable one filter, and "Or" multiple XCAN_AFR_UAF*_MASK values if multiple filters need to be enabled. Any filter not specified in this parameter will keep its previous enable/disable setting.
Returns:
None.
Note:

Acceptance Filter Register is an optional register in Xilinx CAN device. If it is NOT existing in the device, this function should NOT be used. Calling this function in this case will cause an assertion failure.

void XCan_AcceptFilterGet ( XCan InstancePtr,
u32  FilterIndex,
u32 *  MaskValue,
u32 *  IdValue 
)

This function reads the values of the Acceptance Filter Mask and ID Register for the specified Acceptance Filter. Use XCAN_IDR_* defined in xcan_l.h to interpret the values. Read xcan.h and device specification for details.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
FilterIndex defines which Acceptance Filter Mask Register to get Mask and ID from. Use any single XCAN_FILTER_* value.
MaskValue will store the Mask value read from the chosen Acceptance Filter Mask Register after this function returns.
IdValue will store the ID value read from the chosen Acceptance Filter ID Register after this function returns.
Returns:
None.
Note:

Acceptance Filter Mask and ID Registers are optional registers in Xilinx CAN device. If they are NOT existing in the device, this function should NOT be used. Calling this function in this case will cause an assertion failure.

u32 XCan_AcceptFilterGetEnabled ( XCan InstancePtr  ) 

This function returns enabled acceptance filters. Use XCAN_AFR_UAF*_MASK defined in xcan_l.h to interpret the returned value. If no acceptance filters are enabled then all received frames are stored in the RX FIFO.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
Returns:
The value stored in Acceptance Filter Register.
Note:

Acceptance Filter Register is an optional register in Xilinx CAN device. If it is NOT existing in the device, this function should NOT be used. Calling this function in this case will cause an assertion failure.

int XCan_AcceptFilterSet ( XCan InstancePtr,
u32  FilterIndex,
u32  MaskValue,
u32  IdValue 
)

This function sets values to the Acceptance Filter Mask Register (AFMR) and Acceptance Filter ID Register (AFIR) for the specified Acceptance Filter. Use XCAN_IDR_* defined in xcan_l.h to create the values to set the filter. Read xcan.h and device specification for details.

This function should be called only after:

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
FilterIndex defines which Acceptance Filter Mask and ID Register to set. Use any single XCAN_AFR_UAF*_MASK value.
MaskValue is the value to write to the chosen Acceptance Filter Mask Register.
IdValue is the value to write to the chosen Acceptance Filter ID Register.
Returns:
  • XST_SUCCESS if the values were set successfully.
  • XST_FAILURE if the given filter was not disabled, or the CAN device was not ready to accept writes to AFMR and AFIR.
Note:

Acceptance Filter Mask and ID Registers are optional registers in Xilinx CAN device. If they are NOT existing in the device, this function should NOT be used. Calling this function in this case will cause an assertion failure.

void XCan_ClearBusErrorStatus ( XCan InstancePtr,
u32  Mask 
)

This function clears Error Status bit(s) previously set in Error Status Register (ESR). Use the XCAN_ESR_* constants defined in xcan_l.h to create the value to pass in. If a bit was cleared in Error Status Register before this function is called, it will not be touched.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
Mask is he 32-bit mask used to clear bits in Error Status Register. Multiple XCAN_ESR_* values could be 'OR'ed to clear multiple bits
Note:
None.
void XCan_EnterMode ( XCan InstancePtr,
u8  OperationMode 
)

This function allows the CAN device to enter one of the following operation modes:

  • Configuration Mode: Pass in parameter XCAN_MODE_CONFIG
  • Sleep Mode: Pass in parameter XCAN_MODE_SLEEP
  • Normal Mode: Pass in parameter XCAN_MODE_NORMAL
  • Loop Back Mode: Pass in parameter XCAN_MODE_LOOPBACK.

Read xcan.h and device specification for detailed description of each operation mode.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
OperationMode specify which operation mode to enter. Valid value is any of XCAN_MODE_* defined in xcan.h. Please note no multiple modes could be entered at the same time.
Returns:
None.
Note:

This function does NOT ensure CAN device enters the specified operation mode before returns the control to the caller. The caller is responsible for checking current operation mode using XCan_GetMode().

u8 XCan_GetBaudRatePrescaler ( XCan InstancePtr  ) 

This routine gets Baud Rate Prescaler value. The system clock for the CAN controller is divided by (Prescaler + 1) to generate the quantum clock needed for sampling and synchronization. Read the device specification for details.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
Returns:
Current used Baud Rate Prescaler value. The value's range is from 0 to 255.
Note:
None.
void XCan_GetBitTiming ( XCan InstancePtr,
u8 *  SyncJumpWidth,
u8 *  TimeSegment2,
u8 *  TimeSegment1 
)

This routine gets Bit time. Time segment 1, Time segment 2 and Synchronization Jump Width values are read in this function. According to device specification, the actual value of each of these fields is one more than the value read. Read the device specification for details.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
SyncJumpWidth will store the Synchronization Jump Width value after this function returns. Its value ranges from 0 to 3.
TimeSegment2 will store the Time Segment 2 value after this function returns. Its value ranges from 0 to 7.
TimeSegment1 will store the Time Segment 1 value after this function returns. Its value ranges from 0 to 15.
Returns:
None.
Note:
None.
void XCan_GetBusErrorCounter ( XCan InstancePtr,
u8 *  RxErrorCount,
u8 *  TxErrorCount 
)

This function reads Receive and Transmit error counters.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
RxErrorCount will contain Receive Error Counter value after this function returns.
TxErrorCount will contain Transmit Error Counter value after this function returns.
Returns:
None.
Note:
None.
u32 XCan_GetBusErrorStatus ( XCan InstancePtr  ) 

This function reads Error Status value from Error Status Register (ESR). Use the XCAN_ESR_* constants defined in xcan_l.h to interpret the returned value.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
Returns:
The 32-bit value read from Error Status Register.
Note:
None.
XCan_Config* XCan_GetConfig ( unsigned int  InstanceIndex  ) 

This function looks for the device configuration based on the device index. The table XCan_ConfigTable[] contains the configuration information for each device in the system.

Parameters:
InstanceIndex is a 0-based integer indexing all CAN devices in the system.
Returns:
A pointer to the configuration table entry corresponding to the given device ID, or NULL if no match is found.
Note:
None.
u8 XCan_GetMode ( XCan InstancePtr  ) 

This routine returns current operation mode the CAN device is in.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
Returns:
  • XCAN_MODE_CONFIG if the device is in Configuration Mode.
  • XCAN_MODE_SLEEP if the device is in Sleep Mode.
  • XCAN_MODE_NORMAL if the device is in Normal Mode.
  • XCAN_MODE_LOOPBACK if the device is in Loop Back Mode.
Note:
None.
u32 XCan_GetStatus ( XCan InstancePtr  ) 

This function returns Status value from Status Register (SR). Use the XCAN_SR_* constants defined in xcan_l.h to interpret the returned value.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
Returns:
The 32-bit value read from Status Register.
Note:
None.
int XCan_Initialize ( XCan InstancePtr,
u16  DeviceId 
)

This routine initializes a specific XCan instance/driver. This function should only be used when no Virtual Memory support is needed. To use virtual memory, the caller should invoke XCan_VmInitialize(). See the description of XCan_VmInitialize() for detailed information.

This initialization entails:

  • Search for device configuration given the device ID.
  • Initialize Base Address field of the XCan structure using the device address in the found device configuration.
  • Populate all other data fields in the XCan structure
  • Reset the device.
Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
DeviceId is the unique ID of the device controlled by this XCan instance. Passing in a device ID associates the generic XCan instance to a specific device, as chosen by the caller or application developer.
Returns:
  • XST_SUCCESS if initialization was successful
  • XST_DEVICE_NOT_FOUND if device configuration information was not found for a device with the supplied device ID.
Note:
None.
void XCan_InterruptClear ( XCan InstancePtr,
u32  Mask 
)

This function clears interrupt(s). Every bit set in Interrupt Status Register indicates that a specific type of interrupt is occurring, and this function clears one or more interrupts by writing a bit mask to Interrupt Clear Register.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
Mask is the mask to clear. Bit positions of 1 will be cleared. Bit positions of 0 will not change the previous interrupt status. This mask is formed by OR'ing XCAN_IXR_* bits defined in xcan_l.h.
Note:
None.
void XCan_InterruptDisable ( XCan InstancePtr,
u32  Mask 
)

This routine disables interrupt(s). Use the XCAN_IXR_* constants defined in xcan_l.h to create the bit-mask to disable interrupt(s).

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
Mask is the mask to disable. Bit positions of 1 will be disabled. Bit positions of 0 will keep the previous setting. This mask is formed by OR'ing XCAN_IXR_* bits defined in xcan_l.h.
Returns:
None.
Note:
None.
void XCan_InterruptEnable ( XCan InstancePtr,
u32  Mask 
)

This routine enables interrupt(s). Use the XCAN_IXR_* constants defined in xcan_l.h to create the bit-mask to enable interrupts.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
Mask is the mask to enable. Bit positions of 1 will be enabled. Bit positions of 0 will keep the previous setting. This mask is formed by OR'ing XCAN_IXR_* bits defined in xcan_l.h.
Returns:
None.
Note:
None.
u32 XCan_InterruptGetEnabled ( XCan InstancePtr  ) 

This routine returns enabled interrupt(s). Use the XCAN_IXR_* constants defined in xcan_l.h to interpret the returned value.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
Returns:
Enabled interrupt(s) in a 32-bit format.
Note:
None.
u32 XCan_InterruptGetStatus ( XCan InstancePtr  ) 

This routine returns interrupt status read from Interrupt Status Register. Use the XCAN_IXR_* constants defined in xcan_l.h to interpret the returned value.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
Returns:
The value stored in Interrupt Status Register.
Note:
None.
void XCan_IntrHandler ( void *  InstancePtr  ) 

This routine is the interrupt handler for the CAN driver.

This handler reads the interrupt status from the ISR, determines the source of the interrupts, calls according callbacks, and finally clears the interrupts.

Application beyond this driver is responsible for providing callbacks to handle interrupts and installing the callbacks using XCan_SetHandler() during initialization phase. An example delivered with this driver demonstrates how this could be done.

Parameters:
InstancePtr is a pointer to the XCan instance that just interrupted.
Returns:
None.
Note:
None.
XCan_Config* XCan_LookupConfig ( u16  DeviceId  ) 

This function looks for the device configuration based on the unique device ID. The table XCan_ConfigTable[] contains the configuration information for each device in the system.

Parameters:
DeviceId is the unique device ID of the device being looked up.
Returns:
A pointer to the configuration table entry corresponding to the given device ID, or NULL if no match is found.
Note:
None.
int XCan_Recv ( XCan InstancePtr,
u32 *  FramePtr 
)

This function receives a CAN Frame. This function first checks if RX FIFO is empty, if not, it then reads a frame from the RX FIFO into the given buffer. This function returns error code immediately if there is no frame in the RX FIFO.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
FramePtr is a pointer to a 32-bit aligned buffer where the CAN frame to be written.
Returns:
  • XST_SUCCESS if RX FIFO was not empty and a frame was read from RX FIFO successfully and written into the given buffer;
  • XST_NO_DATA if there is no frame to be received from the FIFO
Note:
None.
void XCan_Reset ( XCan InstancePtr  ) 

This function resets the CAN device. Calling this function resets the device immediately, and any pending transmission or reception is terminated at once. Both Object Layer and Transfer Layer are reset. This function does not reset the Physical Layer. All registers are reset to the default values, and no previous status will be restored. TX FIFO, RX FIFO and TX High Priority Buffer are also reset.

When a reset is required due to an internal error, the driver notifies the upper layer software of this need through the error status code or interrupts The upper layer software is responsible for calling this Reset function and then re-configuring the device.

The CAN device will be in Configuration Mode immediately after this function returns.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
Returns:
None.
Note:
None.
int XCan_SelfTest ( XCan InstancePtr  ) 

This function runs a self-test on the CAN driver/device. The test resets the device, sets up the Loop Back mode, sends a standard frame, receives the frame, verifies the contents, and resets the device again.

Note that this is a destructive test in that resets of the device are performed. Refer to the device specification for the device status after the reset operation.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
Returns:
  • XST_SUCCESS if the self-test passed. i.e., the frame received via the internal loop back has the same contents as the sent frame.
  • XST_FAILURE Otherwise.
Note:

If the CAN device does not work properly, this function may enter an infinite loop and will never return to the caller.

If XST_FAILURE is returned, the device is not reset so that the caller could have a chance to check reason(s) causing the failure.

int XCan_Send ( XCan InstancePtr,
u32 *  FramePtr 
)

This function sends a CAN Frame. This function first checks if TX FIFO is full. If not, it then writes the given frame into the TX FIFO; otherwise, it returns error code immediately. This function does not wait for the given frame being sent to CAN bus.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
FramePtr is a pointer to a 32-bit aligned buffer containing the CAN frame to be sent.
Returns:
  • XST_SUCCESS if TX FIFO was not full and the given frame was written into the FIFO;
  • XST_FIFO_NO_ROOM if there is no room in the TX FIFO for the given frame
Note:
None.
int XCan_SendHighPriority ( XCan InstancePtr,
u32 *  FramePtr 
)

This routine sends a CAN High Priority frame. This function first checks if TX High Priority Buffer is empty. If yes, it then writes the given frame into the Buffer. If not, This function returns immediately. This function does not wait for the given frame being sent to CAN bus.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
FramePtr is a pointer to a 32-bit aligned buffer containing the CAN High Priority frame to be sent.
Returns:
  • XST_SUCCESS if TX High Priority Buffer was not full and the given frame was written into the buffer;
  • XST_FIFO_NO_ROOM if there is no room in the TX High Priority Buffer for this frame.
Note:

If the frame needs to be sent immediately and not delayed by processor's interrupts handling, the caller should disable interrupt at processor level before invoking this function.

int XCan_SetBaudRatePrescaler ( XCan InstancePtr,
u8  Prescaler 
)

This routine sets Baud Rate Prescaler value. The system clock for the CAN controller is divided by (Prescaler + 1) to generate the quantum clock needed for sampling and synchronization. Read the device specification for details.

Baud Rate Prescaler could be set only after CAN device entered Configuration Mode. So please call XCan_EnterMode() to enter Configuration Mode before using this function.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
Prescaler is the value to set. Valid values are from 0 to 255.
Returns:
  • XST_SUCCESS if the Baud Rate Prescaler value is set successfully.
  • XST_FAILURE if CAN device is not in Configuration Mode.
Note:
None.
int XCan_SetBitTiming ( XCan InstancePtr,
u8  SyncJumpWidth,
u8  TimeSegment2,
u8  TimeSegment1 
)

This routine sets Bit time. Time segment 1, Time segment 2 and Synchronization Jump Width are set in this function. Device specification requires the values passed into this function be one less than the actual values of these fields. Read the device specification for details.

Bit time could be set only after CAN device entered Configuration Mode. Please call XCan_EnterMode() to enter Configuration Mode before using this function.

Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
SyncJumpWidth is the Synchronization Jump Width value to set. Valid values are from 0 to 3.
TimeSegment2 is the Time Segment 2 value to set. Valid values are from 0 to 7.
TimeSegment1 is the Time Segment 1 value to set. Valid values are from 0 to 15.
Returns:
  • XST_SUCCESS if the Bit time is set successfully.
  • XST_FAILURE if CAN device is not in Configuration Mode.
  • XST_INVALID_PARAM if any value of SyncJumpWidth, TimeSegment2 and TimeSegment1 is invalid.
Note:
None.
int XCan_SetHandler ( XCan InstancePtr,
u32  HandlerType,
void *  CallBackFunc,
void *  CallBackRef 
)

This routine installs an asynchronous callback function for the given HandlerType:

 HandlerType              Callback Function Type
 -----------------------  ---------------------------
 XCAN_HANDLER_SEND        XCan_SendRecvHandler
 XCAN_HANDLER_RECV        XCan_SendRecvHandler
 XCAN_HANDLER_ERROR       XCan_ErrorHandler
 XCAN_HANDLER_EVENT       XCan_EventHandler
 HandlerType              Invoked by this driver when:
 -----------------------  --------------------------------------------------
 XCAN_HANDLER_SEND        A frame transmitted by a call to
                          XCan_Send() has been sent successfully.
 XCAN_HANDLER_RECV        A frame has been received and is sitting in
                          the RX FIFO.
 XCAN_HANDLER_ERROR       An error interrupt is occurring.
 XCAN_HANDLER_EVENT       Any other kind of interrupt is occurring.
 
Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
HandlerType specifies which handler is to be attached.
CallBackFunc is the address of the callback function.
CallBackRef is a user data item that will be passed to the callback function when it is invoked.
Returns:
  • XST_SUCCESS when handler is installed.
  • XST_INVALID_PARAM when HandlerType is invalid.
Note:
Invoking this function for a handler that already has been installed replaces it with the new handler.
int XCan_VmInitialize ( XCan InstancePtr,
u16  DeviceId,
u32  VirtAddr 
)

This routine initializes of a specific XCan instance/driver. This function should only be used if Virtual Memory support is necessary. The caller is responsible for calculating the correct device base address in Virtual memory address space and passing it into this function.

This initialization entails:

  • Search for device configuration given the device ID.
  • Initialize Base Address field of the XCan structure using the given virtual address parameter value.
  • Populate all other data fields in the XCan structure.
  • Reset the device.
Parameters:
InstancePtr is a pointer to the XCan instance to be worked on.
DeviceId is the unique ID of the device controlled by this XCan instance. Passing in a device ID associates the generic XCan instance to a specific device, as chosen by the caller or application developer.
VirtAddr is the device base address in the virtual memory address space. The caller is responsible for keeping the address mapping from VirtAddr to the device physical base address unchanged once this function is invoked. Unexpected errors may occur if the address mapping changes after this function is called.
Returns:
  • XST_SUCCESS if initialization was successful
  • XST_DEVICE_NOT_FOUND if device configuration information was not found for a device with the supplied device ID.
Note:
None.