1 | /** @file wlan_mac_sysmon_util.c |
---|
2 | * @brief System Monitor Utility functions |
---|
3 | * |
---|
4 | * @copyright Copyright 2013-2019, Mango Communications. All rights reserved. |
---|
5 | * Distributed under the Mango Communications Reference Design License |
---|
6 | * See LICENSE.txt included in the design archive or |
---|
7 | * at http://mangocomm.com/802.11/license |
---|
8 | * |
---|
9 | * This file is part of the Mango 802.11 Reference Design (https://mangocomm.com/802.11) |
---|
10 | */ |
---|
11 | /***************************** Include Files *********************************/ |
---|
12 | |
---|
13 | // Xilinx / Standard library includes |
---|
14 | #include "wlan_platform_common.h" |
---|
15 | #include "w3_common.h" |
---|
16 | #include <xil_io.h> |
---|
17 | |
---|
18 | // Hardware includes |
---|
19 | #include <xsysmon_hw.h> |
---|
20 | |
---|
21 | |
---|
22 | /*************************** Constant Definitions ****************************/ |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | /*********************** Global Variable Definitions *************************/ |
---|
27 | |
---|
28 | /*************************** Functions Prototypes ****************************/ |
---|
29 | |
---|
30 | /*************************** Variable Definitions ****************************/ |
---|
31 | |
---|
32 | /******************************** Functions **********************************/ |
---|
33 | |
---|
34 | /*****************************************************************************/ |
---|
35 | /** |
---|
36 | * Initialize the System Monitor |
---|
37 | * |
---|
38 | * @param None |
---|
39 | * |
---|
40 | * @return None |
---|
41 | * |
---|
42 | *****************************************************************************/ |
---|
43 | void init_sysmon() { |
---|
44 | u32 value; |
---|
45 | |
---|
46 | // Reset the system monitor |
---|
47 | XSysMon_WriteReg(PLATFORM_BASEADDR_SYSMON, XSM_SRR_OFFSET, XSM_SRR_IPRST_MASK); |
---|
48 | |
---|
49 | // Disable the Channel Sequencer before configuring the Sequence registers. |
---|
50 | value = XSysMon_ReadReg(PLATFORM_BASEADDR_SYSMON, XSM_CFR1_OFFSET) & (~ XSM_CFR1_SEQ_VALID_MASK); |
---|
51 | XSysMon_WriteReg(PLATFORM_BASEADDR_SYSMON, XSM_CFR1_OFFSET, (value | XSM_CFR1_SEQ_SINGCHAN_MASK)); |
---|
52 | |
---|
53 | // Setup the Averaging to be done for the channels in the Configuration 0 register as 16 samples |
---|
54 | value = XSysMon_ReadReg(PLATFORM_BASEADDR_SYSMON, XSM_CFR0_OFFSET) & (~XSM_CFR0_AVG_VALID_MASK); |
---|
55 | XSysMon_WriteReg(PLATFORM_BASEADDR_SYSMON, XSM_CFR0_OFFSET, (value | XSM_CFR0_AVG16_MASK)); |
---|
56 | |
---|
57 | // Enable the averaging on the following channels in the Sequencer registers: |
---|
58 | // - On-chip Temperature |
---|
59 | // - On-chip VCCAUX supply sensor |
---|
60 | XSysMon_WriteReg(PLATFORM_BASEADDR_SYSMON, XSM_SEQ02_OFFSET, (XSM_SEQ_CH_TEMP | XSM_SEQ_CH_VCCAUX)); |
---|
61 | |
---|
62 | // Enable the following channels in the Sequencer registers: |
---|
63 | // - On-chip Temperature |
---|
64 | // - On-chip VCCAUX supply sensor |
---|
65 | XSysMon_WriteReg(PLATFORM_BASEADDR_SYSMON, XSM_SEQ00_OFFSET, (XSM_SEQ_CH_TEMP | XSM_SEQ_CH_VCCAUX)); |
---|
66 | |
---|
67 | // Set the ADCCLK frequency equal to 1/32 of System clock for the System Monitor/ADC |
---|
68 | // in the Configuration Register 2. |
---|
69 | XSysMon_WriteReg(PLATFORM_BASEADDR_SYSMON, XSM_CFR2_OFFSET, (32 << XSM_CFR2_CD_SHIFT)); |
---|
70 | |
---|
71 | // Enable the Channel Sequencer in continuous sequencer cycling mode. |
---|
72 | value = XSysMon_ReadReg(PLATFORM_BASEADDR_SYSMON, XSM_CFR1_OFFSET) & (~ XSM_CFR1_SEQ_VALID_MASK); |
---|
73 | XSysMon_WriteReg(PLATFORM_BASEADDR_SYSMON, XSM_CFR1_OFFSET, (value | XSM_CFR1_SEQ_CONTINPASS_MASK)); |
---|
74 | |
---|
75 | // Wait till the End of Sequence occurs |
---|
76 | XSysMon_ReadReg(PLATFORM_BASEADDR_SYSMON, XSM_SR_OFFSET); /* Clear the old status */ |
---|
77 | |
---|
78 | #if 1 |
---|
79 | // Initialization without a timeout |
---|
80 | // This has never been an issue during boot. If it ever does, then use the code below |
---|
81 | // |
---|
82 | while (((XSysMon_ReadReg(PLATFORM_BASEADDR_SYSMON, XSM_SR_OFFSET)) & XSM_SR_EOS_MASK) != XSM_SR_EOS_MASK); |
---|
83 | #else |
---|
84 | // Initialization with a timeout |
---|
85 | // Timeout is 100 ms (ie 100000 us) |
---|
86 | // |
---|
87 | u64 timestamp = get_system_time_usec(); |
---|
88 | |
---|
89 | while (((XSysMon_ReadReg(PLATFORM_BASEADDR_SYSMON, XSM_SR_OFFSET)) & XSM_SR_EOS_MASK) != XSM_SR_EOS_MASK) { |
---|
90 | if ((get_system_time_usec() - timestamp) < 100000) { break; } |
---|
91 | } |
---|
92 | #endif |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | |
---|
97 | /*****************************************************************************/ |
---|
98 | /** |
---|
99 | * Initialize the System Monitor |
---|
100 | * |
---|
101 | * @param None |
---|
102 | * |
---|
103 | * @return None |
---|
104 | * |
---|
105 | *****************************************************************************/ |
---|
106 | u32 wlan_platform_get_current_temp ( void ) { return XSysMon_ReadReg(PLATFORM_BASEADDR_SYSMON, XSM_TEMP_OFFSET); } |
---|
107 | u32 wlan_platform_get_min_temp ( void ) { return XSysMon_ReadReg(PLATFORM_BASEADDR_SYSMON, XSM_MIN_TEMP_OFFSET); } |
---|
108 | u32 wlan_platform_get_max_temp ( void ) { return XSysMon_ReadReg(PLATFORM_BASEADDR_SYSMON, XSM_MAX_TEMP_OFFSET); } |
---|
109 | |
---|
110 | |
---|