GetBatteryTemperature for SX110: closed with no success or still an issue?
I have investigated the GetBatteryTemperature-problem (as a remainder: SX110 will crash if battery temperature is shown in OSD). I believe now that it is either hardware related or a fimware bug.
GetBatteryTemperature in firmware does some sanity checks. Nearly each of them (or all...) leads to a DebugAssert-call and this is exactly what happens: we get an assertion. I did some dirty things (removed those sanity checks for instance) and now I have a working battery temperature display. But it shows a temperature of 90°C (0x5a) and this is exactly that temperature delivered by an other sanity check. That means: something is going wrong in advance. It could be a missing sensor or a faulty firmware...
What to do now?
- Disable that function for SX110 (for instance per a global directive in camera.h signalling "not for SX110'. Requires some intervention by main developers and tampers generic code.
- Point to another function (for instance GetCCDTemperature) in firmware. That is the solution used till now. Function returns with wrong temperature.
- Function returns with a hard coded value like "99" or so (and remove it from stubs_entry_2.S)
Any suggestions are welcome.
Greetings.
Following code is my test implementation of GetBatteryTemperature
int __attribute__((noinline)) GetBattTemp_asm(int temperature) {
/*
Removed all sanity checks in GetBatteryTemperature otherwise camera will run into DebugAsserts.
Not fine but who cares. Maybe a firmware error.
*/
asm volatile(
"STMFD SP!, {R4,LR}\n"
" MOV %[temp], #-1\n" // <-------- inserted, save return code to our own variable
"LDR R4, =0x25E0\n"
"LDR R0, [R4,#8]\n"
"CMP R0, #0\n"
/*
"LDREQ R1, =0x116\n"
"LDREQ R0, =0xFFC38950\n" //ADREQ R0, aThermometer_c
"BLEQ sub_FFC0BD98\n" //BLEQ DebugAssert
*/
"NOP \n"
"NOP \n"
"NOP \n"
"LDR R0, [R4,#0xC]\n"
"LDRSH R1, [R0,#0x14]\n"
"CMP R1, #0\n"
"LDMEQFD SP!, {R4,LR}\n"
"BEQ loc_FFC388CC\n" //loc_FFC388CC
"CMP R1, #1\n"
"LDMEQFD SP!, {R4,LR}\n"
"BEQ sub_FFC387EC\n" //GetCCDTemperature
"LDR R0, [R0,#0x10]\n"
"CMP R0, #2\n"
/*
"LDREQ R1, =0x11E\n"
"LDREQ R0, =0xFFC38950\n" //ADREQ R0, aThermometer_c
"BLEQ sub_FFC0BD98\n" //BLEQ DebugAssert
*/
"NOP \n"
"NOP \n"
"NOP \n"
"LDR R1, [R4,#0xC]\n"
"LDRH R0, [R4,#4]\n"
"LDR R1, [R1,#0x10]\n"
"LDR R2, =0xFFE9815C\n" //LDR R2, =unk_FFE9815C
"ADD R1, R1, R1,LSL#3\n"
"LDMFD SP!, {R4,LR}\n"
"ADD R1, R2, R1,LSL#4\n"
"B loc_FFC38784\n"
"loc_FFC388CC:\n"
" STMFD SP!, {R4,LR}\n"
" LDR R4, =0x25E0\n"
" LDR R0, [R4,#8]\n"
" CMP R0, #0\n"
/*
" MOVEQ R1, #0xDE\n"
" LDREQ R0, =0xFFC38950\n" //ADREQ R0, aThermometer_c
" BLEQ sub_FFC0BD98\n" //BLEQ DebugAssert
*/
"NOP \n"
"NOP \n"
"NOP \n"
" LDR R0, [R4,#0xC]\n"
" LDRSH R1, [R0,#4]\n"
" CMP R1, #0\n"
" BNE loc_FFC3892C\n"
" LDR R0, [R0]\n"
" CMP R0, #2\n"
/*
" MOVEQ R1, #0xE0\n"
" LDREQ R0, =0xFFC38950\n" //ADREQ R0, aThermometer_c
" BLEQ sub_FFC0BD98\n" //BLEQ DebugAssert
*/
"NOP \n"
"NOP \n"
"NOP \n"
" LDR R1, [R4,#0xC]\n"
" LDRH R0, [R4]\n"
" LDR R1, [R1]\n"
" LDR R2, =0xFFE9815C\n" //unk_FFE9815C
" ADD R1, R1, R1,LSL#3\n"
" LDMFD SP!, {R4,LR}\n"
" ADD R1, R2, R1,LSL#4\n"
" B loc_FFC38784\n"
"loc_FFC3892C:\n"
" CMP R1, #1\n"
" LDMNEFD SP!, {R4,LR}\n"
" BNE _GetBatteryTemperature\n" //GetBatteryTemperature
" LDMEQFD SP!, {R4,LR}\n"
" BEQ sub_FFC387EC\n" //GetCCDTemperature
"loc_FFC38784:\n"
" LDRH R2, [R1]\n"
" CMP R2, R0\n"
" MOVLS R0, #0xFFFFFFF6\n" //unk_FFFFFFF6
" MOVLS %[temp], R0\n" // <-------- inserted, save return code to our own variable
" BXLS LR\n"
"loc_FFC38794:\n"
" LDRH R2, [R1,#0xC]!\n"
" CMP R2, #0\n"
" MOVEQ R0, #0x5A\n"
" MOVEQ %[temp], R0\n" // <-------- inserted, save return code to our own variable
" BXEQ LR\n"
//execution ends here with return code 0x5a
" CMP R2, R0\n"
" BHI loc_FFC38794\n"
" LDR R2, [R1,#4]\n"
" LDR R1, [R1,#8]\n"
" MUL R0, R1, R0\n"
" SUB R0, R2, R0\n"
" ADDS R1, R0, #0x200\n"
" ADD R0, R0, #0x200\n"
" MOVPL R0, R0,ASR#10\n"
" BPL loc_FFC387E0\n"
" RSB R0, R0, #0\n"
" ADD R0, R0, #0x300\n"
" ADD R0, R0, #0xFF\n"
" MOV R0, R0,ASR#10\n"
" RSB R0, R0, #0\n"
"loc_FFC387E0:\n"
" MOV R0, R0,LSL#16\n"
" MOV R0, R0,ASR#16\n"
" MOVEQ %[temp], R0\n" // <-------- inserted, save return code to our own variable
: [temp] "=r" (temperature)
);
return temperature;
}
int _GetBatteryTemperature()
{
// return _GetBatteryTemperature();
int batterytemperature;
batterytemperature = 0;
batterytemperature = GetBattTemp_asm(batterytemperature);
return batterytemperature;
}