-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmfrtherm_mon.c
104 lines (89 loc) · 3.1 KB
/
mfrtherm_mon.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2017 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include "mfr_temperature.h"
static int g_iTempThresholdHigh = 60;
static int g_iTempThresholdCritical = 75;
/**
* @brief get current temperature of the core
*
* @param [out] curState: the current state of the core temperature
* @param [out] temperatureValue: raw temperature value of the core
* in degrees Celsius
* @param [out] wifiTemp: temperature value of wifi chipset
*
* @return Error Code
*/
mfrError_t mfrGetTemperature(mfrTemperatureState_t *curState, int *temperatureValue, int *wifiTemp)
{
if ( curState == NULL || temperatureValue == NULL || wifiTemp == NULL )
return mfrERR_INVALID_PARAM;
int value = 0;
mfrTemperatureState_t state = mfrTEMPERATURE_NORMAL;
FILE* fp = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
if( fp != NULL )
{
fscanf (fp, "%d", &value);
fclose(fp);
}
value /= 1000;
if( value >= g_iTempThresholdHigh )
state = mfrTEMPERATURE_HIGH;
if( value >= g_iTempThresholdCritical )
state = mfrTEMPERATURE_CRITICAL;
*curState = state;
*temperatureValue = value;
return mfrERR_NONE;
}
/**
* @brief Set temperature thresholds which will determine the state returned
<200b><200b>* from a call to mfrGetTemperature
*
* @param [in] tempHigh: Temperature threshold at which mfrTEMPERATURE_HIGH
* state will be reported.
* @param [in] tempCritical: Temperature threshold at which mfrTEMPERATURE_CRITICAL
* state will be reported.
*
* @return Error Code
*/
mfrError_t mfrSetTempThresholds(int tempHigh, int tempCritical)
{
g_iTempThresholdHigh = tempHigh;
g_iTempThresholdCritical = tempCritical;
return mfrERR_NONE;
}
/**
* @brief Get the temperature thresholds which determine the state returned
<200b><200b>* from a call to mfrGetTemperature
*
* @param [out] tempHigh: Temperature threshold at which mfrTEMPERATURE_HIGH
* state will be reported.
* @param [out] tempCritical: Temperature threshold at which mfrTEMPERATURE_CRITICAL
* state will be reported.
*
* @return Error Code
*/
mfrError_t mfrGetTempThresholds(int *tempHigh, int *tempCritical)
{
if( tempHigh == NULL || tempCritical == NULL )
return mfrERR_INVALID_PARAM;
*tempHigh = g_iTempThresholdHigh;
*tempCritical = g_iTempThresholdCritical;
return mfrERR_NONE;
}