2020-12-10 23:48:55 -08:00
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
|
|
|
#include "chprintf.h"
|
|
|
|
|
2020-12-10 23:56:18 -08:00
|
|
|
#include "lambda_conversion.h"
|
|
|
|
#include "sampling.h"
|
2020-12-10 23:48:55 -08:00
|
|
|
#include "uart.h"
|
|
|
|
|
|
|
|
static const UARTConfig uartCfg =
|
|
|
|
{
|
|
|
|
.txend1_cb = nullptr,
|
|
|
|
.txend2_cb = nullptr,
|
|
|
|
.rxend_cb = nullptr,
|
|
|
|
.rxchar_cb = nullptr,
|
|
|
|
.rxerr_cb = nullptr,
|
|
|
|
.timeout_cb = nullptr,
|
|
|
|
|
|
|
|
.timeout = 0,
|
2020-12-11 00:24:19 -08:00
|
|
|
.speed = 115200,
|
2020-12-10 23:48:55 -08:00
|
|
|
.cr1 = 0,
|
|
|
|
.cr2 = 0,
|
|
|
|
.cr3 = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static char printBuffer[200];
|
|
|
|
|
|
|
|
static THD_WORKING_AREA(waUartThread, 256);
|
|
|
|
static void UartThread(void*)
|
|
|
|
{
|
2020-12-10 23:56:18 -08:00
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
float lambda = GetLambda();
|
|
|
|
int lambdaIntPart = lambda;
|
|
|
|
int lambdaThousandths = (lambda - lambdaIntPart) * 1000;
|
2020-12-10 23:48:55 -08:00
|
|
|
|
2020-12-11 16:51:03 -08:00
|
|
|
size_t writeCount = chsnprintf(printBuffer, 200, "%d.%03d\t%d\t%d\r\n", lambdaIntPart, lambdaThousandths, (int)GetSensorInternalResistance(), (int)(GetPumpNominalCurrent() * 1000));
|
2020-12-10 23:56:18 -08:00
|
|
|
uartStartSend(&UARTD1, writeCount, printBuffer);
|
|
|
|
|
2020-12-11 02:05:41 -08:00
|
|
|
chThdSleepMilliseconds(20);
|
2020-12-10 23:56:18 -08:00
|
|
|
}
|
2020-12-10 23:48:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void InitUart()
|
|
|
|
{
|
|
|
|
uartStart(&UARTD1, &uartCfg);
|
|
|
|
|
|
|
|
chThdCreateStatic(waUartThread, sizeof(waUartThread), NORMALPRIO, UartThread, nullptr);
|
|
|
|
}
|