]> git.sur5r.net Git - freertos/blob
fa53b3856355f96e9e3410a4064164613e9a573a
[freertos] /
1 /******************************************************************************
2 *
3 * Copyright (C) 2010 - 2014 Xilinx, Inc.  All rights reserved.
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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.
18 *
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
25 * SOFTWARE.
26 *
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.
30 *
31 ******************************************************************************/
32 /*****************************************************************************/
33 /**
34 *
35 * @file xttcps_options.c
36 * @addtogroup ttcps_v2_0
37 * @{
38 *
39 * This file contains functions to get or set option features for the device.
40 *
41 * <pre>
42 * MODIFICATION HISTORY:
43 *
44 * Ver   Who    Date     Changes
45 * ----- ------ -------- ---------------------------------------------
46 * 1.00a drg/jz 01/21/10 First release
47 * 1.01a nm     03/05/2012 Removed break statement after return to remove
48 *                         compilation warnings.
49 * </pre>
50 *
51 ******************************************************************************/
52
53 /***************************** Include Files *********************************/
54
55 #include "xttcps.h"
56
57 /************************** Constant Definitions *****************************/
58
59
60 /**************************** Type Definitions *******************************/
61
62
63 /***************** Macros (Inline Functions) Definitions *********************/
64
65
66 /************************** Function Prototypes ******************************/
67
68
69 /************************** Variable Definitions *****************************/
70
71 /*
72  * Create the table of options which are processed to get/set the device
73  * options. These options are table driven to allow easy maintenance and
74  * expansion of the options.
75  */
76 typedef struct {
77         u32 Option;
78         u32 Mask;
79         u32 Register;
80 } OptionsMap;
81
82 static OptionsMap TmrCtrOptionsTable[] = {
83         {XTTCPS_OPTION_EXTERNAL_CLK, XTTCPS_CLK_CNTRL_SRC_MASK,
84          XTTCPS_CLK_CNTRL_OFFSET},
85         {XTTCPS_OPTION_CLK_EDGE_NEG, XTTCPS_CLK_CNTRL_EXT_EDGE_MASK,
86          XTTCPS_CLK_CNTRL_OFFSET},
87         {XTTCPS_OPTION_INTERVAL_MODE, XTTCPS_CNT_CNTRL_INT_MASK,
88          XTTCPS_CNT_CNTRL_OFFSET},
89         {XTTCPS_OPTION_DECREMENT, XTTCPS_CNT_CNTRL_DECR_MASK,
90          XTTCPS_CNT_CNTRL_OFFSET},
91         {XTTCPS_OPTION_MATCH_MODE, XTTCPS_CNT_CNTRL_MATCH_MASK,
92          XTTCPS_CNT_CNTRL_OFFSET},
93         {XTTCPS_OPTION_WAVE_DISABLE, XTTCPS_CNT_CNTRL_EN_WAVE_MASK,
94          XTTCPS_CNT_CNTRL_OFFSET},
95         {XTTCPS_OPTION_WAVE_POLARITY, XTTCPS_CNT_CNTRL_POL_WAVE_MASK,
96          XTTCPS_CNT_CNTRL_OFFSET},
97 };
98
99 #define XTTCPS_NUM_TMRCTR_OPTIONS (sizeof(TmrCtrOptionsTable) / \
100                                 sizeof(OptionsMap))
101
102 /*****************************************************************************/
103 /**
104 *
105 * This function sets the options for the TTC device.
106 *
107 * @param        InstancePtr is a pointer to the XTtcPs instance.
108 * @param        Options contains the specified options to be set. This is a bit
109 *               mask where a 1 means to turn the option on, and a 0 means to
110 *               turn the option off. One or more bit values may be contained
111 *               in the mask. See the bit definitions named XTTCPS_*_OPTION in
112 *               the file xttcps.h.
113 *
114 * @return
115 *               - XST_SUCCESS if options are successfully set.
116 *               - XST_FAILURE if any of the options are unknown.
117 *
118 * @note         None
119 *
120 ******************************************************************************/
121 int XTtcPs_SetOptions(XTtcPs *InstancePtr, u32 Options)
122 {
123         u32 CountReg;
124         u32 ClockReg;
125         unsigned Index;
126
127         Xil_AssertNonvoid(InstancePtr != NULL);
128         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
129
130         ClockReg = XTtcPs_ReadReg(InstancePtr->Config.BaseAddress,
131                                     XTTCPS_CLK_CNTRL_OFFSET);
132         CountReg = XTtcPs_ReadReg(InstancePtr->Config.BaseAddress,
133                                     XTTCPS_CNT_CNTRL_OFFSET);
134
135         /*
136          * Loop through the options table, turning the option on or off
137          * depending on whether the bit is set in the incoming options flag.
138          */
139         for (Index = 0; Index < XTTCPS_NUM_TMRCTR_OPTIONS; Index++) {
140                 if (Options & TmrCtrOptionsTable[Index].Option) {
141
142                         switch (TmrCtrOptionsTable[Index].Register) {
143
144                         case XTTCPS_CLK_CNTRL_OFFSET:
145                                 /* Add option */
146                                 ClockReg |= TmrCtrOptionsTable[Index].Mask;
147                                 break;
148
149                         case XTTCPS_CNT_CNTRL_OFFSET:
150                                 /* Add option */
151                                 CountReg |= TmrCtrOptionsTable[Index].Mask;
152                                 break;
153
154                         default:
155                                 return XST_FAILURE;
156                         }
157                 }
158                 else {
159                         switch (TmrCtrOptionsTable[Index].Register) {
160
161                         case XTTCPS_CLK_CNTRL_OFFSET:
162                                 /* Remove option*/
163                                 ClockReg &= ~TmrCtrOptionsTable[Index].Mask;
164                                 break;
165
166                         case XTTCPS_CNT_CNTRL_OFFSET:
167                                 /* Remove option*/
168                                 CountReg &= ~TmrCtrOptionsTable[Index].Mask;
169                                 break;
170
171                         default:
172                                 return XST_FAILURE;
173                         }
174                 }
175         }
176
177         /*
178          * Now write the registers. Leave it to the upper layers to restart the
179          * device.
180          */
181         XTtcPs_WriteReg(InstancePtr->Config.BaseAddress,
182                           XTTCPS_CLK_CNTRL_OFFSET, ClockReg);
183         XTtcPs_WriteReg(InstancePtr->Config.BaseAddress,
184                           XTTCPS_CNT_CNTRL_OFFSET, CountReg);
185
186         return XST_SUCCESS;
187 }
188
189 /*****************************************************************************/
190 /**
191 *
192 * This function gets the settings for the options for the TTC device.
193 *
194 * @param        InstancePtr is a pointer to the XTtcPs instance.
195 *
196 * @return
197 *
198 * The return u32 contains the specified options that are set. This is a bit
199 * mask where a '1' means the option is on, and a'0' means the option is off.
200 * One or more bit values may be contained in the mask. See the bit definitions
201 * named XTTCPS_*_OPTION in the file xttcps.h.
202 *
203 * @note         None.
204 *
205 ******************************************************************************/
206 u32 XTtcPs_GetOptions(XTtcPs *InstancePtr)
207 {
208         u32 OptionsFlag = 0;
209         u32 Register;
210         unsigned Index;
211
212         Xil_AssertNonvoid(InstancePtr != NULL);
213         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
214
215
216         /*
217          * Loop through the options table to determine which options are set
218          */
219         for (Index = 0; Index < XTTCPS_NUM_TMRCTR_OPTIONS; Index++) {
220                 /*
221                  * Get the control register to determine which options are
222                  * currently set.
223                  */
224                 Register = XTtcPs_ReadReg(InstancePtr->Config.BaseAddress,
225                                               TmrCtrOptionsTable[Index].
226                                               Register);
227
228                 if (Register & TmrCtrOptionsTable[Index].Mask) {
229                         OptionsFlag |= TmrCtrOptionsTable[Index].Option;
230                 }
231         }
232
233         return OptionsFlag;
234 }
235 /** @} */