reducing code duplication around assert

This commit is contained in:
Andrey 2023-09-05 21:28:39 -04:00
parent 0c9b87f00b
commit ba66fdcf82
18 changed files with 27 additions and 27 deletions

View File

@ -167,7 +167,7 @@ void ReturnToothLoggerBuffer(CompositeBuffer* buffer) {
chibios_rt::CriticalSectionLocker csl;
msg_t msg = freeBuffers.postI(buffer);
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, msg == MSG_OK, "Composite logger post to free buffer fail");
criticalAssertVoid(msg == MSG_OK, "Composite logger post to free buffer fail");
}
static CompositeBuffer* findBuffer(efitick_t timestamp) {

View File

@ -23,7 +23,7 @@ size_t TsChannelBase::read(uint8_t* buffer, size_t size) {
void TsChannelBase::copyAndWriteSmallCrcPacket(uint8_t responseCode, const uint8_t* buf, size_t size) {
// don't transmit too large a buffer
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, !isBigPacket(size), "copyAndWriteSmallCrcPacket tried to transmit too large a packet")
criticalAssertVoid(!isBigPacket(size), "copyAndWriteSmallCrcPacket tried to transmit too large a packet")
// If transmitting data, copy it in to place in the scratch buffer
// We want to prevent the data changing itself (higher priority threads could write
@ -37,7 +37,7 @@ void TsChannelBase::copyAndWriteSmallCrcPacket(uint8_t responseCode, const uint8
}
void TsChannelBase::crcAndWriteBuffer(uint8_t responseCode, size_t size) {
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, !isBigPacket(size), "crcAndWriteBuffer tried to transmit too large a packet")
criticalAssertVoid(!isBigPacket(size), "crcAndWriteBuffer tried to transmit too large a packet")
// Index 0/1 = packet size (big endian)
*(uint16_t*)scratchBuffer = SWAP_UINT16(size + 1);

View File

@ -180,7 +180,7 @@ void Engine::periodicSlowCallback() {
#endif // EFI_PROD_CODE
#if ANALOG_HW_CHECK_MODE
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, isAdcChannelValid(engineConfiguration->clt.adcChannel), "No CLT setting");
criticalAssertVoid(isAdcChannelValid(engineConfiguration->clt.adcChannel), "No CLT setting");
efitimesec_t secondsNow = getTimeNowS();
#if ! HW_CHECK_ALWAYS_STIMULATE

View File

@ -256,7 +256,7 @@ static void initTemperatureCurve(float *bins, float *values, int size, float def
}
void prepareVoidConfiguration(engine_configuration_s *engineConfiguration) {
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, engineConfiguration != NULL, "ec NULL");
criticalAssertVoid(engineConfiguration != NULL, "ec NULL");
efi::clear(engineConfiguration);
engineConfiguration->clutchDownPinMode = PI_PULLUP;

View File

@ -165,7 +165,7 @@ void HpfpController::onFastCallback() {
m_deadtime = 0;
} else {
#if EFI_PROD_CODE && EFI_SHAFT_POSITION_INPUT
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, engine->triggerCentral.triggerShape.getSize() > engineConfiguration->hpfpCamLobes * 6, "Too few trigger tooth for this number of HPFP lobes");
criticalAssertVoid(engine->triggerCentral.triggerShape.getSize() > engineConfiguration->hpfpCamLobes * 6, "Too few trigger tooth for this number of HPFP lobes");
#endif // EFI_PROD_CODE
// Convert deadtime from ms to degrees based on current RPM
float deadtime_ms = interpolate2d(

View File

@ -54,7 +54,7 @@ public:
}
void reinit(char *buffer, size_t size) {
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, m_memoryUsed == 0, "Too late to reinit Lua heap");
criticalAssertVoid(m_memoryUsed == 0, "Too late to reinit Lua heap");
m_size = size;
m_buffer = buffer;

View File

@ -107,7 +107,7 @@ void EventQueue::remove(scheduling_s* scheduling) {
return;
}
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, current == scheduling, "current not equal to scheduling");
criticalAssertVoid(current == scheduling, "current not equal to scheduling");
// Link around the removed item
prev->nextScheduling_s = current->nextScheduling_s;

View File

@ -19,7 +19,7 @@ void initialize60_2_2_Renault_F(TriggerWaveform *s) {
NO_LEFT_FILTER, 719);
#if EFI_UNIT_TEST
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, s->wave.phaseCount == (totalTeethCount - skipped) * 2 - 1, "Tooth count 60-3");
criticalAssertVoid(s->wave.phaseCount == (totalTeethCount - skipped) * 2 - 1, "Tooth count 60-3");
#endif // EFI_UNIT_TEST
float specialPosition = 58 * oneTooth;
@ -30,7 +30,7 @@ void initialize60_2_2_Renault_F(TriggerWaveform *s) {
specialPosition - 1, specialPosition - 1 + oneTooth);
#if EFI_UNIT_TEST
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, s->wave.phaseCount == (totalTeethCount - skipped) * 2 + 1, "Tooth count 60-2-2");
criticalAssertVoid(s->wave.phaseCount == (totalTeethCount - skipped) * 2 + 1, "Tooth count 60-2-2");
#endif // EFI_UNIT_TEST
s->addEvent(1, TriggerValue::FALL, TriggerWheel::T_PRIMARY);

