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 /*****************************************************************************/
37 * This header file contains the identifiers and basic driver functions (or
38 * macros) that can be used to access the device. Other driver functions
39 * are defined in xcanps.h.
42 * MODIFICATION HISTORY:
44 * Ver Who Date Changes
45 * ----- ----- -------- -----------------------------------------------
46 * 1.00a xd/sv 01/12/10 First release
47 * 1.01a sbs 12/27/11 Updated the Register/bit definitions
48 * Changed XCANPS_RXFWIR_RXFLL_MASK to XCANPS_WIR_FW_MASK
49 * Changed XCANPS_RXWIR_OFFSET to XCANPS_WIR_OFFSET
50 * Added XCANPS_IXR_TXFEMP_MASK for Tx Fifo Empty
51 * Changed XCANPS_IXR_RXFLL_MASK to
52 * XCANPS_IXR_RXFWMFLL_MASK
54 * XCANPS_TXBUF_ID_OFFSET to XCANPS_TXHPB_ID_OFFSET
55 * XCANPS_TXBUF_DLC_OFFSET to XCANPS_TXHPB_DLC_OFFSET
56 * XCANPS_TXBUF_DW1_OFFSET to XCANPS_TXHPB_DW1_OFFSET
57 * XCANPS_TXBUF_DW2_OFFSET to XCANPS_TXHPB_DW2_OFFSET
58 * 1.02a adk 08/08/13 Updated for inclding the function prototype
59 * 3.00 kvn 02/13/15 Modified code for MISRA-C:2012 compliance.
62 ******************************************************************************/
64 #ifndef XCANPS_HW_H /* prevent circular inclusions */
65 #define XCANPS_HW_H /* by using protection macros */
72 /***************************** Include Files *********************************/
74 #include "xil_types.h"
75 #include "xil_assert.h"
78 /************************** Constant Definitions *****************************/
80 /** @name Register offsets for the CAN. Each register is 32 bits.
83 #define XCANPS_SRR_OFFSET 0x00000000U /**< Software Reset Register */
84 #define XCANPS_MSR_OFFSET 0x00000004U /**< Mode Select Register */
85 #define XCANPS_BRPR_OFFSET 0x00000008U /**< Baud Rate Prescaler */
86 #define XCANPS_BTR_OFFSET 0x0000000CU /**< Bit Timing Register */
87 #define XCANPS_ECR_OFFSET 0x00000010U /**< Error Counter Register */
88 #define XCANPS_ESR_OFFSET 0x00000014U /**< Error Status Register */
89 #define XCANPS_SR_OFFSET 0x00000018U /**< Status Register */
91 #define XCANPS_ISR_OFFSET 0x0000001CU /**< Interrupt Status Register */
92 #define XCANPS_IER_OFFSET 0x00000020U /**< Interrupt Enable Register */
93 #define XCANPS_ICR_OFFSET 0x00000024U /**< Interrupt Clear Register */
94 #define XCANPS_TCR_OFFSET 0x00000028U /**< Timestamp Control Register */
95 #define XCANPS_WIR_OFFSET 0x0000002CU /**< Watermark Interrupt Reg */
97 #define XCANPS_TXFIFO_ID_OFFSET 0x00000030U /**< TX FIFO ID */
98 #define XCANPS_TXFIFO_DLC_OFFSET 0x00000034U /**< TX FIFO DLC */
99 #define XCANPS_TXFIFO_DW1_OFFSET 0x00000038U /**< TX FIFO Data Word 1 */
100 #define XCANPS_TXFIFO_DW2_OFFSET 0x0000003CU /**< TX FIFO Data Word 2 */
102 #define XCANPS_TXHPB_ID_OFFSET 0x00000040U /**< TX High Priority Buffer ID */
103 #define XCANPS_TXHPB_DLC_OFFSET 0x00000044U /**< TX High Priority Buffer DLC */
104 #define XCANPS_TXHPB_DW1_OFFSET 0x00000048U /**< TX High Priority Buf Data 1 */
105 #define XCANPS_TXHPB_DW2_OFFSET 0x0000004CU /**< TX High Priority Buf Data Word 2 */
107 #define XCANPS_RXFIFO_ID_OFFSET 0x00000050U /**< RX FIFO ID */
108 #define XCANPS_RXFIFO_DLC_OFFSET 0x00000054U /**< RX FIFO DLC */
109 #define XCANPS_RXFIFO_DW1_OFFSET 0x00000058U /**< RX FIFO Data Word 1 */
110 #define XCANPS_RXFIFO_DW2_OFFSET 0x0000005CU /**< RX FIFO Data Word 2 */
112 #define XCANPS_AFR_OFFSET 0x00000060U /**< Acceptance Filter Register */
113 #define XCANPS_AFMR1_OFFSET 0x00000064U /**< Acceptance Filter Mask 1 */
114 #define XCANPS_AFIR1_OFFSET 0x00000068U /**< Acceptance Filter ID 1 */
115 #define XCANPS_AFMR2_OFFSET 0x0000006CU /**< Acceptance Filter Mask 2 */
116 #define XCANPS_AFIR2_OFFSET 0x00000070U /**< Acceptance Filter ID 2 */
117 #define XCANPS_AFMR3_OFFSET 0x00000074U /**< Acceptance Filter Mask 3 */
118 #define XCANPS_AFIR3_OFFSET 0x00000078U /**< Acceptance Filter ID 3 */
119 #define XCANPS_AFMR4_OFFSET 0x0000007CU /**< Acceptance Filter Mask 4 */
120 #define XCANPS_AFIR4_OFFSET 0x00000080U /**< Acceptance Filter ID 4 */
123 /** @name Software Reset Register (SRR) Bit Definitions and Masks
126 #define XCANPS_SRR_CEN_MASK 0x00000002U /**< Can Enable */
127 #define XCANPS_SRR_SRST_MASK 0x00000001U /**< Reset */
130 /** @name Mode Select Register (MSR) Bit Definitions and Masks
133 #define XCANPS_MSR_SNOOP_MASK 0x00000004U /**< Snoop Mode Select */
134 #define XCANPS_MSR_LBACK_MASK 0x00000002U /**< Loop Back Mode Select */
135 #define XCANPS_MSR_SLEEP_MASK 0x00000001U /**< Sleep Mode Select */
138 /** @name Baud Rate Prescaler register (BRPR) Bit Definitions and Masks
141 #define XCANPS_BRPR_BRP_MASK 0x000000FFU /**< Baud Rate Prescaler */
144 /** @name Bit Timing Register (BTR) Bit Definitions and Masks
147 #define XCANPS_BTR_SJW_MASK 0x00000180U /**< Synchronization Jump Width */
148 #define XCANPS_BTR_SJW_SHIFT 7U
149 #define XCANPS_BTR_TS2_MASK 0x00000070U /**< Time Segment 2 */
150 #define XCANPS_BTR_TS2_SHIFT 4U
151 #define XCANPS_BTR_TS1_MASK 0x0000000FU /**< Time Segment 1 */
154 /** @name Error Counter Register (ECR) Bit Definitions and Masks
157 #define XCANPS_ECR_REC_MASK 0x0000FF00U /**< Receive Error Counter */
158 #define XCANPS_ECR_REC_SHIFT 8U
159 #define XCANPS_ECR_TEC_MASK 0x000000FFU /**< Transmit Error Counter */
162 /** @name Error Status Register (ESR) Bit Definitions and Masks
165 #define XCANPS_ESR_ACKER_MASK 0x00000010U /**< ACK Error */
166 #define XCANPS_ESR_BERR_MASK 0x00000008U /**< Bit Error */
167 #define XCANPS_ESR_STER_MASK 0x00000004U /**< Stuff Error */
168 #define XCANPS_ESR_FMER_MASK 0x00000002U /**< Form Error */
169 #define XCANPS_ESR_CRCER_MASK 0x00000001U /**< CRC Error */
172 /** @name Status Register (SR) Bit Definitions and Masks
175 #define XCANPS_SR_SNOOP_MASK 0x00001000U /**< Snoop Mask */
176 #define XCANPS_SR_ACFBSY_MASK 0x00000800U /**< Acceptance Filter busy */
177 #define XCANPS_SR_TXFLL_MASK 0x00000400U /**< TX FIFO is full */
178 #define XCANPS_SR_TXBFLL_MASK 0x00000200U /**< TX High Priority Buffer full */
179 #define XCANPS_SR_ESTAT_MASK 0x00000180U /**< Error Status */
180 #define XCANPS_SR_ESTAT_SHIFT 7U
181 #define XCANPS_SR_ERRWRN_MASK 0x00000040U /**< Error Warning */
182 #define XCANPS_SR_BBSY_MASK 0x00000020U /**< Bus Busy */
183 #define XCANPS_SR_BIDLE_MASK 0x00000010U /**< Bus Idle */
184 #define XCANPS_SR_NORMAL_MASK 0x00000008U /**< Normal Mode */
185 #define XCANPS_SR_SLEEP_MASK 0x00000004U /**< Sleep Mode */
186 #define XCANPS_SR_LBACK_MASK 0x00000002U /**< Loop Back Mode */
187 #define XCANPS_SR_CONFIG_MASK 0x00000001U /**< Configuration Mode */
190 /** @name Interrupt Status/Enable/Clear Register Bit Definitions and Masks
193 #define XCANPS_IXR_TXFEMP_MASK 0x00004000U /**< Tx Fifo Empty Interrupt */
194 #define XCANPS_IXR_TXFWMEMP_MASK 0x00002000U /**< Tx Fifo Watermark Empty */
195 #define XCANPS_IXR_RXFWMFLL_MASK 0x00001000U /**< Rx FIFO Watermark Full */
196 #define XCANPS_IXR_WKUP_MASK 0x00000800U /**< Wake up Interrupt */
197 #define XCANPS_IXR_SLP_MASK 0x00000400U /**< Sleep Interrupt */
198 #define XCANPS_IXR_BSOFF_MASK 0x00000200U /**< Bus Off Interrupt */
199 #define XCANPS_IXR_ERROR_MASK 0x00000100U /**< Error Interrupt */
200 #define XCANPS_IXR_RXNEMP_MASK 0x00000080U /**< RX FIFO Not Empty Interrupt */
201 #define XCANPS_IXR_RXOFLW_MASK 0x00000040U /**< RX FIFO Overflow Interrupt */
202 #define XCANPS_IXR_RXUFLW_MASK 0x00000020U /**< RX FIFO Underflow Interrupt */
203 #define XCANPS_IXR_RXOK_MASK 0x00000010U /**< New Message Received Intr */
204 #define XCANPS_IXR_TXBFLL_MASK 0x00000008U /**< TX High Priority Buf Full */
205 #define XCANPS_IXR_TXFLL_MASK 0x00000004U /**< TX FIFO Full Interrupt */
206 #define XCANPS_IXR_TXOK_MASK 0x00000002U /**< TX Successful Interrupt */
207 #define XCANPS_IXR_ARBLST_MASK 0x00000001U /**< Arbitration Lost Interrupt */
208 #define XCANPS_IXR_ALL ((u32)XCANPS_IXR_RXFWMFLL_MASK | \
209 (u32)XCANPS_IXR_WKUP_MASK | \
210 (u32)XCANPS_IXR_SLP_MASK | \
211 (u32)XCANPS_IXR_BSOFF_MASK | \
212 (u32)XCANPS_IXR_ERROR_MASK | \
213 (u32)XCANPS_IXR_RXNEMP_MASK | \
214 (u32)XCANPS_IXR_RXOFLW_MASK | \
215 (u32)XCANPS_IXR_RXUFLW_MASK | \
216 (u32)XCANPS_IXR_RXOK_MASK | \
217 (u32)XCANPS_IXR_TXBFLL_MASK | \
218 (u32)XCANPS_IXR_TXFLL_MASK | \
219 (u32)XCANPS_IXR_TXOK_MASK | \
220 (u32)XCANPS_IXR_ARBLST_MASK)
223 /** @name CAN Timestamp Control Register (TCR) Bit Definitions and Masks
226 #define XCANPS_TCR_CTS_MASK 0x00000001U /**< Clear Timestamp counter mask */
229 /** @name CAN Watermark Register (WIR) Bit Definitions and Masks
232 #define XCANPS_WIR_FW_MASK 0x0000003FU /**< Rx Full Threshold mask */
233 #define XCANPS_WIR_EW_MASK 0x00003F00U /**< Tx Empty Threshold mask */
234 #define XCANPS_WIR_EW_SHIFT 0x00000008U /**< Tx Empty Threshold shift */
238 /** @name CAN Frame Identifier (TX High Priority Buffer/TX/RX/Acceptance Filter
239 Mask/Acceptance Filter ID)
242 #define XCANPS_IDR_ID1_MASK 0xFFE00000U /**< Standard Messg Identifier */
243 #define XCANPS_IDR_ID1_SHIFT 21U
244 #define XCANPS_IDR_SRR_MASK 0x00100000U /**< Substitute Remote TX Req */
245 #define XCANPS_IDR_SRR_SHIFT 20U
246 #define XCANPS_IDR_IDE_MASK 0x00080000U /**< Identifier Extension */
247 #define XCANPS_IDR_IDE_SHIFT 19U
248 #define XCANPS_IDR_ID2_MASK 0x0007FFFEU /**< Extended Message Ident */
249 #define XCANPS_IDR_ID2_SHIFT 1U
250 #define XCANPS_IDR_RTR_MASK 0x00000001U /**< Remote TX Request */
253 /** @name CAN Frame Data Length Code (TX High Priority Buffer/TX/RX)
256 #define XCANPS_DLCR_DLC_MASK 0xF0000000U /**< Data Length Code */
257 #define XCANPS_DLCR_DLC_SHIFT 28U
258 #define XCANPS_DLCR_TIMESTAMP_MASK 0x0000FFFFU /**< Timestamp Mask (Rx only) */
262 /** @name CAN Frame Data Word 1 (TX High Priority Buffer/TX/RX)
265 #define XCANPS_DW1R_DB0_MASK 0xFF000000U /**< Data Byte 0 */
266 #define XCANPS_DW1R_DB0_SHIFT 24U
267 #define XCANPS_DW1R_DB1_MASK 0x00FF0000U /**< Data Byte 1 */
268 #define XCANPS_DW1R_DB1_SHIFT 16U
269 #define XCANPS_DW1R_DB2_MASK 0x0000FF00U /**< Data Byte 2 */
270 #define XCANPS_DW1R_DB2_SHIFT 8U
271 #define XCANPS_DW1R_DB3_MASK 0x000000FFU /**< Data Byte 3 */
274 /** @name CAN Frame Data Word 2 (TX High Priority Buffer/TX/RX)
277 #define XCANPS_DW2R_DB4_MASK 0xFF000000U /**< Data Byte 4 */
278 #define XCANPS_DW2R_DB4_SHIFT 24U
279 #define XCANPS_DW2R_DB5_MASK 0x00FF0000U /**< Data Byte 5 */
280 #define XCANPS_DW2R_DB5_SHIFT 16U
281 #define XCANPS_DW2R_DB6_MASK 0x0000FF00U /**< Data Byte 6 */
282 #define XCANPS_DW2R_DB6_SHIFT 8U
283 #define XCANPS_DW2R_DB7_MASK 0x000000FFU /**< Data Byte 7 */
286 /** @name Acceptance Filter Register (AFR) Bit Definitions and Masks
289 #define XCANPS_AFR_UAF4_MASK 0x00000008U /**< Use Acceptance Filter No.4 */
290 #define XCANPS_AFR_UAF3_MASK 0x00000004U /**< Use Acceptance Filter No.3 */
291 #define XCANPS_AFR_UAF2_MASK 0x00000002U /**< Use Acceptance Filter No.2 */
292 #define XCANPS_AFR_UAF1_MASK 0x00000001U /**< Use Acceptance Filter No.1 */
293 #define XCANPS_AFR_UAF_ALL_MASK ((u32)XCANPS_AFR_UAF4_MASK | \
294 (u32)XCANPS_AFR_UAF3_MASK | \
295 (u32)XCANPS_AFR_UAF2_MASK | \
296 (u32)XCANPS_AFR_UAF1_MASK)
299 /** @name CAN frame length constants
302 #define XCANPS_MAX_FRAME_SIZE sizeof(u32)*16U /**< Maximum CAN frame length in bytes */
305 /* For backwards compatibilty */
306 #define XCANPS_TXBUF_ID_OFFSET XCANPS_TXHPB_ID_OFFSET
307 #define XCANPS_TXBUF_DLC_OFFSET XCANPS_TXHPB_DLC_OFFSET
308 #define XCANPS_TXBUF_DW1_OFFSET XCANPS_TXHPB_DW1_OFFSET
309 #define XCANPS_TXBUF_DW2_OFFSET XCANPS_TXHPB_DW2_OFFSET
311 #define XCANPS_RXFWIR_RXFLL_MASK XCANPS_WIR_FW_MASK
312 #define XCANPS_RXWIR_OFFSET XCANPS_WIR_OFFSET
313 #define XCANPS_IXR_RXFLL_MASK XCANPS_IXR_RXFWMFLL_MASK
318 /**************************** Type Definitions *******************************/
320 /***************** Macros (Inline Functions) Definitions *********************/
322 /****************************************************************************/
325 * This macro reads the given register.
327 * @param BaseAddr is the base address of the device.
328 * @param RegOffset is the register offset to be read.
330 * @return The 32-bit value of the register
334 *****************************************************************************/
335 #define XCanPs_ReadReg(BaseAddr, RegOffset) \
336 Xil_In32((BaseAddr) + (u32)(RegOffset))
339 /****************************************************************************/
342 * This macro writes the given register.
344 * @param BaseAddr is the base address of the device.
345 * @param RegOffset is the register offset to be written.
346 * @param Data is the 32-bit value to write to the register.
352 *****************************************************************************/
353 #define XCanPs_WriteReg(BaseAddr, RegOffset, Data) \
354 Xil_Out32((BaseAddr) + (u32)(RegOffset), (u32)(Data))
356 /************************** Function Prototypes ******************************/
358 * Perform reset operation to the CanPs interface
360 void XCanPs_ResetHw(u32 BaseAddr);
366 #endif /* end of protection macro */