max3185x: restart driver thread on settings change

This commit is contained in:
Andrey Gusakov 2024-03-11 22:48:11 +03:00 committed by rusefillc
parent 5efe1171f4
commit 247bf24a20
4 changed files with 47 additions and 12 deletions

View File

@ -16,7 +16,6 @@
#include "bench_test.h"
#include "yaw_rate_sensor.h"
#include "pin_repository.h"
#include "max3185x.h"
#include "logic_analyzer.h"
#include "smart_gpio.h"
#include "accelerometer.h"
@ -620,10 +619,6 @@ void initHardware() {
initMc33816();
#endif /* EFI_MC33816 */
#if EFI_MAX_31855
initMax3185x(engineConfiguration->max31855spiDevice, engineConfiguration->max31855_cs);
#endif /* EFI_MAX_31855 */
#if EFI_CAN_SUPPORT
#if EFI_SIMULATOR
// Set CAN device name

View File

@ -84,11 +84,28 @@ public:
ThreadController::start();
return 0;
}
efiPrintf("EGT not configured");
return -1;
}
void stop(void) {
ThreadController::stop();
for (size_t i = 0; i < EGT_CHANNEL_COUNT; i++) {
if (!isBrainPinValid(m_cs[i])) {
continue;
}
auto& sensor = egtSensors[i];
brain_pin_markUnused(m_cs[i]);
sensor.unregister();
}
}
void ThreadTask() override {
while (true) {
while (!chThdShouldTerminateX()) {
for (int i = 0; i < EGT_CHANNEL_COUNT; i++) {
float value;
@ -104,6 +121,8 @@ public:
chThdSleepMilliseconds(MAX3185X_REFRESH_TIME);
}
chThdExit((msg_t)0x0);
}
/* Debug stuff */
@ -435,12 +454,20 @@ static void egtRead() {
}
void initMax3185x(spi_device_e device, egt_cs_array_t max31855_cs) {
if (instance.start(device, max31855_cs) == 0) {
addConsoleAction("egtinfo", showEgtInfo);
addConsoleAction("egtread", egtRead);
} else {
efiPrintf("EGT not configured");
}
addConsoleAction("egtinfo", (Void) showEgtInfo);
addConsoleAction("egtread", (Void) egtRead);
startMax3185x(device, max31855_cs);
}
void stopMax3185x(void)
{
instance.stop();
}
void startMax3185x(spi_device_e device, egt_cs_array_t max31855_cs)
{
instance.start(device, max31855_cs);
}
#endif /* EFI_MAX_31855 */

View File

@ -12,4 +12,6 @@
#if HAL_USE_SPI
void initMax3185x(spi_device_e device, egt_cs_array_t max31855_cs);
void stopMax3185x(void);
void startMax3185x(spi_device_e device, egt_cs_array_t max31855_cs);
#endif /* HAL_USE_SPI */

View File

@ -8,6 +8,7 @@
#include "cli_registry.h"
#include "io_pins.h"
#include "lua_hooks.h"
#include "max3185x.h"
static void initSensorCli();
@ -105,6 +106,10 @@ void initNewSensors() {
initOldAnalogInputs();
initAuxDigital();
#if EFI_MAX_31855
initMax3185x(engineConfiguration->max31855spiDevice, engineConfiguration->max31855_cs);
#endif /* EFI_MAX_31855 */
// Init CLI functionality for sensors (mocking)
initSensorCli();
@ -137,6 +142,9 @@ void stopSensors() {
deinitAuxSpeedSensors();
deinitMap();
deinitInputShaftSpeedSensor();
#if EFI_MAX_31855
stopMax3185x();
#endif /* EFI_MAX_31855 */
}
void reconfigureSensors() {
@ -152,6 +160,9 @@ void reconfigureSensors() {
initInputShaftSpeedSensor();
initOldAnalogInputs();
#if EFI_MAX_31855
startMax3185x(engineConfiguration->max31855spiDevice, engineConfiguration->max31855_cs);
#endif /* EFI_MAX_31855 */
}
// Mocking/testing helpers