Jump to content

Improved sunxi_tp_temp for H3


tarkin000

Recommended Posts

Hello,

  My sunxi_tp_temp always reports the same value (429496576.0).

After digging around, it seems like it's not reading the correct registers.

According to the H3 datasheet(1), pp 255-258, the thermal sensor base is at 0x01C25000.

The data register is at 0x01C25080.

 

Using the mod_mmio.h and sunxi_tp_temp.c as a guide, I wrote a little utility to print the current SoC temp.

#include <stdio.h>
#include "mod_mmio.h"

// improved temperature print utility
// GPLv2

int main(int argc, char *argv[]) {
  float reading,celsius,farenheit;

  reading = (float)mmio_read(0x01c25080);
  //celsius = (reading - 2794.0) / -14.882; Allwinner H3 datasheet formula
  celsius = ((reading - 2794.0) / -14.882) - 51.0; // adjustment based on observation
  farenheit = celsius * 1.8 + 32;

#ifdef CEL_ONLY
  printf("%0.3f°C\n",celsius);
#elif defined FAR_ONLY
  printf("%0.3f°F\n",farenheit);
#else
  printf("%0.3f°C / %0.3f°F\n",celsius,farenheit,reading);
#endif

  if (argc > 1) printf("raw sensor data: %0.3f\n",reading);
  return 0;

}

You may have to change the value 51.0; I have no idea why the formula from the datasheet didn't work,

I just printed the results of their formula, compared it to the value obtained from

/sys/class/thermal/thermal_zone0/temp, and came up with this 'fudge factor'.

 

You can grab mod_mmio.h from here: https://github.com/igorpecovnik/lib/tree/master/scripts/sunxi-temp

 

I have left defines in for celsius only (#define CEL_ONLY),

farenheit only (#define FAR_ONLY),

and the default is to display both (to train my American mind to get used to SI units).

 

I named my executable pitemp: gcc -o pitemp pitemp.c

I copied it to /usr/local/bin, chowned it to root, and made it suid root so I don't have to type sudo everytime. (not recommended for security reasons).

 

Hope this helps someone.

 

(1): You can download the datasheet (pdf, ~7.5MB) from here:

http://linux-sunxi.org/H3

(scroll down halfway, it's under "Documentation")

Link to comment
Share on other sites

sunxi_tp_temp was made to read temperature from A10/A20 touchscreen/touchpad controller temperature sensor with some corrections, since

  • there was no dedicated temperature sensor for CPU cores
  • sensor needed additional calibration

There is no need for this utility on H3 because it has properly integrated thermal sensor which can be read via sysfs

Link to comment
Share on other sites

sunxi_tp_temp was made to read temperature from A10/A20 touchscreen/touchpad controller temperature sensor with some corrections, since

  • there was no dedicated temperature sensor for CPU cores
  • sensor needed additional calibration

There is no need for this utility on H3 because it has properly integrated thermal sensor which can be read via sysfs

 

Ah, that explains it then. I suppose the integer value is close enough, and it would be trivial to write a script that reads the value and pipes into bc for conversion into Farenheit.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines