rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
can_bench_test.cpp File Reference

Functions

bool isHwQcMode ()
 
void setHwQcMode ()
 
static void directWritePad (Gpio pin, int value, const char *msg="")
 
static void qcSetEtbState (uint8_t dcIndex, uint8_t direction)
 
static void setPin (const CANRxFrame &frame, int value)
 
void sendQcBenchEventCounters (size_t bus)
 
void sendQcBenchButtonCounters ()
 
void sendQcBenchAuxDigitalCounters ()
 
void sendQcBenchRawAnalogValues (size_t bus)
 
static void sendOutBoardMeta (size_t bus)
 
void sendQcBenchBoardStatus (size_t bus)
 
static void sendManualPinTest (int id)
 
static void sendPinStatePackets (int pinToggleCounter, uint32_t durationsInStateMs[2])
 
static void sendPinStatePackets (bench_mode_e benchModePinIdx)
 
static void sendSavedBenchStatePackets ()
 
static void resetPinStats (bench_mode_e benchModePinIdx)
 
void processCanQcBenchTest (const CANRxFrame &frame)
 
void initQcBenchControls ()
 

Variables

PinRepository pinRepository
 
static bool qcDirectPinControlMode = false
 

Function Documentation

◆ directWritePad()

static void directWritePad ( Gpio  pin,
int  value,
const char msg = "" 
)
static

Definition at line 61 of file can_bench_test.cpp.

61 {
62 if (!isBrainPinValid(pin)) {
63 criticalError("QC of invalid pin %d %s", (int)pin, msg);
64 return;
65 }
66
67#if EFI_GPIO_HARDWARE && EFI_PROD_CODE
69 palWritePad(getHwPort("can_write", pin), getHwPin("can_write", pin), value);
70 } else {
71#if (BOARD_EXT_GPIOCHIPS > 0)
72 gpiochips_writePad(pin, value);
73#endif
74 }
75#endif // EFI_GPIO_HARDWARE && EFI_PROD_CODE
76}
int gpiochips_writePad(brain_pin_e pin, int value)
Set value to gpio of gpiochip.
Definition core.cpp:336
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin)
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin)
bool brain_pin_is_onchip(brain_pin_e brainPin)
bool isBrainPinValid(brain_pin_e brainPin)
brain_pin_e pin
Definition stm32_adc.cpp:15

Referenced by qcSetEtbState(), and setPin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initQcBenchControls()

void initQcBenchControls ( )

Definition at line 341 of file can_bench_test.cpp.

341 {
342#if EFI_CAN_SUPPORT && EFI_PROD_CODE
343 addConsoleActionII("qc_etb", [](int index, int direction) {
344 qcSetEtbState(index, direction);
345 });
346
347 addConsoleActionI("qc_output", [](int index) {
348 Gpio* boardOutputs = getBoardMetaOutputs();
349 criticalAssertVoid(boardOutputs != nullptr, "outputs not defined");
350 Gpio pin = boardOutputs[index];
351 efiSetPadModeWithoutOwnershipAcquisition("qc_output", pin, PAL_MODE_OUTPUT_PUSHPULL);
352
353 int physicalValue = palReadPad(getHwPort("read", pin), getHwPin("read", pin));
354 efiPrintf("original pin %s value %d", hwPortname(pin), physicalValue);
355 palWritePad(getHwPort("write", pin), getHwPin("write", pin), 1 - physicalValue);
356 sendManualPinTest(index);
357 });
358#endif // EFI_PROD_CODE
359}
static void sendManualPinTest(int id)
static void qcSetEtbState(uint8_t dcIndex, uint8_t direction)
void addConsoleActionII(const char *token, VoidIntInt callback)
Register a console command with two Integer parameters.
void addConsoleActionI(const char *token, VoidInt callback)
Register a console command with one Integer parameter.
Gpio * getBoardMetaOutputs()
void efiSetPadModeWithoutOwnershipAcquisition(const char *msg, brain_pin_e brainPin, iomode_t mode)
Definition io_pins.cpp:61
const char * hwPortname(brain_pin_e brainPin)

Referenced by commonEarlyInit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isHwQcMode()

bool isHwQcMode ( )

Definition at line 40 of file can_bench_test.cpp.

40 {
41#if EFI_PROD_CODE
43#else
44 return false;
45#endif // EFI_PROD_CODE
46}
static bool qcDirectPinControlMode

Referenced by CanWrite::PeriodicTask(), and OutputPin::setValue().

Here is the caller graph for this function:

◆ processCanQcBenchTest()

