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-10-30 01:53:54 -07:00
|
|
|
#include "heater_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-29 02:55:55 -07:00
|
|
|
StartSampling();
|
|
|
|
|
2020-10-27 16:33:32 -07:00
|
|
|
InitPumpDac();
|
|
|
|
|
2020-09-19 16:51:02 -07:00
|
|
|
InitCan();
|
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-30 01:53:54 -07:00
|
|
|
StartHeaterControl();
|
2020-09-19 21:39:29 -07:00
|
|
|
|
2020-10-29 02:55:55 -07:00
|
|
|
/*for (int i = 0; i < 500; i++) {
|
|
|
|
SetPumpCurrentTarget(current);
|
|
|
|
chThdSleepMilliseconds(50);
|
|
|
|
|
|
|
|
auto result = AnalogSample();
|
2020-10-26 17:25:05 -07:00
|
|
|
|
2020-10-29 02:55:55 -07:00
|
|
|
//size_t writeCount = chsnprintf(strBuffer, 200, "I: %d\t\tVM: %.3f\tIp: %.3f\n", current, result.VirtualGroundVoltage, result.PumpCurrentVoltage);
|
|
|
|
size_t writeCount = chsnprintf(strBuffer, 200, "%d\t%.4f\n", current, result.PumpCurrentVoltage);
|
|
|
|
uartStartSend(&UARTD1, writeCount, strBuffer);
|
2020-10-27 20:07:16 -07:00
|
|
|
|
2020-10-29 02:55:55 -07:00
|
|
|
//current += 10;
|
|
|
|
}*/
|
2020-10-27 20:07:16 -07:00
|
|
|
|
2020-10-29 02:55:55 -07:00
|
|
|
while(1) {
|
|
|
|
size_t writeCount = chsnprintf(strBuffer, 200, "%.4f\t%.2f\n", GetNernstDc() * 1000, GetSensorInternalResistance());
|
|
|
|
uartStartSend(&UARTD1, writeCount, strBuffer);
|
2020-10-27 20:07:16 -07:00
|
|
|
|
2020-10-29 02:55:55 -07:00
|
|
|
chThdSleepMilliseconds(5);
|
2020-09-19 16:51:02 -07:00
|
|
|
}
|
2020-09-19 02:49:20 -07:00
|
|
|
}
|