Skip to content

Commit 0ffee2b

Browse files
committed
Get both target and host working
1 parent 44466d1 commit 0ffee2b

26 files changed

Lines changed: 404 additions & 68 deletions

examples/chapter11_07a/chapter11_07a.vcxproj

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@
5555
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
5656
</PropertyGroup>
5757
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
58-
<IncludePath>$(SolutionDir)src;$(SolutionDir)src/mcal/host;$(SolutionDir)src/os/FreeRTOS/Source/include/cfg/WIN32-MSVC-Static-Allocation-Only;$(SolutionDir)src/os/FreeRTOS/Source/portable/MSVC-MingW;$(SolutionDir)src/os/FreeRTOS/Source/include;$(IncludePath)</IncludePath>
58+
<IncludePath>$(SolutionDir)src/app;$(SolutionDir)src;$(SolutionDir)src/mcal/host;$(SolutionDir)src/os/FreeRTOS/Source/include/cfg/WIN32-MSVC-Static-Allocation-Only;$(SolutionDir)src/os/FreeRTOS/Source/portable/MSVC-MingW;$(SolutionDir)src/os/FreeRTOS/Source/include;$(IncludePath)</IncludePath>
5959
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
6060
<IntDir>$(Configuration)\</IntDir>
6161
</PropertyGroup>
6262
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
63-
<IncludePath>$(SolutionDir)src;$(SolutionDir)src/mcal/host;$(SolutionDir)src/os/FreeRTOS/Source/include/cfg/WIN32-MSVC-Static-Allocation-Only;$(SolutionDir)src/os/FreeRTOS/Source/portable/MSVC-MingW;$(SolutionDir)src/os/FreeRTOS/Source/include;$(IncludePath)</IncludePath>
63+
<IncludePath>$(SolutionDir)src/app;$(SolutionDir)src;$(SolutionDir)src/mcal/host;$(SolutionDir)src/os/FreeRTOS/Source/include/cfg/WIN32-MSVC-Static-Allocation-Only;$(SolutionDir)src/os/FreeRTOS/Source/portable/MSVC-MingW;$(SolutionDir)src/os/FreeRTOS/Source/include;$(IncludePath)</IncludePath>
6464
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
6565
<IntDir>$(Configuration)\</IntDir>
6666
</PropertyGroup>
@@ -177,6 +177,10 @@
177177
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
178178
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
179179
</ClCompile>
180+
<ClCompile Include="src\mcal\avr\mcal_dev.cpp">
181+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
182+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
183+
</ClCompile>
180184
<ClCompile Include="src\mcal\avr\mcal_gpt.cpp">
181185
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
182186
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
@@ -211,7 +215,9 @@
211215
</ClCompile>
212216
<ClCompile Include="src\mcal\host\mcal_gpt.cpp" />
213217
<ClCompile Include="src\mcal\host\mcal_irq.cpp" />
218+
<ClCompile Include="src\mcal\host\mcal_lcd.cpp" />
214219
<ClCompile Include="src\mcal\host\mcal_led.cpp" />
220+
<ClCompile Include="src\mcal\host\mcal_memory_sram.cpp" />
215221
<ClCompile Include="src\mcal\host\mcal_wdg.cpp" />
216222
<ClCompile Include="src\mcal\host\mcal_wdg_watchdog.cpp" />
217223
<ClCompile Include="src\mcal\mcal.cpp" />
@@ -264,6 +270,10 @@
264270
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
265271
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
266272
</ClInclude>
273+
<ClInclude Include="src\mcal\avr\mcal_dev.h">
274+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
275+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
276+
</ClInclude>
267277
<ClInclude Include="src\mcal\avr\mcal_gpt.h">
268278
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
269279
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
@@ -312,11 +322,15 @@
312322
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
313323
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
314324
</ClInclude>
325+
<ClInclude Include="src\mcal\host\mcal_benchmark.h" />
315326
<ClInclude Include="src\mcal\host\mcal_cpu.h" />
327+
<ClInclude Include="src\mcal\host\mcal_dev.h" />
316328
<ClInclude Include="src\mcal\host\mcal_gpt.h" />
317329
<ClInclude Include="src\mcal\host\mcal_irq.h" />
330+
<ClInclude Include="src\mcal\host\mcal_lcd.h" />
318331
<ClInclude Include="src\mcal\host\mcal_led.h" />
319332
<ClInclude Include="src\mcal\host\mcal_memory_progmem.h" />
333+
<ClInclude Include="src\mcal\host\mcal_memory_sram.h" />
320334
<ClInclude Include="src\mcal\host\mcal_port.h" />
321335
<ClInclude Include="src\mcal\host\mcal_reg_access.h" />
322336
<ClInclude Include="src\mcal\host\mcal_wdg.h" />
@@ -345,6 +359,14 @@
345359
<ClInclude Include="src\mcal_memory\mcal_memory_progmem_iterator.h" />
346360
<ClInclude Include="src\mcal_memory\mcal_memory_progmem_ptr.h" />
347361
<ClInclude Include="src\mcal_memory\mcal_memory_progmem_ref.h" />
362+
<ClInclude Include="src\mcal_memory\mcal_memory_sram_access.h" />
363+
<ClInclude Include="src\mcal_memory\mcal_memory_sram_array.h" />
364+
<ClInclude Include="src\mcal_memory\mcal_memory_sram_generic_host.h" />
365+
<ClInclude Include="src\mcal_memory\mcal_memory_sram_generic_spi.h" />
366+
<ClInclude Include="src\mcal_memory\mcal_memory_sram_ptr.h" />
367+
<ClInclude Include="src\mcal_memory\mcal_memory_sram_ref.h" />
368+
<ClInclude Include="src\mcal_memory\mcal_memory_sram_types.h" />
369+
<ClInclude Include="src\mcal_memory\mcal_memroy_sram_iterator.h" />
348370
<ClInclude Include="src\mcal_spi\mcal_spi_software_dummy.h" />
349371
<ClInclude Include="src\mcal_spi\mcal_spi_software_port_driver.h" />
350372
<ClInclude Include="src\os\FreeRTOS\Source\include\atomic.h" />

