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 file defines the hardware interface to one of the three timer counters
42 * MODIFICATION HISTORY:
44 * Ver Who Date Changes
45 * ----- ------ -------- -------------------------------------------------
46 * 1.00a drg/jz 01/21/10 First release
47 * 3.00 kvn 02/13/15 Modified code for MISRA-C:2012 compliance.
51 ******************************************************************************/
53 #ifndef XTTCPS_HW_H /* prevent circular inclusions */
54 #define XTTCPS_HW_H /* by using protection macros */
60 /***************************** Include Files *********************************/
62 #include "xil_types.h"
63 #include "xil_assert.h"
66 /************************** Constant Definitions *****************************/
68 /** @name Register Map
70 * Register offsets from the base address of the device.
74 #define XTTCPS_CLK_CNTRL_OFFSET 0x00000000U /**< Clock Control Register */
75 #define XTTCPS_CNT_CNTRL_OFFSET 0x0000000CU /**< Counter Control Register*/
76 #define XTTCPS_COUNT_VALUE_OFFSET 0x00000018U /**< Current Counter Value */
77 #define XTTCPS_INTERVAL_VAL_OFFSET 0x00000024U /**< Interval Count Value */
78 #define XTTCPS_MATCH_0_OFFSET 0x00000030U /**< Match 1 value */
79 #define XTTCPS_MATCH_1_OFFSET 0x0000003CU /**< Match 2 value */
80 #define XTTCPS_MATCH_2_OFFSET 0x00000048U /**< Match 3 value */
81 #define XTTCPS_ISR_OFFSET 0x00000054U /**< Interrupt Status Register */
82 #define XTTCPS_IER_OFFSET 0x00000060U /**< Interrupt Enable Register */
85 /** @name Clock Control Register
86 * Clock Control Register definitions
89 #define XTTCPS_CLK_CNTRL_PS_EN_MASK 0x00000001U /**< Prescale enable */
90 #define XTTCPS_CLK_CNTRL_PS_VAL_MASK 0x0000001EU /**< Prescale value */
91 #define XTTCPS_CLK_CNTRL_PS_VAL_SHIFT 1U /**< Prescale shift */
92 #define XTTCPS_CLK_CNTRL_PS_DISABLE 16U /**< Prescale disable */
93 #define XTTCPS_CLK_CNTRL_SRC_MASK 0x00000020U /**< Clock source */
94 #define XTTCPS_CLK_CNTRL_EXT_EDGE_MASK 0x00000040U /**< External Clock edge */
97 /** @name Counter Control Register
98 * Counter Control Register definitions
101 #define XTTCPS_CNT_CNTRL_DIS_MASK 0x00000001U /**< Disable the counter */
102 #define XTTCPS_CNT_CNTRL_INT_MASK 0x00000002U /**< Interval mode */
103 #define XTTCPS_CNT_CNTRL_DECR_MASK 0x00000004U /**< Decrement mode */
104 #define XTTCPS_CNT_CNTRL_MATCH_MASK 0x00000008U /**< Match mode */
105 #define XTTCPS_CNT_CNTRL_RST_MASK 0x00000010U /**< Reset counter */
106 #define XTTCPS_CNT_CNTRL_EN_WAVE_MASK 0x00000020U /**< Enable waveform */
107 #define XTTCPS_CNT_CNTRL_POL_WAVE_MASK 0x00000040U /**< Waveform polarity */
108 #define XTTCPS_CNT_CNTRL_RESET_VALUE 0x00000021U /**< Reset value */
111 /** @name Current Counter Value Register
112 * Current Counter Value Register definitions
115 #define XTTCPS_COUNT_VALUE_MASK 0x0000FFFFU /**< 16-bit counter value */
118 /** @name Interval Value Register
119 * Interval Value Register is the maximum value the counter will count up or
123 #define XTTCPS_INTERVAL_VAL_MASK 0x0000FFFFU /**< 16-bit Interval value*/
126 /** @name Match Registers
127 * Definitions for Match registers, each timer counter has three match
131 #define XTTCPS_MATCH_MASK 0x0000FFFFU /**< 16-bit Match value */
132 #define XTTCPS_NUM_MATCH_REG 3U /**< Num of Match reg */
135 /** @name Interrupt Registers
136 * Following register bit mask is for all interrupt registers.
140 #define XTTCPS_IXR_INTERVAL_MASK 0x00000001U /**< Interval Interrupt */
141 #define XTTCPS_IXR_MATCH_0_MASK 0x00000002U /**< Match 1 Interrupt */
142 #define XTTCPS_IXR_MATCH_1_MASK 0x00000004U /**< Match 2 Interrupt */
143 #define XTTCPS_IXR_MATCH_2_MASK 0x00000008U /**< Match 3 Interrupt */
144 #define XTTCPS_IXR_CNT_OVR_MASK 0x00000010U /**< Counter Overflow */
145 #define XTTCPS_IXR_ALL_MASK 0x0000001FU /**< All valid Interrupts */
149 /***************** Macros (Inline Functions) Definitions *********************/
151 /****************************************************************************/
154 * Read the given Timer Counter register.
156 * @param BaseAddress is the base address of the timer counter device.
157 * @param RegOffset is the register offset to be read
159 * @return The 32-bit value of the register
161 * @note C-style signature:
162 * u32 XTtcPs_ReadReg(u32 BaseAddress, u32 RegOffset)
164 *****************************************************************************/
165 #define XTtcPs_ReadReg(BaseAddress, RegOffset) \
166 (Xil_In32((BaseAddress) + (u32)(RegOffset)))
168 /****************************************************************************/
171 * Write the given Timer Counter register.
173 * @param BaseAddress is the base address of the timer counter device.
174 * @param RegOffset is the register offset to be written
175 * @param Data is the 32-bit value to write to the register
179 * @note C-style signature:
180 * void XTtcPs_WriteReg(XTtcPs BaseAddress, u32 RegOffset,
183 *****************************************************************************/
184 #define XTtcPs_WriteReg(BaseAddress, RegOffset, Data) \
185 (Xil_Out32((BaseAddress) + (u32)(RegOffset), (u32)(Data)))
187 /****************************************************************************/
190 * Calculate a match register offset using the Match Register index.
192 * @param MatchIndex is the 0-2 value of the match register
194 * @return MATCH_N_OFFSET.
196 * @note C-style signature:
197 * u32 XTtcPs_Match_N_Offset(u8 MatchIndex)
199 *****************************************************************************/
200 #define XTtcPs_Match_N_Offset(MatchIndex) \
201 ((u32)XTTCPS_MATCH_0_OFFSET + ((u32)(12U) * (u32)(MatchIndex)))
203 /************************** Function Prototypes ******************************/
205 /************************** Variable Definitions *****************************/
209 #endif /* end of protection macro */