use static asserts (#1003)

This commit is contained in:
Matthew Kennedy 2019-11-11 21:39:38 -08:00 committed by rusefi
parent 4ba7842f52
commit b01a9e1388
3 changed files with 17 additions and 4 deletions

View File

@ -2072,7 +2072,7 @@ typedef enum {
CUSTOM_ERR_6706 = 6706,
CUSTOM_ERR_TIMER_TEST_CALLBACK_NOT_HAPPENED = 6707,
CUSTOM_ERR_TIMER_TEST_CALLBACK_WRONG_TIME = 6708,
CUSTOM_ERR_PIN_COUNT_TOO_LARGE = 6709,
CUSTOM_ERR_6709 = 6709,
CUSTOM_DUTY_INVALID = 6710,
CUSTOM_DUTY_TOO_HIGH = 6711,
CUSTOM_ERR_PWM_STATE_ASSERT = 6712,

View File

@ -52,18 +52,20 @@ EnginePins::EnginePins() {
dizzyOutput.name = PROTOCOL_DIZZY_NAME;
tachOut.name = PROTOCOL_TACH_NAME;
efiAssertVoid(CUSTOM_ERR_PIN_COUNT_TOO_LARGE, (sizeof(sparkNames) / sizeof(char*)) >= IGNITION_PIN_COUNT, "spark pin count");
static_assert(efi::size(sparkNames) >= IGNITION_PIN_COUNT, "Too many ignition pins");
for (int i = 0; i < IGNITION_PIN_COUNT;i++) {
enginePins.coils[i].name = sparkNames[i];
enginePins.coils[i].shortName = sparkShortNames[i];
}
efiAssertVoid(CUSTOM_ERR_PIN_COUNT_TOO_LARGE, (sizeof(injectorNames) / sizeof(char*)) >= INJECTION_PIN_COUNT, "inj pin count");
static_assert(efi::size(injectorNames) >= INJECTION_PIN_COUNT, "Too many injection pins");
for (int i = 0; i < INJECTION_PIN_COUNT;i++) {
enginePins.injectors[i].injectorIndex = i;
enginePins.injectors[i].name = injectorNames[i];
enginePins.injectors[i].shortName = injectorShortNames[i];
}
efiAssertVoid(CUSTOM_ERR_PIN_COUNT_TOO_LARGE, (sizeof(auxValveShortNames) / sizeof(char*)) >= AUX_DIGITAL_VALVE_COUNT, "aux pin count");
static_assert(efi::size(auxValveShortNames) >= AUX_DIGITAL_VALVE_COUNT, "Too many aux valve pins");
for (int i = 0; i < AUX_DIGITAL_VALVE_COUNT;i++) {
enginePins.auxValve[i].name = auxValveShortNames[i];
}

View File

@ -74,6 +74,17 @@ float expf_taylor(float x);
#ifdef __cplusplus
}
// C++ helpers go here
namespace efi
{
template <class T, size_t N>
constexpr size_t size(const T (&)[N])
{
return N;
}
} // namespace efi
#endif /* __cplusplus */
#endif /* EFILIB_H_ */