1 /* $Id: xttcps_options.c,v 1.1.2.1 2011/01/20 04:08:59 sadanan Exp $ */
2 /******************************************************************************
4 * (c) Copyright 2010 Xilinx, Inc. All rights reserved.
6 * This file contains confidential and proprietary information of Xilinx, Inc.
7 * and is protected under U.S. and international copyright and other
8 * intellectual property laws.
11 * This disclaimer is not a license and does not grant any rights to the
12 * materials distributed herewith. Except as otherwise provided in a valid
13 * license issued to you by Xilinx, and to the maximum extent permitted by
14 * applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL
15 * FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS,
16 * IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
17 * MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE;
18 * and (2) Xilinx shall not be liable (whether in contract or tort, including
19 * negligence, or under any other theory of liability) for any loss or damage
20 * of any kind or nature related to, arising under or in connection with these
21 * materials, including for any direct, or any indirect, special, incidental,
22 * or consequential loss or damage (including loss of data, profits, goodwill,
23 * or any type of loss or damage suffered as a result of any action brought by
24 * a third party) even if such damage or loss was reasonably foreseeable or
25 * Xilinx had been advised of the possibility of the same.
27 * CRITICAL APPLICATIONS
28 * Xilinx products are not designed or intended to be fail-safe, or for use in
29 * any application requiring fail-safe performance, such as life-support or
30 * safety devices or systems, Class III medical devices, nuclear facilities,
31 * applications related to the deployment of airbags, or any other applications
32 * that could lead to death, personal injury, or severe property or
33 * environmental damage (individually and collectively, "Critical
34 * Applications"). Customer assumes the sole risk and liability of any use of
35 * Xilinx products in Critical Applications, subject only to applicable laws
36 * and regulations governing limitations on product liability.
38 * THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE
41 ******************************************************************************/
42 /*****************************************************************************/
45 * @file xttcps_options.c
47 * This file contains functions to get or set option features for the device.
50 * MODIFICATION HISTORY:
52 * Ver Who Date Changes
53 * ----- ------ -------- ---------------------------------------------
54 * 1.00a drg/jz 01/21/10 First release
55 * 1.01a nm 03/05/2012 Removed break statement after return to remove
56 * compilation warnings.
59 ******************************************************************************/
61 /***************************** Include Files *********************************/
65 /************************** Constant Definitions *****************************/
68 /**************************** Type Definitions *******************************/
71 /***************** Macros (Inline Functions) Definitions *********************/
74 /************************** Function Prototypes ******************************/
77 /************************** Variable Definitions *****************************/
80 * Create the table of options which are processed to get/set the device
81 * options. These options are table driven to allow easy maintenance and
82 * expansion of the options.
90 static OptionsMap TmrCtrOptionsTable[] = {
91 {XTTCPS_OPTION_EXTERNAL_CLK, XTTCPS_CLK_CNTRL_SRC_MASK,
92 XTTCPS_CLK_CNTRL_OFFSET},
93 {XTTCPS_OPTION_CLK_EDGE_NEG, XTTCPS_CLK_CNTRL_EXT_EDGE_MASK,
94 XTTCPS_CLK_CNTRL_OFFSET},
95 {XTTCPS_OPTION_INTERVAL_MODE, XTTCPS_CNT_CNTRL_INT_MASK,
96 XTTCPS_CNT_CNTRL_OFFSET},
97 {XTTCPS_OPTION_DECREMENT, XTTCPS_CNT_CNTRL_DECR_MASK,
98 XTTCPS_CNT_CNTRL_OFFSET},
99 {XTTCPS_OPTION_MATCH_MODE, XTTCPS_CNT_CNTRL_MATCH_MASK,
100 XTTCPS_CNT_CNTRL_OFFSET},
101 {XTTCPS_OPTION_WAVE_DISABLE, XTTCPS_CNT_CNTRL_EN_WAVE_MASK,
102 XTTCPS_CNT_CNTRL_OFFSET},
103 {XTTCPS_OPTION_WAVE_POLARITY, XTTCPS_CNT_CNTRL_POL_WAVE_MASK,
104 XTTCPS_CNT_CNTRL_OFFSET},
107 #define XTTCPS_NUM_TMRCTR_OPTIONS (sizeof(TmrCtrOptionsTable) / \
110 /*****************************************************************************/
113 * This function sets the options for the TTC device.
115 * @param InstancePtr is a pointer to the XTtcPs instance.
116 * @param Options contains the specified options to be set. This is a bit
117 * mask where a 1 means to turn the option on, and a 0 means to
118 * turn the option off. One or more bit values may be contained
119 * in the mask. See the bit definitions named XTTCPS_*_OPTION in
123 * - XST_SUCCESS if options are successfully set.
124 * - XST_FAILURE if any of the options are unknown.
128 ******************************************************************************/
129 int XTtcPs_SetOptions(XTtcPs *InstancePtr, u32 Options)
135 Xil_AssertNonvoid(InstancePtr != NULL);
136 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
138 ClockReg = XTtcPs_ReadReg(InstancePtr->Config.BaseAddress,
139 XTTCPS_CLK_CNTRL_OFFSET);
140 CountReg = XTtcPs_ReadReg(InstancePtr->Config.BaseAddress,
141 XTTCPS_CNT_CNTRL_OFFSET);
144 * Loop through the options table, turning the option on or off
145 * depending on whether the bit is set in the incoming options flag.
147 for (Index = 0; Index < XTTCPS_NUM_TMRCTR_OPTIONS; Index++) {
148 if (Options & TmrCtrOptionsTable[Index].Option) {
150 switch (TmrCtrOptionsTable[Index].Register) {
152 case XTTCPS_CLK_CNTRL_OFFSET:
154 ClockReg |= TmrCtrOptionsTable[Index].Mask;
157 case XTTCPS_CNT_CNTRL_OFFSET:
159 CountReg |= TmrCtrOptionsTable[Index].Mask;
167 switch (TmrCtrOptionsTable[Index].Register) {
169 case XTTCPS_CLK_CNTRL_OFFSET:
171 ClockReg &= ~TmrCtrOptionsTable[Index].Mask;
174 case XTTCPS_CNT_CNTRL_OFFSET:
176 CountReg &= ~TmrCtrOptionsTable[Index].Mask;
186 * Now write the registers. Leave it to the upper layers to restart the
189 XTtcPs_WriteReg(InstancePtr->Config.BaseAddress,
190 XTTCPS_CLK_CNTRL_OFFSET, ClockReg);
191 XTtcPs_WriteReg(InstancePtr->Config.BaseAddress,
192 XTTCPS_CNT_CNTRL_OFFSET, CountReg);
197 /*****************************************************************************/
200 * This function gets the settings for the options for the TTC device.
202 * @param InstancePtr is a pointer to the XTtcPs instance.
206 * The return u32 contains the specified options that are set. This is a bit
207 * mask where a '1' means the option is on, and a'0' means the option is off.
208 * One or more bit values may be contained in the mask. See the bit definitions
209 * named XTTCPS_*_OPTION in the file xttcps.h.
213 ******************************************************************************/
214 u32 XTtcPs_GetOptions(XTtcPs *InstancePtr)
220 Xil_AssertNonvoid(InstancePtr != NULL);
221 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
225 * Loop through the options table to determine which options are set
227 for (Index = 0; Index < XTTCPS_NUM_TMRCTR_OPTIONS; Index++) {
229 * Get the control register to determine which options are
232 Register = XTtcPs_ReadReg(InstancePtr->Config.BaseAddress,
233 TmrCtrOptionsTable[Index].
236 if (Register & TmrCtrOptionsTable[Index].Mask) {
237 OptionsFlag |= TmrCtrOptionsTable[Index].Option;