void processCanQcBenchTest ( const CANRxFrame frame)

file can_bench_test.h

Definition at line 298 of file can_bench_test.cpp.

298 {
299 if (CAN_EID(frame) != (int)bench_test_packet_ids_e::HW_QC_IO_CONTROL) {
300 return;
301 }
302 if (frame.data8[0] != (int)bench_test_magic_numbers_e::BENCH_HEADER) {
303 return;
304 }
305 setHwQcMode();
306 bench_test_io_control_e command = (bench_test_io_control_e)frame.data8[1];
307 if (command == bench_test_io_control_e::CAN_BENCH_GET_COUNT) {
309 } else if (command == bench_test_io_control_e::CAN_QC_OUTPUT_CONTROL_SET) {
310 // see also "bench_setpin" console command
311 setPin(frame, 1);
312 } else if (command == bench_test_io_control_e::CAN_QC_OUTPUT_CONTROL_CLEAR) {
313 setPin(frame, 0);
314 } else if (command == bench_test_io_control_e::CAN_QC_ETB) {
315 uint8_t dcIndex = frame.data8[2];
316 uint8_t direction = frame.data8[3];
317 qcSetEtbState(dcIndex, direction);
318 } else if (command == bench_test_io_control_e::CAN_BENCH_SET_ENGINE_TYPE) {
319 int eType = frame.data8[2];
320 // todo: fix firmware for 'false' to be possible - i.e. more of properties should be applied on the fly
321 setEngineType(eType, true);
322#if EFI_PROD_CODE
324#endif // EFI_PROD_CODE
325} else if (command == bench_test_io_control_e::CAN_BENCH_START_PIN_TEST) {
326 bench_mode_e benchModePinIdx = (bench_mode_e)frame.data8[2];
327 // ignore previous pin state and stats
328 resetPinStats(benchModePinIdx);
329 } else if (command == bench_test_io_control_e::CAN_BENCH_END_PIN_TEST) {
331 } else if (command == bench_test_io_control_e::CAN_BENCH_EXECUTE_BENCH_TEST) {
332 int benchCommandIdx = frame.data8[2];
333 handleBenchCategory(benchCommandIdx);
334 } else if (command == bench_test_io_control_e::CAN_BENCH_QUERY_PIN_STATE) {
335 bench_mode_e benchModePinIdx = (bench_mode_e)frame.data8[2];
336 sendPinStatePackets(benchModePinIdx);
337 }
338}
void handleBenchCategory(uint16_t index)
static void setPin(const CANRxFrame &frame, int value)
static void sendSavedBenchStatePackets()
void setHwQcMode()
static void resetPinStats(bench_mode_e benchModePinIdx)
static void sendOutBoardMeta(size_t bus)
static void sendPinStatePackets(int pinToggleCounter, uint32_t durationsInStateMs[2])
void scheduleReboot()
Definition rusefi.cpp:158
bench_mode_e
void setEngineType(int value, bool isWriteToFlash)
Definition settings.cpp:735
uint8_t data8[8]
Frame data.
Definition can_mocks.h:55

Referenced by processCanRxMessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ qcSetEtbState()

static void qcSetEtbState ( uint8_t  dcIndex,
uint8_t  direction 
)
static

Definition at line 78 of file can_bench_test.cpp.

78 {
80 const dc_io *io = &engineConfiguration->etbIo[dcIndex];
81 Gpio controlPin = io->controlPin;
82 directWritePad(controlPin, 1, "DC control");
84 // TLE7209 and L6205
85 // let's force proper pin mode to work around potentially uninitialized subsystem
86 efiSetPadModeWithoutOwnershipAcquisition("QC_ETB_1", io->directionPin1, PAL_MODE_OUTPUT_PUSHPULL);
87 efiSetPadModeWithoutOwnershipAcquisition("QC_ETB_2", io->directionPin2, PAL_MODE_OUTPUT_PUSHPULL);
88
89 directWritePad(io->directionPin1, direction, "DC dir1");
90 directWritePad(io->directionPin2, !direction, "DC dir2");
91 } else {
92 // TLE9201 and VNH2SP30
93 efiSetPadModeWithoutOwnershipAcquisition("QC_ETB", controlPin, PAL_MODE_OUTPUT_PUSHPULL);
94 directWritePad(io->directionPin1, direction, "DC dir");
95 directWritePad(io->disablePin, 0, "DC dis"); // disable pin is inverted - here we ENABLE. direct pin access due to qcDirectPinControlMode
96 }
97}
static void directWritePad(Gpio pin, int value, const char *msg="")
static constexpr engine_configuration_s * engineConfiguration

