rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
rusefi_wideband.h File Reference

Functions

size_t getWidebandBus ()
 
void sendWidebandInfo ()
 
void handleWidebandCan (const size_t busIndex, const CANRxFrame &frame)
 
void pingWideband (uint8_t hwIndex)
 
void setWidebandOffsetNoWait (uint8_t hwIndex, uint8_t index)
 
void setWidebandOffset (uint8_t hwIndex, uint8_t index)
 
void setWidebandSensorType (uint8_t hwIndex, uint8_t type)
 
void updateWidebandFirmware (uint8_t hwIndex)
 
void updateWidebandFirmwareFromFile (uint8_t hwIndex)
 

Function Documentation

◆ getWidebandBus()

size_t getWidebandBus ( )

◆ handleWidebandCan()

void handleWidebandCan ( const size_t  busIndex,
const CANRxFrame frame 
)

Definition at line 30 of file rusefi_wideband.cpp.

30 {
31 // wrong bus
32 if (busIndex != getWidebandBus()) {
33 return;
34 }
35
36 // Bootloader acks with address 0x727573 aka ascii "rus"
37 if (CAN_EID(frame) != WB_ACK) {
38 return;
39 }
40
41 if (frame.DLC == 0)
42 {
43 // Ack reply
44 // Nop
45 } else if (frame.DLC == 8)
46 {
47 // Ping reply
48 #if EFI_TUNER_STUDIO
49 auto data = reinterpret_cast<const wbo::PongData*>(&frame.data8[0]);
50
55 #endif
56 } else {
57 // Unknown
58 return;
59 }
60
61 // Wake thread in any case
63 if (t) {
64 chEvtSignal(t, EVT_BOOTLOADER_ACK);
65 }
66}
TunerStudioOutputChannels outputChannels
Definition engine.h:109
static EngineAccessor engine
Definition engine.h:413
static thread_t * waitingBootloaderThread
size_t getWidebandBus()
uint8_t data8[8]
Frame data.
Definition can_mocks.h:55
uint8_t DLC
Data length.
Definition can_mocks.h:42

Referenced by processCanRxMessage().

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

◆ pingWideband()

void pingWideband ( uint8_t  hwIndex)

Definition at line 151 of file rusefi_wideband.cpp.

151 {
152 size_t bus = getWidebandBus();
153
154 setStatus(WBO_RE_BUSY);
155
156#if EFI_TUNER_STUDIO
161#endif
162
163 // Clear any pending acks for this thread
164 chEvtGetAndClearEvents(EVT_BOOTLOADER_ACK);
165
166 // Send messages to the current thread when acks come in
167 waitingBootloaderThread = chThdGetSelfX();
168
169 {
170 // TODO: replace magic number with WB_MSG_PING after updating Wideband submodule
171 CanTxMessage m(CanCategory::WBO_SERVICE, 0xEF6'0000, 1, bus, true);
172 m[0] = hwIndex;
173 }
174
175 // 25mS should be enought, lets do not block TS thread too long while waiting for WBO reply
176 if (!waitAck(25)) {
177 efiPrintf("Wideband ping failed: no controller detected!");
178 setStatus(WBO_RE_FAILED);
179 } else {
180 efiPrintf("WBO_RE_DONE");
181 setStatus(WBO_RE_DONE);
182 }
183
184 waitingBootloaderThread = nullptr;
185}
bool waitAck(int timeout=1000)
static void setStatus(can_wbo_re_status_e status)

Referenced by executeTSCommand(), and initBenchTest().

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

◆ sendWidebandInfo()

void sendWidebandInfo ( )

Definition at line 188 of file rusefi_wideband.cpp.

188 {
189 static int counter = 0;
190
191 CanTxMessage m(CanCategory::WBO_SERVICE, WB_MGS_ECU_STATUS, /*dlc*/2, getWidebandBus(), /*isExtended*/true);
192
194
195 m[0] = vbatt;
196
197 // Offset 1 bit 0 = heater enable
198 m[1] = engine->engineState.heaterControlEnabled ? 0x01 : 0x00;
199
200 // 10 * 50 = 0.5S delay
201 if (counter == 10) {
202 for (size_t i = 0; i < CAN_WBO_COUNT; i++) {
204 (engineConfiguration->canWbo[i].type == RUSEFI)) {
205 // remap
207 }
208 }
209 }
210
211 counter++;
212}
EngineState engineState
Definition engine.h:344
static float getOrZero(SensorType type)
Definition sensor.h:83
void setWidebandOffsetNoWait(uint8_t hwIndex, uint8_t index)

