Skip to content

Commit

Permalink
Rework some syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
ckormanyos committed Jun 30, 2024
1 parent 3355d62 commit bb9d3d0
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 97 deletions.
1 change: 0 additions & 1 deletion ref_app/ref_app.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,6 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="src\os\os.cpp" />
<ClCompile Include="src\os\os_task_control_block.cpp" />
<ClCompile Include="src\sys\idle\sys_idle.cpp" />
<ClCompile Include="src\sys\mon\sys_mon.cpp" />
<ClCompile Include="src\sys\start\coverity.c" />
Expand Down
3 changes: 0 additions & 3 deletions ref_app/ref_app.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,6 @@
<ClCompile Include="src\mcal\am335x\mcal_wdg.cpp">
<Filter>src\mcal\am335x</Filter>
</ClCompile>
<ClCompile Include="src\os\os_task_control_block.cpp">
<Filter>src\os</Filter>
</ClCompile>
<ClCompile Include="src\util\STD_LIBC\memory.c">
<Filter>src\util\STD_LIBC</Filter>
</ClCompile>
Expand Down
6 changes: 3 additions & 3 deletions ref_app/src/os/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
// or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#include <algorithm>
#include <array>

#include <mcal_irq.h>
#include <os/os.h>
#include <os/os_task_control_block.h>

#include <algorithm>
#include <array>

namespace local
{
using task_list_type = std::array<os::task_control_block, OS_TASK_COUNT>;
Expand Down
7 changes: 4 additions & 3 deletions ref_app/src/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
#ifndef OS_2011_10_20_H_
#define OS_2011_10_20_H_

#include <cstdint>
#include <limits>
#include <os/os_cfg.h>
#include <util/utility/util_time.h>

#include <cstdint>
#include <limits>

#if defined(_MSC_VER)
#define OS_NORETURN
#else
Expand All @@ -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;
Expand Down
36 changes: 0 additions & 36 deletions ref_app/src/os/os_task_control_block.cpp

This file was deleted.

50 changes: 33 additions & 17 deletions ref_app/src/os/os_task_control_block.h
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -8,10 +8,11 @@
#ifndef OS_TASK_CONTROL_BLOCK_2013_07_30_H
#define OS_TASK_CONTROL_BLOCK_2013_07_30_H

#include <os/os.h>

#include <cstddef>
#include <cstdint>
#include <limits>
#include <os/os.h>

namespace os
{
Expand All @@ -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;
Expand All @@ -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<event_type>(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<os::tick_type>(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;
Expand Down
53 changes: 20 additions & 33 deletions ref_app/src/util/utility/util_time.h
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -8,12 +8,12 @@
#ifndef UTIL_TIME_2010_04_10_H
#define UTIL_TIME_2010_04_10_H

#include <cstdint>
#include <limits>

#include <mcal_gpt.h>
#include <mcal_wdg.h>

#include <cstdint>
#include <limits>

namespace util
{
template<typename unsigned_tick_type>
Expand All @@ -37,69 +37,56 @@
template<typename other_tick_type> static constexpr auto days (other_tick_type value_days) noexcept -> tick_type { return static_cast<tick_type>( 24UL) * hours (value_days ); }
template<typename other_tick_type> static constexpr auto weeks (other_tick_type value_weeks) noexcept -> tick_type { return static_cast<tick_type>( 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<tick_type>(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<tick_type>(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);

Expand All @@ -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<tick_type>(mcal::gpt::secure::get_time_elapsed());
}
Expand Down
1 change: 0 additions & 1 deletion ref_app/target/app/make/app_files.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bb9d3d0

Please sign in to comment.