Skip to content

Commit

Permalink
fix missing protection for FF registers and others (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwittich authored Feb 6, 2020
1 parent ac5b10c commit 331bd69
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions projects/cm_mcu/I2CSlaveTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,26 @@ static uint8_t getSlaveData(uint8_t address)
value = testreg;
break;
case 0x10U: // MCU temperature
value = (uint8_t) getADCvalue(20);
value = getADCvalue(20)+0.5; // always valid
break;
case 0x12U: // FPGA VU temp
value = (uint8_t) fpga_args.pm_values[0];
if ( value == 0 ) value = 0xFFU; // invalid value
break;
case 0x14U: // FPGA KU temp
value = (uint8_t) fpga_args.pm_values[1];
if ( value == 0 ) value = 0xFFU; // invalid value
break;
case 0x16U: // hottest FF temp
{
int8_t imax_temp = -99.0;
int8_t imax_temp = -55; // turn off value
for ( int i = 0; i < NFIREFLIES; ++i ) {
int8_t v = getFFvalue(i);
if ( v > imax_temp )
imax_temp = v;
}
if ( imax_temp == -99 )
value = 0xFF;
if ( imax_temp < 0 )
value = 0xFFU; // invalid
else
value = (uint8_t) imax_temp;
}
Expand All @@ -90,10 +92,10 @@ static uint8_t getSlaveData(uint8_t address)
max_temp = thistemp;
}
}
if ( max_temp == -99 )
value = 0xFFU;
if ( max_temp < 0 )
value = 0xFFU; // invalid
else
value = (uint8_t) max_temp;
value = (uint8_t) max_temp+0.5;
}
break;
default:
Expand Down

0 comments on commit 331bd69

Please sign in to comment.