Skip to content

Commit d8f9ab8

Browse files
committed
Repair regular builds with some TODOs
1 parent f336973 commit d8f9ab8

29 files changed

Lines changed: 1230 additions & 576 deletions

examples/chapter11_07a/chapter11_07a.vcxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@
171171
</ItemGroup>
172172
<ItemGroup>
173173
<ClCompile Include="src\app\led\app_led.cpp" />
174+
<ClCompile Include="src\app\pi_spigot\pi_spigot.cpp" />
175+
<ClCompile Include="src\app\pi_spigot\pi_spigot_callback.cpp" />
174176
<ClCompile Include="src\mcal\avr\mcal_cpu.cpp">
175177
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
176178
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
@@ -243,7 +245,17 @@
243245
</ItemGroup>
244246
<ItemGroup>
245247
<ClInclude Include="src\app\led\app_led.h" />
248+
<ClInclude Include="src\app\pi_calc_cfg.h" />
246249
<ClInclude Include="src\math\checksums\crc\crc32.h" />
250+
<ClInclude Include="src\math\checksums\hash\hash_base.h" />
251+
<ClInclude Include="src\math\checksums\hash\hash_detail.h" />
252+
<ClInclude Include="src\math\checksums\hash\hash_sha1.h" />
253+
<ClInclude Include="src\math\checksums\hash\hash_sha256.h" />
254+
<ClInclude Include="src\math\pi_spigot\pi_spigot.h" />
255+
<ClInclude Include="src\mcal\avr\mcal_benchmark.h">
256+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
257+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
258+
</ClInclude>
247259
<ClInclude Include="src\mcal\avr\mcal_cpu.h">
248260
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
249261
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>

examples/chapter11_07a/chapter11_07a.vcxproj.filters

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@
103103
<Filter Include="_doc">
104104
<UniqueIdentifier>{ff14b2e1-f38c-4081-8657-97e5320e1911}</UniqueIdentifier>
105105
</Filter>
106+
<Filter Include="src\math\pi_spigot">
107+
<UniqueIdentifier>{79074285-b08d-4878-ab3a-8c373cf08080}</UniqueIdentifier>
108+
</Filter>
109+
<Filter Include="src\app\pi_spigot">
110+
<UniqueIdentifier>{9d719275-19a2-4906-ba59-044aae78b2a4}</UniqueIdentifier>
111+
</Filter>
112+
<Filter Include="src\math\checksums\hash">
113+
<UniqueIdentifier>{499b6f76-e0e7-43ad-aeef-11e3c736d1f7}</UniqueIdentifier>
114+
</Filter>
106115
</ItemGroup>
107116
<ItemGroup>
108117
<ClCompile Include="src\mcal\mcal.cpp">
@@ -189,6 +198,12 @@
189198
<ClCompile Include="src\mcal\avr\mcal_memory_sram.cpp">
190199
<Filter>src\mcal\avr</Filter>
191200
</ClCompile>
201+
<ClCompile Include="src\app\pi_spigot\pi_spigot.cpp">
202+
<Filter>src\app\pi_spigot</Filter>
203+
</ClCompile>
204+
<ClCompile Include="src\app\pi_spigot\pi_spigot_callback.cpp">
205+
<Filter>src\app\pi_spigot</Filter>
206+
</ClCompile>
192207
</ItemGroup>
193208
<ItemGroup>
194209
<ClInclude Include="src\mcal\mcal.h">
@@ -464,6 +479,27 @@
464479
<ClInclude Include="src\mcal\avr\mcal_spi_types.h">
465480
<Filter>src\mcal\avr</Filter>
466481
</ClInclude>
482+
<ClInclude Include="src\math\pi_spigot\pi_spigot.h">
483+
<Filter>src\math\pi_spigot</Filter>
484+
</ClInclude>
485+
<ClInclude Include="src\app\pi_calc_cfg.h">
486+
<Filter>src\app</Filter>
487+
</ClInclude>
488+
<ClInclude Include="src\mcal\avr\mcal_benchmark.h">
489+
<Filter>src\mcal\avr</Filter>
490+
</ClInclude>
491+
<ClInclude Include="src\math\checksums\hash\hash_detail.h">
492+
<Filter>src\math\checksums\hash</Filter>
493+
</ClInclude>
494+
<ClInclude Include="src\math\checksums\hash\hash_sha1.h">
495+
<Filter>src\math\checksums\hash</Filter>
496+
</ClInclude>
497+
<ClInclude Include="src\math\checksums\hash\hash_sha256.h">
498+
<Filter>src\math\checksums\hash</Filter>
499+
</ClInclude>
500+
<ClInclude Include="src\math\checksums\hash\hash_base.h">
501+
<Filter>src\math\checksums\hash</Filter>
502+
</ClInclude>
467503
</ItemGroup>
468504
<ItemGroup>
469505
<None Include="src\util\STL_C++XX_stdfloat\cstdfloat">
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// Copyright Christopher Kormanyos 2023 - 2025.
3+
// Distributed under the Boost Software License,
4+
// Version 1.0. (See accompanying file LICENSE_1_0.txt
5+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
//
7+
8+
#ifndef PI_CALC_CFG_2023_05_09_H
9+
#define PI_CALC_CFG_2023_05_09_H
10+
11+
//#define PI_CRUNCH_METAL_STANDALONE_MAIN
12+
//#define PI_CRUNCH_METAL_DISABLE_IOSTREAM
13+
14+
#define PI_CRUNCH_METAL_PI_SPIGOT_USE_100_DIGITS 100
15+
#define PI_CRUNCH_METAL_PI_SPIGOT_USE_1K_DIGITS 1000
16+
#define PI_CRUNCH_METAL_PI_SPIGOT_USE_10K_DIGITS 10000
17+
#define PI_CRUNCH_METAL_PI_SPIGOT_USE_100K_DIGITS 100000
18+
19+
#if !defined(PI_CRUNCH_METAL_PI_SPIGOT_DIGITS)
20+
#define PI_CRUNCH_METAL_PI_SPIGOT_DIGITS PI_CRUNCH_METAL_PI_SPIGOT_USE_10K_DIGITS
21+
#endif
22+
23+
#endif // PI_CALC_CFG_2023_05_09_H
Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
///////////////////////////////////////////////////////////////////
2+
// //
3+
// Copyright Iliass Mahjoub 2022. //
4+
// Copyright Christopher Kormanyos 2019 - 2025. //
5+
// Distributed under the Boost Software License, //
6+
// Version 1.0. (See accompanying file LICENSE_1_0.txt //
7+
// or copy at http://www.boost.org/LICENSE_1_0.txt) //
8+
// //
9+
///////////////////////////////////////////////////////////////////
10+
11+
// pi_spigot.cpp
12+
13+
// This program can be used to compute many thousands
14+
// of decimal digits of digits of pi. It uses a so-called
15+
// "spigot" algorithm having quadratic complexity.
16+
17+
// In this embedded software adaptation of this work,
18+
// we limit the decimal digit count to about 100k or fewer.
19+
20+
// cd /mnt/c/Users/ckorm/Documents/Ks/uC_Software/Boards/Osek_pi_crunch_cm3
21+
// ./Build.sh
22+
23+
// To build pi_spigot.cpp on LINUX host:
24+
// cd /mnt/c/Users/ckorm/Documents/Ks/uC_Software/Boards/Osek_pi_crunch_cm3
25+
// g++ -std=c++20 -Werror -Wall -Wextra -Wpedantic -O3 -DPI_CRUNCH_METAL_STANDALONE_MAIN -DPI_CRUNCH_METAL_PI_SPIGOT_DIGITS=10000 -I./Application/ref_app/src -I./Application ./Application/pi_spigot/pi_spigot.cpp -o pi_spigot.exe
26+
27+
#include <pi_calc_cfg.h>
28+
29+
#include <math/checksums/hash/hash_sha1.h>
30+
#include <math/pi_spigot/pi_spigot.h>
31+
#if !defined(PI_CRUNCH_METAL_STANDALONE_MAIN)
32+
#include <mcal_benchmark.h>
33+
#include <mcal_memory/mcal_memory_sram_array.h>
34+
#endif
35+
#include <util/utility/util_baselexical_cast.h>
36+
37+
#if !defined(PI_CRUNCH_METAL_DISABLE_IOSTREAM)
38+
#include <array>
39+
#include <chrono>
40+
#include <iomanip>
41+
#include <iostream>
42+
#include <sstream>
43+
#endif // !PI_CRUNCH_METAL_DISABLE_IOSTREAM
44+
45+
namespace local
46+
{
47+
#if defined(PI_CRUNCH_METAL_PI_SPIGOT_DIGITS)
48+
#if (PI_CRUNCH_METAL_PI_SPIGOT_DIGITS == PI_CRUNCH_METAL_PI_SPIGOT_USE_100_DIGITS)
49+
constexpr auto result_digit = static_cast<std::uint32_t>(UINT32_C(101));
50+
#elif (PI_CRUNCH_METAL_PI_SPIGOT_DIGITS == PI_CRUNCH_METAL_PI_SPIGOT_USE_1K_DIGITS)
51+
constexpr auto result_digit = static_cast<std::uint32_t>(UINT32_C(1001));
52+
#elif (PI_CRUNCH_METAL_PI_SPIGOT_DIGITS == PI_CRUNCH_METAL_PI_SPIGOT_USE_10K_DIGITS)
53+
constexpr auto result_digit = static_cast<std::uint32_t>(UINT32_C(10001));
54+
#elif (PI_CRUNCH_METAL_PI_SPIGOT_DIGITS == PI_CRUNCH_METAL_PI_SPIGOT_USE_100K_DIGITS)
55+
constexpr auto result_digit = static_cast<std::uint32_t>(UINT32_C(100001));
56+
#endif
57+
#else
58+
#error Error: Please define PI_CRUNCH_METAL_PI_SPIGOT_DIGITS
59+
#endif
60+
61+
constexpr auto loop_digit = static_cast<std::uint32_t>(UINT8_C(9));
62+
63+
using pi_spigot_type = math::constants::pi_spigot<result_digit, loop_digit>;
64+
65+
pi_spigot_type pi_spigot_instance;
66+
67+
using hash_type = math::checksums::hash::hash_sha1;
68+
69+
hash_type pi_spigot_hash;
70+
71+
auto pi_output_digits10 = static_cast<std::uint32_t>(UINT8_C(0));
72+
73+
#if !defined(PI_CRUNCH_METAL_STANDALONE_MAIN)
74+
using benchmark_port_type = ::mcal::benchmark::benchmark_port_type;
75+
#endif
76+
77+
#if defined(PI_CRUNCH_METAL_STANDALONE_MAIN)
78+
using mcal_sram_uintptr_t = std::uintptr_t;
79+
#endif
80+
81+
constexpr auto pi_spigot_input_start_address = static_cast<mcal_sram_uintptr_t>(UINT8_C(0));
82+
83+
#if !defined(PI_CRUNCH_METAL_DISABLE_IOSTREAM)
84+
using pi_spigot_input_container_type = std::array<std::uint32_t,
85+
pi_spigot_type::input_static_size>;
86+
#else
87+
using pi_spigot_input_container_type = mcal::memory::sram::array<std::uint32_t,
88+
pi_spigot_type::input_static_size,
89+
pi_spigot_input_start_address>;
90+
#endif
91+
92+
pi_spigot_input_container_type pi_spigot_input;
93+
} // namespace local
94+
95+
extern "C"
96+
{
97+
auto mcal_led_toggle() -> void;
98+
99+
auto pi_main() -> int;
100+
101+
auto pi_led_toggle() -> void;
102+
}
103+
104+
extern "C"
105+
auto pi_led_toggle() -> void
106+
{
107+
::mcal_led_toggle();
108+
}
109+
110+
extern auto pi_lcd_progress(const std::uint32_t pi_output_digits10) -> void;
111+
extern auto pi_count_of_calculations() -> std::uint32_t&;
112+
113+
auto pi_main() -> int
114+
{
115+
#if !defined(PI_CRUNCH_METAL_STANDALONE_MAIN)
116+
local::benchmark_port_type::toggle_pin();
117+
#endif
118+
119+
local::pi_spigot_instance.calculate(local::pi_spigot_input.data(), pi_lcd_progress, &local::pi_spigot_hash);
120+
121+
++pi_count_of_calculations();
122+
123+
// Check the hash result of the pi calculation.
124+
const auto hash_control =
125+
typename local::hash_type::result_type
126+
#if (PI_CRUNCH_METAL_PI_SPIGOT_DIGITS == PI_CRUNCH_METAL_PI_SPIGOT_USE_100_DIGITS)
127+
{
128+
0x93U, 0xF1U, 0xB4U, 0xEAU, 0xABU, 0xCBU, 0xC9U, 0xB9U,
129+
0x0CU, 0x93U, 0x93U, 0x24U, 0xF7U, 0x85U, 0x13U, 0x2EU,
130+
0xDFU, 0x3BU, 0xF2U, 0x01U
131+
};
132+
#elif (PI_CRUNCH_METAL_PI_SPIGOT_DIGITS == PI_CRUNCH_METAL_PI_SPIGOT_USE_1K_DIGITS)
133+
{
134+
0xA0U, 0x92U, 0x47U, 0x1FU, 0xD5U, 0xFEU, 0x41U, 0x51U,
135+
0x20U, 0xE7U, 0xDDU, 0x18U, 0x5BU, 0x93U, 0x0DU, 0x05U,
136+
0x3AU, 0x86U, 0xF1U, 0x7EU
137+
};
138+
#elif (PI_CRUNCH_METAL_PI_SPIGOT_DIGITS == PI_CRUNCH_METAL_PI_SPIGOT_USE_10K_DIGITS)
139+
{
140+
// 10001: 4BDF69A5FF25B9BED6BA9802BD2A68306FAB71EC
141+
0x4BU, 0xDFU, 0x69U, 0xA5U, 0xFFU, 0x25U, 0xB9U, 0xBEU,
142+
0xD6U, 0xBAU, 0x98U, 0x02U, 0xBDU, 0x2AU, 0x68U, 0x30U,
143+
0x6FU, 0xABU, 0x71U, 0xECU
144+
};
145+
#elif (PI_CRUNCH_METAL_PI_SPIGOT_DIGITS == PI_CRUNCH_METAL_PI_SPIGOT_USE_100K_DIGITS)
146+
{
147+
// 100001: D9D56240EB6B626A8FE179E3054D332F1767071D
148+
0xD9U, 0xD5U, 0x62U, 0x40U, 0xEBU, 0x6BU, 0x62U, 0x6AU,
149+
0x8FU, 0xE1U, 0x79U, 0xE3U, 0x05U, 0x4DU, 0x33U, 0x2FU,
150+
0x17U, 0x67U, 0x07U, 0x1DU
151+
};
152+
#endif
153+
154+
using local_hash_type = local::hash_type;
155+
using local_hash_result_type = typename local_hash_type::result_type;
156+
157+
local_hash_result_type hash_result { };
158+
159+
local::pi_spigot_hash.get_result(hash_result.data());
160+
161+
const bool result_is_ok { std::equal(hash_result.cbegin(), hash_result.cend(), hash_control.cbegin()) };
162+
163+
const int result_of_pi_main { (result_is_ok ? static_cast<int>(INT8_C(0)) : static_cast<int>(INT8_C(-1))) };
164+
165+
return result_of_pi_main;
166+
}
167+
168+
#if defined(PI_CRUNCH_METAL_STANDALONE_MAIN)
169+
170+
auto pi_count_of_calculations() -> std::uint32_t&;
171+
auto pi_lcd_progress(const std::uint32_t pi_output_digits10) -> void;
172+
173+
auto pi_count_of_calculations() -> std::uint32_t&
174+
{
175+
static std::uint32_t my_count { };
176+
177+
return my_count;
178+
}
179+
180+
auto pi_lcd_progress(const std::uint32_t pi_output_digits10) -> void { static_cast<void>(pi_output_digits10); }
181+
182+
extern "C"
183+
{
184+
auto mcal_init () -> void;
185+
auto mcal_led_toggle() -> void;
186+
187+
auto mcal_init () -> void { }
188+
auto mcal_led_toggle() -> void { }
189+
}
190+
191+
auto main() -> int
192+
{
193+
::mcal_init();
194+
195+
#if !defined(PI_CRUNCH_METAL_DISABLE_IOSTREAM)
196+
std::stringstream strm { };
197+
198+
strm << "Begin pi spigot calculation...\n";
199+
200+
const auto start = std::chrono::high_resolution_clock::now();
201+
#endif
202+
203+
const int result_pi_main { ::pi_main() };
204+
205+
const bool result_is_ok { (result_pi_main == 0) };
206+
207+
#if !defined(PI_CRUNCH_METAL_DISABLE_IOSTREAM)
208+
209+
const auto stop = std::chrono::high_resolution_clock::now();
210+
211+
const float
212+
elapsed
213+
{
214+
static_cast<float>
215+
(
216+
static_cast<float>(std::chrono::duration_cast<std::chrono::milliseconds>(stop - start).count())
217+
/ 1000.0F
218+
)
219+
};
220+
221+
strm << "digits10: " << local::pi_spigot_type::result_digit() << '\n'
222+
<< "time: " << std::fixed << std::setprecision(2) << elapsed << "s\n"
223+
<< "result_is_ok: " << std::boolalpha << result_is_ok;
224+
225+
std::cout << strm.str() << std::endl;
226+
#endif
227+
228+
const int result_of_main { (result_is_ok ? static_cast<int>(INT8_C(0)) : static_cast<int>(INT8_C(-1))) };
229+
230+
return result_of_main;
231+
}
232+
233+
#else
234+
235+
auto pi_calc_dummy() -> void;
236+
237+
auto pi_calc_dummy() -> void { }
238+
239+
#endif
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
///////////////////////////////////////////////////////////////////
2+
// //
3+
// Copyright Christopher Kormanyos 2025. //
4+
// Distributed under the Boost Software License, //
5+
// Version 1.0. (See accompanying file LICENSE_1_0.txt //
6+
// or copy at http://www.boost.org/LICENSE_1_0.txt) //
7+
// //
8+
///////////////////////////////////////////////////////////////////
9+
10+
//#include <mcal_lcd.h>
11+
#include <util/utility/util_baselexical_cast.h>
12+
13+
#include <cstdint>
14+
15+
auto pi_count_of_calculations() -> std::uint32_t&;
16+
17+
auto pi_count_of_calculations() -> std::uint32_t&
18+
{
19+
static std::uint32_t my_count { };
20+
21+
return my_count;
22+
}
23+
24+
auto pi_lcd_progress(const std::uint32_t pi_output_digits10) -> void;
25+
26+
auto pi_lcd_progress(const std::uint32_t pi_output_digits10) -> void
27+
{
28+
#if 0
29+
char p_str[std::size_t { UINT8_C(20) }];
30+
31+
{
32+
std::fill(p_str, p_str + sizeof(p_str), char { INT8_C(0) });
33+
34+
const char* p_end { util::baselexical_cast(pi_output_digits10, p_str, p_str + sizeof(p_str)) };
35+
36+
::mcal_lcd_write_line(p_str, static_cast<std::size_t>(p_end - p_str), std::size_t { UINT8_C(0) });
37+
}
38+
39+
{
40+
std::fill(p_str, p_str + sizeof(p_str), char { INT8_C(0) });
41+
42+
const char* p_end = util::baselexical_cast(pi_count_of_calculations(), p_str, p_str + sizeof(p_str));
43+
44+
::mcal_lcd_write_line(p_str, static_cast<std::size_t>(p_end - p_str), std::size_t { UINT8_C(1) });
45+
}
46+
#else
47+
static_cast<void>(pi_output_digits10);
48+
#endif
49+
}

0 commit comments

Comments
 (0)