2021-01-03 03:59:59 +00:00
|
|
|
// Copyright 2017-2021 Rob Riggs <rob@mobilinkd.com>
|
2018-07-30 02:34:53 +00:00
|
|
|
// All rights reserved.
|
|
|
|
|
2019-06-23 02:53:34 +00:00
|
|
|
#include "AudioLevel.hpp"
|
|
|
|
#include "Log.h"
|
2018-07-30 02:34:53 +00:00
|
|
|
#include "IOEventTask.h"
|
|
|
|
#include "PortInterface.h"
|
|
|
|
#include "PortInterface.hpp"
|
|
|
|
#include "main.h"
|
|
|
|
#include "AudioInput.hpp"
|
|
|
|
#include "HdlcFrame.hpp"
|
|
|
|
#include "Kiss.hpp"
|
|
|
|
#include "KissHardware.hpp"
|
|
|
|
#include "ModulatorTask.hpp"
|
2021-01-03 03:59:59 +00:00
|
|
|
#include "Modulator.hpp"
|
|
|
|
#include "LEDIndicator.h"
|
2018-07-30 02:34:53 +00:00
|
|
|
|
|
|
|
#include "stm32l4xx_hal.h"
|
|
|
|
#include "cmsis_os.h"
|
|
|
|
|
|
|
|
extern osMessageQId hdlcOutputQueueHandle;
|
|
|
|
|
2019-06-23 02:53:34 +00:00
|
|
|
static PTT getPttStyle(const mobilinkd::tnc::kiss::Hardware& hardware)
|
|
|
|
{
|
|
|
|
return hardware.options & KISS_OPTION_PTT_SIMPLEX ? PTT::SIMPLEX : PTT::MULTIPLEX;
|
|
|
|
}
|
|
|
|
|
2018-07-30 02:34:53 +00:00
|
|
|
void startIOEventTask(void const*)
|
|
|
|
{
|
2019-06-23 02:53:34 +00:00
|
|
|
using namespace mobilinkd::tnc;
|
2018-07-30 02:34:53 +00:00
|
|
|
|
2021-01-03 03:59:59 +00:00
|
|
|
indicate_on();
|
2019-06-23 02:53:34 +00:00
|
|
|
initSerial();
|
|
|
|
openSerial();
|
2018-07-30 02:34:53 +00:00
|
|
|
|
2019-06-23 02:53:34 +00:00
|
|
|
print_startup_banner();
|
2018-08-06 02:24:38 +00:00
|
|
|
|
2019-06-23 02:53:34 +00:00
|
|
|
auto& hardware = kiss::settings();
|
2021-01-03 03:59:59 +00:00
|
|
|
if (!hardware.load() or !hardware.crc_ok())
|
2019-06-23 02:53:34 +00:00
|
|
|
{
|
|
|
|
hardware.init();
|
|
|
|
hardware.store();
|
|
|
|
}
|
2018-07-30 02:34:53 +00:00
|
|
|
|
2021-01-03 03:59:59 +00:00
|
|
|
osMutexRelease(hardwareInitMutexHandle);
|
|
|
|
|
2019-06-23 02:53:34 +00:00
|
|
|
hardware.debug();
|
2018-07-30 02:34:53 +00:00
|
|
|
|
2019-06-23 02:53:34 +00:00
|
|
|
audio::init_log_volume();
|
|
|
|
audio::setAudioOutputLevel();
|
|
|
|
audio::setAudioInputLevels();
|
|
|
|
setPtt(getPttStyle(hardware));
|
2018-07-30 02:34:53 +00:00
|
|
|
|
2019-06-23 02:53:34 +00:00
|
|
|
osMessagePut(audioInputQueueHandle, mobilinkd::tnc::audio::DEMODULATOR,
|
|
|
|
osWaitForever);
|
2018-07-30 02:34:53 +00:00
|
|
|
|
2021-01-03 03:59:59 +00:00
|
|
|
indicate_waiting_to_connect();
|
|
|
|
|
2019-06-23 02:53:34 +00:00
|
|
|
/* Infinite loop */
|
|
|
|
for (;;)
|
2018-07-30 02:34:53 +00:00
|
|
|
{
|
2019-06-23 02:53:34 +00:00
|
|
|
osEvent evt = osMessageGet(ioEventQueueHandle, osWaitForever);
|
|
|
|
if (evt.status != osEventMessage)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
uint32_t cmd = evt.value.v;
|
|
|
|
if (cmd < FLASH_BASE) // Assumes FLASH_BASE < SRAM_BASE.
|
|
|
|
{
|
|
|
|
switch (cmd) {
|
|
|
|
case CMD_USER_BUTTON_DOWN:
|
|
|
|
INFO("Button Down");
|
|
|
|
osMessagePut(audioInputQueueHandle,
|
|
|
|
mobilinkd::tnc::audio::AUTO_ADJUST_INPUT_LEVEL,
|
|
|
|
osWaitForever);
|
|
|
|
osMessagePut(audioInputQueueHandle,
|
|
|
|
mobilinkd::tnc::audio::DEMODULATOR, osWaitForever);
|
|
|
|
break;
|
|
|
|
case CMD_USER_BUTTON_UP:
|
2021-08-04 02:32:40 +00:00
|
|
|
TNC_DEBUG("Button Up");
|
2019-06-23 02:53:34 +00:00
|
|
|
break;
|
|
|
|
case CMD_SET_PTT_SIMPLEX:
|
|
|
|
getModulator().set_ptt(&simplexPtt);
|
|
|
|
break;
|
|
|
|
case CMD_SET_PTT_MULTIPLEX:
|
|
|
|
getModulator().set_ptt(&multiplexPtt);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN("unknown command = %04x", static_cast<unsigned int>(cmd));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2018-07-30 02:34:53 +00:00
|
|
|
|
2019-06-23 02:53:34 +00:00
|
|
|
using hdlc::IoFrame;
|
2018-07-30 02:34:53 +00:00
|
|
|
|
2019-06-23 02:53:34 +00:00
|
|
|
auto frame = static_cast<IoFrame*>(evt.value.p);
|
2018-07-30 02:34:53 +00:00
|
|
|
|
2021-01-03 03:59:59 +00:00
|
|
|
if (frame->source() & IoFrame::RF_DATA)
|
|
|
|
{
|
2021-08-04 02:32:40 +00:00
|
|
|
TNC_DEBUG("RF frame");
|
2021-01-03 03:59:59 +00:00
|
|
|
frame->source(frame->source() & 0x70);
|
2021-02-22 02:48:09 +00:00
|
|
|
if (!ioport->write(frame, frame->size() + 100))
|
2019-06-23 02:53:34 +00:00
|
|
|
{
|
|
|
|
ERROR("Timed out sending frame");
|
2021-01-03 03:59:59 +00:00
|
|
|
// The frame has been passed to the write() call. It owns it now.
|
2021-07-17 20:46:07 +00:00
|
|
|
// Do not release here.
|
2019-06-23 02:53:34 +00:00
|
|
|
}
|
2021-01-03 03:59:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-04 02:32:40 +00:00
|
|
|
TNC_DEBUG("Serial frame");
|
2019-06-23 02:53:34 +00:00
|
|
|
if ((frame->type() & 0x0F) == IoFrame::DATA)
|
|
|
|
{
|
2021-01-03 03:59:59 +00:00
|
|
|
kiss::getAFSKTestTone().stop();
|
2019-06-23 02:53:34 +00:00
|
|
|
if (osMessagePut(hdlcOutputQueueHandle,
|
|
|
|
reinterpret_cast<uint32_t>(frame),
|
|
|
|
osWaitForever) != osOK)
|
|
|
|
{
|
|
|
|
ERROR("Failed to write frame to TX queue");
|
|
|
|
hdlc::release(frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
kiss::handle_frame(frame->type(), frame);
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 02:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-23 02:53:34 +00:00
|
|
|
namespace mobilinkd {
|
|
|
|
namespace tnc {
|
2018-07-30 02:34:53 +00:00
|
|
|
|
|
|
|
void print_startup_banner()
|
|
|
|
{
|
2019-06-23 02:53:34 +00:00
|
|
|
#ifdef KISS_LOGGING
|
|
|
|
uint32_t* uid = (uint32_t*) UID_BASE; // STM32L4xx (same for 476 and 432)
|
2018-07-30 02:34:53 +00:00
|
|
|
|
2019-06-23 02:53:34 +00:00
|
|
|
INFO("%s version %s", mobilinkd::tnc::kiss::HARDWARE_VERSION,
|
|
|
|
mobilinkd::tnc::kiss::FIRMWARE_VERSION);
|
2018-07-30 02:34:53 +00:00
|
|
|
INFO("CPU core clock: %luHz", SystemCoreClock);
|
2019-06-23 02:53:34 +00:00
|
|
|
INFO(" Device UID: %08lX %08lX %08lX", uid[0], uid[1], uid[2]);
|
2018-07-30 02:34:53 +00:00
|
|
|
|
2019-06-23 02:53:34 +00:00
|
|
|
uint8_t* version_ptr = (uint8_t*) 0x1FFF6FF2;
|
2018-07-30 02:34:53 +00:00
|
|
|
|
|
|
|
int version = *version_ptr;
|
|
|
|
|
|
|
|
INFO("Bootloader version: 0x%02X", version);
|
2019-06-23 02:53:34 +00:00
|
|
|
#endif
|
2018-07-30 02:34:53 +00:00
|
|
|
}
|
|
|
|
|
2019-06-23 02:53:34 +00:00
|
|
|
}
|
|
|
|
} // mobilinkd::tnc
|