#129 current state of PWM
This commit is contained in:
parent
82f6bc4151
commit
fb8f9410f2
|
@ -219,6 +219,9 @@ scheduling_s *EventQueue::getForUnitText(int index) {
|
||||||
return current;
|
return current;
|
||||||
index--;
|
index--;
|
||||||
}
|
}
|
||||||
|
#if EFI_UNIT_TEST
|
||||||
|
firmwareError(OBD_PCM_Processor_Fault, "getForUnitText: null");
|
||||||
|
#endif /* EFI_UNIT_TEST */
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,27 @@
|
||||||
extern EventQueue schedulingQueue;
|
extern EventQueue schedulingQueue;
|
||||||
extern int timeNowUs;
|
extern int timeNowUs;
|
||||||
|
|
||||||
void testApplyPinState(PwmConfig *state, int stateIndex) {
|
static int nextTime = 800;
|
||||||
|
|
||||||
|
static void testApplyPinState(PwmConfig *state, int stateIndex) {
|
||||||
|
int value = state->multiWave.waves[0].pinStates[stateIndex];
|
||||||
|
|
||||||
|
printf("Applying value %d @ timeNow=%d\r\n", value, timeNowUs);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void assertNextEvent(const char *msg) {
|
||||||
|
printf("Asserting event [%s]\r\n", msg);
|
||||||
|
// only one action expected in queue
|
||||||
|
assertEquals(1, schedulingQueue.size());
|
||||||
|
|
||||||
|
// move time to next event timestamp
|
||||||
|
timeNowUs += nextTime;
|
||||||
|
|
||||||
|
// execute pending actions and assert that only one action was executed
|
||||||
|
assertEqualsM(msg, 1, schedulingQueue.executeAll(timeNowUs));
|
||||||
|
|
||||||
|
// assert that we have one new action in queue
|
||||||
|
assertEquals(1, schedulingQueue.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testPwmGenerator() {
|
void testPwmGenerator() {
|
||||||
|
@ -24,18 +43,42 @@ void testPwmGenerator() {
|
||||||
|
|
||||||
OutputPin pin;
|
OutputPin pin;
|
||||||
|
|
||||||
//pwm.setFrequency(600);
|
|
||||||
|
|
||||||
schedulingQueue.clear();
|
schedulingQueue.clear();
|
||||||
|
|
||||||
startSimplePwm(&pwm, "unit_test",
|
startSimplePwm(&pwm, "unit_test",
|
||||||
&pin,
|
&pin,
|
||||||
600 /* frequency */,
|
1000 /* frequency */,
|
||||||
0.80 /* duty cycle */,
|
0.80 /* duty cycle */,
|
||||||
&testApplyPinState);
|
&testApplyPinState);
|
||||||
|
|
||||||
assertEquals(1, schedulingQueue.size());
|
int start = timeNowUs;
|
||||||
|
|
||||||
|
assertEqualsM2("1@1000/80", start + nextTime, schedulingQueue.getForUnitText(0)->momentX, 0);
|
||||||
|
|
||||||
|
assertNextEvent("exec@0");
|
||||||
|
assertEqualsM("time1", start + 800, timeNowUs);
|
||||||
|
|
||||||
|
nextTime += 200;
|
||||||
|
assertEqualsM2("2@1000/80", start + nextTime, schedulingQueue.getForUnitText(0)->momentX, 0);
|
||||||
|
|
||||||
|
|
||||||
|
pwm.setSimplePwmDutyCycle(0);
|
||||||
|
|
||||||
|
assertNextEvent("exec@1");
|
||||||
|
assertEqualsM("time2", start + 1800, timeNowUs);
|
||||||
|
|
||||||
|
assertEqualsM2("2@1000/80", start + nextTime, schedulingQueue.getForUnitText(0)->momentX, 0);
|
||||||
|
|
||||||
|
assertNextEvent("exec@2");
|
||||||
|
assertEqualsM("time3", start + 2800, timeNowUs);
|
||||||
|
|
||||||
|
assertNextEvent("exec@3");
|
||||||
|
assertEqualsM("time4", start + 3800, timeNowUs);
|
||||||
|
|
||||||
|
assertNextEvent("exec@4");
|
||||||
|
assertNextEvent("exec@5");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue