Finalize logging integration
This commit is contained in:
parent
9f5365f462
commit
75ddd706d0
@ -49,6 +49,7 @@ add_executable(skl_tunnel
|
||||
radio/src/radio_gpio.c
|
||||
radio/src/radio_hw_instance.cpp
|
||||
|
||||
app/src/app_logging.cpp
|
||||
main.cpp
|
||||
)
|
||||
|
||||
@ -74,7 +75,7 @@ target_include_directories(skl_tunnel
|
||||
CMSIS/Core/Include
|
||||
samd21a/include
|
||||
radio/include
|
||||
skullc_interface/include
|
||||
app/include
|
||||
)
|
||||
|
||||
target_link_libraries(skl_tunnel
|
||||
|
||||
15
app/include/app_logging.hpp
Normal file
15
app/include/app_logging.hpp
Normal file
@ -0,0 +1,15 @@
|
||||
//
|
||||
// Created by erki on 28.06.22.
|
||||
//
|
||||
|
||||
#ifndef SKL_TUNNEL_APP_LOGGING_HPP
|
||||
#define SKL_TUNNEL_APP_LOGGING_HPP
|
||||
|
||||
namespace App::Logging
|
||||
{
|
||||
|
||||
void setup();
|
||||
|
||||
}
|
||||
|
||||
#endif //SKL_TUNNEL_APP_LOGGING_HPP
|
||||
@ -2,8 +2,8 @@
|
||||
// Created by erki on 26.06.22.
|
||||
//
|
||||
|
||||
#ifndef SKL_TUNNEL_SAMD21_HAL_HPP
|
||||
#define SKL_TUNNEL_SAMD21_HAL_HPP
|
||||
#ifndef SKL_TUNNEL_SKULLC_SAMD21_HAL_HPP
|
||||
#define SKL_TUNNEL_SKULLC_SAMD21_HAL_HPP
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
@ -107,17 +107,25 @@ struct SerialInterfaceAsync
|
||||
void registerRxCallback(Utility::IFunction<void (const original_handler* const)>* rx_cb)
|
||||
{
|
||||
assert(rx_cb);
|
||||
m_rx_cb = rx_cb;
|
||||
|
||||
handle_wrapper::registerRxCallback(handle, m_rx_cb->template toStaticFunction<SKULLC_TAG>());
|
||||
handle_wrapper::registerRxCallback(handle, rx_cb->template toStaticFunction<SKULLC_TAG>());
|
||||
}
|
||||
|
||||
void registerRxCallback(Detail::async_io_callback<original_handler> rx_cb)
|
||||
{
|
||||
handle_wrapper::registerRxCallback(handle, rx_cb);
|
||||
}
|
||||
|
||||
void registerTxCallback(Utility::IFunction<void (const original_handler* const)>* tx_cb)
|
||||
{
|
||||
assert(tx_cb);
|
||||
m_tx_cb = tx_cb;
|
||||
|
||||
handle_wrapper::registerRxCallback(handle, m_tx_cb->template toStaticFunction<SKULLC_TAG>());
|
||||
handle_wrapper::registerTxCallback(handle, tx_cb->template toStaticFunction<SKULLC_TAG>());
|
||||
}
|
||||
|
||||
void registerTxCallback(Detail::async_io_callback<original_handler> tx_cb)
|
||||
{
|
||||
handle_wrapper::registerTxCallback(handle, tx_cb);
|
||||
}
|
||||
|
||||
bool transmit(std::uint8_t* data, const std::uint32_t data_len)
|
||||
@ -145,14 +153,10 @@ struct SerialInterfaceAsync
|
||||
|
||||
return receive(reinterpret_cast<std::uint8_t*>(array.data()), std::uint32_t(N));
|
||||
}
|
||||
|
||||
private:
|
||||
Utility::IFunction<void (const original_handler* const)>* m_rx_cb = nullptr;
|
||||
Utility::IFunction<void (const original_handler* const)>* m_tx_cb = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif //SKL_TUNNEL_SAMD21_HAL_HPP
|
||||
#endif //SKL_TUNNEL_SKULLC_SAMD21_HAL_HPP
|
||||
43
app/src/app_logging.cpp
Normal file
43
app/src/app_logging.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
//
|
||||
// Created by erki on 28.06.22.
|
||||
//
|
||||
|
||||
#include "app_logging.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;
|
||||
|
||||
void m_txCompleteCb(const usart_async_descriptor* const)
|
||||
{
|
||||
m_logger->txCompleteCallback();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace App::Logging
|
||||
{
|
||||
|
||||
void setup()
|
||||
{
|
||||
Hal::SerialInterfaceAsync<usart_async_descriptor> usart0{&USART_0};
|
||||
usart0.registerTxCallback(m_txCompleteCb);
|
||||
|
||||
m_logger.setup(usart0);
|
||||
Utility::setLogger(*m_logger);
|
||||
}
|
||||
|
||||
}
|
||||
42
main.cpp
42
main.cpp
@ -1,22 +1,16 @@
|
||||
#include <atmel_start.h>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <utility_staticpointer.hpp>
|
||||
#include <samd21_hal.hpp>
|
||||
#include <utility_logging.hpp>
|
||||
|
||||
#include "radio_hw_instance.hpp"
|
||||
#include "app_logging.hpp"
|
||||
#include "skullc_samd21_hal.hpp"
|
||||
|
||||
namespace Hal = Peripherals::Hal::Samd;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
volatile bool can_send_uart = true;
|
||||
|
||||
void tx_cb_USART_0(const struct usart_async_descriptor* const io_descr)
|
||||
{
|
||||
can_send_uart = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(void)
|
||||
@ -26,18 +20,7 @@ int main(void)
|
||||
|
||||
gpio_set_pin_level(OUT_LED_TX, false);
|
||||
|
||||
struct io_descriptor* usart_io = NULL;
|
||||
|
||||
Utility::Function<void (const usart_async_descriptor* const)> callback{tx_cb_USART_0};
|
||||
Peripherals::Hal::Samd::SerialInterfaceAsync<usart_async_descriptor> usart0{&USART_0};
|
||||
|
||||
usart0.registerTxCallback(&callback);
|
||||
|
||||
#if 0
|
||||
usart_async_register_callback(&USART_0, USART_ASYNC_TXC_CB, tx_cb_USART_0);
|
||||
usart_async_get_io_descriptor(&USART_0, &usart_io);
|
||||
usart_async_enable(&USART_0);
|
||||
#endif
|
||||
App::Logging::setup();
|
||||
|
||||
radio::HwInstance* radio_hw = radio::HwInstance::create_instance();
|
||||
|
||||
@ -46,20 +29,11 @@ int main(void)
|
||||
{
|
||||
gpio_toggle_pin_level(OUT_LED_RX);
|
||||
|
||||
uint8_t uart_data[12] = { 0 };
|
||||
|
||||
if (can_send_uart)
|
||||
{
|
||||
can_send_uart = false;
|
||||
const int16_t radio_num = radio_hw->register_read(0x1C);
|
||||
|
||||
std::sprintf((char*)uart_data, "%d\n\r", radio_num);
|
||||
usart0.transmit(uart_data, 12);
|
||||
#if 0
|
||||
io_write(usart_io, uart_data, 12);
|
||||
#endif
|
||||
SKULLC_LOG_INFO("Reg 0x1C: %d", radio_num);
|
||||
|
||||
gpio_toggle_pin_level(OUT_LED_TX);
|
||||
}
|
||||
|
||||
delay_ms(1000);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user