1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-15 12:25:20 +03:00

cpm16 / cmp32 functions

used to compare timestamps with correct wrap. A bit more readable that typecasting in code. Only few uses replaced now
This commit is contained in:
Petr Ledvina 2015-10-09 13:20:35 +02:00 committed by Dominic Clifton
parent 3cdc4a23b5
commit dc5a888633
2 changed files with 5 additions and 2 deletions

View file

@ -46,5 +46,7 @@ http://resnet.uoregon.edu/~gurney_j/jmpc/bitwise.html
const typeof( ((type *)0)->member ) *__mptr = (ptr); \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );}) (type *)( (char *)__mptr - offsetof(type,member) );})
static inline int16_t cmp16(uint16_t a, uint16_t b) { return a-b; }
static inline int32_t cmp32(uint32_t a, uint32_t b) { return a-b; }
#endif #endif

View file

@ -25,6 +25,7 @@
#include "common/maths.h" #include "common/maths.h"
#include "common/axis.h" #include "common/axis.h"
#include "common/color.h" #include "common/color.h"
#include "common/utils.h"
#include "drivers/sensor.h" #include "drivers/sensor.h"
#include "drivers/accgyro.h" #include "drivers/accgyro.h"
@ -236,14 +237,14 @@ void annexCode(void)
} }
if (feature(FEATURE_VBAT)) { if (feature(FEATURE_VBAT)) {
if ((int32_t)(currentTime - vbatLastServiced) >= VBATINTERVAL) { if (cmp32(currentTime, vbatLastServiced) >= VBATINTERVAL) {
vbatLastServiced = currentTime; vbatLastServiced = currentTime;
updateBattery(); updateBattery();
} }
} }
if (feature(FEATURE_CURRENT_METER)) { if (feature(FEATURE_CURRENT_METER)) {
int32_t ibatTimeSinceLastServiced = (int32_t) (currentTime - ibatLastServiced); int32_t ibatTimeSinceLastServiced = cmp32(currentTime, ibatLastServiced);
if (ibatTimeSinceLastServiced >= IBATINTERVAL) { if (ibatTimeSinceLastServiced >= IBATINTERVAL) {
ibatLastServiced = currentTime; ibatLastServiced = currentTime;