Make percentage() safe for 32-bit values. Fixes pwLimit overflow regression
This commit is contained in:
parent
0a5182f353
commit
288b98d31c
|
@ -111,7 +111,7 @@ bool initialisationComplete = false; ///< Tracks whether the setup() function ha
|
||||||
byte fpPrimeTime = 0; ///< The time (in seconds, based on @ref statuses.secl) that the fuel pump started priming
|
byte fpPrimeTime = 0; ///< The time (in seconds, based on @ref statuses.secl) that the fuel pump started priming
|
||||||
uint8_t softLimitTime = 0; //The time (in 0.1 seconds, based on seclx10) that the soft limiter started
|
uint8_t softLimitTime = 0; //The time (in 0.1 seconds, based on seclx10) that the soft limiter started
|
||||||
volatile uint16_t mainLoopCount; //Main loop counter (incremented at each main loop rev., used for maintaining currentStatus.loopsPerSecond)
|
volatile uint16_t mainLoopCount; //Main loop counter (incremented at each main loop rev., used for maintaining currentStatus.loopsPerSecond)
|
||||||
unsigned long revolutionTime; //The time in uS that one revolution would take at current speed (The time tooth 1 was last seen, minus the time it was seen prior to that)
|
uint32_t revolutionTime; //The time in uS that one revolution would take at current speed (The time tooth 1 was last seen, minus the time it was seen prior to that)
|
||||||
volatile unsigned long timer5_overflow_count = 0; //Increments every time counter 5 overflows. Used for the fast version of micros()
|
volatile unsigned long timer5_overflow_count = 0; //Increments every time counter 5 overflows. Used for the fast version of micros()
|
||||||
volatile unsigned long ms_counter = 0; //A counter that increments once per ms
|
volatile unsigned long ms_counter = 0; //A counter that increments once per ms
|
||||||
uint16_t fixedCrankingOverride = 0;
|
uint16_t fixedCrankingOverride = 0;
|
||||||
|
|
|
@ -183,10 +183,12 @@ static inline uint32_t div360(uint32_t n) {
|
||||||
* @param value The value to operate on
|
* @param value The value to operate on
|
||||||
* @return uint32_t
|
* @return uint32_t
|
||||||
*/
|
*/
|
||||||
static inline uint16_t percentage(uint8_t percent, uint16_t value) {
|
static inline uint32_t percentage(uint8_t percent, uint32_t value)
|
||||||
return (uint16_t)div100((uint32_t)value * (uint32_t)percent);
|
{
|
||||||
|
return (uint32_t)div100((uint32_t)value * (uint32_t)percent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Integer based half-percentage calculation.
|
* @brief Integer based half-percentage calculation.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue