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