wideband/firmware/main.cpp

76 lines
1.4 KiB
C++
Raw Normal View History

2020-09-19 02:49:20 -07:00
#include "ch.h"
#include "hal.h"
2020-10-29 02:55:55 -07:00
#include "chprintf.h"
2020-09-19 02:49:20 -07:00
2020-09-19 16:51:02 -07:00
#include "can.h"
2020-12-10 18:32:41 -08:00
#include "fault.h"
2020-10-30 01:53:54 -07:00
#include "heater_control.h"
2020-10-31 16:59:35 -07:00
#include "pump_control.h"
2020-10-27 16:33:32 -07:00
#include "pump_dac.h"
2020-10-29 02:55:55 -07:00
#include "sampling.h"
2020-09-19 15:44:10 -07:00
2020-10-26 17:25:05 -07:00
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-10-29 02:55:55 -07:00
.speed = 500000,
2020-10-26 17:25:05 -07:00
.cr1 = 0,
.cr2 = 0,
.cr3 = 0,
};
2020-10-29 02:55:55 -07:00
char strBuffer[200];
2020-09-19 02:49:20 -07:00
/*
* Application entry point.
*/
2020-09-19 21:39:29 -07:00
int main() {
2020-09-19 16:51:02 -07:00
halInit();
chSysInit();
2020-09-19 02:49:20 -07:00
2020-10-31 16:59:35 -07:00
// Fire up all of our threads
2020-10-29 02:55:55 -07:00
StartSampling();
2020-10-27 16:33:32 -07:00
InitPumpDac();
2020-10-31 16:59:35 -07:00
StartHeaterControl();
StartPumpControl();
2020-09-19 15:44:10 -07:00
2020-10-26 17:25:05 -07:00
uartStart(&UARTD1, &uartCfg);
2020-10-26 12:45:50 -07:00
2020-10-31 16:59:35 -07:00
InitCan();
2020-09-19 21:39:29 -07:00
2020-12-10 18:08:06 -08:00
while(true)
{
2020-12-10 18:32:41 -08:00
auto fault = getCurrentFault();
switch (fault)
{
case Fault::None:
// blue is off
palClearPad(GPIOB, 5);
// Green is blinking
palTogglePad(GPIOB, 6);
// Fast blink if closed loop, slow if not
chThdSleepMilliseconds(IsRunningClosedLoop() ? 50 : 400);
break;
case Fault::SensorDidntHeat:
// Blue is blinking
palTogglePad(GPIOB, 5);
// green is off
palClearPad(GPIOB, 6);
// fast blink
chThdSleepMilliseconds(50);
break;
}
2020-09-19 16:51:02 -07:00
}
2020-09-19 02:49:20 -07:00
}