From 9a842f6bb0f8976197057b820bf07a615905a266 Mon Sep 17 00:00:00 2001 From: timecop Date: Wed, 15 Aug 2012 08:47:23 +0000 Subject: [PATCH] fix for 32bit overflow of currentTime killing baro/mag after 72 minutes (yes, someone noticed) thanks to enots @ feenode. git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@194 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61 --- src/imu.c | 2 +- src/mw.c | 12 ++++++------ src/sensors.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/imu.c b/src/imu.c index 497416ff26..c2d55c854d 100755 --- a/src/imu.c +++ b/src/imu.c @@ -268,7 +268,7 @@ void getEstimatedAltitude(void) int32_t temp32; int16_t last; - if (currentTime < deadLine) + if ((int32_t)(currentTime - deadLine) < 0) return; deadLine = currentTime + UPDATE_INTERVAL; diff --git a/src/mw.c b/src/mw.c index bfd8258bdc..501a05481b 100755 --- a/src/mw.c +++ b/src/mw.c @@ -176,14 +176,14 @@ void annexCode(void) #ifdef LEDRING if (feature(FEATURE_LED_RING)) { static uint32_t LEDTime; - if (currentTime > LEDTime) { + if ((int32_t)(currentTime - LEDTime) >= 0) { LEDTime = currentTime + 50000; ledringState(); } } #endif - if (currentTime > calibratedAccTime) { + if ((int32_t)(currentTime - calibratedAccTime) >= 0) { if (!f.SMALL_ANGLES_25) { f.ACC_CALIBRATED = 0; // the multi uses ACC and is not calibrated or is too much inclinated LED0_TOGGLE; @@ -197,7 +197,7 @@ void annexCode(void) if (sensors(SENSOR_GPS)) { static uint32_t GPSLEDTime; - if (currentTime > GPSLEDTime && (GPS_numSat >= 5)) { + if ((int32_t)(currentTime - GPSLEDTime) >= 0 && (GPS_numSat >= 5)) { GPSLEDTime = currentTime + 150000; LED1_TOGGLE; } @@ -270,7 +270,7 @@ void loop(void) if (spektrumFrameComplete()) computeRC(); - if (currentTime > rcTime) { // 50Hz + if ((int32_t)(currentTime - rcTime) >= 0) { // 50Hz rcTime = currentTime + 20000; // TODO clean this up. computeRC should handle this check if (!feature(FEATURE_SPEKTRUM)) @@ -523,13 +523,13 @@ void loop(void) } currentTime = micros(); - if (cfg.looptime == 0 || currentTime > loopTime) { + if (cfg.looptime == 0 || (int32_t)(currentTime - loopTime) >= 0) { loopTime = currentTime + cfg.looptime; computeIMU(); // Measure loop rate just afer reading the sensors currentTime = micros(); - cycleTime = currentTime - previousTime; + cycleTime = (int32_t)(currentTime - previousTime); previousTime = currentTime; #ifdef MPU6050_DMP diff --git a/src/sensors.c b/src/sensors.c index a0c3167503..ae782d1976 100755 --- a/src/sensors.c +++ b/src/sensors.c @@ -243,7 +243,7 @@ void Baro_update(void) { int32_t pressure; - if (currentTime < baroDeadline) + if ((int32_t)(currentTime - baroDeadline) < 0) return; baroDeadline = currentTime; @@ -414,7 +414,7 @@ void Mag_getADC(void) static int16_t magZeroTempMax[3]; uint32_t axis; - if (currentTime < t) + if ((int32_t)(currentTime - t) < 0) return; //each read is spaced by 100ms t = currentTime + 100000;