Software Drivers

xcanps.h File Reference

#include "xstatus.h"
#include "xcanps_hw.h"

Classes

struct  XCanPs_Config
struct  XCanPs

Defines

#define XCANPS_H
#define XCanPs_IsTxDone(InstancePtr)
#define XCanPs_IsTxFifoFull(InstancePtr)
#define XCanPs_IsHighPriorityBufFull(InstancePtr)
#define XCanPs_IsRxEmpty(InstancePtr)
#define XCanPs_IsAcceptFilterBusy(InstancePtr)
#define XCanPs_CreateIdValue(StandardId, SubRemoteTransReq, IdExtension, ExtendedId, RemoteTransReq)
#define XCanPs_CreateDlcValue(DataLengCode)   (((DataLengCode) << XCANPS_DLCR_DLC_SHIFT) & XCANPS_DLCR_DLC_MASK)
#define XCanPs_ClearTimestamp(InstancePtr)
CAN operation modes



#define XCANPS_MODE_CONFIG   0x00000001
#define XCANPS_MODE_NORMAL   0x00000002
#define XCANPS_MODE_LOOPBACK   0x00000004
#define XCANPS_MODE_SLEEP   0x00000008
#define XCANPS_MODE_SNOOP   0x00000010
Callback identifiers used as parameters to XCanPs_SetHandler()



#define XCANPS_HANDLER_SEND   1
#define XCANPS_HANDLER_RECV   2
#define XCANPS_HANDLER_ERROR   3
#define XCANPS_HANDLER_EVENT   4

Typedefs

typedef void(* XCanPs_SendRecvHandler )(void *CallBackRef)
typedef void(* XCanPs_ErrorHandler )(void *CallBackRef, u32 ErrorMask)
typedef void(* XCanPs_EventHandler )(void *CallBackRef, u32 Mask)

Functions

int XCanPs_CfgInitialize (XCanPs *InstancePtr, XCanPs_Config *ConfigPtr, u32 EffectiveAddr)
void XCanPs_Reset (XCanPs *InstancePtr)
u8 XCanPs_GetMode (XCanPs *InstancePtr)
void XCanPs_EnterMode (XCanPs *InstancePtr, u8 OperationMode)
u32 XCanPs_GetStatus (XCanPs *InstancePtr)
void XCanPs_GetBusErrorCounter (XCanPs *InstancePtr, u8 *RxErrorCount, u8 *TxErrorCount)
u32 XCanPs_GetBusErrorStatus (XCanPs *InstancePtr)
void XCanPs_ClearBusErrorStatus (XCanPs *InstancePtr, u32 Mask)
int XCanPs_Send (XCanPs *InstancePtr, u32 *FramePtr)
int XCanPs_Recv (XCanPs *InstancePtr, u32 *FramePtr)
int XCanPs_SendHighPriority (XCanPs *InstancePtr, u32 *FramePtr)
void XCanPs_AcceptFilterEnable (XCanPs *InstancePtr, u32 FilterIndexes)
void XCanPs_AcceptFilterDisable (XCanPs *InstancePtr, u32 FilterIndexes)
u32 XCanPs_AcceptFilterGetEnabled (XCanPs *InstancePtr)
int XCanPs_AcceptFilterSet (XCanPs *InstancePtr, u32 FilterIndex, u32 MaskValue, u32 IdValue)
void XCanPs_AcceptFilterGet (XCanPs *InstancePtr, u32 FilterIndex, u32 *MaskValue, u32 *IdValue)
int XCanPs_SetBaudRatePrescaler (XCanPs *InstancePtr, u8 Prescaler)
u8 XCanPs_GetBaudRatePrescaler (XCanPs *InstancePtr)
int XCanPs_SetBitTiming (XCanPs *InstancePtr, u8 SyncJumpWidth, u8 TimeSegment2, u8 TimeSegment1)
void XCanPs_GetBitTiming (XCanPs *InstancePtr, u8 *SyncJumpWidth, u8 *TimeSegment2, u8 *TimeSegment1)
int XCanPs_SetRxIntrWatermark (XCanPs *InstancePtr, u8 Threshold)
u8 XCanPs_GetRxIntrWatermark (XCanPs *InstancePtr)
int XCanPs_SelfTest (XCanPs *InstancePtr)
void XCanPs_IntrEnable (XCanPs *InstancePtr, u32 Mask)
void XCanPs_IntrDisable (XCanPs *InstancePtr, u32 Mask)
u32 XCanPs_IntrGetEnabled (XCanPs *InstancePtr)
u32 XCanPs_IntrGetStatus (XCanPs *InstancePtr)
void XCanPs_IntrClear (XCanPs *InstancePtr, u32 Mask)
void XCanPs_IntrHandler (void *InstancePtr)
int XCanPs_SetHandler (XCanPs *InstancePtr, u32 HandlerType, void *CallBackFunc, void *CallBackRef)
XCanPs_ConfigXCanPs_LookupConfig (u16 DeviceId)

