]> git.sur5r.net Git - freertos/blob
e83dc7ab0440451462a104d620d23d9d1b633897
[freertos] /
1 /* $Id: xttcps_options.c,v 1.1.2.1 2011/01/20 04:08:59 sadanan Exp $ */
2 /******************************************************************************
3 *
4 * (c) Copyright 2010 Xilinx, Inc. All rights reserved.
5 *
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.
9 *
10 * DISCLAIMER
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.
26 *
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.
37 *
38 * THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE
39 * AT ALL TIMES.
40 *
41 ******************************************************************************/
42 /*****************************************************************************/
43 /**
44 *
45 * @file xttcps_options.c
46 *
47 * This file contains functions to get or set option features for the device.
48 *
49 * <pre>
50 * MODIFICATION HISTORY:
51 *
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.
57 * </pre>
58 *
59 ******************************************************************************/
60
61 /***************************** Include Files *********************************/
62
63 #include "xttcps.h"
64
65 /************************** Constant Definitions *****************************/
66
67
68 /**************************** Type Definitions *******************************/
69
70
71 /***************** Macros (Inline Functions) Definitions *********************/
72
73
74 /************************** Function Prototypes ******************************/
75
76
77 /************************** Variable Definitions *****************************/
78
79 /*
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.
83  */
84 typedef struct {
85         u32 Option;
86         u32 Mask;
87         u32 Register;
88 } OptionsMap;
89
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},
105 };
106
107 #define XTTCPS_NUM_TMRCTR_OPTIONS (sizeof(TmrCtrOptionsTable) / \
108                                 sizeof(OptionsMap))
109
110 /*****************************************************************************/
111 /**
112 *
113 * This function sets the options for the TTC device.
114 *
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
120 *               the file xttcps.h.
121 *
122 * @return
123 *               - XST_SUCCESS if options are successfully set.
124 *               - XST_FAILURE if any of the options are unknown.
125 *
126 * @note         None
127 *
128 ******************************************************************************/
129 int XTtcPs_SetOptions(XTtcPs *InstancePtr, u32 Options)
130 {
131         u32 CountReg;
132         u32 ClockReg;
133         unsigned Index;
134
135         Xil_AssertNonvoid(InstancePtr != NULL);
136         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
137
138         ClockReg = XTtcPs_ReadReg(InstancePtr->Config.BaseAddress,
139                                     XTTCPS_CLK_CNTRL_OFFSET);
140         CountReg = XTtcPs_ReadReg(InstancePtr->Config.BaseAddress,
141                                     XTTCPS_CNT_CNTRL_OFFSET);
142
143         /*
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.
146          */
147         for (Index = 0; Index < XTTCPS_NUM_TMRCTR_OPTIONS; Index++) {
148                 if (Options & TmrCtrOptionsTable[Index].Option) {
149
150                         switch (TmrCtrOptionsTable[Index].Register) {
151
152                         case XTTCPS_CLK_CNTRL_OFFSET:
153                                 /* Add option */
154                                 ClockReg |= TmrCtrOptionsTable[Index].Mask;
155                                 break;
156
157                         case XTTCPS_CNT_CNTRL_OFFSET:
158                                 /* Add option */
159                                 CountReg |= TmrCtrOptionsTable[Index].Mask;
160                                 break;
161
162                         default:
163                                 return XST_FAILURE;
164                         }
165                 }
166                 else {
167                         switch (TmrCtrOptionsTable[Index].Register) {
168
169                         case XTTCPS_CLK_CNTRL_OFFSET:
170                                 /* Remove option*/
171                                 ClockReg &= ~TmrCtrOptionsTable[Index].Mask;
172                                 break;
173
174                         case XTTCPS_CNT_CNTRL_OFFSET:
175                                 /* Remove option*/
176                                 CountReg &= ~TmrCtrOptionsTable[Index].Mask;
177                                 break;
178
179                         default:
180                                 return XST_FAILURE;
181                         }
182                 }
183         }
184
185         /*
186          * Now write the registers. Leave it to the upper layers to restart the
187          * device.
188          */
189         XTtcPs_WriteReg(InstancePtr->Config.BaseAddress,
190                           XTTCPS_CLK_CNTRL_OFFSET, ClockReg);
191         XTtcPs_WriteReg(InstancePtr->Config.BaseAddress,
192                           XTTCPS_CNT_CNTRL_OFFSET, CountReg);
193
194         return XST_SUCCESS;
195 }
196
197 /*****************************************************************************/
198 /**
199 *
200 * This function gets the settings for the options for the TTC device.
201 *
202 * @param        InstancePtr is a pointer to the XTtcPs instance.
203 *
204 * @return
205 *
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.
210 *
211 * @note         None.
212 *
213 ******************************************************************************/
214 u32 XTtcPs_GetOptions(XTtcPs *InstancePtr)
215 {
216         u32 OptionsFlag = 0;
217         u32 Register;
218         unsigned Index;
219
220         Xil_AssertNonvoid(InstancePtr != NULL);
221         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
222
223
224         /*
225          * Loop through the options table to determine which options are set
226          */
227         for (Index = 0; Index < XTTCPS_NUM_TMRCTR_OPTIONS; Index++) {
228                 /*
229                  * Get the control register to determine which options are
230                  * currently set.
231                  */
232                 Register = XTtcPs_ReadReg(InstancePtr->Config.BaseAddress,
233                                               TmrCtrOptionsTable[Index].
234                                               Register);
235
236                 if (Register & TmrCtrOptionsTable[Index].Mask) {
237                         OptionsFlag |= TmrCtrOptionsTable[Index].Option;
238                 }
239         }
240
241         return OptionsFlag;
242 }