From 1c695fbaa880175b19162a55684a78da7704a195 Mon Sep 17 00:00:00 2001 From: Erki Date: Sat, 16 Jul 2022 12:23:07 +0300 Subject: [PATCH] Implement millis() function --- CMakeLists.txt | 2 +- app/include/app_logging.hpp | 15 ----------- app/include/skullc_samd21_hal.hpp | 19 ++++++++++---- app/src/app_board.cpp | 7 ++--- app/src/app_logging.cpp | 43 ------------------------------- main.cpp | 5 ++-- 6 files changed, 21 insertions(+), 70 deletions(-) delete mode 100644 app/include/app_logging.hpp delete mode 100644 app/src/app_logging.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a133231..e49436d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,7 @@ add_executable(skl_tunnel radio/src/radio_gpio.c radio/src/radio_hw_instance.cpp - app/src/app_logging.cpp + app/src/app_board.cpp app/src/app_transparent_client.cpp main.cpp syscalls.c diff --git a/app/include/app_logging.hpp b/app/include/app_logging.hpp deleted file mode 100644 index f65a993..0000000 --- a/app/include/app_logging.hpp +++ /dev/null @@ -1,15 +0,0 @@ -// -// 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 diff --git a/app/include/skullc_samd21_hal.hpp b/app/include/skullc_samd21_hal.hpp index 3963f3e..f789061 100644 --- a/app/include/skullc_samd21_hal.hpp +++ b/app/include/skullc_samd21_hal.hpp @@ -5,10 +5,6 @@ #ifndef SKL_TUNNEL_SKULLC_SAMD21_HAL_HPP #define SKL_TUNNEL_SKULLC_SAMD21_HAL_HPP -#include -#include -#include - #include #include #include @@ -16,6 +12,12 @@ #include #include +#include +#include +#include + +#include "app_board.hpp" + namespace Peripherals { namespace Hal @@ -26,7 +28,14 @@ namespace Samd struct StaticHal { static void initialize() - { } + { + App::Board::setup(); + } + + static std::uint32_t getMillis() + { + return App::Board::systickGet(); + } static void delay(const std::uint32_t milliseconds) { diff --git a/app/src/app_board.cpp b/app/src/app_board.cpp index 96b42e5..50a7a83 100644 --- a/app/src/app_board.cpp +++ b/app/src/app_board.cpp @@ -2,15 +2,16 @@ // Created by erki on 15.07.22. // +#include "driver_init.h" + #include "app_board.hpp" -#include "driver_init.h" +#include "skullc_samd21_hal.hpp" #include #include #include -#include "skullc_samd21_hal.hpp" namespace Hal = Peripherals::Hal::Samd; @@ -46,7 +47,7 @@ void setup() m_logger.setup(usart0); Utility::setLogger(*m_logger); - SysTick_Config(1000); + SysTick_Config(F_CPU / 1000u); } std::uint32_t systickGet() diff --git a/app/src/app_logging.cpp b/app/src/app_logging.cpp deleted file mode 100644 index 09257a1..0000000 --- a/app/src/app_logging.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// -// Created by erki on 28.06.22. -// - -#include "app_logging.hpp" - -#include "driver_init.h" - -#include -#include -#include - -#include "skullc_samd21_hal.hpp" - -namespace Hal = Peripherals::Hal::Samd; - -using Logger = Utility::AsyncLogger, Hal::StaticHal, 5, 255>; - -namespace -{ - -Utility::StaticPointer m_logger; - -void m_txCompleteCb(const usart_async_descriptor* const) -{ - m_logger->txCompleteCallback(); -} - -} - -namespace App::Logging -{ - -void setup() -{ - Hal::SerialInterfaceAsync usart0{&USART_0}; - usart0.registerTxCallback(m_txCompleteCb); - - m_logger.setup(usart0); - Utility::setLogger(*m_logger); -} - -} diff --git a/main.cpp b/main.cpp index f1bcde1..1a0c03d 100644 --- a/main.cpp +++ b/main.cpp @@ -6,7 +6,6 @@ #include #include "radio_hw_instance.hpp" -#include "app_logging.hpp" #include "skullc_samd21_hal.hpp" #include "app_transparent_client.hpp" @@ -34,11 +33,10 @@ int main() atmel_start_init(); Utility::Assert::setHandler(m_faultHandler); + Hal::StaticHal::initialize(); gpio_set_pin_level(OUT_LED_TX, false); - App::Logging::setup(); - SKULLC_LOG_DEBUG("Begin."); const App::RadioSettings settings; @@ -57,6 +55,7 @@ int main() radio_status &= 0x1F; SKULLC_LOG_INFO("Status: %d", radio_status); + SKULLC_LOG_INFO("Millis: %u", Hal::StaticHal::getMillis()); delay_ms(1000); }