OpenBLT reset functionality (#259)

* ts: support reset and reset to OpenBLT commands

(cherry picked from commit 2f2fca401d7dc9a29e806013efec4d41570dd613)

* f1_xxx: ini: reset commands

(cherry picked from commit 628994ba0a70901edb9b59360646aa195b3307cf)

* typo

* f1_xxx: ini: update signature

(cherry picked from commit 7aa57fe09c6c684855838e36c9b65d8ae3618a7a)

---------

Co-authored-by: Andrey Gusakov <dron0gus@gmail.com>
This commit is contained in:
rusefillc 2023-06-11 15:51:41 -04:00 committed by GitHub
parent 7f0186705a
commit 8646d10067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 137 additions and 40 deletions

View File

@ -125,6 +125,23 @@ SensorType GetSensorType()
return cfg.sensorType;
}
void rebootNow()
{
NVIC_SystemReset();
}
void rebootToOpenblt()
{
#if USE_OPENBLT
/* safe to call on already inited shares area */
SharedParamsInit();
/* Store flag to stay in OpenBLT */
SharedParamsWriteByIndex(0, 0x01);
rebootNow();
#endif
}
void ToggleESRDriver(SensorType sensor)
{
switch (sensor) {

View File

@ -1,7 +1,7 @@
#pragma once
// TS settings
#define TS_SIGNATURE "rusEFI 2023.03.23.wideband_dual"
#define TS_SIGNATURE "rusEFI 2023.05.10.wideband_dual"
// This board implements two channels
#define AFR_CHANNELS 2

View File

@ -1,7 +1,7 @@
#pragma once
// TS settings
#define TS_SIGNATURE "rusEFI 2023.03.23.wideband_dual"
#define TS_SIGNATURE "rusEFI 2023.05.10.wideband_dual"
// This board implements two channels
#define AFR_CHANNELS 2

View File

@ -1,7 +1,7 @@
#pragma once
// TS settings
#define TS_SIGNATURE "rusEFI 2023.03.23.wideband_f1"
#define TS_SIGNATURE "rusEFI 2023.05.10.wideband_f1"
// Fundamental board constants
#define VCC_VOLTS (3.3f)

View File

@ -1,7 +1,7 @@
#pragma once
// TS settings
#define TS_SIGNATURE "rusEFI 2023.03.23.wideband_f1"
#define TS_SIGNATURE "rusEFI 2023.05.10.wideband_f1"
// Fundamental board constants
#define VCC_VOLTS (3.3f)

View File

@ -74,6 +74,9 @@ size_t GetConfigurationSize();
int SaveConfiguration();
const char *getTsSignature();
void rebootNow();
void rebootToOpenblt();
// LSU4.2, LSU4.9 or LSU_ADV
SensorType GetSensorType();
void SetupESRDriver(SensorType sensor);

View File

@ -204,13 +204,41 @@ static void handleBurnCommand(TsChannelBase* tsChannel, ts_response_format_e mod
sendResponseCode(mode, tsChannel, TS_RESPONSE_BURN_OK);
}
static void handleIoTestCommand(TsChannelBase* tsChannel, ts_response_format_e mode, uint16_t subsystem, uint16_t /* index */) {
/* index is not used yet */
switch (subsystem) {
#if 0
/* DFU */
case 0xba:
jump_to_bootloader();
break;
#endif
case 0xbb:
rebootNow();
break;
#if USE_OPENBLT
case 0xbc:
/* Jump to OpenBLT if present */
rebootToOpenblt();
break;
#endif
default:
tunerStudioError(tsChannel, "Unexpected IoTest command");
}
}
static bool isKnownCommand(char command) {
return command == TS_HELLO_COMMAND || command == TS_READ_COMMAND || command == TS_OUTPUT_COMMAND
|| command == TS_BURN_COMMAND
|| command == TS_CHUNK_WRITE_COMMAND
|| command == TS_GET_SCATTERED_GET_COMMAND
|| command == TS_CRC_CHECK_COMMAND
|| command == TS_GET_FIRMWARE_VERSION;
|| command == TS_GET_FIRMWARE_VERSION
|| command == TS_IO_TEST_COMMAND;
}
/**
@ -503,43 +531,62 @@ int TunerStudio::handleCrcCommand(TsChannelBase* tsChannel, char *data, size_t i
if (handled)
return true;
/* check if we can extract subsystem and index for IoTest command */
if (incomingPacketSize < sizeof(TunerStudioCmdPacketHeader)) {
sendErrorCode(tsChannel, TS_RESPONSE_UNDERRUN);
tunerStudioError(tsChannel, "ERROR: underrun");
return false;
} else {
const TunerStudioCmdPacketHeader* header = reinterpret_cast<TunerStudioCmdPacketHeader*>(data);
handled = true;
switch (command) {
case TS_IO_TEST_COMMAND:
handleIoTestCommand(tsChannel, TS_CRC, SWAP_UINT16(header->subsystem), SWAP_UINT16(header->index));
break;
default:
/* noone of simple commands */
handled = false;
}
}
/* check if we can extract page, offset and count */
if (incomingPacketSize < sizeof(TunerStudioDataPacketHeader)) {
sendErrorCode(tsChannel, TS_RESPONSE_UNDERRUN);
tunerStudioError(tsChannel, "ERROR: underrun");
return false;
}
} else {
const TunerStudioDataPacketHeader* header = reinterpret_cast<TunerStudioDataPacketHeader*>(data);
const TunerStudioDataPacketHeader* header = reinterpret_cast<TunerStudioDataPacketHeader*>(data);
switch(command)
{
case TS_OUTPUT_COMMAND:
tsState.outputChannelsCommandCounter++;
cmdOutputChannels(tsChannel, header->offset, header->count);
break;
case TS_CHUNK_WRITE_COMMAND:
if (header->page == 0)
handleWriteChunkCommand(tsChannel, TS_CRC, header->offset, header->count, data + sizeof(TunerStudioDataPacketHeader));
else
handleScatterListWriteCommand(tsChannel, header->offset, header->count, data + sizeof(TunerStudioDataPacketHeader));
break;
case TS_CRC_CHECK_COMMAND:
if (header->page == 0)
handleCrc32Check(tsChannel, TS_CRC, header->offset, header->count);
else
handleScatterListCrc32Check(tsChannel, header->offset, header->count);
break;
case TS_READ_COMMAND:
if (header->page == 0)
handlePageReadCommand(tsChannel, TS_CRC, header->offset, header->count);
else
handleScatterListReadCommand(tsChannel, header->offset, header->count);
break;
default:
sendErrorCode(tsChannel, TS_RESPONSE_UNRECOGNIZED_COMMAND);
tunerStudioError(tsChannel, "ERROR: ignoring unexpected command");
return false;
switch(command)
{
case TS_OUTPUT_COMMAND:
tsState.outputChannelsCommandCounter++;
cmdOutputChannels(tsChannel, header->offset, header->count);
break;
case TS_CHUNK_WRITE_COMMAND:
if (header->page == 0)
handleWriteChunkCommand(tsChannel, TS_CRC, header->offset, header->count, data + sizeof(TunerStudioDataPacketHeader));
else
handleScatterListWriteCommand(tsChannel, header->offset, header->count, data + sizeof(TunerStudioDataPacketHeader));
break;
case TS_CRC_CHECK_COMMAND:
if (header->page == 0)
handleCrc32Check(tsChannel, TS_CRC, header->offset, header->count);
else
handleScatterListCrc32Check(tsChannel, header->offset, header->count);
break;
case TS_READ_COMMAND:
if (header->page == 0)
handlePageReadCommand(tsChannel, TS_CRC, header->offset, header->count);
else
handleScatterListReadCommand(tsChannel, header->offset, header->count);
break;
default:
sendErrorCode(tsChannel, TS_RESPONSE_UNRECOGNIZED_COMMAND);
tunerStudioError(tsChannel, "ERROR: ignoring unexpected command");
return false;
}
}
return true;

View File

@ -29,6 +29,12 @@ uint8_t* getWorkingPageAddr();
void startTunerStudioConnectivity(void);
typedef struct {
uint8_t cmd;
uint16_t subsystem;
uint16_t index;
} __attribute__((packed)) TunerStudioCmdPacketHeader;
typedef struct {
uint8_t cmd;
uint16_t page;

View File

@ -28,6 +28,7 @@
#define TS_READ_COMMAND 'R'
#define TS_TEST_COMMAND 't'
#define TS_GET_SCATTERED_GET_COMMAND '9'
#define TS_IO_TEST_COMMAND 'Z'
#define TS_RESPONSE_BURN_OK 4
#define TS_RESPONSE_COMMAND_OK 7

View File

@ -12,12 +12,12 @@ enable2ndByteCanID = false
[MegaTune]
; https://rusefi.com/forum/viewtopic.php?p=36201#p36201
signature = "rusEFI 2023.03.23.wideband_dual"
signature = "rusEFI 2023.05.10.wideband_dual"
[TunerStudio]
queryCommand = "S"
versionInfo = "V" ; firmware version for title bar.
signature = "rusEFI 2023.03.23.wideband_dual" ; signature is expected to be 7 or more characters.
signature = "rusEFI 2023.05.10.wideband_dual" ; signature is expected to be 7 or more characters.
; TS will try to use legacy temp units in some cases, showing "deg F" on a CLT gauge that's actually deg C
useLegacyFTempUnits = false
@ -297,6 +297,9 @@ menuDialog = main
subMenu = auxOut0, "AUX analog output 0"
subMenu = auxOut1, "AUX analog output 1"
menu = "&Controller"
subMenu = ecuTools, "ECU tools"
[ControllerCommands]
; commandName = command1, command2, commandn...
; command in standard ini format, a command name can be assigned to 1 to n commands that will be executed in order.
@ -311,6 +314,8 @@ menuDialog = main
cmd_reset_controller = "Z\x00\xbb\x00\x00"
; jump to DFU mode
cmd_dfu = "Z\x00\xba\x00\x00"
; restart to OpenBlt
cmd_openblt = "Z\x00\xbc\x00\x00"
[UserDefined]
@ -328,4 +333,12 @@ dialog = auxOut1, "AUX analog out 1 Settings"
field = "Signal", Aux1InputSel
panel = auxOut1Curve
dialog = ecuReset, "Reset"
commandButton = "Reset ECU", cmd_reset_controller
commandButton = "Reset to DFU", cmd_dfu
commandButton = "Reset to OpenBLT", cmd_openblt
dialog = ecuTools, "ECU tools and Commands", xAxis
panel = ecuReset
[Tools]

View File

@ -12,12 +12,12 @@ enable2ndByteCanID = false
[MegaTune]
; https://rusefi.com/forum/viewtopic.php?p=36201#p36201
signature = "rusEFI 2023.03.23.wideband_f1"
signature = "rusEFI 2023.05.10.wideband_f1"
[TunerStudio]
queryCommand = "S"
versionInfo = "V" ; firmware version for title bar.
signature = "rusEFI 2023.03.23.wideband_f1" ; signature is expected to be 7 or more characters.
signature = "rusEFI 2023.05.10.wideband_f1" ; signature is expected to be 7 or more characters.
; TS will try to use legacy temp units in some cases, showing "deg F" on a CLT gauge that's actually deg C
useLegacyFTempUnits = false
@ -192,6 +192,8 @@ menuDialog = main
cmd_reset_controller = "Z\x00\xbb\x00\x00"
; jump to DFU mode
cmd_dfu = "Z\x00\xba\x00\x00"
; restart to OpenBlt
cmd_openblt = "Z\x00\xbc\x00\x00"
[UserDefined]
@ -201,4 +203,12 @@ dialog = sensor_settings, "Sensor Settings"
dialog = can_settings, "CAN Settings"
field = "CAN message ID offset", CanIndexOffset
dialog = ecuReset, "Reset"
commandButton = "Reset ECU", cmd_reset_controller
commandButton = "Reset to DFU", cmd_dfu
commandButton = "Reset to OpenBLT", cmd_openblt
dialog = ecuTools, "ECU tools and Commands", xAxis
panel = ecuReset
[Tools]