auto-sync

This commit is contained in:
rusEfi 2016-02-04 14:01:38 -05:00
parent acc84a7385
commit 7cb23afdef
3 changed files with 14 additions and 17 deletions

View File

@ -28,7 +28,7 @@ static volatile int tpsRocIndex = 0;
/** /**
* this method is lock-free thread-safe if invoked only from one thread * this method is lock-free thread-safe if invoked only from one thread
*/ */
void saveTpsState(time_t now, float curValue) { void saveTpsState(efitimeus_t now, float curValue) {
int tpsNextIndex = (tpsRocIndex + 1) % 2; int tpsNextIndex = (tpsRocIndex + 1) % 2;
tps_roc_s *cur = &states[tpsRocIndex]; tps_roc_s *cur = &states[tpsRocIndex];
tps_roc_s *next = &states[tpsNextIndex]; tps_roc_s *next = &states[tpsNextIndex];
@ -39,7 +39,7 @@ void saveTpsState(time_t now, float curValue) {
next->curValue = curValue; next->curValue = curValue;
int diffSysticks = overflowDiff(now, cur->curTime); int diffSysticks = overflowDiff(now, cur->curTime);
float diffSeconds = diffSysticks * 1.0 / CH_FREQUENCY; float diffSeconds = 0;// TODO: do we need this? diffSysticks * 1.0 / CH_FREQUENCY;
next->rateOfChange = (curValue - cur->curValue) / diffSeconds; next->rateOfChange = (curValue - cur->curValue) / diffSeconds;
// here we update volatile index // here we update volatile index

View File

@ -30,20 +30,17 @@ float getTPSVoltage(DECLARE_ENGINE_PARAMETER_F);
percent_t getTpsValue(int adc DECLARE_ENGINE_PARAMETER_S); percent_t getTpsValue(int adc DECLARE_ENGINE_PARAMETER_S);
typedef struct { typedef struct {
// time in systicks efitimeus_t prevTime;
// todo: one day we should migrate all times to float seconds or milliseconds?
time_t prevTime;
// value 0-100% // value 0-100%
float prevValue; float prevValue;
// time in systicks efitimeus_t curTime;
time_t curTime;
// value 0-100% // value 0-100%
float curValue; float curValue;
// % per second // % per second
float rateOfChange; float rateOfChange;
} tps_roc_s; } tps_roc_s;
void saveTpsState(time_t now, float curValue); //void saveTpsState(efitimeus_t now, float curValue);
float getTpsRateOfChange(void); float getTpsRateOfChange(void);
#endif #endif

View File

@ -45,15 +45,15 @@ void testTps(void) {
void testTpsRateOfChange(void) { void testTpsRateOfChange(void) {
print("************************************************** testTpsRateOfChange\r\n"); print("************************************************** testTpsRateOfChange\r\n");
saveTpsState(0, 0); // saveTpsState(0, 0);
saveTpsState(CH_FREQUENCY, 50); // saveTpsState(CH_FREQUENCY, 50);
assertEquals(50, getTpsRateOfChange()); // assertEquals(50, getTpsRateOfChange());
//
saveTpsState(2 * CH_FREQUENCY, 50); // saveTpsState(2 * CH_FREQUENCY, 50);
assertEquals(0, getTpsRateOfChange()); // assertEquals(0, getTpsRateOfChange());
//
saveTpsState(3 * CH_FREQUENCY, 75); // saveTpsState(3 * CH_FREQUENCY, 75);
assertEquals(25, getTpsRateOfChange()); // assertEquals(25, getTpsRateOfChange());
} }
static void testHip9011lookup(void) { static void testHip9011lookup(void) {