examples/chapter11_07a/chapter11_07a.vcxproj.filters

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,15 @@
210210
<ClCompile Include="src\mcal\avr\mcal_lcd.cpp">
211211
<Filter>src\mcal\avr</Filter>
212212
</ClCompile>
213+
<ClCompile Include="src\mcal\host\mcal_lcd.cpp">
214+
<Filter>src\mcal\host</Filter>
215+
</ClCompile>
216+
<ClCompile Include="src\mcal\host\mcal_memory_sram.cpp">
217+
<Filter>src\mcal\host</Filter>
218+
</ClCompile>
219+
<ClCompile Include="src\mcal\avr\mcal_dev.cpp">
220+
<Filter>src\mcal\avr</Filter>
221+
</ClCompile>
213222
</ItemGroup>
214223
<ItemGroup>
215224
<ClInclude Include="src\mcal\mcal.h">
@@ -530,6 +539,45 @@
530539
<ClInclude Include="src\mcal\mcal_helper.h">
531540
<Filter>src\mcal</Filter>
532541
</ClInclude>
542+
<ClInclude Include="src\mcal\host\mcal_lcd.h">
543+
<Filter>src\mcal\host</Filter>
544+
</ClInclude>
545+
<ClInclude Include="src\mcal\host\mcal_benchmark.h">
546+
<Filter>src\mcal\host</Filter>
547+
</ClInclude>
548+
<ClInclude Include="src\mcal_memory\mcal_memory_sram_access.h">
549+
<Filter>src\mcal_memory</Filter>
550+
</ClInclude>
551+
<ClInclude Include="src\mcal_memory\mcal_memory_sram_array.h">
552+
<Filter>src\mcal_memory</Filter>
553+
</ClInclude>
554+
<ClInclude Include="src\mcal_memory\mcal_memory_sram_generic_spi.h">
555+
<Filter>src\mcal_memory</Filter>
556+
</ClInclude>
557+
<ClInclude Include="src\mcal_memory\mcal_memory_sram_ptr.h">
558+
<Filter>src\mcal_memory</Filter>
559+
</ClInclude>
560+
<ClInclude Include="src\mcal_memory\mcal_memory_sram_ref.h">
561+
<Filter>src\mcal_memory</Filter>
562+
</ClInclude>
563+
<ClInclude Include="src\mcal_memory\mcal_memory_sram_types.h">
564+
<Filter>src\mcal_memory</Filter>
565+
</ClInclude>
566+
<ClInclude Include="src\mcal_memory\mcal_memroy_sram_iterator.h">
567+
<Filter>src\mcal_memory</Filter>
568+
</ClInclude>
569+
<ClInclude Include="src\mcal\host\mcal_memory_sram.h">
570+
<Filter>src\mcal\host</Filter>
571+
</ClInclude>
572+
<ClInclude Include="src\mcal_memory\mcal_memory_sram_generic_host.h">
573+
<Filter>src\mcal_memory</Filter>
574+
</ClInclude>
575+
<ClInclude Include="src\mcal\avr\mcal_dev.h">
576+
<Filter>src\mcal\avr</Filter>
577+
</ClInclude>
578+
<ClInclude Include="src\mcal\host\mcal_dev.h">
579+
<Filter>src\mcal\host</Filter>
580+
</ClInclude>
533581
</ItemGroup>
534582
<ItemGroup>
535583
<None Include="src\util\STL_C++XX_stdfloat\cstdfloat">

