xcan.c File Reference
#include "xil_types.h"
#include "xil_assert.h"
#include "xil_io.h"
#include "xenv.h"
#include "xcan.h"
#include "xparameters.h"
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_Config * | XCan_LookupConfig (u16 DeviceId) |
XCan_Config * | XCan_GetConfig (unsigned int InstanceIndex) |
Variables |
XCan_Config | XCan_ConfigTable [] |
Detailed Description
The XCan driver. Functions in this file are the minimum required functions for this driver. See xcan.h for a detailed description of the driver.
MODIFICATION HISTORY:
Ver Who Date Changes
----- ---- -------- -------------------------------------------------------
1.00a xd 04/12/05 First release
1.10a mta 05/13/07 Updated to new coding style
2.00a ktn 10/22/09 Updated to use the HAL APIs/macros.
The macros have been renamed to remove _m from the name in
all the driver files.
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().
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.
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_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_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.
Variable Documentation
This table contains configuration information for each CAN device in the system.
Copyright © 1995-2014 Xilinx, Inc. All rights reserved.