Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rusefi committed Dec 17, 2017
1 parent 5c0be05 commit 9d372a2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
29 changes: 17 additions & 12 deletions firmware/controllers/core/fsio_impl.cpp
Expand Up @@ -272,23 +272,25 @@ static const char *getGpioPinName(int index) {
return NULL;
}

float getFsioOutputValue(int index DECLARE_ENGINE_PARAMETER_SUFFIX) {
if (fsioLogics[index] == NULL) {
warning(CUSTOM_NO_FSIO, "no FSIO for #%d %s", index + 1, hwPortname(boardConfiguration->fsioOutputPins[index]));
return NAN;
} else {
return calc.getValue2(engine->fsioLastValue[index], fsioLogics[index] PASS_ENGINE_PARAMETER_SUFFIX);
}
}

/**
* @param index from zero for (FSIO_COMMAND_COUNT - 1)
*/
static void handleFsio(Engine *engine, int index) {
static void handleFsio(int index DECLARE_ENGINE_PARAMETER_SUFFIX) {
if (boardConfiguration->fsioOutputPins[index] == GPIO_UNASSIGNED)
return;

bool isPwmMode = boardConfiguration->fsioFrequency[index] != NO_PWM;

float fvalue;
if (fsioLogics[index] == NULL) {
warning(CUSTOM_NO_FSIO, "no FSIO for #%d %s", index + 1, hwPortname(boardConfiguration->fsioOutputPins[index]));
fvalue = NAN;
} else {
fvalue = calc.getValue2(engine->fsioLastValue[index], fsioLogics[index] PASS_ENGINE_PARAMETER_SUFFIX);
}
engine->fsioLastValue[index] = fvalue;
engine->fsioLastValue[index] = getFsioOutputValue(index PASS_ENGINE_PARAMETER_SUFFIX);

if (isPwmMode) {
fsioPwm[index].setSimplePwmDutyCycle(fvalue);
Expand Down Expand Up @@ -365,9 +367,12 @@ static void setFsioFrequency(int index, int frequency) {
}
}

void runFsio(void) {
for (int i = 0; i < FSIO_COMMAND_COUNT; i++) {
handleFsio(engine, i);
/**
* this method should be invoked periodically to calculate FSIO and toggle corresponding FSIO outputs
*/
void runFsio(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
for (int index = 0; index < FSIO_COMMAND_COUNT; index++) {
handleFsio(index PASS_ENGINE_PARAMETER_SUFFIX);
}

#if EFI_FUEL_PUMP || defined(__DOXYGEN__)
Expand Down
3 changes: 2 additions & 1 deletion firmware/controllers/core/fsio_impl.h
Expand Up @@ -23,7 +23,8 @@ void setFsio(int index, brain_pin_e pin, const char * exp DECLARE_ENGINE_PARAMET
void setFsioExt(int index, brain_pin_e pin, const char * exp, int pwmFrequency DECLARE_ENGINE_PARAMETER_SUFFIX);

void initFsioImpl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX);
void runFsio(void);
void runFsio(DECLARE_ENGINE_PARAMETER_SIGNATURE);
float getFsioOutputValue(int index DECLARE_ENGINE_PARAMETER_SUFFIX);
void applyFsioConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void prepareFsio(void);

Expand Down
2 changes: 1 addition & 1 deletion firmware/controllers/engine_controller.cpp
Expand Up @@ -274,7 +274,7 @@ static void periodicSlowCallback(Engine *engine) {
engine->checkShutdown();

#if (EFI_PROD_CODE && EFI_FSIO) || defined(__DOXYGEN__)
runFsio();
runFsio(PASS_ENGINE_PARAMETER_SIGNATURE);
#endif /* EFI_PROD_CODE && EFI_FSIO */

cylinderCleanupControl(engine);
Expand Down

0 comments on commit 9d372a2

Please sign in to comment.