View File

@ -342,7 +342,7 @@ void TriggerWaveform::setTriggerSynchronizationGap2(float syncRatioFrom, float s
void TriggerWaveform::setTriggerSynchronizationGap3(int gapIndex, float syncRatioFrom, float syncRatioTo) {
isSynchronizationNeeded = true;
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, gapIndex >= 0 && gapIndex < GAP_TRACKING_LENGTH, "gapIndex out of range");
criticalAssertVoid(gapIndex >= 0 && gapIndex < GAP_TRACKING_LENGTH, "gapIndex out of range");
syncronizationRatioFrom[gapIndex] = syncRatioFrom;
syncronizationRatioTo[gapIndex] = syncRatioTo;
if (gapIndex == 0) {

View File

@ -979,7 +979,7 @@ static void resetRunningTriggerCounters() {
void onConfigurationChangeTriggerCallback() {
bool changed = false;
// todo: how do we static_assert here?
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, efi::size(engineConfiguration->camInputs) == efi::size(engineConfiguration->vvtOffsets), "sizes");
criticalAssertVoid(efi::size(engineConfiguration->camInputs) == efi::size(engineConfiguration->vvtOffsets), "sizes");
for (size_t camIndex = 0; camIndex < efi::size(engineConfiguration->camInputs); camIndex++) {
changed |= isConfigurationChanged(camInputs[camIndex]);

View File

@ -163,7 +163,7 @@ void TriggerFormDetails::prepareEventAngles(TriggerWaveform *shape) {
fixAngle(angle, "trgSync", ObdCode::CUSTOM_TRIGGER_SYNC_ANGLE_RANGE);
if (shape->useOnlyRisingEdges) {
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, triggerDefinitionIndex < triggerShapeLength, "trigger shape fail");
criticalAssertVoid(triggerDefinitionIndex < triggerShapeLength, "trigger shape fail");
assertIsInBounds(triggerDefinitionIndex, shape->isRiseEvent, "isRise");
// In case this is a rising event, replace the following fall event with the rising as well

View File

@ -42,7 +42,7 @@ void efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, Exti
return;
}
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, msg, "efiExtiEnablePin msg must not be null");
criticalAssertVoid(msg, "efiExtiEnablePin msg must not be null");
ioportid_t port = getHwPort(msg, brainPin);
if (port == NULL) {

View File

@ -50,7 +50,7 @@ static bool hwStarted = false;
* This function should be invoked under kernel lock which would disable interrupts.
*/
void setHardwareSchedulerTimer(efitick_t nowNt, efitick_t setTimeNt) {
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, hwStarted, "HW.started");
criticalAssertVoid(hwStarted, "HW.started");
// How many ticks in the future is this event?
auto timeDeltaNt = setTimeNt - nowNt;

View File

@ -221,7 +221,7 @@ void initSmartGpio() {
tle6240.spi_bus = getSpiDevice(engineConfiguration->tle6240spiDevice);
int ret = tle6240_add(Gpio::TLE6240_PIN_1, 0, &tle6240);
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, ret == (int)Gpio::TLE6240_PIN_1, "tle6240");
criticalAssertVoid(ret == (int)Gpio::TLE6240_PIN_1, "tle6240");
}
#endif /* (BOARD_TLE6240_COUNT > 0) */
@ -234,7 +234,7 @@ void initSmartGpio() {
// todo: propogate 'basePinOffset' parameter
int ret = mc33972_add(Gpio::MC33972_PIN_1, 0, &mc33972);
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, ret == (int)Gpio::MC33972_PIN_1, "mc33972");
criticalAssertVoid(ret == (int)Gpio::MC33972_PIN_1, "mc33972");
}
#endif /* (BOARD_MC33972_COUNT > 0) */
@ -247,7 +247,7 @@ void initSmartGpio() {
// todo: propogate 'basePinOffset' parameter
int ret = l9779_add(Gpio::L9779_IGN_1, 0, &l9779_cfg);
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, ret == (int)Gpio::L9779_IGN_1, "l9779");
criticalAssertVoid(ret == (int)Gpio::L9779_IGN_1, "l9779");
}
#endif /* (BOARD_L9779_COUNT > 0) */
@ -264,7 +264,7 @@ void initSmartGpio() {
/* spi_bus == null checked in _add function */
int ret = tle8888_add(Gpio::TLE8888_PIN_1, 0, &tle8888_cfg);
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, ret == (int)Gpio::TLE8888_PIN_1, "tle8888");
criticalAssertVoid(ret == (int)Gpio::TLE8888_PIN_1, "tle8888");
}
#endif /* (BOARD_TLE8888_COUNT > 0) */
@ -275,7 +275,7 @@ void initSmartGpio() {
drv8860.spi_bus = getSpiDevice(engineConfiguration->drv8860spiDevice);
int ret = drv8860_add(Gpio::DRV8860_PIN_1, 0, &drv8860);
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, ret == (int)Gpio::DRV8860_PIN_1, "drv8860");
criticalAssertVoid(ret == (int)Gpio::DRV8860_PIN_1, "drv8860");
}
#endif /* (BOARD_DRV8860_COUNT > 0) */