Referenced by initQcBenchControls(), and processCanQcBenchTest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetPinStats()

static void resetPinStats ( bench_mode_e  benchModePinIdx)
static

Definition at line 287 of file can_bench_test.cpp.

287 {
289
290 if (pin == nullptr)
291 return;
292
293#if EFI_SIMULATOR
295#endif // EFI_SIMULATOR
296}
OutputPin * getOutputPinForBenchMode(bench_mode_e idx)
Definition efi_gpio.cpp:356
Single output pin reference and state.
Definition efi_output.h:49
void resetToggleStats()
Definition efi_gpio.cpp:598
EnginePins enginePins
Definition efi_gpio.cpp:24

Referenced by processCanQcBenchTest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendManualPinTest()

static void sendManualPinTest ( int  id)
static

Definition at line 253 of file can_bench_test.cpp.

253 {
254 CanTxMessage msg(CanCategory::BENCH_TEST, (int)bench_test_packet_ids_e::MANUAL_PIN_TEST, 8, /*bus*/0, /*isExtended*/true);
255 msg[0] = id;
256}

Referenced by initQcBenchControls().

Here is the caller graph for this function:

◆ sendOutBoardMeta()

static void sendOutBoardMeta ( size_t  bus)
static

Definition at line 221 of file can_bench_test.cpp.

221 {
222#if EFI_PROD_CODE
223 CanTxMessage msg(CanCategory::BENCH_TEST, (int)bench_test_packet_ids_e::IO_META_INFO, 8, bus, /*isExtended*/true);
224 msg[0] = (int)bench_test_magic_numbers_e::BENCH_HEADER;
225 msg[1] = 0;
226 msg[2] = getBoardMetaOutputsCount();
229#endif // EFI_PROD_CODE
230}
int getBoardMetaOutputsCount()
int getBoardMetaLowSideOutputsCount()
int getBoardMetaDcOutputsCount()

Referenced by processCanQcBenchTest(), and sendQcBenchBoardStatus().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendPinStatePackets() [1/2]

static void sendPinStatePackets ( bench_mode_e  benchModePinIdx)
static

Definition at line 272 of file can_bench_test.cpp.

272 {
274 if (pin == nullptr)
275 return;
276#if EFI_SIMULATOR
277 sendPinStatePackets(pin->pinToggleCounter, pin->durationsInStateMs);
278#endif // EFI_SIMULATOR
279}
Here is the call graph for this function:

◆ sendPinStatePackets() [2/2]

static void sendPinStatePackets ( int  pinToggleCounter,
uint32_t  durationsInStateMs[2] 
)
static

Definition at line 259 of file can_bench_test.cpp.

259 {
260 CanTxMessage msg(CanCategory::BENCH_TEST, (int)bench_test_packet_ids_e::PIN_STATE, 8, /*bus*/0, /*isExtended*/true);
261 msg[0] = TRUNCATE_TO_BYTE(pinToggleCounter >> 8);
262 msg[1] = TRUNCATE_TO_BYTE(pinToggleCounter);
263
264 for (int i = 0, mIdx = 2; i < 2; i++) {
265 msg[mIdx++] = TRUNCATE_TO_BYTE(durationsInStateMs[i] >> 16);
266 msg[mIdx++] = TRUNCATE_TO_BYTE(durationsInStateMs[i] >> 8);
267 msg[mIdx++] = TRUNCATE_TO_BYTE(durationsInStateMs[i]);
268 }
269}

Referenced by processCanQcBenchTest(), sendPinStatePackets(), and sendSavedBenchStatePackets().

Here is the caller graph for this function:

◆ sendQcBenchAuxDigitalCounters()

void sendQcBenchAuxDigitalCounters ( )

Definition at line 155 of file can_bench_test.cpp.

155 {
156 CanTxMessage msg(CanCategory::BENCH_TEST, (int)bench_test_packet_ids_e::AUX_DIGITAL_COUNTERS, 8, /*bus*/0, /*isExtended*/true);
157 for (int i =0;i<LUA_DIGITAL_INPUT_COUNT;i++) {
158 msg[i] = TRUNCATE_TO_BYTE(engine->luaDigitalInputState[i].state.getCounter());
159 }
160}
SimpleSwitchedState luaDigitalInputState[LUA_DIGITAL_INPUT_COUNT]
Definition engine.h:217
uint16_t getCounter() const
static EngineAccessor engine
Definition engine.h:413
SwitchedState state
Definition efi_output.h:36