Referenced by CanWrite::PeriodicTask().

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

◆ setWidebandOffset()

void setWidebandOffset ( uint8_t  hwIndex,
uint8_t  index 
)

Definition at line 92 of file rusefi_wideband.cpp.

92 {
93 setStatus(WBO_RE_BUSY);
94
95 // Clear any pending acks for this thread
96 chEvtGetAndClearEvents(EVT_BOOTLOADER_ACK);
97
98 // Send messages to the current thread when acks come in
99 waitingBootloaderThread = chThdGetSelfX();
100
101 efiPrintf("***************************************");
102 efiPrintf(" WIDEBAND INDEX SET");
103 efiPrintf("***************************************");
104
105 if (hwIndex == 0xff) {
106 efiPrintf("Setting all connected widebands to index %d...", index);
107 } else {
108 efiPrintf("Setting wideband with hwIndex %d to CAN index %d...", hwIndex, index);
109 }
110 setWidebandOffsetNoWait(hwIndex, index);
111
112 if (!waitAck()) {
113 efiPrintf("Wideband index set failed: no controller detected!");
114 setStatus(WBO_RE_FAILED);
115 } else {
116 setStatus(WBO_RE_DONE);
117 }
118
119 waitingBootloaderThread = nullptr;
120}

Referenced by executeTSCommand(), and initBenchTest().

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

◆ setWidebandOffsetNoWait()

void setWidebandOffsetNoWait ( uint8_t  hwIndex,
uint8_t  index 
)

Definition at line 79 of file rusefi_wideband.cpp.

79 {
80 size_t bus = getWidebandBus();
81
82 if (hwIndex == 0xff) {
83 CanTxMessage m(CanCategory::WBO_SERVICE, WB_MSG_SET_INDEX, 1, bus, true);
84 m[0] = index;
85 } else {
86 CanTxMessage m(CanCategory::WBO_SERVICE, WB_MSG_SET_INDEX, 2, bus, true);
87 m[0] = index;
88 m[1] = hwIndex;
89 }
90}

Referenced by sendWidebandInfo(), and setWidebandOffset().

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

◆ setWidebandSensorType()

void setWidebandSensorType ( uint8_t  hwIndex,
uint8_t  type 
)

Definition at line 122 of file rusefi_wideband.cpp.

