Skip to contentSkip to conversation

How to define IN_TO_REG and IN_FROM_REG in w83627hf.c

lm-sensors dave jones 2 participants 5 messages Aug 9, 2007 – Aug 13, 2007

lore
Share & tools
lore
#1 lore raw

Re: [lm-sensors] How to define IN_TO_REG and IN_FROM_REG in

Hi Dave,

Quoted 4 lines

Hello,

I don't understand why the IN_TO_REG(val) is defined by (SENSORS_LIMIT((((val) + 8)/16),0,255))

(val+8)/16 is equal to val/16 with rounding, i.e. round(val/16), and then the result is clipped to stay within the range 0-255.

Hope this helps
...juerg

Quoted 5 lines

and IN_FROM_REG(val) is
defined by ((val) * 16)

Would you teach me? Thank you.

Quoted 8 lines

BR,
Dave.

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

author
#2 lore raw

Re: [lm-sensors] How to define IN_TO_REG and IN_FROM_REG in

In reply to dave jones
Quoted 1 line · Juerg Haefliger

Hi Dave,

Hi Jeurg,

Quoted 7 lines
Quoted 4 lines

Hello,

I don't understand why the IN_TO_REG(val) is defined by (SENSORS_LIMIT((((val) + 8)/16),0,255))

(val+8)/16 is equal to val/16 with rounding, i.e. round(val/16), and then the result is clipped to stay within the range 0-255.

Thanks. But I just don't understand why the variable val plus 8? How do you know?
Another example I see is IN_TO_REG(val) defined:

(SENSORS_LIMIT((((val) + 4 / 8),0,255)), why is val plus 4? why not 8? Thanks.

Quoted 13 lines

Hope this helps
...juerg

Quoted 8 lines

and IN_FROM_REG(val) is
defined by ((val) * 16)

Would you teach me? Thank you.

BR,
Dave.

BR,Dave.

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#3 lore raw

Re: [lm-sensors] How to define IN_TO_REG and IN_FROM_REG in

In reply to dave jones

Hi Dave,,

Quoted 6 lines
Quoted 1 line

Hi Dave,

Hi Jeurg,

Quoted 2 lines
Quoted 2 lines

Hello,

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

I don't understand why the IN_TO_REG(val) is defined by (SENSORS_LIMIT((((val) + 8)/16),0,255))

(val+8)/16 is equal to val/16 with rounding, i.e. round(val/16), and then the result is clipped to stay within the range 0-255.

Thanks. But I just don't understand why the variable val plus 8? How do you know?

The kernel can't do floating point arithmetic, it truncates the results. So we have to add (divisor/2) before doing the division to achieve rounding. For example if val=8, (8/16) would result in 0 (in the kernel). But round(8/16) is actually 1, which is what we want. We achieve this by adding 8 (which is 16/2) before dividing by 16.

Bottom line, you have to add (divisor/2) before dividing to get correct rounding of the result.

Quoted 3 lines

Another example I see is IN_TO_REG(val) defined:

(SENSORS_LIMIT((((val) + 4 / 8),0,255)), why is val plus 4? why not 8? Thanks.

Same here 4 is divisor/2 (8/2).

...juerg

Quoted 8 lines
Quoted 8 lines

Hope this helps
...juerg

Quoted 3 lines

and IN_FROM_REG(val) is
defined by ((val) * 16)

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

Would you teach me? Thank you.

BR,
Dave.

BR,Dave.

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

author
#4 lore raw

Re: [lm-sensors] How to define IN_TO_REG and IN_FROM_REG in

In reply to dave jones
Quoted 1 line · Juerg Haefliger

Hi Dave,,

Hi Juerg,

Quoted 25 lines
Quoted 6 lines
Quoted 1 line

Hi Dave,

Hi Jeurg,

Quoted 2 lines
Quoted 2 lines

Hello,

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

I don't understand why the IN_TO_REG(val) is defined by (SENSORS_LIMIT((((val) + 8)/16),0,255))

(val+8)/16 is equal to val/16 with rounding, i.e. round(val/16), and then the result is clipped to stay within the range 0-255.

Thanks. But I just don't understand why the variable val plus 8? How do you know?

The kernel can't do floating point arithmetic, it truncates the results. So we have to add (divisor/2) before doing the division to achieve rounding. For example if val=8, (8/16) would result in 0 (in the kernel). But round(8/16) is actually 1, which is what we want. We achieve this by adding 8 (which is 16/2) before dividing by 16.

Bottom line, you have to add (divisor/2) before dividing to get correct rounding of the result.

Quoted 5 lines
Quoted 3 lines

Another example I see is IN_TO_REG(val) defined:

(SENSORS_LIMIT((((val) + 4 / 8),0,255)), why is val plus 4? why not 8? Thanks.

Same here 4 is divisor/2 (8/2).

Thank you for your clear explanation. Now I completely understand, thank you very much!
I'd really appreciate!

Quoted 21 lines

...juerg

Quoted 16 lines
Quoted 13 lines

Hope this helps
...juerg

Quoted 8 lines

and IN_FROM_REG(val) is
defined by ((val) * 16)

Would you teach me? Thank you.

BR,
Dave.

BR,Dave.

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors