A lot of WIP state
This commit is contained in:
parent
e25b54add4
commit
00810009ec
19
app/include/app_board.hpp
Normal file
19
app/include/app_board.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
//
|
||||
// Created by erki on 15.07.22.
|
||||
//
|
||||
|
||||
#ifndef SKL_TUNNEL_APP_BOARD_HPP
|
||||
#define SKL_TUNNEL_APP_BOARD_HPP
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace App::Board
|
||||
{
|
||||
|
||||
void setup();
|
||||
|
||||
std::uint32_t systickGet();
|
||||
|
||||
}
|
||||
|
||||
#endif //SKL_TUNNEL_APP_BOARD_HPP
|
||||
@ -5,7 +5,11 @@
|
||||
#ifndef SKL_TUNNEL_APP_TRANSPARENT_CLIENT_HPP
|
||||
#define SKL_TUNNEL_APP_TRANSPARENT_CLIENT_HPP
|
||||
|
||||
#include <optional>
|
||||
#include <utility_function.hpp>
|
||||
|
||||
#include "app_settings.hpp"
|
||||
#include "radio_interrupts.hpp"
|
||||
|
||||
namespace radio
|
||||
{
|
||||
@ -20,14 +24,20 @@ class TransparentClient
|
||||
public:
|
||||
TransparentClient(const RadioSettings& initial_settings);
|
||||
|
||||
void apply_settings(const RadioSettings& settings);
|
||||
|
||||
TransparentClient(const TransparentClient&) = delete;
|
||||
TransparentClient(TransparentClient&&) = delete;
|
||||
TransparentClient& operator=(const TransparentClient&) = delete;
|
||||
TransparentClient& operator=(TransparentClient&&) = delete;
|
||||
|
||||
void apply_settings(const RadioSettings& settings);
|
||||
void process();
|
||||
private:
|
||||
radio::HwInstance* m_radio;
|
||||
Utility::FunctionOwned<TransparentClient, void (radio::HwInstance*)> m_isr_cb_pointer;
|
||||
std::optional<radio::Interrupts> m_pending_irqs = std::nullopt;
|
||||
|
||||
void m_cbRadioIrqHandler(radio::HwInstance*);
|
||||
void m_processInterrupts();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
57
app/src/app_board.cpp
Normal file
57
app/src/app_board.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
//
|
||||
// Created by erki on 15.07.22.
|
||||
//
|
||||
|
||||
#include "app_board.hpp"
|
||||
|
||||
#include "driver_init.h"
|
||||
|
||||
#include <utility_logging.hpp>
|
||||
#include <utility_asynclogger.hpp>
|
||||
#include <utility_staticpointer.hpp>
|
||||
|
||||
#include "skullc_samd21_hal.hpp"
|
||||
|
||||
namespace Hal = Peripherals::Hal::Samd;
|
||||
|
||||
using Logger = Utility::AsyncLogger<Hal::SerialInterfaceAsync<usart_async_descriptor>, Hal::StaticHal, 5, 255>;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
Utility::StaticPointer<Logger> m_logger;
|
||||
std::uint32_t m_systick_counter = 0;
|
||||
|
||||
void m_txCompleteCb(const usart_async_descriptor* const)
|
||||
{
|
||||
m_logger->txCompleteCallback();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extern "C" void SysTick_Handler()
|
||||
{
|
||||
m_systick_counter++;
|
||||
}
|
||||
|
||||
namespace App::Board
|
||||
{
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Logging
|
||||
Hal::SerialInterfaceAsync<usart_async_descriptor> usart0{&USART_0};
|
||||
usart0.registerTxCallback(m_txCompleteCb);
|
||||
|
||||
m_logger.setup(usart0);
|
||||
Utility::setLogger(*m_logger);
|
||||
|
||||
SysTick_Config(1000);
|
||||
}
|
||||
|
||||
std::uint32_t systickGet()
|
||||
{
|
||||
return m_systick_counter;
|
||||
}
|
||||
|
||||
}
|
||||
@ -11,6 +11,7 @@ namespace App
|
||||
|
||||
TransparentClient::TransparentClient(const RadioSettings& initial_settings)
|
||||
: m_radio(radio::HwInstance::instance())
|
||||
, m_isr_cb_pointer(*this, &TransparentClient::m_cbRadioIrqHandler)
|
||||
{
|
||||
apply_settings(initial_settings);
|
||||
|
||||
@ -27,4 +28,24 @@ void TransparentClient::apply_settings(const RadioSettings& settings)
|
||||
m_radio->set_max_retries(settings.retries);
|
||||
}
|
||||
|
||||
void TransparentClient::process()
|
||||
{
|
||||
if (m_pending_irqs)
|
||||
m_processInterrupts();
|
||||
}
|
||||
|
||||
void TransparentClient::m_cbRadioIrqHandler(radio::HwInstance*)
|
||||
{
|
||||
const radio::Interrupts new_irqs = m_radio->get_pending_irq();
|
||||
if (m_pending_irqs)
|
||||
m_pending_irqs = (*m_pending_irqs) | new_irqs;
|
||||
else
|
||||
m_pending_irqs = new_irqs;
|
||||
}
|
||||
|
||||
void TransparentClient::m_processInterrupts()
|
||||
{
|
||||
m_pending_irqs = std::nullopt;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,4 +6,6 @@
|
||||
void atmel_start_init(void)
|
||||
{
|
||||
system_init();
|
||||
|
||||
SysTick_Config(1000);
|
||||
}
|
||||
|
||||
16
main.cpp
16
main.cpp
@ -26,13 +26,6 @@ Utility::StaticPointer<App::TransparentClient> m_app;
|
||||
while (true);
|
||||
}
|
||||
|
||||
volatile bool irq_seen = false;
|
||||
|
||||
void m_irqHandler(radio::HwInstance*)
|
||||
{
|
||||
irq_seen = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
@ -49,11 +42,9 @@ int main()
|
||||
SKULLC_LOG_DEBUG("Begin.");
|
||||
|
||||
const App::RadioSettings settings;
|
||||
Utility::Function<void (radio::HwInstance*)> irq_handler{m_irqHandler};
|
||||
|
||||
m_app.setup(settings);
|
||||
radio::HwInstance* radio_hw = radio::HwInstance::instance();
|
||||
radio_hw->set_irq_handler(&irq_handler);
|
||||
|
||||
/* Replace with your application code */
|
||||
while (true)
|
||||
@ -67,13 +58,6 @@ int main()
|
||||
|
||||
SKULLC_LOG_INFO("Status: %d", radio_status);
|
||||
|
||||
if (irq_seen)
|
||||
{
|
||||
irq_seen = false;
|
||||
const radio::Interrupts irqs = radio_hw->get_pending_irq();
|
||||
SKULLC_LOG_INFO("IRQ received. %X", std::uint8_t(irqs));
|
||||
}
|
||||
|
||||
delay_ms(1000);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user