examples/chapter11_07a/src/app/led/app_led.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,10 @@
1212
#include <os/os_task.h>
1313
#include <util/utility/util_time.h>
1414

15-
namespace
15+
namespace local
1616
{
17-
using app_led_timer_type = util::timer<std::uint32_t>;
18-
using app_led_tick_type = typename app_led_timer_type::tick_type;
19-
20-
app_led_timer_type app_led_timer_background;
21-
app_led_timer_type app_led_timer_toggle_led0;
22-
2317
bool result_pi_calc_is_ok { true };
24-
}
18+
} // namespace local
2519

2620
extern "C"
2721
auto pi_main() -> int;
@@ -38,9 +32,9 @@ void app_led_task_background(void*)
3832
{
3933
const int next_pi_result { pi_main() };
4034

41-
result_pi_calc_is_ok = ((next_pi_result == int { INT8_C(0) }) && result_pi_calc_is_ok);
35+
local::result_pi_calc_is_ok = ((next_pi_result == int { INT8_C(0) }) && local::result_pi_calc_is_ok);
4236

43-
if(!result_pi_calc_is_ok)
37+
if(!local::result_pi_calc_is_ok)
4438
{
4539
// If the pi calculation is wrong, exercise a hard, visible error
4640
// that stops the perpetual calculation loop.
@@ -69,8 +63,21 @@ void app_led_task_toggle_led0(void*)
6963
// thread scheduler supports preemptive scheduling and emulates
7064
// the desired timing quite well.
7165

66+
using app_led_timer_type = util::timer<std::uint32_t>;
67+
using app_led_tick_type = typename app_led_timer_type::tick_type;
68+
69+
app_led_timer_type app_led_timer_toggle_led0 { app_led_timer_type::seconds(app_led_tick_type { UINT8_C(1) }) };
70+
71+
auto& local_led0 { mcal::led::led0() };
72+
73+
local_led0.toggle();
74+
7275
for(;;)
7376
{
77+
// This application task is programmed to cyclically yield for 125ms.
78+
79+
OS_TASK_WAIT_YIELD(TickType_t { UINT8_C(125) });
80+
7481
mcal::wdg::secure::trigger();
7582

7683
// Toggle led0 every 1s.
@@ -79,11 +86,7 @@ void app_led_task_toggle_led0(void*)
7986
{
8087
app_led_timer_toggle_led0.start_interval(app_led_timer_type::seconds(app_led_tick_type { UINT8_C(1) }));
8188

82-
mcal::led::led0().toggle();
89+
local_led0.toggle();
8390
}
84-
85-
// This application task is programmed to cyclically yield for 125ms.
86-
87-
OS_TASK_WAIT_YIELD(TickType_t { UINT8_C(125) });
8891
}
8992
}

examples/chapter11_07a/src/app/pi_calc_cfg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define PI_CRUNCH_METAL_PI_SPIGOT_USE_100K_DIGITS 100000
2020

2121
#if !defined(PI_CRUNCH_METAL_PI_SPIGOT_DIGITS)
22-
#define PI_CRUNCH_METAL_PI_SPIGOT_DIGITS PI_CRUNCH_METAL_PI_SPIGOT_USE_1K_DIGITS
22+
#define PI_CRUNCH_METAL_PI_SPIGOT_DIGITS PI_CRUNCH_METAL_PI_SPIGOT_USE_10K_DIGITS
2323
#endif
2424

2525
#endif // PI_CALC_CFG_2023_05_09_H

examples/chapter11_07a/src/app/pi_spigot/pi_spigot.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,14 @@ namespace local
6262

6363
using pi_spigot_type = math::constants::pi_spigot<result_digit, loop_digit>;
6464

65-
pi_spigot_type pi_spigot_instance;
65+
auto pi_spigot_instance() -> pi_spigot_type&;
66+
67+
auto pi_spigot_instance() -> pi_spigot_type&
68+
{
69+
static pi_spigot_type instance { };
70+
71+
return instance;
72+
}
6673

6774
using hash_type = math::checksums::hash::hash_sha1;
6875

@@ -102,7 +109,9 @@ auto pi_main() -> int
102109
{
103110
local::benchmark_port_type::toggle_pin();
104111

105-
local::pi_spigot_instance.calculate(local::pi_spigot_input.data(), pi_lcd_progress, &local::pi_spigot_hash);
112+
auto& local_pi_spigot_instance { local::pi_spigot_instance() };
113+
114+
local_pi_spigot_instance.calculate(local::pi_spigot_input.data(), pi_lcd_progress, &local::pi_spigot_hash);
106115

107116
++pi_count_of_calculations();
108117

examples/chapter11_07a/src/app/pi_spigot/pi_spigot_callback.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
///////////////////////////////////////////////////////////////////
22
// //
3-
// Copyright Christopher Kormanyos 2025. //
3+
// Copyright Christopher Kormanyos 2023 - 2025. //
44
// Distributed under the Boost Software License, //
55
// Version 1.0. (See accompanying file LICENSE_1_0.txt //
66
// or copy at http://www.boost.org/LICENSE_1_0.txt) //

examples/chapter11_07a/src/mcal/avr/mcal_cpu.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
{
1717
void init();
1818

19-
inline auto post_init() -> void { }
20-
2119
inline auto nop() -> void { asm volatile("nop"); }
2220
}
2321
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// Copyright Christopher Kormanyos 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+
#include <mcal_benchmark.h>
9+
#include <mcal_dev.h>
10+
#include <mcal_memory/mcal_memory_sram_array.h>
11+
12+
auto mcal::dev::post_init() -> void
13+
{
14+
using benchmark_port_type = ::mcal::benchmark::benchmark_port_type;
15+
16+
benchmark_port_type::set_direction_output();
17+
18+
mcal::spi::sram::mcal_spi_sram_type::init();
19+
mcal::spi::lcd::mcal_spi_lcd_type::init();
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// Copyright Christopher Kormanyos 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 MCAL_DEV_2025_12_14_H
9+
#define MCAL_DEV_2025_12_14_H
10+
11+
#include <cstdint>
12+
13+
namespace mcal
14+
{
15+
namespace dev
16+
{
17+
auto post_init() -> void;
18+
}
19+
}
20+
21+
#endif // MCAL_DEV_2025_12_14_H

examples/chapter11_07a/src/mcal/avr/mcal_lcd.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Iliass Mahjoub 2023 - 2024
3-
// Copyright Christopher Kormanyos 2024
2+
// Copyright Iliass Mahjoub 2023 - 2025
3+
// Copyright Christopher Kormanyos 2024 - 2025
44
// Distributed under the Boost Software License,
55
// Version 1.0. (See accompanying file LICENSE_1_0.txt
66
// or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -16,7 +16,7 @@ namespace local_lcd
1616

1717
auto lcd_sparkfun() -> mcal::lcd::lcd_base&
1818
{
19-
static mcal::lcd::lcd_serlcd_sparkfun<mcal::spi::lcd::mcal_spi_lcd_type> my_lcd;
19+
static mcal::lcd::lcd_serlcd_sparkfun<mcal::spi::lcd::mcal_spi_lcd_type> my_lcd { };
2020

2121
return my_lcd;
2222
}

0 commit comments

Comments
 (0)