Use signed types for temperatures.

Check limits on register writes.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@2724 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare committed 2004-10-11 20:36:45 +00:00
1 parent 34f6be661f
commit a8379104e0
2 files changed
+21 -21

No files matched your search

+5 -7
View File
@@ -80,14 +80,12 @@ SENSORS_INSMOD_1(lm83);
/*
* Conversions and various macros
* The LM83 uses signed 8-bit values.
* The LM83 uses signed 8-bit values with LSB = 1 degree Celcius.
*/
#define TEMP_FROM_REG(val) ((val) > 127 ? (val) - 0x100 : (val))
#define TEMP_TO_REG(val) ((val) <= -50 ? -50 + 0x100 : \
(val) >= 127 ? 127 : \
(val) >= 0 ? (val) : \
(val) + 0x100)
#define TEMP_FROM_REG(val) (val)
#define TEMP_TO_REG(val) ((val) <= -50 ? -50 : \
(val) >= 127 ? 127 : (val))
static const u8 LM83_REG_R_TEMP[] = {
LM83_REG_R_LOCAL_TEMP,
@@ -153,7 +151,7 @@ struct lm83_data
unsigned long last_updated; /* in jiffies */
/* registers values */
u8 temp[4], temp_high[4], tcrit;
s8 temp[4], temp_high[4], tcrit;
u16 alarms; /* bitvector, combined */
};
+16 -14
View File
@@ -131,19 +131,21 @@ SENSORS_INSMOD_5(lm90, adm1032, lm99, lm86, max6657);
/*
* Conversions and various macros
* The LM90 uses signed 8-bit values for the local temperatures,
* and signed 11-bit values for the remote temperatures (except
* T_CRIT). The 11-bit conversion formulas may not round negative
* numbers perfectly, but who cares?
* For local temperatures and limits, critical limits and the hysteresis
* value, the LM90 uses signed 8-bit values with LSB = 1 degree Celcius.
* For remote temperatures and limits, it uses signed 11-bit values with
* LSB = 0.125 degree Celcius, left-justified in 16-bit registers.
*/
#define TEMP1_FROM_REG(val) (val & 0x80 ? val-0x100 : val)
#define TEMP1_TO_REG(val) (val < 0 ? val+0x100 : val)
#define TEMP2_FROM_REG(val) (((val & 0x8000 ? val-0x10000 : val) \
* 10 + 128) >> 8)
#define TEMP2_TO_REG(val) (((val << 8) / 10 + (val < 0 ? \
0x10000 : 0)) & 0xFFE0)
#define HYST_TO_REG(val) (val < 0 ? 0 : val > 31 ? 31 : val)
#define TEMP1_FROM_REG(val) (val)
#define TEMP1_TO_REG(val) ((val) <= -128 ? -128 : \
(val) >= 127 ? 127 : (val))
#define TEMP2_FROM_REG(val) ((val) / 32 * 125 / 100)
#define TEMP2_TO_REG(val) ((val) <= -1280 ? 0x8000 : \
(val) >= 1270 ? 0x7FE0 : \
((val) * 100 / 125 * 32))
#define HYST_TO_REG(val) ((val) <= 0 ? 0 : \
(val) >= 31 ? 31 : (val))
/*
* Functions declaration
@@ -196,9 +198,9 @@ struct lm90_data
unsigned long last_updated; /* in jiffies */
/* registers values */
u8 local_temp, local_high, local_low;
u16 remote_temp, remote_high, remote_low; /* combined */
u8 local_crit, remote_crit;
s8 local_temp, local_high, local_low;
s16 remote_temp, remote_high, remote_low; /* combined */
s8 local_crit, remote_crit;
u8 hyst; /* linked to two sysctl files (hyst1 RW, hyst2 RO) */
u8 alarms; /* bitvector */
};