]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R5_UltraScale_MPSoC/RTOSDemo_R5_bsp/psu_cortexr5_0/libsrc/ttcps_v3_1/src/xttcps_options.c
Correct alignment issue in GCC and RVDS Cortex-A9 port that was preventing full float...
[freertos] / FreeRTOS / Demo / CORTEX_R5_UltraScale_MPSoC / RTOSDemo_R5_bsp / psu_cortexr5_0 / libsrc / ttcps_v3_1 / 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 * @addtogroup ttcps_v3_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 * 3.00  kvn    02/13/15 Modified code for MISRA-C:2012 compliance.
50 * </pre>
51 *
52 ******************************************************************************/
53
54 /***************************** Include Files *********************************/
55
56 #include "xttcps.h"
57
58 /************************** Constant Definitions *****************************/
59
60
61 /**************************** Type Definitions *******************************/
62
63
64 /***************** Macros (Inline Functions) Definitions *********************/
65
66
67 /************************** Function Prototypes ******************************/
68
69
70 /************************** Variable Definitions *****************************/
71
72 /*
73  * Create the table of options which are processed to get/set the device
74  * options. These options are table driven to allow easy maintenance and
75  * expansion of the options.
76  */
77 typedef struct {
78         u32 Option;
79         u32 Mask;
80         u32 Register;
81 } OptionsMap;
82
83 static OptionsMap TmrCtrOptionsTable[] = {
84         {XTTCPS_OPTION_EXTERNAL_CLK, XTTCPS_CLK_CNTRL_SRC_MASK,
85          XTTCPS_CLK_CNTRL_OFFSET},
86         {XTTCPS_OPTION_CLK_EDGE_NEG, XTTCPS_CLK_CNTRL_EXT_EDGE_MASK,
87          XTTCPS_CLK_CNTRL_OFFSET},
88         {XTTCPS_OPTION_INTERVAL_MODE, XTTCPS_CNT_CNTRL_INT_MASK,
89          XTTCPS_CNT_CNTRL_OFFSET},
90         {XTTCPS_OPTION_DECREMENT, XTTCPS_CNT_CNTRL_DECR_MASK,
91          XTTCPS_CNT_CNTRL_OFFSET},
92         {XTTCPS_OPTION_MATCH_MODE, XTTCPS_CNT_CNTRL_MATCH_MASK,
93          XTTCPS_CNT_CNTRL_OFFSET},
94         {XTTCPS_OPTION_WAVE_DISABLE, XTTCPS_CNT_CNTRL_EN_WAVE_MASK,
95          XTTCPS_CNT_CNTRL_OFFSET},
96         {XTTCPS_OPTION_WAVE_POLARITY, XTTCPS_CNT_CNTRL_POL_WAVE_MASK,
97          XTTCPS_CNT_CNTRL_OFFSET},
98 };
99
100 #define XTTCPS_NUM_TMRCTR_OPTIONS (sizeof(TmrCtrOptionsTable) / \
101                                 sizeof(OptionsMap))
102
103 /*****************************************************************************/
104 /**
105 *
106 * This function sets the options for the TTC device.
107 *
108 * @param        InstancePtr is a pointer to the XTtcPs instance.
109 * @param        Options contains the specified options to be set. This is a bit
110 *               mask where a 1 means to turn the option on, and a 0 means to
111 *               turn the option off. One or more bit values may be contained
112 *               in the mask. See the bit definitions named XTTCPS_*_OPTION in
113 *               the file xttcps.h.
114 *
115 * @return
116 *               - XST_SUCCESS if options are successfully set.
117 *               - XST_FAILURE if any of the options are unknown.
118 *
119 * @note         None
120 *
121 ******************************************************************************/
122 s32 XTtcPs_SetOptions(XTtcPs *InstancePtr, u32 Options)
123 {
124         u32 CountReg;
125         u32 ClockReg;
126         u32 Index;
127         s32 Status = XST_SUCCESS;
128
129         Xil_AssertNonvoid(InstancePtr != NULL);
130         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
131
132         ClockReg = XTtcPs_ReadReg(InstancePtr->Config.BaseAddress,
133                                     XTTCPS_CLK_CNTRL_OFFSET);
134         CountReg = XTtcPs_ReadReg(InstancePtr->Config.BaseAddress,
135                                     XTTCPS_CNT_CNTRL_OFFSET);
136
137         /*
138          * Loop through the options table, turning the option on or off
139          * depending on whether the bit is set in the incoming options flag.
140          */
141         for (Index = 0U; Index < XTTCPS_NUM_TMRCTR_OPTIONS; Index++) {
142                 if(Status != (s32)XST_FAILURE) {
143                         if ((Options & TmrCtrOptionsTable[Index].Option) != (u32)0) {
144
145                         switch (TmrCtrOptionsTable[Index].Register) {
146
147                         case XTTCPS_CLK_CNTRL_OFFSET:
148                                 /* Add option */
149                                 ClockReg |= TmrCtrOptionsTable[Index].Mask;
150                                 break;
151
152                         case XTTCPS_CNT_CNTRL_OFFSET:
153                                 /* Add option */
154                                 CountReg |= TmrCtrOptionsTable[Index].Mask;
155                                 break;
156
157                         default:
158                                 Status = XST_FAILURE;
159                                 break;
160                         }
161                 }
162                 else {
163                         switch (TmrCtrOptionsTable[Index].Register) {
164
165                         case XTTCPS_CLK_CNTRL_OFFSET:
166                                 /* Remove option*/
167                                 ClockReg &= ~TmrCtrOptionsTable[Index].Mask;
168                                 break;
169
170                         case XTTCPS_CNT_CNTRL_OFFSET:
171                                 /* Remove option*/
172                                 CountReg &= ~TmrCtrOptionsTable[Index].Mask;
173                                 break;
174
175                         default:
176                                 Status = XST_FAILURE;
177                                 break;
178                                 }
179                         }
180                 }
181         }
182
183         /*
184          * Now write the registers. Leave it to the upper layers to restart the
185          * device.
186          */
187         if (Status != (s32)XST_FAILURE ) {
188                 XTtcPs_WriteReg(InstancePtr->Config.BaseAddress,
189                                   XTTCPS_CLK_CNTRL_OFFSET, ClockReg);
190                 XTtcPs_WriteReg(InstancePtr->Config.BaseAddress,
191                                   XTTCPS_CNT_CNTRL_OFFSET, CountReg);
192         }
193
194         return Status;
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 = 0U;
217         u32 Register;
218         u32 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 = 0U; 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) != (u32)0) {
237                         OptionsFlag |= TmrCtrOptionsTable[Index].Option;
238                 }
239         }
240
241         return OptionsFlag;
242 }
243 /** @} */