Skip to content

Commit 2a723ca

Browse files
authored
Merge pull request #689 from ckormanyos/more_modernization
More modernization
2 parents 84db26c + e08a208 commit 2a723ca

27 files changed

Lines changed: 195 additions & 194 deletions

File tree

examples/chapter09_08/src/os/os.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2007 - 2018.
2+
// Copyright Christopher Kormanyos 2007 - 2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
66
//
77

8-
#include <algorithm>
9-
#include <array>
10-
#include <iterator>
118
#include <mcal_irq.h>
129
#include <mcal_led_sys_start_interface.h>
1310
#include <os/os.h>
1411
#include <os/os_task_control_block.h>
1512

13+
#include <algorithm>
14+
#include <array>
15+
#include <iterator>
16+
1617
namespace
1718
{
18-
typedef std::array<os::task_control_block, OS_TASK_COUNT> task_list_type;
19+
using task_list_type = std::array<os::task_control_block, OS_TASK_COUNT>;
1920

20-
typedef std::uint_fast8_t task_index_type;
21+
using task_index_type = std::uint_fast8_t;
2122

2223
// The one (and only one) operating system task list.
2324
task_list_type os_task_list(OS_TASK_LIST);
2425

2526
// The index of the running task.
26-
task_index_type os_task_index;
27+
task_index_type os_task_index { };
2728
}
2829

29-
void os::start_os()
30+
auto os::start_os() -> void
3031
{
3132
// Initialize each task once (and only once) before the task scheduling begins.
3233
auto const it_init_func = std::for_each(os_task_list.cbegin(),
@@ -50,7 +51,7 @@ void os::start_os()
5051
// In this way, each task in the loop will be checked for being
5152
// ready using the same time-point.
5253

53-
const os::tick_type timepoint_of_ckeck_ready = os::timer_type::get_mark();
54+
const os::tick_type timepoint_of_ckeck_ready { os::timer_type::get_mark() };
5455

5556
os_task_index = static_cast<task_index_type>(0U);
5657

@@ -74,7 +75,7 @@ void os::start_os()
7475
}
7576
}
7677

77-
bool os::set_event(const task_id_type task_id, const event_type& event_to_set)
78+
auto os::set_event(const task_id_type task_id, const event_type& event_to_set) -> bool
7879
{
7980
if(task_id < task_id_end)
8081
{
@@ -98,7 +99,7 @@ bool os::set_event(const task_id_type task_id, const event_type& event_to_set)
9899
}
99100
}
100101

101-
void os::get_event(event_type& event_to_get)
102+
auto os::get_event(event_type& event_to_get) -> void
102103
{
103104
// Get the iterator of the control block of the running task.
104105
const auto it_running_task = (os_task_list.cbegin() + os_task_index);
@@ -108,7 +109,7 @@ void os::get_event(event_type& event_to_get)
108109
// Get the event of the running task.
109110
mcal::irq::disable_all();
110111

111-
const volatile event_type the_event = it_running_task->my_event;
112+
const volatile event_type the_event { it_running_task->my_event };
112113

113114
mcal::irq::enable_all();
114115

@@ -120,14 +121,14 @@ void os::get_event(event_type& event_to_get)
120121
}
121122
}
122123

