]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A53_64-bit_UltraScale_MPSoC/RTOSDemo_A53_bsp/psu_cortexa53_0/libsrc/sysmonpsu_v2_3/src/xsysmonpsu.h
Update Zynq, MPSoc Cortex-A53 and MPSoc Cortex-R5 demo projects to build with the...
[freertos] / FreeRTOS / Demo / CORTEX_A53_64-bit_UltraScale_MPSoC / RTOSDemo_A53_bsp / psu_cortexa53_0 / libsrc / sysmonpsu_v2_3 / src / xsysmonpsu.h
1 /******************************************************************************
2 *
3 * Copyright (C) 2016-2017 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 * @file xsysmonpsu.h
35 *
36 * The XSysMon driver supports the Xilinx System Monitor device.
37 *
38 * The System Monitor device has the following features:
39 *       - PL Sysmon instance has 10-bit, 200-KSPS (kilo samples per second)
40 *               Analog-to-Digital Converter (ADC)
41 *       - PS Sysmon instance has 10-bit, 1000-KSPS ADC.
42 *       - Monitoring of on-chip supply voltages and temperature
43 *       - 1 dedicated differential analog-input pair and
44 *         16 auxiliary differential analog-input pairs
45 *       - Automatic alarms based on user defined limits for the on-chip
46 *         supply voltages and temperature
47 *       - Automatic Channel Sequencer, programmable averaging, programmable
48 *         acquisition time for the external inputs, unipolar or differential
49 *         input selection for the external inputs
50 *       - Inbuilt Calibration
51 *       - Optional interrupt request generation
52 *       - External Mux
53 *
54 *
55 * The user should refer to the hardware device specification for detailed
56 * information about the device.
57 *
58 * This header file contains the prototypes of driver functions that can
59 * be used to access the System Monitor device.
60 *
61 *
62 * <b> System Monitor Channel Sequencer Modes </b>
63 *
64 * The  System Monitor Channel Sequencer supports the following operating modes:
65 *
66 *   - <b> Default </b>: This is the default mode after power up.
67 *               In this mode of operation the System Monitor operates in
68 *               a sequence mode, monitoring the on chip sensors:
69 *               Temperature, VCCINT, and VCCAUX.
70 *   - <b> One pass through sequence </b>: In this mode the System Monitor
71 *               converts the channels enabled in the Sequencer Channel Enable
72 *               registers for a single pass and then stops.
73 *   - <b> Continuous cycling of sequence </b>: In this mode the System Monitor
74 *               converts the channels enabled in the Sequencer Channel Enable
75 *               registers continuously.
76 *   - <b> Single channel mode</b>: In this mode the System Monitor Channel
77 *               Sequencer is disabled and the System Monitor operates in a
78 *               Single Channel Mode.
79 *               The System Monitor can operate either in a Continuous or Event
80 *               driven sampling mode in the single channel mode.
81 *
82 *
83 * <b> Initialization and Configuration </b>
84 *
85 * The device driver enables higher layer software (e.g., an application) to
86 * communicate to the System Monitor device.
87 *
88 * XSysMonPsu_CfgInitialize() API is used to initialize the System Monitor
89 * device. The user needs to first call the XSysMonPsu_LookupConfig() API which
90 * returns the Configuration structure pointer which is passed as a parameter to
91 * the XSysMonPsu_CfgInitialize() API.
92 *
93 *
94 * <b>Interrupts</b>
95 *
96 * The System Monitor device supports interrupt driven mode and the default
97 * operation mode is polling mode.
98 *
99 * This driver does not provide a Interrupt Service Routine (ISR) for the device.
100 * It is the responsibility of the application to provide one if needed. Refer to
101 * the interrupt example provided with this driver for details on using the
102 * device in interrupt mode.
103 *
104 *
105 * <b> Virtual Memory </b>
106 *
107 * This driver supports Virtual Memory. The RTOS is responsible for calculating
108 * the correct device base address in Virtual Memory space.
109 *
110 *
111 * <b> Threads </b>
112 *
113 * This driver is not thread safe. Any needs for threads or thread mutual
114 * exclusion must be satisfied by the layer above this driver.
115 *
116 *
117 * <b> Asserts </b>
118 *
119 * Asserts are used within all Xilinx drivers to enforce constraints on argument
120 * values. Asserts can be turned off on a system-wide basis by defining, at
121 * compile time, the NDEBUG identifier. By default, asserts are turned on and it
122 * is recommended that users leave asserts on during development.
123 *
124 *
125 * <b> Building the driver </b>
126 *
127 * The XSysMonPsu driver is composed of several source files. This allows the user
128 * to build and link only those parts of the driver that are necessary.
129 *
130 *
131 * <b> Limitations of the driver </b>
132 *
133 * System Monitor device can be accessed through the JTAG port and the AXI
134 * interface. The driver implementation does not support the simultaneous access
135 * of the device by both these interfaces. The user has to take care of this
136 * situation in the user application code.
137 *
138 *
139 *
140 * <br><br>
141 *
142 *
143 * <pre>
144 * MODIFICATION HISTORY:
145 *
146 * Ver   Who    Date     Changes
147 * ----- -----  -------- -----------------------------------------------
148 * 1.00  kvn    12/15/15 First release
149 *              02/15/16 Corrected Assert function call in
150 *                       XSysMonPsu_GetMonitorStatus API.
151 *              03/03/16 Added Temperature remote channel for Setsingle
152 *                       channel API. Also corrected external mux channel
153 *                       numbers.
154 * 1.1   kvn    05/05/16 Modified code for MISRA-C:2012 Compliance.
155 * 2.0   vns    08/14/16 Fixed CR #956780, added support for enabling/disabling
156 *                       SEQ_CH2 and SEQ_AVG2 registers, modified function
157 *                       prototypes of XSysMonPsu_GetSeqAvgEnables,
158 *                       XSysMonPsu_SetSeqAvgEnables, XSysMonPsu_SetSeqChEnables,
159 *                       XSysMonPsu_GetSeqChEnables,
160 *                       XSysMonPsu_SetSeqInputMode, XSysMonPsu_GetSeqInputMode,
161 *                       XSysMonPsu_SetSeqAcqTime
162 *                       and XSysMonPsu_GetSeqAcqTime to provide support for
163 *                       set/get 64 bit value.
164 *                       Added constants XSM_CFR_ALM_SUPPLY*(8-31)_MASKs to
165 *                       provide support for enabling extra PS alarams.
166 * 2.1   sk     03/03/16 Check for PL reset before doing PL Sysmon reset.
167 *       ms     03/17/17 Added readme.txt file in examples folder for doxygen
168 *                       generation.
169 *       ms     04/05/17 Modified Comment lines in functions of sysmonpsu
170 *                       examples to recognize it as documentation block
171 *                       for doxygen generation.
172 * 2.2   sk     04/14/17 Corrected temperature conversion formulas.
173 * 2.3   mn     12/11/17 Added missing closing bracket error when C++ is used
174 *       mn     12/12/17 Added Conversion Support for voltages having Range of
175 *                       1 Volt
176 *       mn     12/13/17 Correct the AMS block channel numbers
177 *       ms     12/15/17 Added peripheral test support.
178 *       ms     01/04/18 Provided conditional checks for interrupt example
179 *                       in sysmonpsu_header.h
180 *       mn     03/08/18 Update Clock Divisor to the proper value
181 *
182 * </pre>
183 *
184 ******************************************************************************/
185
186
187 #ifndef XSYSMONPSU_H_                   /* prevent circular inclusions */
188 #define XSYSMONPSU_H_                   /* by using protection macros */
189
190 #ifdef __cplusplus
191 extern "C" {
192 #endif
193
194 /***************************** Include Files *********************************/
195
196 #include "xstatus.h"
197 #include "xil_assert.h"
198 #include "xil_io.h"
199 #include "xsysmonpsu_hw.h"
200 #include "xil_types.h"
201
202 /************************** Constant Definitions *****************************/
203
204 /**
205  * @name Indexes for the different channels.
206  * @{
207  */
208 #define XSM_CH_TEMP             0x0U  /**< On Chip Temperature */
209 #define XSM_CH_SUPPLY1          0x1U  /**< SUPPLY1 VCC_PSINTLP */
210 #define XSM_CH_SUPPLY2          0x2U  /**< SUPPLY2 VCC_PSINTFP */
211 #define XSM_CH_VPVN             0x3U  /**< VP/VN Dedicated analog inputs */
212 #define XSM_CH_VREFP            0x4U  /**< VREFP */
213 #define XSM_CH_VREFN            0x5U  /**< VREFN */
214 #define XSM_CH_SUPPLY3          0x6U  /**< SUPPLY3 VCC_PSAUX */
215 #define XSM_CH_SUPPLY_CALIB     0x08U /**< Supply Calib Data Reg */
216 #define XSM_CH_ADC_CALIB        0x09U /**< ADC Offset Channel Reg */
217 #define XSM_CH_GAINERR_CALIB    0x0AU /**< Gain Error Channel Reg  */
218 #define XSM_CH_SUPPLY4          0x0DU /**< SUPPLY4 VCC_PSDDR_504 */
219 #define XSM_CH_SUPPLY5          0x0EU /**< SUPPLY5 VCC_PSIO3_503 */
220 #define XSM_CH_SUPPLY6          0x0FU /**< SUPPLY6 VCC_PSIO0_500 */
221 #define XSM_CH_AUX_MIN          16U   /**< Channel number for 1st Aux Channel */
222 #define XSM_CH_AUX_MAX          31U   /**< Channel number for Last Aux channel */
223 #define XSM_CH_SUPPLY7      32U   /**< SUPPLY7 VCC_PSIO1_501 */
224 #define XSM_CH_SUPPLY8      33U   /**< SUPPLY8 VCC_PSIO2_502 */
225 #define XSM_CH_SUPPLY9      34U   /**< SUPPLY9 PS_MGTRAVCC */
226 #define XSM_CH_SUPPLY10     35U   /**< SUPPLY10 PS_MGTRAVTT */
227 #define XSM_CH_VCCAMS       36U   /**< VCCAMS */
228 #define XSM_CH_TEMP_REMTE   37U   /**< Temperature Remote */
229 #define XSM_CH_VCC_PSLL0    48U   /**< VCC_PSLL0 */
230 #define XSM_CH_VCC_PSLL3    51U   /**< VCC_PSLL3 */
231 #define XSM_CH_VCCINT       54U   /**< VCCINT */
232 #define XSM_CH_VCCBRAM      55U   /**< VCCBRAM */
233 #define XSM_CH_VCCAUX       56U   /**< VCCAUX */
234 #define XSM_CH_VCC_PSDDRPLL 57U   /**< VCC_PSDDRPLL */
235 #define XSM_CH_DDRPHY_VREF  58U   /**< DDRPHY_VREF */
236 #define XSM_CH_RESERVE1     63U   /**< PSGT_AT0 */
237
238 /*@}*/
239
240 /**
241  * @name Indexes for reading the Calibration Coefficient Data.
242  * @{
243  */
244 #define XSM_CALIB_SUPPLY_OFFSET_COEFF 0U /**< Supply Offset Calib Coefficient */
245 #define XSM_CALIB_ADC_OFFSET_COEFF    1U /**< ADC Offset Calib Coefficient */
246 #define XSM_CALIB_GAIN_ERROR_COEFF    2U /**< Gain Error Calib Coefficient*/
247
248 /*@}*/
249
250 /**
251  * @name Indexes for reading the Minimum/Maximum Measurement Data.
252  * @{
253  */
254 #define XSM_MAX_TEMP            0U    /**< Maximum Temperature Data */
255 #define XSM_MAX_SUPPLY1         1U    /**< Maximum SUPPLY1 Data */
256 #define XSM_MAX_SUPPLY2         2U    /**< Maximum SUPPLY2 Data */
257 #define XSM_MAX_SUPPLY3         3U    /**< Maximum SUPPLY3 Data */
258 #define XSM_MIN_TEMP            4U    /**< Minimum Temperature Data */
259 #define XSM_MIN_SUPPLY1         5U    /**< Minimum SUPPLY1 Data */
260 #define XSM_MIN_SUPPLY2     6U    /**< Minimum SUPPLY2 Data */
261 #define XSM_MIN_SUPPLY3     7U    /**< Minimum SUPPLY3 Data */
262 #define XSM_MAX_SUPPLY4         8U    /**< Maximum SUPPLY4 Data */
263 #define XSM_MAX_SUPPLY5         9U    /**< Maximum SUPPLY5 Data */
264 #define XSM_MAX_SUPPLY6         0xAU  /**< Maximum SUPPLY6 Data */
265 #define XSM_MIN_SUPPLY4     0xCU  /**< Minimum SUPPLY4 Data */
266 #define XSM_MIN_SUPPLY5     0xDU  /**< Minimum SUPPLY5 Data */
267 #define XSM_MIN_SUPPLY6     0xEU  /**< Minimum SUPPLY6 Data */
268 #define XSM_MAX_SUPPLY7         0x80U  /**< Maximum SUPPLY7 Data */
269 #define XSM_MAX_SUPPLY8         0x81U  /**< Maximum SUPPLY8 Data */
270 #define XSM_MAX_SUPPLY9         0x82U  /**< Maximum SUPPLY9 Data */
271 #define XSM_MAX_SUPPLY10        0x83U  /**< Maximum SUPPLY10 Data */
272 #define XSM_MAX_VCCAMS          0x84U  /**< Maximum VCCAMS Data */
273 #define XSM_MAX_TEMP_REMOTE     0x85U  /**< Maximum Remote Temperature Data */
274 #define XSM_MIN_SUPPLY7     0x88U  /**< Minimum SUPPLY7 Data */
275 #define XSM_MIN_SUPPLY8     0x89U  /**< Minimum SUPPLY8 Data */
276 #define XSM_MIN_SUPPLY9     0x8AU  /**< Minimum SUPPLY9 Data */
277 #define XSM_MIN_SUPPLY10    0x8BU  /**< Minimum SUPPLY10 Data */
278 #define XSM_MIN_VCCAMS      0x8CU  /**< Minimum VCCAMS Data */
279 #define XSM_MIN_TEMP_REMOTE     0x8DU  /**< Minimum Remote Temperature Data */
280
281 /*@}*/
282
283 /**
284  * @name Averaging to be done for the channels.
285  * @{
286  */
287 #define XSM_AVG_0_SAMPLES       0U /**< No Averaging */
288 #define XSM_AVG_16_SAMPLES      1U /**< Average 16 samples */
289 #define XSM_AVG_64_SAMPLES      2U /**< Average 64 samples */
290 #define XSM_AVG_256_SAMPLES     3U /**< Average 256 samples */
291
292 /*@}*/
293
294 /**
295  * @name Channel Sequencer Modes of operation.
296  * @{
297  */
298 #define XSM_SEQ_MODE_SAFE        0U /**< Default Safe Mode */
299 #define XSM_SEQ_MODE_ONEPASS     1U /**< Onepass through Sequencer */
300 #define XSM_SEQ_MODE_CONTINPASS  2U /**< Continuous Cycling Seqquencer */
301 #define XSM_SEQ_MODE_SINGCHAN    3U /**< Single channel - No Sequencing */
302 #define XSM_SEQ_MODE_OYLMPUS     6U /**< Olympus mode */
303
304 /*@}*/
305
306 /**
307  * @name Clock Divisor values range.
308  * @{
309  */
310 #define XSM_CLK_DIV_MIN  0U /**< Minimum Clock Divisor value */
311 #define XSM_CLK_DIV_MAX  255U /**< Maximum Clock Divisor value */
312
313 /*@}*/
314
315 /**
316  * @name Alarm Threshold(Limit) Register (ATR) indexes.
317  * @{
318  */
319 #define XSM_ATR_TEMP_UPPER       0U   /**< High user Temperature limit */
320 #define XSM_ATR_SUP1_UPPER       1U   /**< Supply1 high voltage limit */
321 #define XSM_ATR_SUP2_UPPER       2U   /**< Supply2 high voltage limit */
322 #define XSM_ATR_OT_UPPER         3U   /**< Upper Over Temperature limit */
323 #define XSM_ATR_TEMP_LOWER       4U   /**< Low user Temperature */
324 #define XSM_ATR_SUP1_LOWER       5U   /**< Suuply1 low voltage limit */
325 #define XSM_ATR_SUP2_LOWER       6U   /**< Supply2 low voltage limit */
326 #define XSM_ATR_OT_LOWER         7U   /**< Lower Over Temperature limit */
327 #define XSM_ATR_SUP3_UPPER       8U   /**< Supply3 high voltage limit */
328 #define XSM_ATR_SUP4_UPPER       9U   /**< Supply4 high voltage limit */
329 #define XSM_ATR_SUP5_UPPER       0xAU /**< Supply5 high voltage limit */
330 #define XSM_ATR_SUP6_UPPER       0xBU /**< Supply6 high voltage limit */
331 #define XSM_ATR_SUP3_LOWER       0xCU /**< Supply3 low voltage limit */
332 #define XSM_ATR_SUP4_LOWER       0xDU /**< Supply4 low voltage limit */
333 #define XSM_ATR_SUP5_LOWER       0xEU /**< Supply5 low voltage limit */
334 #define XSM_ATR_SUP6_LOWER       0xFU /**< Supply6 low voltage limit */
335 #define XSM_ATR_SUP7_UPPER       0x10U /**< Supply7 high voltage limit */
336 #define XSM_ATR_SUP8_UPPER       0x11U /**< Supply8 high voltage limit */
337 #define XSM_ATR_SUP9_UPPER       0x12U /**< Supply9 high voltage limit */
338 #define XSM_ATR_SUP10_UPPER      0x13U /**< Supply10 high voltage limit */
339 #define XSM_ATR_VCCAMS_UPPER     0x14U /**< VCCAMS high voltage limit */
340 #define XSM_ATR_TEMP_RMTE_UPPER  0x15U /**< High remote Temperature limit */
341 #define XSM_ATR_SUP7_LOWER       0x18U /**< Supply7 low voltage limit */
342 #define XSM_ATR_SUP8_LOWER       0x19U /**< Supply8 low voltage limit */
343 #define XSM_ATR_SUP9_LOWER       0x1AU /**< Supply9 low voltage limit */
344 #define XSM_ATR_SUP10_LOWER      0x1BU /**< Supply10 low voltage limit */
345 #define XSM_ATR_VCCAMS_LOWER     0x1CU /**< VCCAMS low voltage limit */
346 #define XSM_ATR_TEMP_RMTE_LOWER  0x1DU /**< Low remote Temperature limit */
347
348 /*@}*/
349
350 /**
351  * @name Alarm masks for channels in Configuration registers 1
352  * @{
353  */
354 #define XSM_CFR_ALM_SUPPLY13_MASK       0x200000 /**< Alarm 6 - SUPPLY6 */
355 #define XSM_CFR_ALM_SUPPLY12_MASK       0x100000 /**< Alarm 6 - SUPPLY6 */
356 #define XSM_CFR_ALM_SUPPLY11_MASK       0x080000 /**< Alarm 6 - SUPPLY6 */
357 #define XSM_CFR_ALM_SUPPLY10_MASK       0x040000 /**< Alarm 6 - SUPPLY6 */
358 #define XSM_CFR_ALM_SUPPLY9_MASK        0x020000 /**< Alarm 6 - SUPPLY6 */
359 #define XSM_CFR_ALM_SUPPLY8_MASK        0x010000 /**< Alarm 6 - SUPPLY6 */
360 #define XSM_CFR_ALM_SUPPLY6_MASK        0x0800 /**< Alarm 6 - SUPPLY6 */
361 #define XSM_CFR_ALM_SUPPLY5_MASK        0x0400 /**< Alarm 5 - SUPPLY5 */
362 #define XSM_CFR_ALM_SUPPLY4_MASK        0x0200 /**< Alarm 4 - SUPPLY4 */
363 #define XSM_CFR_ALM_SUPPLY3_MASK        0x0100 /**< Alarm 3 - SUPPLY3 */
364 #define XSM_CFR_ALM_SUPPLY2_MASK        0x0008 /**< Alarm 2 - SUPPLY2 */
365 #define XSM_CFR_ALM_SUPPLY1_MASK        0x0004 /**< Alarm 1 - SUPPLY1 */
366 #define XSM_CFR_ALM_TEMP_MASK           0x0002 /**< Alarm 0 - Temperature */
367 #define XSM_CFR_ALM_OT_MASK             0x0001 /**< Over Temperature Alarm */
368
369 /*@}*/
370
371 /**************************** Type Definitions *******************************/
372
373 /******************************************************************************/
374 /**
375  * This data type defines a handler that an application defines to communicate
376  * with interrupt system to retrieve state information about an application.
377  *
378  * @param       CallBackRef is a callback reference passed in by the upper layer
379  *              when setting the handler, and is passed back to the upper layer
380  *              when the handler is called. It is used to find the device driver
381  *              instance.
382  *
383  ******************************************************************************/
384 typedef void (*XSysMonPsu_Handler) (void *CallBackRef);
385
386 /**
387  * This typedef contains configuration information for a device.
388  */
389 typedef struct {
390         u16 DeviceId;           /**< Unique ID of device */
391         u32 BaseAddress;        /**< Register base address */
392         u16 InputClockMHz;      /**< Input clock frequency */
393 } XSysMonPsu_Config;
394
395 /**
396  * The XSysmonPsu driver instance data. The user is required to allocate a
397  * variable of this type for the SYSMON device in the system. A pointer
398  * to a variable of this type is then passed to the driver API functions.
399  */
400 typedef struct {
401         XSysMonPsu_Config Config;       /**< Device configuration */
402         u32 IsReady;                            /**< Device is initialized and ready */
403         XSysMonPsu_Handler Handler;
404         void *CallBackRef;                      /**< Callback reference for event handler */
405 } XSysMonPsu;
406
407 /* BaseAddress Offsets */
408 #define XSYSMON_PS 1U
409 #define XSYSMON_PL 2U
410 #define XSYSMON_AMS 3U
411 #define XPS_BA_OFFSET   0x00000800U
412 #define XPL_BA_OFFSET   0x00000C00U
413 #define XSM_ADC_CH_OFFSET 0x00000200U
414 #define XSM_AMS_CH_OFFSET 0x00000060U
415 #define XSM_MIN_MAX_CH_OFFSET 0x00000080U
416
417 /************************* Variable Definitions ******************************/
418
419 /***************** Macros (Inline Functions) Definitions *********************/
420
421 /****************************************************************************/
422 /**
423 *
424 * This macro converts System Monitor Raw Data to Temperature(centigrades)
425 * for On-Chip Sensors.
426 *
427 * @param        AdcData is the SysMon Raw ADC Data.
428 *
429 * @return       The Temperature in centigrades.
430 *
431 * @note         C-Style signature:
432 *               float XSysMon_RawToTemperature_OnChip(u32 AdcData)
433 *
434 *****************************************************************************/
435 #define XSysMonPsu_RawToTemperature_OnChip(AdcData)                             \
436         ((((float)(AdcData)/65536.0f)/0.00196342531f ) - 280.2309f)
437
438 /****************************************************************************/
439 /**
440 *
441 * This macro converts System Monitor Raw Data to Temperature(centigrades)
442 * for external reference.
443 *
444 * @param        AdcData is the SysMon Raw ADC Data.
445 *
446 * @return       The Temperature in centigrades.
447 *
448 * @note         C-Style signature:
449 *               float XSysMon_RawToTemperature_ExternalRef(u32 AdcData)
450 *
451 *****************************************************************************/
452 #define XSysMonPsu_RawToTemperature_ExternalRef(AdcData)                        \
453         ((((float)(AdcData)/65536.0f)/0.00197008621f ) - 279.4266f)
454
455 /****************************************************************************/
456 /**
457 *
458 * This macro converts System Monitor Raw Data to Voltage(volts) for VpVn
459 * supply.
460 *
461 * @param        AdcData is the System Monitor ADC Raw Data.
462 *
463 * @return       The Voltage in volts.
464 *
465 * @note         C-Style signature:
466 *               float XSysMon_VpVnRawToVoltage(u32 AdcData)
467 *
468 *****************************************************************************/
469 #define XSysMonPsu_VpVnRawToVoltage(AdcData)                                    \
470         ((((float)(AdcData))* (1.0f))/65536.0f)
471
472 /****************************************************************************/
473 /**
474 *
475 * This macro converts System Monitor Raw Data to Voltage(volts) other than
476 * VCCO_PSIO supply.
477 *
478 * @param        AdcData is the System Monitor ADC Raw Data.
479 *
480 * @return       The Voltage in volts.
481 *
482 * @note         C-Style signature:
483 *               float XSysMon_RawToVoltage(u32 AdcData)
484 *
485 *****************************************************************************/
486 #define XSysMonPsu_RawToVoltage(AdcData)                                        \
487         ((((float)(AdcData))* (3.0f))/65536.0f)
488
489 /****************************************************************************/
490 /**
491 *
492 * This macro converts System Monitor Raw Data to Voltage(volts) for
493 * VCCO_PSIO supply.
494 *
495 * @param        AdcData is the System Monitor ADC Raw Data.
496 *
497 * @return       The Voltage in volts.
498 *
499 * @note         C-Style signature:
500 *               float XSysMon_RawToVoltage(u32 AdcData)
501 *
502 *****************************************************************************/
503 #define XSysMonPsu_VccopsioRawToVoltage(AdcData)                                        \
504         ((((float)(AdcData))* (6.0f))/65536.0f)
505
506 /****************************************************************************/
507 /**
508 *
509 * This macro converts Temperature in centigrades to System Monitor Raw Data
510 * for On-Chip Sensors.
511 *
512 * @param        Temperature is the Temperature in centigrades to be
513 *               converted to System Monitor ADC Raw Data.
514 *
515 * @return       The System Monitor ADC Raw Data.
516 *
517 * @note         C-Style signature:
518 *               int XSysMon_TemperatureToRaw_OnChip(float Temperature)
519 *
520 *****************************************************************************/
521 #define XSysMonPsu_TemperatureToRaw_OnChip(Temperature)                         \
522         ((s32)(((Temperature) + 280.2309f)*65536.0f*0.00196342531f))
523
524 /****************************************************************************/
525 /**
526 *
527 * This macro converts Temperature in centigrades to System Monitor Raw Data
528 * for external reference.
529 *
530 * @param        Temperature is the Temperature in centigrades to be
531 *               converted to System Monitor ADC Raw Data.
532 *
533 * @return       The System Monitor ADC Raw Data.
534 *
535 * @note         C-Style signature:
536 *               int XSysMon_TemperatureToRaw_ExternalRef(float Temperature)
537 *
538 *****************************************************************************/
539 #define XSysMonPsu_TemperatureToRaw_ExternalRef(Temperature)            \
540         ((s32)(((Temperature) + 279.4266f)*65536.0f*0.00197008621f))
541
542 /****************************************************************************/
543 /**
544 *
545 * This macro converts Voltage in Volts to System Monitor Raw Data other than
546 * VCCO_PSIO supply
547 *
548 * @param        Voltage is the Voltage in volts to be converted to
549 *               System Monitor/ADC Raw Data.
550 *
551 * @return       The System Monitor ADC Raw Data.
552 *
553 * @note         C-Style signature:
554 *               int XSysMon_VoltageToRaw(float Voltage)
555 *
556 *****************************************************************************/
557 #define XSysMonPsu_VoltageToRaw(Voltage)                                        \
558         ((s32)((Voltage)*65536.0f/3.0f))
559
560 /****************************************************************************/
561 /**
562 *
563 * This macro converts Voltage in Volts to System Monitor Raw Data for
564 * VCCO_PSIO supply
565 *
566 * @param        Voltage is the Voltage in volts to be converted to
567 *               System Monitor/ADC Raw Data.
568 *
569 * @return       The System Monitor ADC Raw Data.
570 *
571 * @note         C-Style signature:
572 *               int XSysMon_VoltageToRaw(float Voltage)
573 *
574 *****************************************************************************/
575 #define XSysMonPsu_VccopsioVoltageToRaw(Voltage)                                        \
576         ((s32)((Voltage)*65536.0f/6.0f))
577
578 /****************************************************************************/
579 /**
580 *
581 * This static inline macro calculates the effective baseaddress based on the
582 * Sysmon instance. For PS Sysmon, use additional offset XPS_BA_OFFSET and For
583 * PL Sysmon, use additional offset XPL_BA_OFFSET.
584 *
585 * @param        BaseAddress is the starting address of the SysMon block in
586 *               register database.
587 * @param        SysmonBlk is the value that tells whether it is for PS Sysmon block
588 *       or PL Sysmon block or the AMS controller register region.
589 *
590 * @return       Returns the effective baseaddress of the sysmon instance.
591 *
592 *****************************************************************************/
593 static inline u32 XSysMonPsu_GetEffBaseAddress(u32 BaseAddress, u32 SysmonBlk)
594         {
595                 u32 EffBaseAddr;
596
597                 if (SysmonBlk == XSYSMON_PS) {
598                         EffBaseAddr = BaseAddress + XPS_BA_OFFSET;
599                 } else if(SysmonBlk == XSYSMON_PL) {
600                         EffBaseAddr = BaseAddress + XPL_BA_OFFSET;
601                 } else {
602                         EffBaseAddr = BaseAddress;
603                 }
604
605                 return EffBaseAddr;
606         }
607
608 /************************** Function Prototypes ******************************/
609
610 /* Functions in xsysmonpsu.c */
611 s32 XSysMonPsu_CfgInitialize(XSysMonPsu *InstancePtr, XSysMonPsu_Config *ConfigPtr,
612                           u32 EffectiveAddr);
613 void XSysMonPsu_Reset(XSysMonPsu *InstancePtr);
614 void XSysMonPsu_Reset_FromLPD(XSysMonPsu *InstancePtr);
615 u32 XSysMonPsu_GetStatus(XSysMonPsu *InstancePtr, u32 SysmonBlk);
616 void XSysMonPsu_StartAdcConversion(XSysMonPsu *InstancePtr);
617 u16 XSysMonPsu_GetAdcData(XSysMonPsu *InstancePtr, u8 Channel, u32 Block);
618 u16 XSysMonPsu_GetCalibCoefficient(XSysMonPsu *InstancePtr, u8 CoeffType, u32 SysmonBlk);
619 u16 XSysMonPsu_GetMinMaxMeasurement(XSysMonPsu *InstancePtr, u8 MeasurementType,
620                 u32 SysmonBlk);
621 void XSysMonPsu_SetAvg(XSysMonPsu *InstancePtr, u8 Average, u32 SysmonBlk);
622 u8 XSysMonPsu_GetAvg(XSysMonPsu *InstancePtr, u32 SysmonBlk);
623 s32 XSysMonPsu_SetSingleChParams(XSysMonPsu *InstancePtr, u8 Channel,
624                                 u32 IncreaseAcqCycles, u32 IsEventMode,
625                                 u32 IsDifferentialMode, u32 SysmonBlk);
626 void XSysMonPsu_SetAlarmEnables(XSysMonPsu *InstancePtr, u32 AlmEnableMask,
627                 u32 SysmonBlk);
628 u32 XSysMonPsu_GetAlarmEnables(XSysMonPsu *InstancePtr, u32 SysmonBlk);
629 void XSysMonPsu_SetSequencerMode(XSysMonPsu *InstancePtr, u8 SequencerMode,
630                 u32 SysmonBlk);
631 u8 XSysMonPsu_GetSequencerMode(XSysMonPsu *InstancePtr, u32 SysmonBlk);
632 void XSysMonPsu_SetSequencerEvent(XSysMonPsu *InstancePtr, u32 IsEventMode,
633                 u32 SysmonBlk);
634 s32 XSysMonPsu_GetSequencerEvent(XSysMonPsu *InstancePtr, u32 SysmonBlk);
635 void XSysMonPsu_SetExtenalMux(XSysMonPsu *InstancePtr, u8 Channel, u32 SysmonBlk);
636 u32 XSysMonPsu_GetExtenalMux(XSysMonPsu *InstancePtr, u32 SysmonBlk);
637 void XSysMonPsu_SetAdcClkDivisor(XSysMonPsu *InstancePtr, u8 Divisor, u32 SysmonBlk);
638 u8 XSysMonPsu_GetAdcClkDivisor(XSysMonPsu *InstancePtr, u32 SysmonBlk);
639 u8 XSysMonPsu_UpdateAdcClkDivisor(XSysMonPsu *InstancePtr, u32 SysmonBlk);
640 s32 XSysMonPsu_SetSeqChEnables(XSysMonPsu *InstancePtr, u64 ChEnableMask,
641                 u32 SysmonBlk);
642 u64 XSysMonPsu_GetSeqAvgEnables(XSysMonPsu *InstancePtr, u32 SysmonBlk);
643 u64 XSysMonPsu_GetSeqChEnables(XSysMonPsu *InstancePtr, u32 SysmonBlk);
644 s32 XSysMonPsu_SetSeqAvgEnables(XSysMonPsu *InstancePtr, u64 AvgEnableChMask,
645                 u32 SysmonBlk);
646 s32 XSysMonPsu_SetSeqInputMode(XSysMonPsu *InstancePtr, u64 InputModeChMask,
647                 u32 SysmonBlk);
648 u64 XSysMonPsu_GetSeqInputMode(XSysMonPsu *InstancePtr, u32 SysmonBlk);
649 s32 XSysMonPsu_SetSeqAcqTime(XSysMonPsu *InstancePtr, u64 AcqCyclesChMask,
650                 u32 SysmonBlk);
651 u64 XSysMonPsu_GetSeqAcqTime(XSysMonPsu *InstancePtr, u32 SysmonBlk);
652 void XSysMonPsu_SetAlarmThreshold(XSysMonPsu *InstancePtr, u8 AlarmThrReg,
653                 u16 Value, u32 SysmonBlk);
654 u16 XSysMonPsu_GetAlarmThreshold(XSysMonPsu *InstancePtr, u8 AlarmThrReg,
655                 u32 SysmonBlk);
656 void XSysMonPsu_SetPSAutoConversion(XSysMonPsu *InstancePtr);
657 u32 XSysMonPsu_GetMonitorStatus(XSysMonPsu *InstancePtr);
658
659 /* interrupt functions in xsysmonpsu_intr.c */
660 void XSysMonPsu_IntrEnable(XSysMonPsu *InstancePtr, u64 Mask);
661 void XSysMonPsu_IntrDisable(XSysMonPsu *InstancePtr, u64 Mask);
662 u64 XSysMonPsu_IntrGetEnabled(XSysMonPsu *InstancePtr);
663 u64 XSysMonPsu_IntrGetStatus(XSysMonPsu *InstancePtr);
664 void XSysMonPsu_IntrClear(XSysMonPsu *InstancePtr, u64 Mask);
665
666 /* Functions in xsysmonpsu_selftest.c */
667 s32 XSysMonPsu_SelfTest(XSysMonPsu *InstancePtr);
668
669 /* Functions in xsysmonpsu_sinit.c */
670 XSysMonPsu_Config *XSysMonPsu_LookupConfig(u16 DeviceId);
671
672
673 #ifdef __cplusplus
674 }
675 #endif
676
677 #endif /* XSYSMONPSU_H_ */