rusefi/firmware/bootloader/bootloader_main.cpp

89 lines
1.9 KiB
C++
Raw Permalink Normal View History

2017-05-30 15:38:51 -07:00
#include "pch.h"
2023-12-26 12:31:31 -08:00
#include "usbconsole.h"
2017-05-30 15:38:51 -07:00
#include "hardware.h"
2023-12-26 12:31:31 -08:00
extern "C" {
#include "boot.h"
#include "flash.h"
2023-12-26 12:31:31 -08:00
#include "shared_params.h"
}
class BlinkyThread : public chibios_rt::BaseStaticThread<256> {
protected:
void main(void) override {
Gpio yellow = getWarningLedPin();
2024-03-13 00:59:06 -07:00
Gpio blue = getCommsLedPin();
Gpio green = getRunningLedPin();
efiSetPadMode("yellow", yellow, PAL_MODE_OUTPUT_PUSHPULL);
2024-03-13 00:59:06 -07:00
efiSetPadMode("blue", blue, PAL_MODE_OUTPUT_PUSHPULL);
efiSetPadMode("green", green, PAL_MODE_OUTPUT_PUSHPULL);
auto yellowPort = getBrainPinPort(yellow);
auto yellowPin = getBrainPinIndex(yellow);
2024-03-13 00:59:06 -07:00
auto bluePort = getBrainPinPort(blue);
auto bluePin = getBrainPinIndex(blue);
auto greenPort = getBrainPinPort(green);
auto greenPin = getBrainPinIndex(green);
2024-03-13 00:59:06 -07:00
if (yellowPort) {
palSetPad(yellowPort, yellowPin);
}
if (bluePort) {
palSetPad(bluePort, bluePin);
}
if (greenPort) {
palSetPad(greenPort, greenPin);
}
while (true) {
2024-03-13 00:59:06 -07:00
if (yellowPort) {
palTogglePad(yellowPort, yellowPin);
}
if (bluePort) {
palTogglePad(bluePort, bluePin);
}
if (greenPort) {
palTogglePad(greenPort, greenPin);
}
// blink 3 times faster if Dual Bank is not enabled
chThdSleepMilliseconds(isFlashDualBank() ? 250 : 80);
}
}
};
static BlinkyThread blinky;
2017-05-30 15:38:51 -07:00
int main(void) {
halInit();
chSysInit();
2023-08-25 22:34:36 -07:00
2023-12-26 12:31:31 -08:00
baseMCUInit();
// start the blinky thread
blinky.start(NORMALPRIO + 10);
2023-12-26 12:31:31 -08:00
// Init openblt shared params
SharedParamsInit();
// Init openblt itself
BootInit();
2017-05-30 15:38:51 -07:00
2023-08-25 22:34:36 -07:00
while (true) {
2023-12-26 12:31:31 -08:00
BootTask();
2023-08-25 22:34:36 -07:00
}
2017-05-30 15:38:51 -07:00
}
2023-12-26 12:31:31 -08:00
// very basic version, supports on chip pins only (really only used for USB)
void efiSetPadMode(const char* msg, brain_pin_e brainPin, iomode_t mode) {
ioportid_t port = getHwPort(msg, brainPin);
ioportmask_t pin = getHwPin(msg, brainPin);
/* paranoid */
if (port == GPIO_NULL) {
return;
}
palSetPadMode(port, pin, mode);
}