wideband/firmware/main.cpp

76 lines
1.5 KiB
C++
Raw Normal View History

2020-09-19 02:49:20 -07:00
#include "ch.h"
#include "hal.h"
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-12-10 23:48:47 -08:00
#include "uart.h"
#include "io_pins.h"
#include "auxout.h"
#include "max31855.h"
#include "wideband_config.h"
2020-09-19 15:44:10 -07:00
2022-01-01 21:10:55 -08:00
using namespace wbo;
2020-10-26 17:25:05 -07:00
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();
InitAuxDac();
2020-10-31 16:59:35 -07:00
InitCan();
InitUart();
2020-09-19 21:39:29 -07:00
#if (EGT_CHANNELS > 0)
StartEgt();
#endif
2020-12-10 18:08:06 -08:00
while(true)
{
/* TODO: show error for all AFR channels */
/* TODO: show EGT errors */
auto fault = GetCurrentFault(0);
2020-12-10 21:58:59 -08:00
if (fault == Fault::None)
2020-12-10 21:46:41 -08:00
{
// blue is off
2021-12-27 20:45:55 -08:00
palClearPad(LED_BLUE_PORT, LED_BLUE_PIN);
2020-12-10 21:46:41 -08:00
// Green is blinking
2021-12-27 20:45:55 -08:00
palTogglePad(LED_GREEN_PORT, LED_GREEN_PIN);
2020-12-10 21:46:41 -08:00
2020-12-19 16:06:35 -08:00
// Slow blink if closed loop, fast if not
chThdSleepMilliseconds(IsRunningClosedLoop(0) ? 700 : 50);
2020-12-10 21:46:41 -08:00
}
2020-12-10 21:58:59 -08:00
else
{
// green is off
2021-12-27 20:45:55 -08:00
palClearPad(LED_GREEN_PORT, LED_GREEN_PIN);
2020-12-10 21:46:41 -08:00
2020-12-10 21:58:59 -08:00
// Blink out the error code
for (int i = 0; i < 2 * static_cast<int>(fault); i++)
{
// Blue is blinking
2021-12-27 20:45:55 -08:00
palTogglePad(LED_BLUE_PORT, LED_BLUE_PIN);
2020-12-10 21:58:09 -08:00
2020-12-10 21:58:59 -08:00
// fast blink
chThdSleepMilliseconds(300);
}
2020-12-10 21:58:09 -08:00
2020-12-10 21:58:59 -08:00
chThdSleepMilliseconds(2000);
2020-12-10 18:32:41 -08:00
}
2020-09-19 16:51:02 -07:00
}
2020-09-19 02:49:20 -07:00
}