Boot directly into bootloader when USB is connected and BOOT button is pressed.

cert
Rob Riggs 2018-10-29 13:37:30 -05:00
rodzic a5cf64dfcd
commit d2ad6698be
1 zmienionych plików z 38 dodań i 28 usunięć

Wyświetl plik

@ -34,11 +34,13 @@ extern "C" void startLedBlinkerTask(void const*);
void startIOEventTask(void const*) void startIOEventTask(void const*)
{ {
using namespace mobilinkd::tnc;
indicate_on(); indicate_on();
mobilinkd::tnc::print_startup_banner(); print_startup_banner();
auto& hardware = mobilinkd::tnc::kiss::settings(); auto& hardware = kiss::settings();
if (! hardware.load() or reset_requested or !hardware.crc_ok()) if (! hardware.load() or reset_requested or !hardware.crc_ok())
{ {
@ -49,9 +51,9 @@ void startIOEventTask(void const*)
} }
hardware.debug(); hardware.debug();
mobilinkd::tnc::audio::init_log_volume(); audio::init_log_volume();
mobilinkd::tnc::audio::setAudioOutputLevel(); audio::setAudioOutputLevel();
mobilinkd::tnc::audio::setAudioInputLevels(); audio::setAudioInputLevels();
// Cannot enable these interrupts until we start the io loop because // Cannot enable these interrupts until we start the io loop because
// they send messages on the queue. // they send messages on the queue.
@ -112,14 +114,14 @@ void startIOEventTask(void const*)
INFO("CDC Opened"); INFO("CDC Opened");
indicate_connected_via_usb(); indicate_connected_via_usb();
osMessagePut(audioInputQueueHandle, osMessagePut(audioInputQueueHandle,
mobilinkd::tnc::audio::DEMODULATOR, osWaitForever); audio::DEMODULATOR, osWaitForever);
} }
break; break;
case CMD_USB_DISCONNECTED: case CMD_USB_DISCONNECTED:
INFO("VBUS Lost"); INFO("VBUS Lost");
HAL_PCD_MspDeInit(&hpcd_USB_FS); HAL_PCD_MspDeInit(&hpcd_USB_FS);
HAL_GPIO_WritePin(USB_CE_GPIO_Port, USB_CE_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(USB_CE_GPIO_Port, USB_CE_Pin, GPIO_PIN_SET);
if (mobilinkd::tnc::ioport != mobilinkd::tnc::getUsbPort()) if (ioport != getUsbPort())
{ {
break; break;
} }
@ -137,14 +139,14 @@ void startIOEventTask(void const*)
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn); HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
indicate_waiting_to_connect(); indicate_waiting_to_connect();
osMessagePut(audioInputQueueHandle, mobilinkd::tnc::audio::IDLE, osMessagePut(audioInputQueueHandle, audio::IDLE,
osWaitForever); osWaitForever);
break; break;
case CMD_POWER_BUTTON_DOWN: case CMD_POWER_BUTTON_DOWN:
INFO("Power Down"); INFO("Power Down");
power_button_counter = osKernelSysTick(); power_button_counter = osKernelSysTick();
HAL_GPIO_WritePin(VDD_EN_GPIO_Port, VDD_EN_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(VDD_EN_GPIO_Port, VDD_EN_Pin, GPIO_PIN_SET);
osMessagePut(audioInputQueueHandle, mobilinkd::tnc::audio::IDLE, osMessagePut(audioInputQueueHandle, audio::IDLE,
osWaitForever); osWaitForever);
break; break;
case CMD_POWER_BUTTON_UP: case CMD_POWER_BUTTON_UP:
@ -154,8 +156,8 @@ void startIOEventTask(void const*)
stop2(); stop2();
INFO("RUN mode"); INFO("RUN mode");
HAL_GPIO_WritePin(BT_SLEEP_GPIO_Port, BT_SLEEP_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(BT_SLEEP_GPIO_Port, BT_SLEEP_Pin, GPIO_PIN_SET);
mobilinkd::tnc::audio::setAudioOutputLevel(); audio::setAudioOutputLevel();
mobilinkd::tnc::audio::setAudioInputLevels(); audio::setAudioInputLevels();
bm78_wait_until_ready(); bm78_wait_until_ready();
HAL_NVIC_SetPriority(EXTI4_IRQn, 5, 0); HAL_NVIC_SetPriority(EXTI4_IRQn, 5, 0);
@ -176,21 +178,29 @@ void startIOEventTask(void const*)
break; break;
case CMD_BOOT_BUTTON_DOWN: case CMD_BOOT_BUTTON_DOWN:
DEBUG("BOOT Down"); DEBUG("BOOT Down");
// If the TNC has USB power, reboot. The boot pin is being
// held so it will boot into the bootloader. This is a bit
// of a hack, since we really should check if the port is a
// standard USB port and not just a charging port.
if (gpio::USB_POWER::get() and ioport == getNullPort())
{
HAL_NVIC_SystemReset();
}
break; break;
case CMD_BOOT_BUTTON_UP: case CMD_BOOT_BUTTON_UP:
DEBUG("BOOT Up"); DEBUG("BOOT Up");
osMessagePut(audioInputQueueHandle, osMessagePut(audioInputQueueHandle,
mobilinkd::tnc::audio::AUTO_ADJUST_INPUT_LEVEL, audio::AUTO_ADJUST_INPUT_LEVEL,
osWaitForever); osWaitForever);
if (mobilinkd::tnc::ioport != mobilinkd::tnc::getNullPort()) if (ioport != getNullPort())
{ {
osMessagePut(audioInputQueueHandle, osMessagePut(audioInputQueueHandle,
mobilinkd::tnc::audio::DEMODULATOR, osWaitForever); audio::DEMODULATOR, osWaitForever);
} }
else else
{ {
osMessagePut(audioInputQueueHandle, osMessagePut(audioInputQueueHandle,
mobilinkd::tnc::audio::IDLE, osWaitForever); audio::IDLE, osWaitForever);
} }
break; break;
case CMD_BT_CONNECT: case CMD_BT_CONNECT:
@ -198,7 +208,7 @@ void startIOEventTask(void const*)
if (openSerial()) if (openSerial())
{ {
osMessagePut(audioInputQueueHandle, osMessagePut(audioInputQueueHandle,
mobilinkd::tnc::audio::DEMODULATOR, osWaitForever); audio::DEMODULATOR, osWaitForever);
INFO("BT Opened"); INFO("BT Opened");
indicate_connected_via_ble(); indicate_connected_via_ble();
HAL_PCD_EP_SetStall(&hpcd_USB_FS, CDC_CMD_EP); HAL_PCD_EP_SetStall(&hpcd_USB_FS, CDC_CMD_EP);
@ -209,7 +219,7 @@ void startIOEventTask(void const*)
closeSerial(); closeSerial();
indicate_waiting_to_connect(); indicate_waiting_to_connect();
HAL_PCD_EP_ClrStall(&hpcd_USB_FS, CDC_CMD_EP); HAL_PCD_EP_ClrStall(&hpcd_USB_FS, CDC_CMD_EP);
osMessagePut(audioInputQueueHandle, mobilinkd::tnc::audio::IDLE, osMessagePut(audioInputQueueHandle, audio::IDLE,
osWaitForever); osWaitForever);
INFO("BT Closed"); INFO("BT Closed");
break; break;
@ -224,8 +234,8 @@ void startIOEventTask(void const*)
stop2(); stop2();
INFO("RUN mode"); INFO("RUN mode");
HAL_GPIO_WritePin(BT_SLEEP_GPIO_Port, BT_SLEEP_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(BT_SLEEP_GPIO_Port, BT_SLEEP_Pin, GPIO_PIN_SET);
mobilinkd::tnc::audio::setAudioOutputLevel(); audio::setAudioOutputLevel();
mobilinkd::tnc::audio::setAudioInputLevels(); audio::setAudioInputLevels();
bm78_wait_until_ready(); bm78_wait_until_ready();
HAL_NVIC_SetPriority(EXTI4_IRQn, 5, 0); HAL_NVIC_SetPriority(EXTI4_IRQn, 5, 0);
@ -284,8 +294,8 @@ void startIOEventTask(void const*)
// No need to reload settings. SRAM was retained. // No need to reload settings. SRAM was retained.
INFO("RUN mode"); INFO("RUN mode");
HAL_GPIO_WritePin(BT_SLEEP_GPIO_Port, BT_SLEEP_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(BT_SLEEP_GPIO_Port, BT_SLEEP_Pin, GPIO_PIN_SET);
mobilinkd::tnc::audio::setAudioOutputLevel(); audio::setAudioOutputLevel();
mobilinkd::tnc::audio::setAudioInputLevels(); audio::setAudioInputLevels();
bm78_wait_until_ready(); bm78_wait_until_ready();
HAL_NVIC_SetPriority(EXTI4_IRQn, 5, 0); HAL_NVIC_SetPriority(EXTI4_IRQn, 5, 0);
@ -311,18 +321,18 @@ void startIOEventTask(void const*)
continue; continue;
} }
using mobilinkd::tnc::hdlc::IoFrame; using hdlc::IoFrame;
auto frame = static_cast<IoFrame*>(evt.value.p); auto frame = static_cast<IoFrame*>(evt.value.p);
switch (frame->source()) { switch (frame->source()) {
case IoFrame::RF_DATA: case IoFrame::RF_DATA:
DEBUG("RF frame"); DEBUG("RF frame");
if (!mobilinkd::tnc::ioport->write(frame, 100)) if (!ioport->write(frame, 100))
{ {
ERROR("Timed out sending frame"); ERROR("Timed out sending frame");
// The frame has been passed to the write() call. It owns it now. // The frame has been passed to the write() call. It owns it now.
// mobilinkd::tnc::hdlc::release(frame); // hdlc::release(frame);
} }
break; break;
case IoFrame::SERIAL_DATA: case IoFrame::SERIAL_DATA:
@ -334,12 +344,12 @@ void startIOEventTask(void const*)
osWaitForever) != osOK) osWaitForever) != osOK)
{ {
ERROR("Failed to write frame to TX queue"); ERROR("Failed to write frame to TX queue");
mobilinkd::tnc::hdlc::release(frame); hdlc::release(frame);
} }
} }
else else
{ {
mobilinkd::tnc::kiss::handle_frame(frame->type(), frame); kiss::handle_frame(frame->type(), frame);
} }
break; break;
case IoFrame::DIGI_DATA: case IoFrame::DIGI_DATA:
@ -348,11 +358,11 @@ void startIOEventTask(void const*)
reinterpret_cast<uint32_t>(frame), reinterpret_cast<uint32_t>(frame),
osWaitForever) != osOK) osWaitForever) != osOK)
{ {
mobilinkd::tnc::hdlc::release(frame); hdlc::release(frame);
} }
break; break;
case IoFrame::FRAME_RETURN: case IoFrame::FRAME_RETURN:
mobilinkd::tnc::hdlc::release(frame); hdlc::release(frame);
break; break;
} }
} }