122 {
123 size_t bus = getWidebandBus();
124
125 setStatus(WBO_RE_BUSY);
126
127 // Clear any pending acks for this thread
128 chEvtGetAndClearEvents(EVT_BOOTLOADER_ACK);
129
130 // Send messages to the current thread when acks come in
131 waitingBootloaderThread = chThdGetSelfX();
132
133 {
134 // Note position of hwIndex, compared to WB_MSG_SET_INDEX
135 // TODO: replace madic number after updating WBO submodule
136 CanTxMessage m(CanCategory::WBO_SERVICE, 0xEF7'0000 /* WB_MSG_SET_SENS_TYPE */, 2, bus, true);
137 m[0] = hwIndex;
138 m[1] = type;
139 }
140
141 if (!waitAck()) {
142 efiPrintf("Wideband sensor type set failed: no controller detected!");
143 setStatus(WBO_RE_FAILED);
144 } else {
145 setStatus(WBO_RE_DONE);
146 }
147
148 waitingBootloaderThread = nullptr;
149}

Referenced by executeTSCommand().

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

◆ updateWidebandFirmware()

void updateWidebandFirmware ( uint8_t  hwIndex)

Definition at line 390 of file rusefi_wideband.cpp.

390 {
391 size_t bus = getWidebandBus();
392 size_t totalSize = sizeof(build_wideband_image_bin);
393
394 // this also sets waitingBootloaderThread
395 int ret = updateWidebandFirmwarePrepare(bus, hwIndex);
396 if (ret < 0) {
397 goto exit;
398 }
399
400 efiPrintf("Wideband Update: Flash erased! Sending %d bytes...", totalSize);
401
402 // Send flash data 8 bytes at a time
403 for (size_t i = 0; i < totalSize; i += 8) {
404 {
405 CanTxMessage m(CanCategory::WBO_SERVICE, WB_BL_DATA_BASE | i, 8, bus, true);
406 memcpy(&m[0], build_wideband_image_bin + i, 8);
407 }
408
409 if (!waitAck()) {
410 efiPrintf("Wideband Update ERROR: Expected ACK from data write, didn't get one.");
411 setStatus(WBO_RE_FAILED);
412 goto exit;
413 }
414 }
415
416 ret = updateWidebandFirmwareFinalize(bus, hwIndex);
417 if (ret) {
418 goto exit;
419 }
420
421 setStatus(WBO_RE_DONE);
422
423exit:
424 waitingBootloaderThread = nullptr;
425}
static int updateWidebandFirmwarePrepare(size_t bus, uint8_t hwIndex)
static int updateWidebandFirmwareFinalize(size_t bus, uint8_t)
Here is the call graph for this function:

◆ updateWidebandFirmwareFromFile()

void updateWidebandFirmwareFromFile ( uint8_t  hwIndex)

Definition at line 316 of file rusefi_wideband.cpp.

317{
318#if EFI_FILE_LOGGING
319 int ret = 0;
320 size_t totalSize = 0;
321 size_t bus = 0;
322 FIL fil;
323
324 if (f_open(&fil, wboFileName, FA_READ) != FR_OK) {
325 efiPrintf("Wideband Update: filed to open %s", wboFileName);
326 return;
327 }
328
329 if (f_lseek(&fil, wboFwOffset) != FR_OK) {
330 efiPrintf("Wideband Update: filed to seek");
331 goto exit;
332 }
333
334 totalSize = f_size(&fil) - wboFwOffset;
335 bus = getWidebandBus();
336
337 // this also sets waitingBootloaderThread
338 ret = updateWidebandFirmwarePrepare(bus, hwIndex);
339 if (ret < 0) {
340 goto exit;
341 }
342
343 for (size_t i = 0; i < totalSize; i += 8) {
344 UINT br;
345 uint8_t tmp[8];
346
347 if (f_read(&fil, tmp, sizeof(tmp), &br) != FR_OK) {
348 efiPrintf("Wideband Update: filed to read");
349 setStatus(WBO_RE_FAILED);
350 goto exit;
351 }
352
353 if (br == 0) {
354 // EOF
355 break;
356 }
357
358 {
359 CanTxMessage m(CanCategory::WBO_SERVICE, WB_BL_DATA_BASE | i, 8, bus, true);
360 memcpy(&m[0], tmp, 8);
361 }
362
363 if (!waitAck()) {
364 efiPrintf("Wideband Update ERROR: Expected ACK from data write, didn't get one.");
365 setStatus(WBO_RE_FAILED);
366 goto exit;
367 }
368 }
369
370 ret = updateWidebandFirmwareFinalize(bus, hwIndex);
371 if (ret) {
372 goto exit;
373 }
374
375 setStatus(WBO_RE_DONE);
376
377exit:
378 waitingBootloaderThread = nullptr;
379 f_close(&fil);
380#else
381 // Not supported
382#endif
383}
static const size_t wboFwOffset
static const char wboFileName[]
Here is the call graph for this function:

Go to the source code of this file.