Referenced by CanWrite::PeriodicTask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendQcBenchBoardStatus()

void sendQcBenchBoardStatus ( size_t  bus)

Definition at line 232 of file can_bench_test.cpp.

232 {
233#if EFI_PROD_CODE
234 CanTxMessage msg(CanCategory::BENCH_TEST, (int)bench_test_packet_ids_e::BOARD_STATUS, 8, bus, /*isExtended*/true);
235
236 int boardId = getBoardId();
237 msg[0] = TRUNCATE_TO_BYTE(boardId >> 8);
238 msg[1] = TRUNCATE_TO_BYTE(boardId);
239
240 int numSecondsSinceReset = getTimeNowS();
241 msg[2] = TRUNCATE_TO_BYTE(numSecondsSinceReset >> 16);
242 msg[3] = TRUNCATE_TO_BYTE(numSecondsSinceReset >> 8);
243 msg[4] = TRUNCATE_TO_BYTE(numSecondsSinceReset);
244
245 int engineType = (int) engineConfiguration->engineType;
246 msg[5] = engineType >> 8;
247 msg[6] = engineType;
248 sendOutBoardMeta(bus);
249#endif // EFI_PROD_CODE
250}
board_id_t getBoardId()
Definition board_id.cpp:15
efitimesec_t getTimeNowS()
Current system time in seconds (32 bits)
Definition efitime.cpp:42

Referenced by CanWrite::PeriodicTask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendQcBenchButtonCounters()

void sendQcBenchButtonCounters ( )

Definition at line 147 of file can_bench_test.cpp.

147 {
148 CanTxMessage msg(CanCategory::BENCH_TEST, (int)bench_test_packet_ids_e::BUTTON_COUNTERS, 8, /*bus*/0, /*isExtended*/true);
149 msg[0] = TRUNCATE_TO_BYTE(engine->brakePedalSwitchedState.getCounter());
150 msg[1] = TRUNCATE_TO_BYTE(engine->clutchUpSwitchedState.getCounter());
151 msg[2] = TRUNCATE_TO_BYTE(engine->acButtonSwitchedState.getCounter());
152 // todo: start button
153}
SwitchedState brakePedalSwitchedState
Definition engine.h:215
SwitchedState clutchUpSwitchedState
Definition engine.h:214
SwitchedState acButtonSwitchedState
Definition engine.h:216

Referenced by CanWrite::PeriodicTask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendQcBenchEventCounters()

void sendQcBenchEventCounters ( size_t  bus)

Definition at line 120 of file can_bench_test.cpp.

120 {
121#if EFI_SHAFT_POSITION_INPUT
122 CanTxMessage msg(CanCategory::BENCH_TEST, (int)bench_test_packet_ids_e::EVENT_COUNTERS, 8, bus, /*isExtended*/true);
123
128
129 msg[0] = TRUNCATE_TO_BYTE(primaryRise + primaryFall);
130 msg[1] = TRUNCATE_TO_BYTE(secondaryRise + secondaryFall);
131
132 for (int camIdx = 0; camIdx < 4; camIdx++) {
133 int vvtRise = 0, vvtFall = 0;
134 if (camIdx < CAM_INPUTS_COUNT) {
135 vvtRise = engine->triggerCentral.vvtEventRiseCounter[camIdx];
136 vvtFall = engine->triggerCentral.vvtEventFallCounter[camIdx];
137 }
138
139 msg[2 + camIdx] = TRUNCATE_TO_BYTE(vvtRise + vvtFall);
140 }
141
143 msg[6] = TRUNCATE_TO_BYTE(vehicleSpeedSensor.eventCounter);
144#endif // EFI_SHAFT_POSITION_INPUT
145}
TriggerCentral triggerCentral
Definition engine.h:318
int getHwEventCounter(int index) const
FrequencySensor vehicleSpeedSensor(SensorType::VehicleSpeed, MS2NT(500))
@ SHAFT_SECONDARY_RISING
@ SHAFT_SECONDARY_FALLING
@ SHAFT_PRIMARY_FALLING
@ SHAFT_PRIMARY_RISING
uint16_t vvtEventRiseCounter[CAM_INPUTS_COUNT]
uint16_t vvtEventFallCounter[CAM_INPUTS_COUNT]

Referenced by CanWrite::PeriodicTask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendQcBenchRawAnalogValues()

void sendQcBenchRawAnalogValues ( size_t  bus)

Definition at line 162 of file can_bench_test.cpp.