Detailed Description


Define Documentation

#define XCanPs_ClearTimestamp ( InstancePtr   ) 
Value:
XCanPs_WriteReg((InstancePtr)->CanConfig.BaseAddr,              \
                                XCANPS_TCR_OFFSET, XCANPS_TCR_CTS_MASK)

This macro clears the timestamp in the Timestamp Control Register.

Parameters:
InstancePtr is a pointer to the XCanPs instance.
Returns:
None.
Note:
C-Style signature: void XCanPs_ClearTimestamp(XCanPs *InstancePtr);
#define XCanPs_CreateDlcValue ( DataLengCode   )     (((DataLengCode) << XCANPS_DLCR_DLC_SHIFT) & XCANPS_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 XCanPs_CreateDlcValue(u32 DataLengCode);

Read the CAN specification for meaning of Data Length Code.

#define XCanPs_CreateIdValue ( StandardId,
SubRemoteTransReq,
IdExtension,
ExtendedId,
RemoteTransReq   ) 
Value:
((((StandardId) << XCANPS_IDR_ID1_SHIFT) & XCANPS_IDR_ID1_MASK) |       \
 (((SubRemoteTransReq) << XCANPS_IDR_SRR_SHIFT) & XCANPS_IDR_SRR_MASK)|\
 (((IdExtension) << XCANPS_IDR_IDE_SHIFT) & XCANPS_IDR_IDE_MASK) |      \
 (((ExtendedId) << XCANPS_IDR_ID2_SHIFT) & XCANPS_IDR_ID2_MASK) |       \
 ((RemoteTransReq) & XCANPS_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 XCanPs_CreateIdValue(u32 StandardId, u32 SubRemoteTransReq, u32 IdExtension, u32 ExtendedId, u32 RemoteTransReq);

Read the CAN specification for meaning of each parameter.

#define XCANPS_H
#define XCANPS_HANDLER_ERROR   3

Handler type for error interrupt

#define XCANPS_HANDLER_EVENT   4

Handler type for all other interrupts

#define XCANPS_HANDLER_RECV   2

Handler type for frame reception interrupt

#define XCANPS_HANDLER_SEND   1

Handler type for frame sending interrupt

#define XCanPs_IsAcceptFilterBusy ( InstancePtr   ) 
Value:
((XCanPs_ReadReg(((InstancePtr)->CanConfig.BaseAddr),   \
                XCANPS_SR_OFFSET) & XCANPS_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. The filter can be disabled using the XCanPs_AcceptFilterDisable function.

Use the XCanPs_Accept_* functions for configuring the acceptance filters.

Parameters:
InstancePtr is a pointer to the XCanPs instance.
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 XCanPs_IsAcceptFilterBusy(XCanPs *InstancePtr);
#define XCanPs_IsHighPriorityBufFull ( InstancePtr   ) 
Value:
((XCanPs_ReadReg(((InstancePtr)->CanConfig.BaseAddr),   \
                XCANPS_SR_OFFSET) & XCANPS_SR_TXBFLL_MASK) ? TRUE : FALSE)

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

Parameters:
InstancePtr is a pointer to the XCanPs instance.
Returns:
  • TRUE if the TX High Priority Buffer is full.
  • FALSE if the TX High Priority Buffer is NOT full.
Note:
C-Style signature: int XCanPs_IsHighPriorityBufFull(XCanPs *InstancePtr);
#define XCanPs_IsRxEmpty ( InstancePtr   ) 
Value:
((XCanPs_ReadReg(((InstancePtr)->CanConfig.BaseAddr),   \
                XCANPS_ISR_OFFSET) & XCANPS_IXR_RXNEMP_MASK) ? FALSE : TRUE)

This macro checks if the receive FIFO is empty.

Parameters:
InstancePtr is a pointer to the XCanPs instance.
Returns:
  • TRUE if RX FIFO is empty.
  • FALSE if the RX FIFO is NOT empty.
Note:
C-Style signature: int XCanPs_IsRxEmpty(XCanPs *InstancePtr);
#define XCanPs_IsTxDone ( InstancePtr   ) 
Value:
((XCanPs_ReadReg(((InstancePtr)->CanConfig.BaseAddr),           \
                XCANPS_ISR_OFFSET) & XCANPS_IXR_TXOK_MASK) ? TRUE : FALSE)

This macro checks if the transmission is complete.

Parameters:
InstancePtr is a pointer to the XCanPs instance.
Returns:
  • TRUE if the transmission is done.
  • FALSE if the transmission is not done.
Note:
C-Style signature: int XCanPs_IsTxDone(XCanPs *InstancePtr);
#define XCanPs_IsTxFifoFull ( InstancePtr   ) 
Value:
((XCanPs_ReadReg(((InstancePtr)->CanConfig.BaseAddr),   \
                XCANPS_SR_OFFSET) & XCANPS_SR_TXFLL_MASK) ? TRUE : FALSE)

This macro checks if the transmission FIFO is full.

Parameters:
InstancePtr is a pointer to the XCanPs instance.
Returns:
  • TRUE if TX FIFO is full.
  • FALSE if the TX FIFO is NOT full.
Note:
C-Style signature: int XCanPs_IsTxFifoFull(XCanPs *InstancePtr);
#define XCANPS_MODE_CONFIG   0x00000001

Configuration mode

#define XCANPS_MODE_LOOPBACK   0x00000004

Loop Back mode

#define XCANPS_MODE_NORMAL   0x00000002

Normal mode

#define XCANPS_MODE_SLEEP   0x00000008

Sleep mode

#define XCANPS_MODE_SNOOP   0x00000010

Snoop mode


Typedef Documentation

typedef void(* XCanPs_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 XCANPS_ESR_* values defined in xcanps_hw.h
typedef void(* XCanPs_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 XCANPS_IXR_* defined in xcanps_hw.h
typedef void(* XCanPs_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 XCanPs_AcceptFilterDisable ( XCanPs InstancePtr,
u32  FilterIndexes 
)

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

Parameters:
InstancePtr is a pointer to the XCanPs instance.
FilterIndexes specifies which filter(s) to disable. Use any XCANPS_AFR_UAF*_MASK to disable one filter, and "Or" multiple XCANPS_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:
None.
void XCanPs_AcceptFilterEnable ( XCanPs InstancePtr,
u32  FilterIndexes 
)

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

Parameters:
InstancePtr is a pointer to the XCanPs instance.
FilterIndexes specifies which filter(s) to enable. Use any XCANPS_AFR_UAF*_MASK to enable one filter, and "Or" multiple XCANPS_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:
None.
void XCanPs_AcceptFilterGet ( XCanPs 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 XCANPS_IDR_* defined in xcanps_hw.h to interpret the values. Read the xcanps.h file and device specification for details.

Parameters:
InstancePtr is a pointer to the XCanPs instance.
FilterIndex defines which Acceptance Filter Mask Register to get Mask and ID from. Use any single XCANPS_FILTER_* value.
MaskValue is a pointer to the data in which the Mask value read from the chosen Acceptance Filter Mask Register is returned.
IdValue is a pointer to the data in which the ID value read from the chosen Acceptance Filter ID Register is returned.
Returns:
None.
Note:
None.
u32 XCanPs_AcceptFilterGetEnabled ( XCanPs InstancePtr  ) 

This function returns enabled acceptance filters. Use XCANPS_AFR_UAF*_MASK defined in xcanps_hw.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 XCanPs instance.
Returns:
The value stored in Acceptance Filter Register.
Note:
None.
int XCanPs_AcceptFilterSet ( XCanPs 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 XCANPS_IDR_* defined in xcanps_hw.h to create the values to set the filter. Read the xcanps.h file and device specification for details.

This function should be called only after:

Parameters:
InstancePtr is a pointer to the XCanPs instance.
FilterIndex defines which Acceptance Filter Mask and ID Register to set. Use any single XCANPS_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:
None.
int XCanPs_CfgInitialize ( XCanPs InstancePtr,
XCanPs_Config ConfigPtr,
u32  EffectiveAddr 
)
void XCanPs_ClearBusErrorStatus ( XCanPs InstancePtr,
u32  Mask 
)

This function clears Error Status bit(s) previously set in Error Status Register (ESR). Use the XCANPS_ESR_* constants defined in xcanps_hw.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 modified.

Parameters:
InstancePtr is a pointer to the XCanPs instance.
Mask is he 32-bit mask used to clear bits in Error Status Register. Multiple XCANPS_ESR_* values can be 'OR'ed to clear multiple bits.
Note:
None.
void XCanPs_EnterMode ( XCanPs InstancePtr,
u8  OperationMode 
)

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

  • Configuration Mode: Pass in parameter XCANPS_MODE_CONFIG
  • Sleep Mode: Pass in parameter XCANPS_MODE_SLEEP
  • Normal Mode: Pass in parameter XCANPS_MODE_NORMAL
  • Loop Back Mode: Pass in parameter XCANPS_MODE_LOOPBACK.
  • Snoop Mode: Pass in parameter XCANPS_MODE_SNOOP.

Read the xcanps.h file and device specification for detailed description of each operation mode.

Parameters:
InstancePtr is a pointer to the XCanPs instance.
OperationMode specify which operation mode to enter. Valid value is any of XCANPS_MODE_* defined in xcanps.h. Multiple modes can not be entered at the same time.
Returns:
None.
Note:

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

u8 XCanPs_GetBaudRatePrescaler ( XCanPs 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 XCanPs instance.
Returns:
Current used Baud Rate Prescaler value. The value's range is from 0 to 255.
Note:
None.
void XCanPs_GetBitTiming ( XCanPs 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 XCanPs instance.
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 XCanPs_GetBusErrorCounter ( XCanPs InstancePtr,
u8 *  RxErrorCount,
u8 *  TxErrorCount 
)

This function reads Receive and Transmit error counters.

Parameters:
InstancePtr is a pointer to the XCanPs instance.
RxErrorCount is a pointer to data in which the Receive Error counter value is returned.
TxErrorCount is a pointer to data in which the Transmit Error counter value is returned.
Returns:
None.
Note:
None.
u32 XCanPs_GetBusErrorStatus ( XCanPs InstancePtr  ) 

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

Parameters:
InstancePtr is a pointer to the XCanPs instance.
Returns:
The 32-bit value read from Error Status Register.
Note:
None.
u8 XCanPs_GetMode ( XCanPs InstancePtr  ) 

This routine returns the current operation mode of the CAN device.

Parameters:
InstancePtr is a pointer to the XCanPs instance.
Returns:
  • XCANPS_MODE_CONFIG if the device is in Configuration Mode.
  • XCANPS_MODE_SLEEP if the device is in Sleep Mode.
  • XCANPS_MODE_NORMAL if the device is in Normal Mode.
  • XCANPS_MODE_LOOPBACK if the device is in Loop Back Mode.
  • XCANPS_MODE_SNOOP if the device is in Snoop Mode.
Note:
None.
u8 XCanPs_GetRxIntrWatermark ( XCanPs InstancePtr  ) 

This routine gets the Rx Full threshold from the Watermark Interrupt Register.

Parameters:
InstancePtr is a pointer to the XCanPs instance.
Returns:
The Rx FIFO full watermark threshold value. The valid values are 1 to 63.
Note:
None.
u32 XCanPs_GetStatus ( XCanPs InstancePtr  ) 

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

Parameters:
InstancePtr is a pointer to the XCanPs instance.
Returns:
The 32-bit value read from Status Register.
Note:
None.
void XCanPs_IntrClear ( XCanPs 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 XCanPs instance.
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 XCANPS_IXR_* bits defined in xcanps_hw.h.
Note:
None.
void XCanPs_IntrDisable ( XCanPs InstancePtr,
u32  Mask 
)

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

Parameters:
InstancePtr is a pointer to the XCanPs instance.
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 XCANPS_IXR_* bits defined in xcanps_hw.h.
Returns:
None.
Note:
None.
void XCanPs_IntrEnable ( XCanPs InstancePtr,
u32  Mask 
)

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

Parameters:
InstancePtr is a pointer to the XCanPs instance.
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 XCANPS_IXR_* bits defined in xcanps_hw.h.
Returns:
None.
Note:
None.
u32 XCanPs_IntrGetEnabled ( XCanPs InstancePtr  ) 

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

Parameters:
InstancePtr is a pointer to the XCanPs instance.
Returns:
Enabled interrupt(s) in a 32-bit format.
Note:
None.
u32 XCanPs_IntrGetStatus ( XCanPs InstancePtr  ) 

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

Parameters:
InstancePtr is a pointer to the XCanPs instance.
Returns:
The value stored in Interrupt Status Register.
Note:
None.
void XCanPs_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 XCanPs_SetHandler() during initialization phase. An example delivered with this driver demonstrates how this could be done.

Parameters:
InstancePtr is a pointer to the XCanPs instance that just interrupted.
Returns:
None.
Note:
None.
XCanPs_Config* XCanPs_LookupConfig ( u16  DeviceId  ) 

This function looks for the device configuration based on the unique device ID. The table XCanPs_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 XCanPs_Recv ( XCanPs 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 XCanPs instance.
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 XCanPs_Reset ( XCanPs 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 XCanPs instance.
Returns:
None.
Note:
None.
int XCanPs_SelfTest ( XCanPs 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 the device specification for the device status after the reset operation.

Parameters:
InstancePtr is a pointer to the XCanPs instance.
Returns:
  • XST_SUCCESS if the self-test passed. i.e., the frame received via the internal loop back has the same contents as the frame sent.
  • 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 XCanPs_Send ( XCanPs InstancePtr,
u32 *  FramePtr 
)

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

Parameters:
InstancePtr is a pointer to the XCanPs instance.
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 XCanPs_SendHighPriority ( XCanPs 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 XCanPs instance.
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 interrupt handling, the caller should disable interrupt at processor level before invoking this function.

int XCanPs_SetBaudRatePrescaler ( XCanPs 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 can be set only if the CAN device is in Configuration Mode. Call XCanPs_EnterMode() to enter Configuration Mode before using this function.

Parameters:
InstancePtr is a pointer to the XCanPs instance.
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 XCanPs_SetBitTiming ( XCanPs 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 can be set only if the CAN device is in Configuration Mode. Call XCanPs_EnterMode() to enter Configuration Mode before using this function.

Parameters:
InstancePtr is a pointer to the XCanPs instance.
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.
Note:
None.
int XCanPs_SetHandler ( XCanPs InstancePtr,
u32  HandlerType,
void *  CallBackFunc,
void *  CallBackRef 
)

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

 HandlerType			Callback Function Type
 -----------------------	------------------------
 XCANPS_HANDLER_SEND		XCanPs_SendRecvHandler
 XCANPS_HANDLER_RECV		XCanPs_SendRecvHandler
 XCANPS_HANDLER_ERROR		XCanPs_ErrorHandler
 XCANPS_HANDLER_EVENT		XCanPs_EventHandler
 HandlerType			Invoked by this driver when:
 -------------------------------------------------------------------------
 XCANPS_HANDLER_SEND		A frame transmitted by a call to
				XCanPs_Send() has been sent successfully.
 XCANPS_HANDLER_RECV		A frame(s) has been received and is sitting in
				the RX FIFO.
 XCANPS_HANDLER_ERROR		An error interrupt is occurring.
 XCANPS_HANDLER_EVENT		Any other kind of interrupt is occurring.
 
Parameters:
InstancePtr is a pointer to the XCanPs instance.
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 XCanPs_SetRxIntrWatermark ( XCanPs InstancePtr,
u8  Threshold 
)

This routine sets the Rx Full threshold in the Watermark Interrupt Register.

Parameters:
InstancePtr is a pointer to the XCanPs instance.
Threshold is the threshold to be set. The valid values are from 1 to 63.
Returns:
  • XST_FAILURE - If the CAN device is not in Configuration Mode.
  • XST_SUCCESS - If the Rx Full threshold is set in Watermark Interrupt Register.
Note:
The threshold can only be set when the CAN device is in the configuration mode.