move CAN loop

This commit is contained in:
Matthew Kennedy 2020-12-10 18:08:06 -08:00
parent 2d483cc586
commit ea1f528aea
2 changed files with 23 additions and 9 deletions

View File

@ -3,6 +3,8 @@
#include "can_helper.h" #include "can_helper.h"
#include "heater_control.h" #include "heater_control.h"
#include "lambda_conversion.h"
#include "sampling.h"
static const CANConfig canConfig500 = static const CANConfig canConfig500 =
{ {
@ -10,9 +12,25 @@ static const CANConfig canConfig500 =
CAN_BTR_SJW(0) | CAN_BTR_BRP(5) | CAN_BTR_TS1(12) | CAN_BTR_TS2(1) | CAN_BTR_LBKM, CAN_BTR_SJW(0) | CAN_BTR_BRP(5) | CAN_BTR_TS1(12) | CAN_BTR_TS2(1) | CAN_BTR_LBKM,
}; };
static THD_WORKING_AREA(waCanTxThread, 256);
void CanTxThread(void*)
{
while(1)
{
float esr = GetSensorInternalResistance();
float lambda = GetLambda();
SendCanData(lambda, esr);
SendEmulatedAemXseries(lambda, 0);
chThdSleepMilliseconds(10);
}
}
void InitCan() void InitCan()
{ {
canStart(&CAND1, &canConfig500); canStart(&CAND1, &canConfig500);
chThdCreateStatic(waCanTxThread, sizeof(waCanTxThread), NORMALPRIO, CanTxThread, nullptr);
} }
struct StandardDataFrame struct StandardDataFrame

View File

@ -7,7 +7,6 @@
#include "pump_control.h" #include "pump_control.h"
#include "pump_dac.h" #include "pump_dac.h"
#include "sampling.h" #include "sampling.h"
#include "lambda_conversion.h"
static const UARTConfig uartCfg = static const UARTConfig uartCfg =
{ {
@ -44,13 +43,10 @@ int main() {
InitCan(); InitCan();
while(1) { while(true)
float esr = GetSensorInternalResistance(); {
float lambda = GetLambda(); palTogglePad(GPIOB, 6);
chThdSleepMilliseconds(400);
SendCanData(lambda, esr);
SendEmulatedAemXseries(lambda, 0);
chThdSleepMilliseconds(10);
} }
} }