162 {
163 const float values_1[] = {
172 };
173
174 const float values_2[] = {
183 };
184 const float lua_values_1[] = {
193 };
194 static_assert(efi::size(values_1) <= 8);
195 static_assert(efi::size(values_2) <= 8);
196 static_assert(efi::size(lua_values_1) <= 8);
197
198
199 // send the first packet
200 {
201 CanTxMessage msg(CanCategory::BENCH_TEST, (int)bench_test_packet_ids_e::RAW_ANALOG_1, 8, bus, /*isExtended*/true);
202 for (size_t valueIdx = 0; valueIdx < efi::size(values_1); valueIdx++) {
203 msg[valueIdx] = RAW_TO_BYTE(values_1[valueIdx]);
204 }
205 }
206 {
207 CanTxMessage msg(CanCategory::BENCH_TEST, (int)bench_test_packet_ids_e::RAW_ANALOG_2, 8, bus, /*isExtended*/true);
208 for (size_t valueIdx = 0; valueIdx < efi::size(values_2); valueIdx++) {
209 msg[valueIdx] = RAW_TO_BYTE(values_2[valueIdx]);
210 }
211 }
212 // todo: time to extract method already?
213 {
214 CanTxMessage msg(CanCategory::BENCH_TEST, (int)bench_test_packet_ids_e::RAW_LUA_ANALOG_1, 8, bus, /*isExtended*/true);
215 for (size_t valueIdx = 0; valueIdx < efi::size(lua_values_1); valueIdx++) {
216 msg[valueIdx] = RAW_TO_BYTE(lua_values_1[valueIdx]);
217 }
218 }
219}
virtual float getRaw() const
Definition sensor.h:148
@ AcceleratorPedalPrimary
@ AcceleratorPedalSecondary

Referenced by CanWrite::PeriodicTask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendSavedBenchStatePackets()

static void sendSavedBenchStatePackets ( )
static

Definition at line 281 of file can_bench_test.cpp.

281 {
282 uint32_t savedDurationsInStateMs[2];
285}
int getSavedBenchTestPinStates(uint32_t durationsInStateMs[2])
static uint32_t savedDurationsInStateMs[2]
static int savedPinToggleCounter

Referenced by processCanQcBenchTest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setHwQcMode()

void setHwQcMode ( )

Definition at line 48 of file can_bench_test.cpp.

48 {
49#if EFI_PROD_CODE
51#if HW_HELLEN
52 if (!getHellenBoardEnabled()) {
53 hellenEnableEn("HW QC");
54 }
55#endif // HW_HELLEN
56#endif // EFI_PROD_CODE
57}
void hellenEnableEn(const char *msg)
bool getHellenBoardEnabled()

Referenced by initSettings(), processCanQcBenchTest(), and qcSetEtbState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPin()

static void setPin ( const CANRxFrame frame,
int  value 
)
static

Definition at line 99 of file can_bench_test.cpp.

99 {
100 size_t outputIndex = frame.data8[2];
101 if (outputIndex >= getBoardMetaOutputsCount()) {
102 criticalError("QC pin index %d out of range", outputIndex);
103 return;
104 }
105#if EFI_GPIO_HARDWARE && EFI_PROD_CODE
106 Gpio* boardOutputs = getBoardMetaOutputs();
107 criticalAssertVoid(boardOutputs != nullptr, "outputs not defined");
108 Gpio pin = boardOutputs[outputIndex];
109
110 int hwIndex = brainPin_to_index(pin);
111 if (pinRepository.getBrainUsedPin(hwIndex) == nullptr) {
112 // if pin is assigned we better configure it
113 efiSetPadModeWithoutOwnershipAcquisition("QC_SET", pin, PAL_MODE_OUTPUT_PUSHPULL);
114 }
115
116 directWritePad(pin, value);
117#endif // EFI_GPIO_HARDWARE && EFI_PROD_CODE
118}
PinRepository pinRepository
const char *& getBrainUsedPin(size_t idx)
int brainPin_to_index(Gpio brainPin)

Referenced by processCanQcBenchTest().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ pinRepository

PinRepository pinRepository
extern

◆ qcDirectPinControlMode

bool qcDirectPinControlMode = false
static

QC direct output control API is used by https://github.com/rusefi/stim test device quite different from bench testing user functionality: QC direct should never be engaged on a real vehicle Once QC direct control mode is activated the only way out is to reboot the unit!

Definition at line 37 of file can_bench_test.cpp.

Referenced by isHwQcMode(), and setHwQcMode().

Go to the source code of this file.