From bb9d3d08a8a956fce0a7c0f49ea32b8fe54487c2 Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Sun, 30 Jun 2024 09:23:17 +0200 Subject: [PATCH] Rework some syntax --- ref_app/ref_app.vcxproj | 1 - ref_app/ref_app.vcxproj.filters | 3 -- ref_app/src/os/os.cpp | 6 +-- ref_app/src/os/os.h | 7 ++-- ref_app/src/os/os_task_control_block.cpp | 36 ---------------- ref_app/src/os/os_task_control_block.h | 50 ++++++++++++++-------- ref_app/src/util/utility/util_time.h | 53 +++++++++--------------- ref_app/target/app/make/app_files.gmk | 1 - 8 files changed, 60 insertions(+), 97 deletions(-) delete mode 100644 ref_app/src/os/os_task_control_block.cpp diff --git a/ref_app/ref_app.vcxproj b/ref_app/ref_app.vcxproj index 984b1b141..852640349 100644 --- a/ref_app/ref_app.vcxproj +++ b/ref_app/ref_app.vcxproj @@ -1109,7 +1109,6 @@ true - diff --git a/ref_app/ref_app.vcxproj.filters b/ref_app/ref_app.vcxproj.filters index d9efe45cb..a7ee0d074 100644 --- a/ref_app/ref_app.vcxproj.filters +++ b/ref_app/ref_app.vcxproj.filters @@ -274,9 +274,6 @@ src\mcal\am335x - - src\os - src\util\STD_LIBC diff --git a/ref_app/src/os/os.cpp b/ref_app/src/os/os.cpp index a47b78b9c..15eee3b51 100644 --- a/ref_app/src/os/os.cpp +++ b/ref_app/src/os/os.cpp @@ -5,13 +5,13 @@ // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#include -#include - #include #include #include +#include +#include + namespace local { using task_list_type = std::array; diff --git a/ref_app/src/os/os.h b/ref_app/src/os/os.h index 916d8846b..5a471d7b6 100644 --- a/ref_app/src/os/os.h +++ b/ref_app/src/os/os.h @@ -8,11 +8,12 @@ #ifndef OS_2011_10_20_H_ #define OS_2011_10_20_H_ - #include - #include #include #include + #include + #include + #if defined(_MSC_VER) #define OS_NORETURN #else @@ -21,7 +22,7 @@ namespace os { - OS_NORETURN auto start_os () -> void; + OS_NORETURN auto start_os() -> void; auto set_event (const task_id_type task_id, const event_type& event_to_set) -> bool; auto get_event (event_type& event_to_get) -> void; auto clear_event(const event_type& event_to_clear) -> void; diff --git a/ref_app/src/os/os_task_control_block.cpp b/ref_app/src/os/os_task_control_block.cpp deleted file mode 100644 index f353ef1bb..000000000 --- a/ref_app/src/os/os_task_control_block.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2021. -// Distributed under the Boost Software License, -// Version 1.0. (See accompanying file LICENSE_1_0.txt -// or copy at http://www.boost.org/LICENSE_1_0.txt) -// - -#include - -auto os::task_control_block::execute(const os::tick_type& timepoint_of_ckeck_ready) -> bool -{ - // Check for a task event. - const auto task_does_have_event = (my_event != static_cast(UINT8_C(0))); - - if(task_does_have_event) - { - // Call the task function because of an event. - my_func(); - } - - // Check for a task timeout. - const bool task_does_have_timeout = ( (my_cycle != static_cast(UINT8_C(0))) - && my_timer.timeout_of_specific_timepoint(timepoint_of_ckeck_ready)); - - if(task_does_have_timeout) - { - // Increment the task's interval timer with the task cycle. - my_timer.start_interval(my_cycle); - - // Call the task function because of a timer timeout. - my_func(); - } - - return (task_does_have_event || task_does_have_timeout); -} - diff --git a/ref_app/src/os/os_task_control_block.h b/ref_app/src/os/os_task_control_block.h index 7d0f2f4ec..85d626e92 100644 --- a/ref_app/src/os/os_task_control_block.h +++ b/ref_app/src/os/os_task_control_block.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2023. +// Copyright Christopher Kormanyos 2007 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -8,10 +8,11 @@ #ifndef OS_TASK_CONTROL_BLOCK_2013_07_30_H #define OS_TASK_CONTROL_BLOCK_2013_07_30_H + #include + #include #include #include - #include namespace os { @@ -21,29 +22,19 @@ task_control_block(const function_type init, const function_type func, const tick_type cycle, - const tick_type offset) noexcept + const tick_type offset) : my_init (init), my_func (func), my_cycle(cycle), my_timer(offset) { } - task_control_block(const task_control_block& other_tcb) noexcept - : my_init (other_tcb.my_init), - my_func (other_tcb.my_func), - my_cycle(other_tcb.my_cycle), - my_timer(other_tcb.my_timer), - my_event(other_tcb.my_event) { } + task_control_block(const task_control_block& other_tcb) = default; - task_control_block(task_control_block&& other_tcb) noexcept - : my_init (other_tcb.my_init), - my_func (other_tcb.my_func), - my_cycle(other_tcb.my_cycle), - my_timer(other_tcb.my_timer), - my_event(other_tcb.my_event) { } + task_control_block(task_control_block&& other_tcb) noexcept = default; task_control_block() = delete; - ~task_control_block() { } + ~task_control_block() = default; auto operator=(const task_control_block&) -> task_control_block& = delete; auto operator=(task_control_block&&) noexcept -> task_control_block& = delete; @@ -57,7 +48,32 @@ auto initialize() const -> void { my_init(); } - auto execute(const tick_type& timepoint_of_ckeck_ready) -> bool; + auto execute(const tick_type& timepoint_of_ckeck_ready) -> bool + { + // Check for a task event. + const auto task_does_have_event = (my_event != static_cast(UINT8_C(0))); + + if(task_does_have_event) + { + // Call the task function because of an event. + my_func(); + } + + // Check for a task timeout. + const bool task_does_have_timeout = ( (my_cycle != static_cast(UINT8_C(0))) + && my_timer.timeout_of_specific_timepoint(timepoint_of_ckeck_ready)); + + if(task_does_have_timeout) + { + // Increment the task's interval timer with the task cycle. + my_timer.start_interval(my_cycle); + + // Call the task function because of a timer timeout. + my_func(); + } + + return (task_does_have_event || task_does_have_timeout); + } friend auto start_os () -> void; friend auto set_event (const task_id_type, const event_type&) -> bool; diff --git a/ref_app/src/util/utility/util_time.h b/ref_app/src/util/utility/util_time.h index 3c149e82d..bb6fa34b0 100644 --- a/ref_app/src/util/utility/util_time.h +++ b/ref_app/src/util/utility/util_time.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2022. +// Copyright Christopher Kormanyos 2007 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -8,12 +8,12 @@ #ifndef UTIL_TIME_2010_04_10_H #define UTIL_TIME_2010_04_10_H - #include - #include - #include #include + #include + #include + namespace util { template @@ -37,69 +37,56 @@ template static constexpr auto days (other_tick_type value_days) noexcept -> tick_type { return static_cast( 24UL) * hours (value_days ); } template static constexpr auto weeks (other_tick_type value_weeks) noexcept -> tick_type { return static_cast( 7UL) * days (value_weeks ); } - constexpr timer() noexcept = default; - - constexpr timer(tick_type tick_value) noexcept : my_tick(my_now() + tick_value) { } + constexpr timer() = default; - constexpr timer(const timer& other) noexcept : my_tick(other.my_tick) { } + constexpr timer(tick_type tick_value) : my_tick(my_now() + tick_value) { } - constexpr timer(timer&& other) noexcept : my_tick(other.my_tick) { } + constexpr timer(const timer& other) = default; - ~timer() { } + constexpr timer(timer&& other) noexcept = default; - auto operator=(const timer& other) noexcept -> timer& - { - if(this != &other) - { - my_tick = other.my_tick; - } + ~timer() = default; - return *this; - } + auto operator=(const timer& other) -> timer& = default; - auto operator=(timer&& other) noexcept -> timer& - { - my_tick = other.my_tick; - - return *this; - } + auto operator=(timer&& other) noexcept -> timer& = default; - auto start_interval(const tick_type& tick_value) noexcept -> void + auto start_interval(const tick_type& tick_value) -> void { my_tick += tick_value; } - auto start_relative(const tick_type& tick_value) noexcept -> void + auto start_relative(const tick_type& tick_value) -> void { my_tick = my_now() + tick_value; } - constexpr auto timeout() const noexcept -> bool + constexpr auto timeout() const -> bool { return (static_cast(my_now() - my_tick) <= timer_mask); } - constexpr auto timeout_of_specific_timepoint(const tick_type timepoint) const noexcept -> bool + constexpr auto timeout_of_specific_timepoint(const tick_type timepoint) const -> bool { return (static_cast(timepoint - my_tick) <= timer_mask); } - auto set_mark() noexcept -> void + auto set_mark() -> void { return (my_tick = my_now()); } - static constexpr auto get_mark() noexcept -> tick_type + static constexpr auto get_mark() -> tick_type { return my_now(); } - constexpr auto get_ticks_since_mark() const noexcept -> tick_type + constexpr auto get_ticks_since_mark() const -> tick_type { return my_now() - my_tick; } - static auto blocking_delay(const tick_type& delay) noexcept -> void + static auto blocking_delay(const tick_type& delay) -> void { const timer t_delay(delay); @@ -112,7 +99,7 @@ private: tick_type my_tick { my_now() }; - constexpr static auto my_now() noexcept -> tick_type + constexpr static auto my_now() -> tick_type { return static_cast(mcal::gpt::secure::get_time_elapsed()); } diff --git a/ref_app/target/app/make/app_files.gmk b/ref_app/target/app/make/app_files.gmk index 68b06756d..94a46a34f 100644 --- a/ref_app/target/app/make/app_files.gmk +++ b/ref_app/target/app/make/app_files.gmk @@ -44,7 +44,6 @@ FILES_CPP = $(PATH_APP)/app/benchmark/app_benchmark $(PATH_APP)/mcal/$(TGT)/mcal_wdg \ $(PATH_APP)/mcal/mcal \ $(PATH_APP)/os/os \ - $(PATH_APP)/os/os_task_control_block \ $(PATH_APP)/sys/idle/sys_idle \ $(PATH_APP)/sys/mon/sys_mon \ $(PATH_APP)/sys/start/sys_start