ref: c013393923b925557a8a7f23cd065a19fe87f48f
parent: ffb48be969338833a69e576e7d62353bbd831226
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Thu Sep 8 18:54:26 EDT 2022
reform/pm: measure CPU temperature only when requested, disable monitoring right away
--- a/sys/src/cmd/reform/pm.c
+++ b/sys/src/cmd/reform/pm.c
@@ -111,11 +111,15 @@
}
static int
-gettemp(int c[3])
+getcputemp(void)
{
- int i, r[] = {TMUTRITSR0, TMUTRITSR1, TMUTRITSR2};
u32int s;
+ int i, c;
+ /* enable: all sites, ALPF 11=0.125 */
+ wr(tmu, TMUTMR, TMR_ME | 3<<TMR_ALPF_SHIFT | 0<<TMR_MSITE_SHIFT);
+ sleep(50);
+
s = rd(tmu, TMUTSR);
if(s & TSR_MIE){
werrstr("monitoring interval exceeded");
@@ -126,19 +130,11 @@
return -1;
}
- c[0] = c[1] = c[2] = 0;
- for(;;){
- for(i = 0; i < 3; i++)
- if(c[i] >= 0)
- c[i] = rd(tmu, r[i]);
- if(c[0] < 0 && c[1] < 0 && c[2] < 0)
- break;
+ for(i = 0; (c = rd(tmu, TMUTRITSR0)) >= 0 && i < 10; i++)
sleep(10);
- }
- c[0] &= 0xff;
- c[1] &= 0xff;
- c[2] &= 0xff;
- return 0;
+ wr(tmu, TMUTMR, 0);
+
+ return c & 0xff;
}
static void
@@ -170,9 +166,6 @@
wr(tmu, TMUTSCFGR, cfg[i][j]);
}
}
-
- /* enable: all sites, ALPF 11=0.125 */
- wr(tmu, TMUTMR, TMR_ME | 3<<TMR_ALPF_SHIFT | 7<<TMR_MSITE_SHIFT);
}
static void
@@ -316,7 +309,7 @@
{
char msg[256];
void *aux;
- int c[3];
+ int c;
msg[0] = 0;
if(r->ifcall.offset == 0){
@@ -324,12 +317,11 @@
if(aux == (void*)Light){
snprint(msg, sizeof(msg), "lcd %d\n", getlight());
}else if(aux == (void*)Temp){
- if(gettemp(c) != 0){
+ if((c = getcputemp()) < 0){
responderror(r);
return;
}
- /* only the first one is CPU temperature */
- snprint(msg, sizeof(msg), "%d.0\n", c[0]);
+ snprint(msg, sizeof(msg), "%d.0\n", c);
}else if(aux == (void*)Battery){
reqqueuepush(lpcreq, r, readbattery);
return;