]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/tmrctr_v3_0/src/xtmrctr_options.c
cc20dd0073a56f1091dc0921e7fc2094eec9b1a5
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / BSP / microblaze_0 / libsrc / tmrctr_v3_0 / src / xtmrctr_options.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2002 - 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 xtmrctr_options.c
36 *
37 * Contains configuration options functions for the XTmrCtr component.
38 *
39 * <pre>
40 * MODIFICATION HISTORY:
41 *
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
47 *                     definitions.
48 * 2.04a sdm  07/12/11 Added support for the cascade mode operation.
49 * </pre>
50 *
51 ******************************************************************************/
52
53 /***************************** Include Files *********************************/
54
55 #include "xtmrctr.h"
56 #include "xtmrctr_i.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  * The following data type maps an option to a register mask such that getting
74  * and setting the options may be table driven.
75  */
76 typedef struct {
77         u32 Option;
78         u32 Mask;
79 } Mapping;
80
81 /*
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.
85  */
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}
95 };
96
97 /* Create a constant for the number of entries in the table */
98
99 #define XTC_NUM_OPTIONS   (sizeof(OptionsTable) / sizeof(Mapping))
100
101 /*****************************************************************************/
102 /**
103 *
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.
109 *
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.
120 *
121 * @return       None.
122 *
123 * @note         None.
124 *
125 ******************************************************************************/
126 void XTmrCtr_SetOptions(XTmrCtr * InstancePtr, u8 TmrCtrNumber, u32 Options)
127 {
128         u32 CounterControlReg = 0;
129         u32 Index;
130
131         Xil_AssertVoid(InstancePtr != NULL);
132         Xil_AssertVoid(TmrCtrNumber < XTC_DEVICE_TIMER_COUNT);
133         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
134
135         /*
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.
138          */
139
140         for (Index = 0; Index < XTC_NUM_OPTIONS; Index++) {
141                 if (Options & OptionsTable[Index].Option) {
142
143                         /*
144                          * Turn the option on
145                          */
146                         CounterControlReg |= OptionsTable[Index].Mask;
147                 }
148                 else {
149                         /*
150                          * Turn the option off
151                          */
152                         CounterControlReg &= ~OptionsTable[Index].Mask;
153                 }
154         }
155
156         /*
157          * Write out the updated value to the actual register
158          */
159         XTmrCtr_WriteReg(InstancePtr->BaseAddress, TmrCtrNumber,
160                           XTC_TCSR_OFFSET, CounterControlReg);
161 }
162
163 /*****************************************************************************/
164 /**
165 *
166 * Get the options for the specified timer counter.
167 *
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).
173 *
174 * @return
175 *
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.
179 *
180 * @note         None.
181 *
182 ******************************************************************************/
183 u32 XTmrCtr_GetOptions(XTmrCtr * InstancePtr, u8 TmrCtrNumber)
184 {
185
186         u32 Options = 0;
187         u32 CounterControlReg;
188         u32 Index;
189
190         Xil_AssertNonvoid(InstancePtr != NULL);
191         Xil_AssertNonvoid(TmrCtrNumber < XTC_DEVICE_TIMER_COUNT);
192         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
193
194         /*
195          * Read the current contents of the control status register to allow
196          * the current options to be determined
197          */
198         CounterControlReg = XTmrCtr_ReadReg(InstancePtr->BaseAddress,
199                                                TmrCtrNumber, XTC_TCSR_OFFSET);
200         /*
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.
203          */
204         for (Index = 0; Index < XTC_NUM_OPTIONS; Index++) {
205                 if (CounterControlReg & OptionsTable[Index].Mask) {
206                         Options |= OptionsTable[Index].Option;  /* turn it on */
207                 }
208                 else {
209                         Options &= ~OptionsTable[Index].Option; /* turn it off */
210                 }
211         }
212
213         return Options;
214 }