|
1 | 1 | /////////////////////////////////////////////////////////////////////////////// |
2 | | -// Copyright Christopher Kormanyos 2020 - 2022. |
| 2 | +// Copyright Christopher Kormanyos 2020 - 2025. |
3 | 3 | // Distributed under the Boost Software License, |
4 | 4 | // Version 1.0. (See accompanying file LICENSE_1_0.txt |
5 | 5 | // or copy at http://www.boost.org/LICENSE_1_0.txt) |
6 | 6 | // |
7 | 7 |
|
8 | | -#ifndef MCAL_RANDOM_2020_06_11_H_ |
9 | | - #define MCAL_RANDOM_2020_06_11_H_ |
10 | | - |
11 | | - #include <cstdint> |
12 | | - #include <limits> |
| 8 | +#ifndef MCAL_RANDOM_2020_06_11_H |
| 9 | + #define MCAL_RANDOM_2020_06_11_H |
13 | 10 |
|
14 | 11 | #include <mcal_cpu.h> |
15 | 12 | #include <mcal_port.h> |
16 | 13 | #include <mcal_port_pin_dummy.h> |
17 | 14 | #include <mcal_spi/mcal_spi_software_port_driver.h> |
18 | 15 | #include <util/utility/util_time.h> |
19 | 16 |
|
| 17 | + #include <cstdint> |
| 18 | + #include <limits> |
| 19 | + |
20 | 20 | namespace mcal { namespace random { |
21 | 21 |
|
22 | 22 | namespace detail { |
|
31 | 31 | public: |
32 | 32 | using result_type = UnsignedIntegralType; |
33 | 33 |
|
34 | | - static_assert(std::uint_fast8_t(std::numeric_limits<result_type>::digits % 8) == 0U, |
| 34 | + static_assert(static_cast<std::uint_fast8_t>(std::numeric_limits<result_type>::digits % 8) == std::uint_fast8_t { UINT8_C(0) }, |
35 | 35 | "Error: Integral type must have a multiple of 8 digits."); |
36 | 36 |
|
37 | | - static_assert(( (std::numeric_limits<result_type>::is_integer == true) |
38 | | - && (std::numeric_limits<result_type>::is_signed == false)), |
| 37 | + static_assert(( std::numeric_limits<result_type>::is_integer |
| 38 | + && (!std::numeric_limits<result_type>::is_signed)), |
39 | 39 | "Error: Integral type must an unsigned integral type."); |
40 | 40 |
|
41 | | - random_engine_reverse_z_diode_raw(const result_type = result_type()) noexcept |
42 | | - : my_spi() { } |
| 41 | + explicit random_engine_reverse_z_diode_raw(const result_type = result_type()) noexcept { } |
| 42 | + |
| 43 | + random_engine_reverse_z_diode_raw(const random_engine_reverse_z_diode_raw&) noexcept { } |
43 | 44 |
|
44 | | - random_engine_reverse_z_diode_raw(const random_engine_reverse_z_diode_raw&) |
45 | | - : my_spi() { } |
| 45 | + random_engine_reverse_z_diode_raw(const random_engine_reverse_z_diode_raw&&) noexcept { } |
46 | 46 |
|
47 | | - random_engine_reverse_z_diode_raw(const random_engine_reverse_z_diode_raw&&) |
48 | | - : my_spi() { } |
| 47 | + ~random_engine_reverse_z_diode_raw() noexcept { } |
49 | 48 |
|
50 | | - random_engine_reverse_z_diode_raw& operator=(const random_engine_reverse_z_diode_raw&) |
| 49 | + auto operator=(const random_engine_reverse_z_diode_raw&) noexcept -> random_engine_reverse_z_diode_raw& |
51 | 50 | { |
52 | 51 | return *this; |
53 | 52 | } |
54 | 53 |
|
55 | | - random_engine_reverse_z_diode_raw& operator=(const random_engine_reverse_z_diode_raw&&) |
| 54 | + auto operator=(const random_engine_reverse_z_diode_raw&&) noexcept -> random_engine_reverse_z_diode_raw& |
56 | 55 | { |
57 | 56 | return *this; |
58 | 57 | } |
59 | 58 |
|
60 | | - static constexpr result_type(min)() noexcept |
| 59 | + static constexpr auto (min)() noexcept -> result_type |
61 | 60 | { |
62 | | - return result_type(0U); |
| 61 | + return result_type { UINT8_C(0) }; |
63 | 62 | } |
64 | 63 |
|
65 | | - static constexpr result_type(max)() noexcept |
| 64 | + static constexpr auto (max)() noexcept -> result_type |
66 | 65 | { |
67 | 66 | return (std::numeric_limits<result_type>::max)(); |
68 | 67 | } |
69 | 68 |
|
70 | | - void seed(result_type = result_type()) { } |
| 69 | + auto seed(result_type = result_type()) noexcept -> void { } |
71 | 70 |
|
72 | | - result_type operator()() noexcept |
| 71 | + auto operator()() noexcept -> result_type |
73 | 72 | { |
74 | 73 | // Get random value having type result_type. |
75 | 74 | return get_value(my_spi); |
76 | 75 | } |
77 | 76 |
|
78 | | - void discard(unsigned long long skip) noexcept |
| 77 | + auto discard(unsigned long long skip) noexcept -> void |
79 | 78 | { |
80 | | - for(unsigned long long i = 0U; i < skip; ++i) |
| 79 | + for(unsigned long long i = static_cast<unsigned long long>(UINT8_C(0)); i < skip; ++i) |
81 | 80 | { |
82 | | - const result_type tmp = get_value(my_spi); |
| 81 | + const result_type tmp { get_value(my_spi) }; |
83 | 82 |
|
84 | 83 | static_cast<void>(tmp); |
85 | 84 | } |
86 | 85 | } |
87 | 86 |
|
88 | 87 | private: |
89 | | - spi_type my_spi; |
| 88 | + spi_type my_spi { }; |
90 | 89 |
|
91 | | - static result_type get_value(util::communication_base& com) noexcept |
| 90 | + static auto get_value(util::communication_base& com) noexcept -> result_type |
92 | 91 | { |
93 | | - result_type value = result_type(0U); |
| 92 | + result_type value { UINT8_C(0) }; |
94 | 93 |
|
95 | | - for(std::uint_fast8_t i = 0U; i < std::uint_fast8_t(std::numeric_limits<result_type>::digits / 8); ++i) |
| 94 | + for(std::uint_fast8_t i { std::uint_fast8_t { UINT8_C(0) } }; |
| 95 | + i < static_cast<std::uint_fast8_t>(std::numeric_limits<result_type>::digits / 8); |
| 96 | + ++i) |
96 | 97 | { |
97 | 98 | std::uint8_t by; |
98 | 99 |
|
99 | | - com.send(UINT8_C(0xFFU)); |
| 100 | + com.send(UINT8_C(0xFF)); |
100 | 101 | com.recv(by); |
101 | 102 |
|
102 | | - value |= result_type(result_type(by) << (i * 8U)); |
| 103 | + value |= static_cast<result_type>(static_cast<result_type>(by) << static_cast<unsigned>(i * 8U)); |
103 | 104 | } |
104 | 105 |
|
105 | 106 | return value; |
106 | 107 | } |
107 | 108 | }; |
108 | 109 |
|
109 | 110 | using spi_software_port_driver_type = |
110 | | - mcal::spi::spi_software_port_driver<mcal::port::port_pin<std::uint8_t, std::uint8_t, mcal::reg::portc, 4U>, |
| 111 | + mcal::spi::spi_software_port_driver<mcal::port::port_pin<std::uint8_t, std::uint8_t, mcal::reg::portc, std::uint8_t { UINT8_C(4) }>, |
111 | 112 | mcal::port::port_pin_dummy, |
112 | 113 | mcal::port::port_pin_dummy, |
113 | | - mcal::port::port_pin<std::uint8_t, std::uint8_t, mcal::reg::portc, 5U>, |
114 | | - 45U, |
| 114 | + mcal::port::port_pin<std::uint8_t, std::uint8_t, mcal::reg::portc, std::uint8_t { UINT8_C(5) }>, |
| 115 | + static_cast<std::uint_fast16_t>(UINT8_C(45)), |
115 | 116 | false>; |
116 | 117 |
|
117 | 118 | } // namespace detail |
118 | 119 |
|
119 | | - using default_random_engine = |
120 | | - detail::random_engine_reverse_z_diode_raw<detail::spi_software_port_driver_type, |
121 | | - std::uint8_t>; |
| 120 | + using default_random_engine = detail::random_engine_reverse_z_diode_raw<detail::spi_software_port_driver_type, std::uint8_t>; |
122 | 121 |
|
123 | 122 | } } // namespace mcal::random |
124 | 123 |
|
125 | | -#endif // MCAL_RANDOM_2020_06_11_H_ |
| 124 | +#endif // MCAL_RANDOM_2020_06_11_H |
0 commit comments