1 /******************************************************************************
3 * Copyright (C) 2002 - 2014 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 /*****************************************************************************/
35 * @file xtmrctr_options.c
37 * Contains configuration options functions for the XTmrCtr component.
40 * MODIFICATION HISTORY:
42 * Ver Who Date Changes
43 * ----- ---- -------- -----------------------------------------------
44 * 1.00b jhl 02/06/02 First release
45 * 1.10b mta 03/21/07 Updated to new coding style
46 * 2.00a ktn 10/30/09 Updated to use HAL API's. _m is removed from all the macro
48 * 2.04a sdm 07/12/11 Added support for the cascade mode operation.
51 ******************************************************************************/
53 /***************************** Include Files *********************************/
56 #include "xtmrctr_i.h"
58 /************************** Constant Definitions *****************************/
61 /**************************** Type Definitions *******************************/
64 /***************** Macros (Inline Functions) Definitions *********************/
67 /************************** Function Prototypes ******************************/
70 /************************** Variable Definitions *****************************/
73 * The following data type maps an option to a register mask such that getting
74 * and setting the options may be table driven.
82 * Create the table which contains options which are to be processed to get/set
83 * the options. These options are table driven to allow easy maintenance and
84 * expansion of the options.
86 static Mapping OptionsTable[] = {
87 {XTC_CASCADE_MODE_OPTION, XTC_CSR_CASC_MASK},
88 {XTC_ENABLE_ALL_OPTION, XTC_CSR_ENABLE_ALL_MASK},
89 {XTC_DOWN_COUNT_OPTION, XTC_CSR_DOWN_COUNT_MASK},
90 {XTC_CAPTURE_MODE_OPTION, XTC_CSR_CAPTURE_MODE_MASK |
91 XTC_CSR_EXT_CAPTURE_MASK},
92 {XTC_INT_MODE_OPTION, XTC_CSR_ENABLE_INT_MASK},
93 {XTC_AUTO_RELOAD_OPTION, XTC_CSR_AUTO_RELOAD_MASK},
94 {XTC_EXT_COMPARE_OPTION, XTC_CSR_EXT_GENERATE_MASK}
97 /* Create a constant for the number of entries in the table */
99 #define XTC_NUM_OPTIONS (sizeof(OptionsTable) / sizeof(Mapping))
101 /*****************************************************************************/
104 * Enables the specified options for the specified timer counter. This function
105 * sets the options without regard to the current options of the driver. To
106 * prevent a loss of the current options, the user should call
107 * XTmrCtr_GetOptions() prior to this function and modify the retrieved options
108 * to pass into this function to prevent loss of the current options.
110 * @param InstancePtr is a pointer to the XTmrCtr instance.
111 * @param TmrCtrNumber is the timer counter of the device to operate on.
112 * Each device may contain multiple timer counters. The timer
113 * number is a zero based number with a range of
114 * 0 - (XTC_DEVICE_TIMER_COUNT - 1).
115 * @param Options contains the desired options to be set or cleared.
116 * Setting the option to '1' enables the option, clearing the to
117 * '0' disables the option. The options are bit masks such that
118 * multiple options may be set or cleared. The options are
119 * described in xtmrctr.h.
125 ******************************************************************************/
126 void XTmrCtr_SetOptions(XTmrCtr * InstancePtr, u8 TmrCtrNumber, u32 Options)
128 u32 CounterControlReg = 0;
131 Xil_AssertVoid(InstancePtr != NULL);
132 Xil_AssertVoid(TmrCtrNumber < XTC_DEVICE_TIMER_COUNT);
133 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
136 * Loop through the Options table, turning the enable on or off
137 * depending on whether the bit is set in the incoming Options flag.
140 for (Index = 0; Index < XTC_NUM_OPTIONS; Index++) {
141 if (Options & OptionsTable[Index].Option) {
146 CounterControlReg |= OptionsTable[Index].Mask;
150 * Turn the option off
152 CounterControlReg &= ~OptionsTable[Index].Mask;
157 * Write out the updated value to the actual register
159 XTmrCtr_WriteReg(InstancePtr->BaseAddress, TmrCtrNumber,
160 XTC_TCSR_OFFSET, CounterControlReg);
163 /*****************************************************************************/
166 * Get the options for the specified timer counter.
168 * @param InstancePtr is a pointer to the XTmrCtr instance.
169 * @param TmrCtrNumber is the timer counter of the device to operate on
170 * Each device may contain multiple timer counters. The timer
171 * number is a zero based number with a range of
172 * 0 - (XTC_DEVICE_TIMER_COUNT - 1).
176 * The currently set options. An option which is set to a '1' is enabled and
177 * set to a '0' is disabled. The options are bit masks such that multiple
178 * options may be set or cleared. The options are described in xtmrctr.h.
182 ******************************************************************************/
183 u32 XTmrCtr_GetOptions(XTmrCtr * InstancePtr, u8 TmrCtrNumber)
187 u32 CounterControlReg;
190 Xil_AssertNonvoid(InstancePtr != NULL);
191 Xil_AssertNonvoid(TmrCtrNumber < XTC_DEVICE_TIMER_COUNT);
192 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
195 * Read the current contents of the control status register to allow
196 * the current options to be determined
198 CounterControlReg = XTmrCtr_ReadReg(InstancePtr->BaseAddress,
199 TmrCtrNumber, XTC_TCSR_OFFSET);
201 * Loop through the Options table, turning the enable on or off
202 * depending on whether the bit is set in the current register settings.
204 for (Index = 0; Index < XTC_NUM_OPTIONS; Index++) {
205 if (CounterControlReg & OptionsTable[Index].Mask) {
206 Options |= OptionsTable[Index].Option; /* turn it on */
209 Options &= ~OptionsTable[Index].Option; /* turn it off */