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 ttcps_v3_0
39 * This file defines the hardware interface to one of the three timer counters
44 * MODIFICATION HISTORY:
46 * Ver Who Date Changes
47 * ----- ------ -------- -------------------------------------------------
48 * 1.00a drg/jz 01/21/10 First release
49 * 3.00 kvn 02/13/15 Modified code for MISRA-C:2012 compliance.
53 ******************************************************************************/
55 #ifndef XTTCPS_HW_H /* prevent circular inclusions */
56 #define XTTCPS_HW_H /* by using protection macros */
62 /***************************** Include Files *********************************/
64 #include "xil_types.h"
65 #include "xil_assert.h"
68 /************************** Constant Definitions *****************************/
70 /** @name Register Map
72 * Register offsets from the base address of the device.
76 #define XTTCPS_CLK_CNTRL_OFFSET 0x00000000U /**< Clock Control Register */
77 #define XTTCPS_CNT_CNTRL_OFFSET 0x0000000CU /**< Counter Control Register*/
78 #define XTTCPS_COUNT_VALUE_OFFSET 0x00000018U /**< Current Counter Value */
79 #define XTTCPS_INTERVAL_VAL_OFFSET 0x00000024U /**< Interval Count Value */
80 #define XTTCPS_MATCH_0_OFFSET 0x00000030U /**< Match 1 value */
81 #define XTTCPS_MATCH_1_OFFSET 0x0000003CU /**< Match 2 value */
82 #define XTTCPS_MATCH_2_OFFSET 0x00000048U /**< Match 3 value */
83 #define XTTCPS_ISR_OFFSET 0x00000054U /**< Interrupt Status Register */
84 #define XTTCPS_IER_OFFSET 0x00000060U /**< Interrupt Enable Register */
87 /** @name Clock Control Register
88 * Clock Control Register definitions
91 #define XTTCPS_CLK_CNTRL_PS_EN_MASK 0x00000001U /**< Prescale enable */
92 #define XTTCPS_CLK_CNTRL_PS_VAL_MASK 0x0000001EU /**< Prescale value */
93 #define XTTCPS_CLK_CNTRL_PS_VAL_SHIFT 1U /**< Prescale shift */
94 #define XTTCPS_CLK_CNTRL_PS_DISABLE 16U /**< Prescale disable */
95 #define XTTCPS_CLK_CNTRL_SRC_MASK 0x00000020U /**< Clock source */
96 #define XTTCPS_CLK_CNTRL_EXT_EDGE_MASK 0x00000040U /**< External Clock edge */
99 /** @name Counter Control Register
100 * Counter Control Register definitions
103 #define XTTCPS_CNT_CNTRL_DIS_MASK 0x00000001U /**< Disable the counter */
104 #define XTTCPS_CNT_CNTRL_INT_MASK 0x00000002U /**< Interval mode */
105 #define XTTCPS_CNT_CNTRL_DECR_MASK 0x00000004U /**< Decrement mode */
106 #define XTTCPS_CNT_CNTRL_MATCH_MASK 0x00000008U /**< Match mode */
107 #define XTTCPS_CNT_CNTRL_RST_MASK 0x00000010U /**< Reset counter */
108 #define XTTCPS_CNT_CNTRL_EN_WAVE_MASK 0x00000020U /**< Enable waveform */
109 #define XTTCPS_CNT_CNTRL_POL_WAVE_MASK 0x00000040U /**< Waveform polarity */
110 #define XTTCPS_CNT_CNTRL_RESET_VALUE 0x00000021U /**< Reset value */
113 /** @name Current Counter Value Register
114 * Current Counter Value Register definitions
117 #define XTTCPS_COUNT_VALUE_MASK 0x0000FFFFU /**< 16-bit counter value */
120 /** @name Interval Value Register
121 * Interval Value Register is the maximum value the counter will count up or
125 #define XTTCPS_INTERVAL_VAL_MASK 0x0000FFFFU /**< 16-bit Interval value*/
128 /** @name Match Registers
129 * Definitions for Match registers, each timer counter has three match
133 #define XTTCPS_MATCH_MASK 0x0000FFFFU /**< 16-bit Match value */
134 #define XTTCPS_NUM_MATCH_REG 3U /**< Num of Match reg */
137 /** @name Interrupt Registers
138 * Following register bit mask is for all interrupt registers.
142 #define XTTCPS_IXR_INTERVAL_MASK 0x00000001U /**< Interval Interrupt */
143 #define XTTCPS_IXR_MATCH_0_MASK 0x00000002U /**< Match 1 Interrupt */
144 #define XTTCPS_IXR_MATCH_1_MASK 0x00000004U /**< Match 2 Interrupt */
145 #define XTTCPS_IXR_MATCH_2_MASK 0x00000008U /**< Match 3 Interrupt */
146 #define XTTCPS_IXR_CNT_OVR_MASK 0x00000010U /**< Counter Overflow */
147 #define XTTCPS_IXR_ALL_MASK 0x0000001FU /**< All valid Interrupts */
151 /***************** Macros (Inline Functions) Definitions *********************/
153 /****************************************************************************/
156 * Read the given Timer Counter register.
158 * @param BaseAddress is the base address of the timer counter device.
159 * @param RegOffset is the register offset to be read
161 * @return The 32-bit value of the register
163 * @note C-style signature:
164 * u32 XTtcPs_ReadReg(u32 BaseAddress, u32 RegOffset)
166 *****************************************************************************/
167 #define XTtcPs_ReadReg(BaseAddress, RegOffset) \
168 (Xil_In32((BaseAddress) + (u32)(RegOffset)))
170 /****************************************************************************/
173 * Write the given Timer Counter register.
175 * @param BaseAddress is the base address of the timer counter device.
176 * @param RegOffset is the register offset to be written
177 * @param Data is the 32-bit value to write to the register
181 * @note C-style signature:
182 * void XTtcPs_WriteReg(XTtcPs BaseAddress, u32 RegOffset,
185 *****************************************************************************/
186 #define XTtcPs_WriteReg(BaseAddress, RegOffset, Data) \
187 (Xil_Out32((BaseAddress) + (u32)(RegOffset), (u32)(Data)))
189 /****************************************************************************/
192 * Calculate a match register offset using the Match Register index.
194 * @param MatchIndex is the 0-2 value of the match register
196 * @return MATCH_N_OFFSET.
198 * @note C-style signature:
199 * u32 XTtcPs_Match_N_Offset(u8 MatchIndex)
201 *****************************************************************************/
202 #define XTtcPs_Match_N_Offset(MatchIndex) \
203 ((u32)XTTCPS_MATCH_0_OFFSET + ((u32)(12U) * (u32)(MatchIndex)))
205 /************************** Function Prototypes ******************************/
207 /************************** Variable Definitions *****************************/
211 #endif /* end of protection macro */