1 /******************************************************************************
3 * Copyright (C) 2010 - 2015 Xilinx, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
31 ******************************************************************************/
32 /*****************************************************************************/
36 * @addtogroup canps_v3_0
39 * This header file contains the identifiers and basic driver functions (or
40 * macros) that can be used to access the device. Other driver functions
41 * are defined in xcanps.h.
44 * MODIFICATION HISTORY:
46 * Ver Who Date Changes
47 * ----- ----- -------- -----------------------------------------------
48 * 1.00a xd/sv 01/12/10 First release
49 * 1.01a sbs 12/27/11 Updated the Register/bit definitions
50 * Changed XCANPS_RXFWIR_RXFLL_MASK to XCANPS_WIR_FW_MASK
51 * Changed XCANPS_RXWIR_OFFSET to XCANPS_WIR_OFFSET
52 * Added XCANPS_IXR_TXFEMP_MASK for Tx Fifo Empty
53 * Changed XCANPS_IXR_RXFLL_MASK to
54 * XCANPS_IXR_RXFWMFLL_MASK
56 * XCANPS_TXBUF_ID_OFFSET to XCANPS_TXHPB_ID_OFFSET
57 * XCANPS_TXBUF_DLC_OFFSET to XCANPS_TXHPB_DLC_OFFSET
58 * XCANPS_TXBUF_DW1_OFFSET to XCANPS_TXHPB_DW1_OFFSET
59 * XCANPS_TXBUF_DW2_OFFSET to XCANPS_TXHPB_DW2_OFFSET
60 * 1.02a adk 08/08/13 Updated for inclding the function prototype
61 * 3.00 kvn 02/13/15 Modified code for MISRA-C:2012 compliance.
64 ******************************************************************************/
66 #ifndef XCANPS_HW_H /* prevent circular inclusions */
67 #define XCANPS_HW_H /* by using protection macros */
74 /***************************** Include Files *********************************/
76 #include "xil_types.h"
77 #include "xil_assert.h"
80 /************************** Constant Definitions *****************************/
82 /** @name Register offsets for the CAN. Each register is 32 bits.
85 #define XCANPS_SRR_OFFSET 0x00000000U /**< Software Reset Register */
86 #define XCANPS_MSR_OFFSET 0x00000004U /**< Mode Select Register */
87 #define XCANPS_BRPR_OFFSET 0x00000008U /**< Baud Rate Prescaler */
88 #define XCANPS_BTR_OFFSET 0x0000000CU /**< Bit Timing Register */
89 #define XCANPS_ECR_OFFSET 0x00000010U /**< Error Counter Register */
90 #define XCANPS_ESR_OFFSET 0x00000014U /**< Error Status Register */
91 #define XCANPS_SR_OFFSET 0x00000018U /**< Status Register */
93 #define XCANPS_ISR_OFFSET 0x0000001CU /**< Interrupt Status Register */
94 #define XCANPS_IER_OFFSET 0x00000020U /**< Interrupt Enable Register */
95 #define XCANPS_ICR_OFFSET 0x00000024U /**< Interrupt Clear Register */
96 #define XCANPS_TCR_OFFSET 0x00000028U /**< Timestamp Control Register */
97 #define XCANPS_WIR_OFFSET 0x0000002CU /**< Watermark Interrupt Reg */
99 #define XCANPS_TXFIFO_ID_OFFSET 0x00000030U /**< TX FIFO ID */
100 #define XCANPS_TXFIFO_DLC_OFFSET 0x00000034U /**< TX FIFO DLC */
101 #define XCANPS_TXFIFO_DW1_OFFSET 0x00000038U /**< TX FIFO Data Word 1 */
102 #define XCANPS_TXFIFO_DW2_OFFSET 0x0000003CU /**< TX FIFO Data Word 2 */
104 #define XCANPS_TXHPB_ID_OFFSET 0x00000040U /**< TX High Priority Buffer ID */
105 #define XCANPS_TXHPB_DLC_OFFSET 0x00000044U /**< TX High Priority Buffer DLC */
106 #define XCANPS_TXHPB_DW1_OFFSET 0x00000048U /**< TX High Priority Buf Data 1 */
107 #define XCANPS_TXHPB_DW2_OFFSET 0x0000004CU /**< TX High Priority Buf Data Word 2 */
109 #define XCANPS_RXFIFO_ID_OFFSET 0x00000050U /**< RX FIFO ID */
110 #define XCANPS_RXFIFO_DLC_OFFSET 0x00000054U /**< RX FIFO DLC */
111 #define XCANPS_RXFIFO_DW1_OFFSET 0x00000058U /**< RX FIFO Data Word 1 */
112 #define XCANPS_RXFIFO_DW2_OFFSET 0x0000005CU /**< RX FIFO Data Word 2 */
114 #define XCANPS_AFR_OFFSET 0x00000060U /**< Acceptance Filter Register */
115 #define XCANPS_AFMR1_OFFSET 0x00000064U /**< Acceptance Filter Mask 1 */
116 #define XCANPS_AFIR1_OFFSET 0x00000068U /**< Acceptance Filter ID 1 */
117 #define XCANPS_AFMR2_OFFSET 0x0000006CU /**< Acceptance Filter Mask 2 */
118 #define XCANPS_AFIR2_OFFSET 0x00000070U /**< Acceptance Filter ID 2 */
119 #define XCANPS_AFMR3_OFFSET 0x00000074U /**< Acceptance Filter Mask 3 */
120 #define XCANPS_AFIR3_OFFSET 0x00000078U /**< Acceptance Filter ID 3 */
121 #define XCANPS_AFMR4_OFFSET 0x0000007CU /**< Acceptance Filter Mask 4 */
122 #define XCANPS_AFIR4_OFFSET 0x00000080U /**< Acceptance Filter ID 4 */
125 /** @name Software Reset Register (SRR) Bit Definitions and Masks
128 #define XCANPS_SRR_CEN_MASK 0x00000002U /**< Can Enable */
129 #define XCANPS_SRR_SRST_MASK 0x00000001U /**< Reset */
132 /** @name Mode Select Register (MSR) Bit Definitions and Masks
135 #define XCANPS_MSR_SNOOP_MASK 0x00000004U /**< Snoop Mode Select */
136 #define XCANPS_MSR_LBACK_MASK 0x00000002U /**< Loop Back Mode Select */
137 #define XCANPS_MSR_SLEEP_MASK 0x00000001U /**< Sleep Mode Select */
140 /** @name Baud Rate Prescaler register (BRPR) Bit Definitions and Masks
143 #define XCANPS_BRPR_BRP_MASK 0x000000FFU /**< Baud Rate Prescaler */
146 /** @name Bit Timing Register (BTR) Bit Definitions and Masks
149 #define XCANPS_BTR_SJW_MASK 0x00000180U /**< Synchronization Jump Width */
150 #define XCANPS_BTR_SJW_SHIFT 7U
151 #define XCANPS_BTR_TS2_MASK 0x00000070U /**< Time Segment 2 */
152 #define XCANPS_BTR_TS2_SHIFT 4U
153 #define XCANPS_BTR_TS1_MASK 0x0000000FU /**< Time Segment 1 */
156 /** @name Error Counter Register (ECR) Bit Definitions and Masks
159 #define XCANPS_ECR_REC_MASK 0x0000FF00U /**< Receive Error Counter */
160 #define XCANPS_ECR_REC_SHIFT 8U
161 #define XCANPS_ECR_TEC_MASK 0x000000FFU /**< Transmit Error Counter */
164 /** @name Error Status Register (ESR) Bit Definitions and Masks
167 #define XCANPS_ESR_ACKER_MASK 0x00000010U /**< ACK Error */
168 #define XCANPS_ESR_BERR_MASK 0x00000008U /**< Bit Error */
169 #define XCANPS_ESR_STER_MASK 0x00000004U /**< Stuff Error */
170 #define XCANPS_ESR_FMER_MASK 0x00000002U /**< Form Error */
171 #define XCANPS_ESR_CRCER_MASK 0x00000001U /**< CRC Error */
174 /** @name Status Register (SR) Bit Definitions and Masks
177 #define XCANPS_SR_SNOOP_MASK 0x00001000U /**< Snoop Mask */
178 #define XCANPS_SR_ACFBSY_MASK 0x00000800U /**< Acceptance Filter busy */
179 #define XCANPS_SR_TXFLL_MASK 0x00000400U /**< TX FIFO is full */
180 #define XCANPS_SR_TXBFLL_MASK 0x00000200U /**< TX High Priority Buffer full */
181 #define XCANPS_SR_ESTAT_MASK 0x00000180U /**< Error Status */
182 #define XCANPS_SR_ESTAT_SHIFT 7U
183 #define XCANPS_SR_ERRWRN_MASK 0x00000040U /**< Error Warning */
184 #define XCANPS_SR_BBSY_MASK 0x00000020U /**< Bus Busy */
185 #define XCANPS_SR_BIDLE_MASK 0x00000010U /**< Bus Idle */
186 #define XCANPS_SR_NORMAL_MASK 0x00000008U /**< Normal Mode */
187 #define XCANPS_SR_SLEEP_MASK 0x00000004U /**< Sleep Mode */
188 #define XCANPS_SR_LBACK_MASK 0x00000002U /**< Loop Back Mode */
189 #define XCANPS_SR_CONFIG_MASK 0x00000001U /**< Configuration Mode */
192 /** @name Interrupt Status/Enable/Clear Register Bit Definitions and Masks
195 #define XCANPS_IXR_TXFEMP_MASK 0x00004000U /**< Tx Fifo Empty Interrupt */
196 #define XCANPS_IXR_TXFWMEMP_MASK 0x00002000U /**< Tx Fifo Watermark Empty */
197 #define XCANPS_IXR_RXFWMFLL_MASK 0x00001000U /**< Rx FIFO Watermark Full */
198 #define XCANPS_IXR_WKUP_MASK 0x00000800U /**< Wake up Interrupt */
199 #define XCANPS_IXR_SLP_MASK 0x00000400U /**< Sleep Interrupt */
200 #define XCANPS_IXR_BSOFF_MASK 0x00000200U /**< Bus Off Interrupt */
201 #define XCANPS_IXR_ERROR_MASK 0x00000100U /**< Error Interrupt */
202 #define XCANPS_IXR_RXNEMP_MASK 0x00000080U /**< RX FIFO Not Empty Interrupt */
203 #define XCANPS_IXR_RXOFLW_MASK 0x00000040U /**< RX FIFO Overflow Interrupt */
204 #define XCANPS_IXR_RXUFLW_MASK 0x00000020U /**< RX FIFO Underflow Interrupt */
205 #define XCANPS_IXR_RXOK_MASK 0x00000010U /**< New Message Received Intr */
206 #define XCANPS_IXR_TXBFLL_MASK 0x00000008U /**< TX High Priority Buf Full */
207 #define XCANPS_IXR_TXFLL_MASK 0x00000004U /**< TX FIFO Full Interrupt */
208 #define XCANPS_IXR_TXOK_MASK 0x00000002U /**< TX Successful Interrupt */
209 #define XCANPS_IXR_ARBLST_MASK 0x00000001U /**< Arbitration Lost Interrupt */
210 #define XCANPS_IXR_ALL ((u32)XCANPS_IXR_RXFWMFLL_MASK | \
211 (u32)XCANPS_IXR_WKUP_MASK | \
212 (u32)XCANPS_IXR_SLP_MASK | \
213 (u32)XCANPS_IXR_BSOFF_MASK | \
214 (u32)XCANPS_IXR_ERROR_MASK | \
215 (u32)XCANPS_IXR_RXNEMP_MASK | \
216 (u32)XCANPS_IXR_RXOFLW_MASK | \
217 (u32)XCANPS_IXR_RXUFLW_MASK | \
218 (u32)XCANPS_IXR_RXOK_MASK | \
219 (u32)XCANPS_IXR_TXBFLL_MASK | \
220 (u32)XCANPS_IXR_TXFLL_MASK | \
221 (u32)XCANPS_IXR_TXOK_MASK | \
222 (u32)XCANPS_IXR_ARBLST_MASK)
225 /** @name CAN Timestamp Control Register (TCR) Bit Definitions and Masks
228 #define XCANPS_TCR_CTS_MASK 0x00000001U /**< Clear Timestamp counter mask */
231 /** @name CAN Watermark Register (WIR) Bit Definitions and Masks
234 #define XCANPS_WIR_FW_MASK 0x0000003FU /**< Rx Full Threshold mask */
235 #define XCANPS_WIR_EW_MASK 0x00003F00U /**< Tx Empty Threshold mask */
236 #define XCANPS_WIR_EW_SHIFT 0x00000008U /**< Tx Empty Threshold shift */
240 /** @name CAN Frame Identifier (TX High Priority Buffer/TX/RX/Acceptance Filter
241 Mask/Acceptance Filter ID)
244 #define XCANPS_IDR_ID1_MASK 0xFFE00000U /**< Standard Messg Identifier */
245 #define XCANPS_IDR_ID1_SHIFT 21U
246 #define XCANPS_IDR_SRR_MASK 0x00100000U /**< Substitute Remote TX Req */
247 #define XCANPS_IDR_SRR_SHIFT 20U
248 #define XCANPS_IDR_IDE_MASK 0x00080000U /**< Identifier Extension */
249 #define XCANPS_IDR_IDE_SHIFT 19U
250 #define XCANPS_IDR_ID2_MASK 0x0007FFFEU /**< Extended Message Ident */
251 #define XCANPS_IDR_ID2_SHIFT 1U
252 #define XCANPS_IDR_RTR_MASK 0x00000001U /**< Remote TX Request */
255 /** @name CAN Frame Data Length Code (TX High Priority Buffer/TX/RX)
258 #define XCANPS_DLCR_DLC_MASK 0xF0000000U /**< Data Length Code */
259 #define XCANPS_DLCR_DLC_SHIFT 28U
260 #define XCANPS_DLCR_TIMESTAMP_MASK 0x0000FFFFU /**< Timestamp Mask (Rx only) */
264 /** @name CAN Frame Data Word 1 (TX High Priority Buffer/TX/RX)
267 #define XCANPS_DW1R_DB0_MASK 0xFF000000U /**< Data Byte 0 */
268 #define XCANPS_DW1R_DB0_SHIFT 24U
269 #define XCANPS_DW1R_DB1_MASK 0x00FF0000U /**< Data Byte 1 */
270 #define XCANPS_DW1R_DB1_SHIFT 16U
271 #define XCANPS_DW1R_DB2_MASK 0x0000FF00U /**< Data Byte 2 */
272 #define XCANPS_DW1R_DB2_SHIFT 8U
273 #define XCANPS_DW1R_DB3_MASK 0x000000FFU /**< Data Byte 3 */
276 /** @name CAN Frame Data Word 2 (TX High Priority Buffer/TX/RX)
279 #define XCANPS_DW2R_DB4_MASK 0xFF000000U /**< Data Byte 4 */
280 #define XCANPS_DW2R_DB4_SHIFT 24U
281 #define XCANPS_DW2R_DB5_MASK 0x00FF0000U /**< Data Byte 5 */
282 #define XCANPS_DW2R_DB5_SHIFT 16U
283 #define XCANPS_DW2R_DB6_MASK 0x0000FF00U /**< Data Byte 6 */
284 #define XCANPS_DW2R_DB6_SHIFT 8U
285 #define XCANPS_DW2R_DB7_MASK 0x000000FFU /**< Data Byte 7 */
288 /** @name Acceptance Filter Register (AFR) Bit Definitions and Masks
291 #define XCANPS_AFR_UAF4_MASK 0x00000008U /**< Use Acceptance Filter No.4 */
292 #define XCANPS_AFR_UAF3_MASK 0x00000004U /**< Use Acceptance Filter No.3 */
293 #define XCANPS_AFR_UAF2_MASK 0x00000002U /**< Use Acceptance Filter No.2 */
294 #define XCANPS_AFR_UAF1_MASK 0x00000001U /**< Use Acceptance Filter No.1 */
295 #define XCANPS_AFR_UAF_ALL_MASK ((u32)XCANPS_AFR_UAF4_MASK | \
296 (u32)XCANPS_AFR_UAF3_MASK | \
297 (u32)XCANPS_AFR_UAF2_MASK | \
298 (u32)XCANPS_AFR_UAF1_MASK)
301 /** @name CAN frame length constants
304 #define XCANPS_MAX_FRAME_SIZE sizeof(u32)*16U /**< Maximum CAN frame length in bytes */
307 /* For backwards compatibilty */
308 #define XCANPS_TXBUF_ID_OFFSET XCANPS_TXHPB_ID_OFFSET
309 #define XCANPS_TXBUF_DLC_OFFSET XCANPS_TXHPB_DLC_OFFSET
310 #define XCANPS_TXBUF_DW1_OFFSET XCANPS_TXHPB_DW1_OFFSET
311 #define XCANPS_TXBUF_DW2_OFFSET XCANPS_TXHPB_DW2_OFFSET
313 #define XCANPS_RXFWIR_RXFLL_MASK XCANPS_WIR_FW_MASK
314 #define XCANPS_RXWIR_OFFSET XCANPS_WIR_OFFSET
315 #define XCANPS_IXR_RXFLL_MASK XCANPS_IXR_RXFWMFLL_MASK
320 /**************************** Type Definitions *******************************/
322 /***************** Macros (Inline Functions) Definitions *********************/
324 /****************************************************************************/
327 * This macro reads the given register.
329 * @param BaseAddr is the base address of the device.
330 * @param RegOffset is the register offset to be read.
332 * @return The 32-bit value of the register
336 *****************************************************************************/
337 #define XCanPs_ReadReg(BaseAddr, RegOffset) \
338 Xil_In32((BaseAddr) + (u32)(RegOffset))
341 /****************************************************************************/
344 * This macro writes the given register.
346 * @param BaseAddr is the base address of the device.
347 * @param RegOffset is the register offset to be written.
348 * @param Data is the 32-bit value to write to the register.
354 *****************************************************************************/
355 #define XCanPs_WriteReg(BaseAddr, RegOffset, Data) \
356 Xil_Out32((BaseAddr) + (u32)(RegOffset), (u32)(Data))
358 /************************** Function Prototypes ******************************/
360 * Perform reset operation to the CanPs interface
362 void XCanPs_ResetHw(u32 BaseAddr);
368 #endif /* end of protection macro */