View File

@ -189,7 +189,7 @@ bool isDigitalTps1() {
}
void initTps() {
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, engineConfiguration != nullptr, "null engineConfiguration");
criticalAssertVoid(engineConfiguration != nullptr, "null engineConfiguration");
percent_t min = engineConfiguration->tpsErrorDetectionTooLow;
percent_t max = engineConfiguration->tpsErrorDetectionTooHigh;

View File

@ -90,7 +90,7 @@ bool isPhaseInRange(float test, float current, float next);
#define IS_NEGATIVE_ZERO(value) (__builtin_signbit(value) && value==0)
#define fixNegativeZero(value) (IS_NEGATIVE_ZERO(value) ? 0 : value)
#define assertIsInBounds(length, array, msg) efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, std::is_unsigned_v<decltype(length)> && (length) < efi::size(array), msg)
#define assertIsInBounds(length, array, msg) criticalAssertVoid(std::is_unsigned_v<decltype(length)> && (length) < efi::size(array), msg)
#define assertIsInBoundsWithResult(length, array, msg, failedResult) efiAssert(ObdCode::OBD_PCM_Processor_Fault, std::is_unsigned_v<decltype(length)> && (length) < efi::size(array), msg, failedResult)

View File

@ -30,7 +30,7 @@ static float getNorm(float K, float Q) {
}
void Biquad::configureBandpass(float samplingFrequency, float centerFrequency, float Q) {
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, samplingFrequency >= 2.5f * centerFrequency, "Invalid biquad parameters");
criticalAssertVoid(samplingFrequency >= 2.5f * centerFrequency, "Invalid biquad parameters");
float K = getK(samplingFrequency, centerFrequency);
float norm = getNorm(K, Q);
@ -43,7 +43,7 @@ void Biquad::configureBandpass(float samplingFrequency, float centerFrequency, f
}
void Biquad::configureLowpass(float samplingFrequency, float cutoffFrequency, float Q) {
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, samplingFrequency >= 2.5f * cutoffFrequency, "Invalid biquad parameters");
criticalAssertVoid(samplingFrequency >= 2.5f * cutoffFrequency, "Invalid biquad parameters");
float K = getK(samplingFrequency, cutoffFrequency);
float norm = getNorm(K, Q);

View File

@ -118,13 +118,13 @@ static void runToothLoggerTest() {
{
CompositeBuffer * toothBuffer = GetToothLoggerBufferNonblocking();
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, toothBuffer != nullptr, "filled buffer expected");
criticalAssertVoid(toothBuffer != nullptr, "filled buffer expected");
size_t size = toothBuffer->nextIdx * sizeof(composite_logger_s);
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, size != 0, "Positive payload size expected");
criticalAssertVoid(size != 0, "Positive payload size expected");
const uint8_t* ptr = reinterpret_cast<const uint8_t*>(toothBuffer->buffer);
efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, ptr != nullptr, "Payload reference expected");
criticalAssertVoid(ptr != nullptr, "Payload reference expected");
}
}