SPRZ452I july 2018 – may 2023 AM6526 , AM6528 , AM6546 , AM6548
VTM: Software Reads from On-Die Temperature Sensors Can Be Corrupted
AM65x SR 1.0
The VTM_TMPSENSj_STAT[9-0] DTEMP, where j = 0-7, registers can be read in software to determine the last sampled temperature of each of the ‘j’ number of on die temp sensors on the SoC. If a read happens on the same exact cycle that a temperature sample is updated then there is a chance that the read data can be corrupted due to incorrect resynchronization between clock domains.
Software should perform three reads from the VTM_TMPSENSj_STAT[9-0] DTEMP, where j = 0-7, registers. Software should then compute the temperature to be used based on the average of the two samples that are closest to each other.
The software pseudo code is as follows:
#define abs(x) (((x)<0)?-(x):(x))
unsigned int get_best_value(unsigned int s0, unsigned int s1, unsigned int s2)
{
int d01 = abs(s0 - s1);
int d02 = abs(s0 - s2);
int d12 = abs(s1 - s2);
// if delta 01 is least, take 0 and 1
if ((d01 <= d02) && (d01 <=d12)) {
return (s0+s1)/2;
}
// if delta 02 is least, take 0 and 2
if ((d02 <= d01) && (d02 <=d12)) {
return (s0+s2)/2;
}
/* in all other cases, take 1 and 2 */
return (s1+s2)/2;
}
unsigned int get_temp()
{
unsigned int s0,s1,s2;
s0 = Read VTM_TMPSENSj_STAT[9-0] DTEMP;
s1 = Read VTM_TMPSENSj_STAT[9-0] DTEMP;
s2 = Read VTM_TMPSENSj_STAT[9-0] DTEMP;
return get_best_value(s0,s1,s2);
}