Skip to content

Commit e699834

Browse files
committed
Add SYS_{Get,Set}TAUCalibration
1 parent 004e6b3 commit e699834

2 files changed

Lines changed: 78 additions & 3 deletions

File tree

include/ogc/system.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,11 @@ void SYS_ResetPMC(void);
342342
u32 SYS_GetBusFrequency(void);
343343
f32 SYS_GetCoreMultiplier(void);
344344
u32 SYS_GetCoreFrequency(void);
345+
#if defined(HW_DOL)
345346
s8 SYS_GetCoreTemperature(void);
347+
s8 SYS_GetTAUCalibration(void);
348+
void SYS_SetTAUCalibration(s8 calib);
349+
#endif
346350

347351

348352
/*! \fn s32 SYS_CreateAlarm(syswd_t *thealarm)

libogc/system.c

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,73 @@ void SYS_SetEuRGB60(u8 enable)
17731773
__SYS_UnlockSram(write);
17741774
}
17751775

1776+
#if defined(HW_DOL)
1777+
s8 SYS_GetTAUCalibration(void)
1778+
{
1779+
s8 calib;
1780+
u8 calib_bits;
1781+
syssram *sram;
1782+
1783+
sram = __SYS_LockSram();
1784+
if(!(sram->ntd&0x20)) calib_bits = 0x04;
1785+
else calib_bits = (sram->ntd&0x1f);
1786+
__SYS_UnlockSram(0);
1787+
1788+
calib = 0;
1789+
if(calib_bits&0x01) calib += 4;
1790+
if(calib_bits&0x02) calib += 12;
1791+
if(calib_bits&0x04) calib += 24;
1792+
if(calib_bits&0x08) calib += 40;
1793+
if(calib_bits&0x10) calib = -calib;
1794+
return calib;
1795+
}
1796+
1797+
u8 __SYS_SetTAUCalibration(s8 calib)
1798+
{
1799+
u8 calib_bits = 0x20;
1800+
1801+
if(calib<0) {
1802+
calib = -calib;
1803+
calib_bits |= 0x10;
1804+
}
1805+
if(calib>=40) {
1806+
calib -= 40;
1807+
calib_bits |= 0x08;
1808+
}
1809+
if(calib>=24) {
1810+
calib -= 24;
1811+
calib_bits |= 0x04;
1812+
}
1813+
if(calib>=12) {
1814+
calib -= 12;
1815+
calib_bits |= 0x02;
1816+
}
1817+
if(calib>=4) {
1818+
calib -= 4;
1819+
calib_bits |= 0x01;
1820+
}
1821+
mtthrm3((mfthrm3()&~THRM3_CALIBRATION_MASK)|THRM3_CALIBRATION(calib_bits));
1822+
return calib_bits;
1823+
}
1824+
1825+
void SYS_SetTAUCalibration(s8 calib)
1826+
{
1827+
u32 write;
1828+
u8 calib_bits;
1829+
syssram *sram;
1830+
1831+
calib_bits = __SYS_SetTAUCalibration(calib);
1832+
1833+
write = 0;
1834+
sram = __SYS_LockSram();
1835+
if((sram->ntd&0x3f)!=calib_bits) {
1836+
sram->ntd = (sram->ntd&~0x3f)|(calib_bits&0x3f);
1837+
write = 1;
1838+
}
1839+
__SYS_UnlockSram(write);
1840+
}
1841+
#endif
1842+
17761843
u8 SYS_GetLanguage(void)
17771844
{
17781845
u8 lang;
@@ -2044,15 +2111,18 @@ u32 SYS_GetCoreFrequency(void)
20442111
return clock;
20452112
}
20462113

2114+
#if defined(HW_DOL)
20472115
s8 SYS_GetCoreTemperature(void)
20482116
{
20492117
s32 i,temp;
20502118
u32 pvr,thrm;
20512119

20522120
pvr = mfpvr();
20532121
if(_SHIFTR(pvr,16,16)!=0x8 || _SHIFTR(pvr,12,4)==0x7) return -1;
2054-
if(!(mfthrm3()&THRM3_E))
2055-
mtthrm3(THRM3_CALIBRATION(0x04)|THRM3_SITV(8000)|THRM3_E);
2122+
if(!(mfthrm3()&THRM3_E)) {
2123+
mtthrm3(THRM3_SITV(8000)|THRM3_E);
2124+
__SYS_SetTAUCalibration(SYS_GetTAUCalibration());
2125+
}
20562126

20572127
i = 5;
20582128
temp = 64;
@@ -2065,5 +2135,6 @@ s8 SYS_GetCoreTemperature(void)
20652135
else temp -= (2<<i);
20662136
}
20672137
mtthrm2(0);
2068-
return temp;
2138+
return (temp+2);
20692139
}
2140+
#endif

0 commit comments

Comments
 (0)