Skip to content

Commit

Permalink
Native SENT TPS input #5079
Browse files Browse the repository at this point in the history
  • Loading branch information
rusefillc committed Feb 20, 2023
1 parent bc6e910 commit bb3b43f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
3 changes: 2 additions & 1 deletion firmware/controllers/sensors/sent_state.txt
@@ -1,4 +1,5 @@
struct sent_state_s
uint16_t value1
uint16_t value0;"ETB: SENT value0";"value", 1,0, 0,3, 0,@@GAUGE_CATEGORY_ETB@@
uint16_t value1;"ETB: SENT value1";"value", 1,0, 0,3, 0,@@GAUGE_CATEGORY_ETB@@
float errorRate;"ETB: SENT error rate";"ratio", 1,0, 0,3, 2,@@GAUGE_CATEGORY_ETB@@
end_struct
48 changes: 21 additions & 27 deletions firmware/hw_layer/drivers/sent/sent.cpp
Expand Up @@ -57,8 +57,7 @@
/* convert CPU ticks to float Us */
#define TicksToUs(ticks) ((float)(ticks) * 1000.0 * 1000.0 / CORE_CLOCK)

void sent_channel::restart(void)
{
void sent_channel::restart(void) {
state = SENT_STATE_CALIB;
pulseCounter = 0;
currentStatePulseCounter = 0;
Expand All @@ -82,20 +81,17 @@ void sent_channel::restart(void)
#endif
}

uint32_t sent_channel::calcTickPerUnit(uint32_t clocks)
{
uint32_t sent_channel::calcTickPerUnit(uint32_t clocks) {
/* int division with rounding */
return (clocks + (SENT_SYNC_INTERVAL + SENT_OFFSET_INTERVAL) / 2) /
(SENT_SYNC_INTERVAL + SENT_OFFSET_INTERVAL);
}

float sent_channel::getTickTime(void)
{
float sent_channel::getTickTime(void) {
return tickPerUnit;
}

int sent_channel::Decoder(uint16_t clocks)
{
int sent_channel::Decoder(uint16_t clocks) {
int ret = 0;
int interval;

Expand Down Expand Up @@ -275,8 +271,7 @@ int sent_channel::Decoder(uint16_t clocks)
return ret;
}

int sent_channel::GetMsg(uint32_t* rx)
{
int sent_channel::GetMsg(uint32_t* rx) {
if (rx) {
*rx = rxLast;
}
Expand Down Expand Up @@ -507,10 +502,7 @@ uint8_t sent_channel::crc6(uint32_t data)

static sent_channel channels[SENT_CHANNELS_NUM];

void sent_channel::Info(void)
{
int i;

void sent_channel::Info(void) {
uint8_t stat;
uint16_t sig0, sig1;

Expand All @@ -523,7 +515,7 @@ void sent_channel::Info(void)

if (scMsgFlags) {
efiPrintf("Slow channels:");
for (i = 0; i < SENT_SLOW_CHANNELS_MAX; i++) {
for (int i = 0; i < SENT_SLOW_CHANNELS_MAX; i++) {
if (scMsgFlags & BIT(i)) {
efiPrintf(" ID %d: %d", scMsg[i].id, scMsg[i].data);
}
Expand Down Expand Up @@ -551,8 +543,7 @@ static MAILBOX_DECL(sent_mb, sent_mb_buffer, SENT_MB_SIZE);

static THD_WORKING_AREA(waSentDecoderThread, 256);

void SENT_ISR_Handler(uint8_t ch, uint16_t clocks)
{
void SENT_ISR_Handler(uint8_t ch, uint16_t clocks) {
/* encode to fit msg_t */
msg_t msg = (ch << 16) | clocks;

Expand All @@ -562,12 +553,10 @@ void SENT_ISR_Handler(uint8_t ch, uint16_t clocks)
chSysUnlockFromISR();
}

static void SentDecoderThread(void*)
{
msg_t msg;
while(true)
{
static void SentDecoderThread(void*) {
while (true) {
msg_t ret;
msg_t msg;

ret = chMBFetchTimeout(&sent_mb, &msg, TIME_INFINITE);

Expand All @@ -579,18 +568,23 @@ static void SentDecoderThread(void*)
sent_channel &ch = channels[n];

if (ch.Decoder(tick) > 0) {

uint16_t sig0, sig1;
ch.GetSignals(NULL, &sig0, &sig1);
engine->sent_state.value0 = sig0;
engine->sent_state.value1 = sig1;
engine->sent_state.errorRate = ch.getErrorRate();


/* Call high level decoder from here */
}
}
}
}
}

static void printSentInfo()
{
int i;

for (i = 0; i < SENT_CHANNELS_NUM; i++) {
static void printSentInfo() {
for (int i = 0; i < SENT_CHANNELS_NUM; i++) {
sent_channel &ch = channels[i];

efiPrintf("---- SENT ch %d ----", i);
Expand Down
8 changes: 8 additions & 0 deletions firmware/hw_layer/drivers/sent/sent_logic.h
Expand Up @@ -41,6 +41,14 @@ struct sent_channel_stat {
/* Slow channel */
uint32_t sc;
uint32_t scCrcErr;
uint32_t getTotalError() {
return ShortIntervalErr + LongIntervalErr + SyncErr + CrcErrCnt;
}

float getErrorRate() {
return getTotalError() * 1.0 / FrameCnt;
}

};

class sent_channel {
Expand Down

0 comments on commit bb3b43f

Please sign in to comment.