123-
void os::clear_event(const event_type& event_to_clear)
124+
auto os::clear_event(const event_type& event_to_clear) -> void
124125
{
125126
// Get the iterator of the control block of the running task.
126127
const auto it_running_task = (os_task_list.begin() + os_task_index);
127128

128129
if(it_running_task != os_task_list.end())
129130
{
130-
const volatile event_type event_clear_mask(~event_to_clear);
131+
const volatile event_type event_clear_mask { static_cast<event_type>(~event_to_clear) };
131132

132133
// Clear the event of the running task.
133134
mcal::irq::disable_all();

examples/chapter09_08/src/os/os.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2007 - 2016.
2+
// Copyright Christopher Kormanyos 2007 - 2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
66
//
77

8-
#ifndef OS_2011_10_20_H_
9-
#define OS_2011_10_20_H_
8+
#ifndef OS_2011_10_20_H
9+
#define OS_2011_10_20_H
1010

11-
#include <cstdint>
12-
#include <limits>
1311
#include <os/os_cfg.h>
1412
#include <util/utility/util_time.h>
1513

1614
namespace os
1715
{
18-
void start_os ();
19-
bool set_event (const task_id_type task_id, const event_type& event_to_set);
20-
void get_event (event_type& event_to_get);
21-
void clear_event(const event_type& event_to_clear);
16+
auto start_os() -> void;
17+
auto set_event(const task_id_type task_id, const event_type& event_to_set) -> bool;
18+
auto get_event(event_type& event_to_get) -> void;
19+
auto clear_event(const event_type& event_to_clear) -> void;
2220
}
2321

24-
#endif // OS_2011_10_20_H_
22+
#endif // OS_2011_10_20_H

examples/chapter09_08/src/os/os_cfg.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2007 - 2016.
2+
// Copyright Christopher Kormanyos 2007 - 2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
66
//
77

8-
#ifndef OS_CFG_2011_10_20_H_
9-
#define OS_CFG_2011_10_20_H_
8+
#ifndef OS_CFG_2011_10_20_H
9+
#define OS_CFG_2011_10_20_H
1010

1111
#include <cstddef>
1212
#include <cstdint>
@@ -15,15 +15,15 @@
1515
#include <util/utility/util_time.h>
1616

1717
// Declare the task initialization and the task function of the idle process.
18-
namespace sys { namespace idle { void task_init(); void task_func(); } }
18+
namespace sys { namespace idle { auto task_init() -> void; auto task_func() -> void; } }
1919

2020
// Define symbols for the task initialization and the task function of the idle process.
2121
#define OS_IDLE_TASK_INIT() sys::idle::task_init()
2222
#define OS_IDLE_TASK_FUNC() sys::idle::task_func()
2323

2424
// Declare all of the task initializations and the task functions.
25-
namespace app { namespace led { void task_init(); void task_func(); } }
26-
namespace sys { namespace mon { void task_init(); void task_func(); } }
25+
namespace app { namespace led { auto task_init() -> void; auto task_func() -> void; } }
26+
namespace sys { namespace mon { auto task_init() -> void; auto task_func() -> void; } }
2727

2828
namespace os
2929
{
@@ -38,11 +38,11 @@
3838
task_id_type;
3939

4040
// Configure the operating system types.
41-
typedef void(*function_type)();
41+
using function_type = void(*)();
4242

43-
typedef util::timer<std::uint_fast32_t> timer_type;
44-
typedef timer_type::tick_type tick_type;
45-
typedef std::uint_fast16_t event_type;
43+
using timer_type = util::timer<std::uint_fast32_t>;
44+
using tick_type = timer_type::tick_type;
45+
using event_type = std::uint_fast16_t;
4646

4747
static_assert(std::numeric_limits<os::tick_type>::digits >= 32,
4848
"The operating system timer_type must be at least 32-bits wide.");
@@ -83,4 +83,4 @@
8383

8484
static_assert(OS_TASK_COUNT > std::size_t(0U), "the task count must exceed zero");
8585

86-
#endif // OS_CFG_2011_10_20_H_
86+
#endif // OS_CFG_2011_10_20_H

examples/chapter09_08/src/os/os_task_control_block.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include <os/os_task_control_block.h>
99

10-
bool os::task_control_block::execute(const os::tick_type& timepoint_of_ckeck_ready)
10+
auto os::task_control_block::execute(const os::tick_type& timepoint_of_ckeck_ready) -> bool
1111
{
1212
// Check for a task event.
1313
const bool task_does_have_event = (my_event != event_type(0U));
@@ -33,4 +33,3 @@ bool os::task_control_block::execute(const os::tick_type& timepoint_of_ckeck_rea
3333

3434
return (task_does_have_event || task_does_have_timeout);
3535
}
36-
Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,68 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2007 - 2016.
2+
// Copyright Christopher Kormanyos 2007 - 2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
66
//
77

8-
#ifndef OS_TASK_CONTROL_BLOCK_2013_07_30_H_
9-
#define OS_TASK_CONTROL_BLOCK_2013_07_30_H_
8+
#ifndef OS_TASK_CONTROL_BLOCK_2013_07_30_H
9+
#define OS_TASK_CONTROL_BLOCK_2013_07_30_H
10+
11+
#include <os/os.h>
1012

1113
#include <cstddef>
1214
#include <cstdint>
1315
#include <limits>
14-
#include <os/os.h>
1516

1617
namespace os
1718
{
1819
class task_control_block final
1920
{
2021
public:
21-
task_control_block(const function_type init,
22-
const function_type func,
23-
const tick_type cycle,
24-
const tick_type offset) : my_init (init),
25-
my_func (func),
26-
my_cycle(cycle),
27-
my_timer(offset),
28-
my_event() { }
22+
explicit task_control_block(const function_type init,
23+
const function_type func,
24+
const tick_type cycle,
25+
const tick_type offset)
26+
: my_init (init),
27+
my_func (func),
28+
my_cycle(cycle),
29+
my_timer(offset) { }
2930

3031
task_control_block(const task_control_block& other_tcb) : my_init (other_tcb.my_init),
3132
my_func (other_tcb.my_func),
3233
my_cycle(other_tcb.my_cycle),
3334
my_timer(other_tcb.my_timer),
3435
my_event(other_tcb.my_event) { }
3536

37+
task_control_block(task_control_block&& other_tcb) : my_init (other_tcb.my_init),
38+
my_func (other_tcb.my_func),
39+
my_cycle(other_tcb.my_cycle),
40+
my_timer(other_tcb.my_timer),
41+
my_event(other_tcb.my_event) { }
42+
3643
~task_control_block() { }
3744

45+
task_control_block() = delete;
46+
47+
auto operator=(const task_control_block&) -> task_control_block& = default;
48+
auto operator=(task_control_block&&) -> task_control_block& = default;
49+
3850
private:
3951
const function_type my_init;
4052
const function_type my_func;
4153
const tick_type my_cycle;
4254
timer_type my_timer;
43-
event_type my_event;
44-
45-
void initialize() const { my_init(); }
55+
event_type my_event { };
4656

47-
bool execute(const tick_type& timepoint_of_ckeck_ready);
57+
auto initialize() const -> void { my_init(); }
4858

49-
task_control_block();
50-
task_control_block& operator=(const task_control_block&);
59+
auto execute(const tick_type& timepoint_of_ckeck_ready) -> bool;
5160

52-
friend void start_os ();
53-
friend bool set_event (const task_id_type, const event_type&);
54-
friend void get_event (event_type&);
55-
friend void clear_event(const event_type&);
61+
friend auto start_os() -> void;
62+
friend auto set_event(const task_id_type, const event_type&) -> bool;
63+
friend auto get_event (event_type&) -> void;
64+
friend auto clear_event(const event_type&) -> void;
5665
};
5766
}
5867

59-
#endif // OS_TASK_CONTROL_BLOCK_2013_07_30_H_
68+
#endif // OS_TASK_CONTROL_BLOCK_2013_07_30_H

examples/chapter09_08/src/sys/idle/sys_idle.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ namespace sys
1111
{
1212
namespace idle
1313
{
14-
void task_init();
15-
void task_func();
14+
auto task_init() -> void;
15+
auto task_func() -> void;
1616
}
1717
}
1818

19-
void sys::idle::task_init() { }
19+
auto sys::idle::task_init() -> void { }
2020

21-
void sys::idle::task_func()
21+
auto sys::idle::task_func() -> void
2222
{
2323
// Service the watchdog.
2424
mcal::wdg::secure::trigger();

examples/chapter09_08/src/sys/mon/sys_mon.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ namespace sys
1010
{
1111
namespace mon
1212
{
13-
void task_init();
14-
void task_func();
13+
auto task_init() -> void;
14+
auto task_func() -> void;
1515
}
1616
}
1717

18-
void sys::mon::task_init()
18+
auto sys::mon::task_init() -> void
1919
{
2020
}
2121

22-
void sys::mon::task_func()
22+
auto sys::mon::task_func() -> void
2323
{
2424
}

examples/chapter09_08/src/sys/start/sys_start.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// support for the PC application (because the PC
1515
// program uses WinMain() instead of main().
1616

17-
void mcal::led::sys_start_interface::my_sys_start()
17+
auto mcal::led::sys_start_interface::my_sys_start() -> void
1818
{
1919
// Initialize the microcontroller abstraction layer.
2020
mcal::init();

examples/chapter09_08/target/micros/avr/startup/crt0.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2007 - 2019.
2+
// Copyright Christopher Kormanyos 2007 - 2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
66
//
77

88
// ATMEL(R) AVR(R) startup code.
9-
// Expressed with C++ for AtmegaX by Chris.
109

1110
#include <mcal/mcal.h>
1211

0 commit comments

Comments
 (0)