mirror of https://github.com/rusefi/wideband.git
Livedata update (#163)
* max31855: add EGT to livedata * livedata: getEgtLiveDataStructAddr() returns NULL for boards with no EGT * livedata: report AFR sensor(s) state * livedata: report heater state * uart: fix for max31855 update
This commit is contained in:
parent
adae19db09
commit
516747b629
|
@ -5,6 +5,8 @@
|
||||||
#include "sampling.h"
|
#include "sampling.h"
|
||||||
#include "pump_dac.h"
|
#include "pump_dac.h"
|
||||||
#include "heater_control.h"
|
#include "heater_control.h"
|
||||||
|
#include "max31855.h"
|
||||||
|
#include "fault.h"
|
||||||
|
|
||||||
#include <rusefi/arrays.h>
|
#include <rusefi/arrays.h>
|
||||||
#include <rusefi/fragments.h>
|
#include <rusefi/fragments.h>
|
||||||
|
@ -24,6 +26,8 @@ void SamplingUpdateLiveData()
|
||||||
data->pumpCurrentTarget = GetPumpCurrent(ch);
|
data->pumpCurrentTarget = GetPumpCurrent(ch);
|
||||||
data->pumpCurrentMeasured = GetPumpNominalCurrent(ch);
|
data->pumpCurrentMeasured = GetPumpNominalCurrent(ch);
|
||||||
data->heaterDuty = GetHeaterDuty(ch);
|
data->heaterDuty = GetHeaterDuty(ch);
|
||||||
|
data->fault = (uint8_t)GetCurrentFault(ch);
|
||||||
|
data->heaterState = (uint8_t)GetHeaterState(ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
livedata_common.vbatt = GetInternalBatteryVoltage(0);
|
livedata_common.vbatt = GetInternalBatteryVoltage(0);
|
||||||
|
@ -42,8 +46,11 @@ const struct livedata_afr_s * getAfrLiveDataStructAddr(const int ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
static const FragmentEntry fragments[] = {
|
static const FragmentEntry fragments[] = {
|
||||||
getCommonLiveDataStructAddr(),
|
getCommonLiveDataStructAddr(),
|
||||||
getAfrLiveDataStructAddr(0),
|
getAfrLiveDataStructAddr(0),
|
||||||
|
getAfrLiveDataStructAddr(1),
|
||||||
|
getEgtLiveDataStructAddr(0),
|
||||||
|
getEgtLiveDataStructAddr(1)
|
||||||
};
|
};
|
||||||
|
|
||||||
FragmentList getFragments() {
|
FragmentList getFragments() {
|
||||||
|
|
|
@ -25,7 +25,9 @@ struct livedata_afr_s {
|
||||||
float pumpCurrentTarget;
|
float pumpCurrentTarget;
|
||||||
float pumpCurrentMeasured;
|
float pumpCurrentMeasured;
|
||||||
float heaterDuty;
|
float heaterDuty;
|
||||||
};
|
uint8_t fault; // See wbo::Fault
|
||||||
|
uint8_t heaterState;
|
||||||
|
} __attribute__((packed));
|
||||||
uint8_t pad[32];
|
uint8_t pad[32];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "hal.h"
|
|
||||||
#include "io_pins.h"
|
#include "io_pins.h"
|
||||||
#include "wideband_config.h"
|
#include "wideband_config.h"
|
||||||
#include "bit.h"
|
#include "bit.h"
|
||||||
|
#include "livedata.h"
|
||||||
|
|
||||||
#include "max31855.h"
|
#include "max31855.h"
|
||||||
|
|
||||||
|
@ -74,48 +74,54 @@ int Max31855::spi_rx(uint32_t *data)
|
||||||
int Max31855::readPacket()
|
int Max31855::readPacket()
|
||||||
{
|
{
|
||||||
uint32_t data;
|
uint32_t data;
|
||||||
state = MAX31855_NO_REPLY;
|
|
||||||
|
|
||||||
int ret = spi_rx(&data);
|
int ret = spi_rx(&data);
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
if (data == 0xffffffff) {
|
/* TODO: also check for 0x00000000? */
|
||||||
state = MAX31855_NO_REPLY;
|
if ((ret) || (data == 0xffffffff)) {
|
||||||
return -1;
|
livedata.state = MAX31855_NO_REPLY;
|
||||||
}
|
|
||||||
|
|
||||||
if (data & BIT(16)) {
|
ret = -1;
|
||||||
|
} else if (data & BIT(16)) {
|
||||||
if (data & BIT(0)) {
|
if (data & BIT(0)) {
|
||||||
state = MAX31855_OPEN_CIRCUIT;
|
livedata.state = MAX31855_OPEN_CIRCUIT;
|
||||||
} else if (data & BIT(1)) {
|
} else if (data & BIT(1)) {
|
||||||
state = MAX31855_SHORT_TO_GND;
|
livedata.state = MAX31855_SHORT_TO_GND;
|
||||||
} else if (data & BIT(2)) {
|
} else if (data & BIT(2)) {
|
||||||
state = MAX31855_SHORT_TO_VCC;
|
livedata.state = MAX31855_SHORT_TO_VCC;
|
||||||
}
|
}
|
||||||
|
|
||||||
cold_joint_temperature = NAN;
|
ret = -1;
|
||||||
temperature = NAN;
|
} else {
|
||||||
|
livedata.state = MAX31855_OK;
|
||||||
|
|
||||||
return -1;
|
/* D[15:4] */
|
||||||
|
int16_t tmp = (data >> 4) & 0xfff;
|
||||||
|
/* extend sign */
|
||||||
|
tmp = tmp << 4;
|
||||||
|
tmp = tmp >> 4; /* shifting right signed is not a good idea */
|
||||||
|
coldJunctionTemperature = (float)tmp * 0.0625;
|
||||||
|
|
||||||
|
/* D[31:18] */
|
||||||
|
tmp = (data >> 18) & 0x3fff;
|
||||||
|
/* extend sign */
|
||||||
|
tmp = tmp << 2;
|
||||||
|
tmp = tmp >> 2; /* shifting right signed is not a good idea */
|
||||||
|
temperature = (float) tmp * 0.25;
|
||||||
}
|
}
|
||||||
state = MAX31855_OK;
|
|
||||||
|
|
||||||
/* D[15:4] */
|
if (ret) {
|
||||||
int16_t tmp = (data >> 4) & 0xfff;
|
coldJunctionTemperature = NAN;
|
||||||
/* extend sign */
|
livedata.coldJunctionTemperature = 0;
|
||||||
tmp = tmp << 4;
|
temperature = NAN;
|
||||||
tmp = tmp >> 4; /* shifting right signed is not a good idea */
|
livedata.temperature = 0;
|
||||||
cold_joint_temperature = (float)tmp * 0.0625;
|
} else {
|
||||||
|
/* update livedata: float to int */
|
||||||
|
livedata.coldJunctionTemperature = coldJunctionTemperature;
|
||||||
|
livedata.temperature = temperature;
|
||||||
|
}
|
||||||
|
|
||||||
/* D[31:18] */
|
return ret;
|
||||||
tmp = (data >> 18) & 0x3fff;
|
|
||||||
/* extend sign */
|
|
||||||
tmp = tmp << 2;
|
|
||||||
tmp = tmp >> 2; /* shifting right signed is not a good idea */
|
|
||||||
temperature = (float) tmp * 0.25;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Max31855Thread::ThreadTask() {
|
void Max31855Thread::ThreadTask() {
|
||||||
|
@ -138,4 +144,18 @@ Max31855* getEgtDrivers() {
|
||||||
return instances;
|
return instances;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const struct livedata_egt_s * getEgtLiveDataStructAddr(const int ch)
|
||||||
|
{
|
||||||
|
if (ch < EGT_CHANNELS)
|
||||||
|
return &getEgtDrivers()[ch].livedata;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
const struct livedata_egt_s * getEgtLiveDataStructAddr(const int ch)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* HAL_USE_SPI */
|
#endif /* HAL_USE_SPI */
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "hal.h"
|
||||||
|
|
||||||
#include "wideband_config.h"
|
#include "wideband_config.h"
|
||||||
#include "thread_controller.h"
|
#include "thread_controller.h"
|
||||||
|
|
||||||
#if HAL_USE_SPI
|
|
||||||
|
|
||||||
#define MAX31855_THREAD_STACK (512)
|
|
||||||
#define MAX31855_THREAD_PRIO (NORMALPRIO + 1)
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MAX31855_OK = 0,
|
MAX31855_OK = 0,
|
||||||
MAX31855_OPEN_CIRCUIT = 1,
|
MAX31855_OPEN_CIRCUIT = 1,
|
||||||
|
@ -16,13 +13,34 @@ typedef enum {
|
||||||
MAX31855_NO_REPLY = 4,
|
MAX31855_NO_REPLY = 4,
|
||||||
} Max31855State;
|
} Max31855State;
|
||||||
|
|
||||||
|
/* livedata: +96/112 offset, size = 16 */
|
||||||
|
struct livedata_egt_s {
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
float temperature;
|
||||||
|
float coldJunctionTemperature;
|
||||||
|
uint8_t state;
|
||||||
|
} __attribute__((packed));
|
||||||
|
uint8_t pad[16];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// for all board. in case of no EGT - returns NULL
|
||||||
|
const struct livedata_egt_s * getEgtLiveDataStructAddr(const int ch);
|
||||||
|
|
||||||
|
#if HAL_USE_SPI
|
||||||
|
|
||||||
|
#define MAX31855_THREAD_STACK (512)
|
||||||
|
#define MAX31855_THREAD_PRIO (NORMALPRIO + 1)
|
||||||
|
|
||||||
class Max31855 {
|
class Max31855 {
|
||||||
public:
|
public:
|
||||||
Max31855(SPIConfig *spi) {
|
Max31855(SPIConfig *spi) {
|
||||||
this->spi = spi;
|
this->spi = spi;
|
||||||
}
|
}
|
||||||
Max31855State state;
|
livedata_egt_s livedata;
|
||||||
float cold_joint_temperature;
|
/* do we need float temperatures? */
|
||||||
|
float coldJunctionTemperature;
|
||||||
float temperature;
|
float temperature;
|
||||||
int readPacket();
|
int readPacket();
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -62,7 +62,7 @@ static void UartThread(void*)
|
||||||
size_t writeCount = chsnprintf(printBuffer, 200,
|
size_t writeCount = chsnprintf(printBuffer, 200,
|
||||||
"EGT[%d]: %d C (int %d C)\r\n",
|
"EGT[%d]: %d C (int %d C)\r\n",
|
||||||
(int)getEgtDrivers()[ch].temperature,
|
(int)getEgtDrivers()[ch].temperature,
|
||||||
(int)getEgtDrivers()[ch].cold_joint_temperature);
|
(int)getEgtDrivers()[ch].coldJunctionTemperature);
|
||||||
chnWrite(&SD1, (const uint8_t *)printBuffer, writeCount);
|
chnWrite(&SD1, (const uint8_t *)printBuffer, writeCount);
|
||||||
}
|
}
|
||||||
#endif /* HAL_USE_SPI */
|
#endif /* HAL_USE_SPI */
|
||||||
|
|
Loading…
Reference in New Issue