From e069f18842aaf62f01853530620a87bc97435026 Mon Sep 17 00:00:00 2001 From: Khalil Estell Date: Tue, 6 Aug 2024 14:19:15 -0700 Subject: [PATCH] :art: Upgrade to bootstrap-4.0.0 --- conanfile.py | 2 +- demos/CMakeLists.txt | 3 +++ demos/applications/__device__.cpp | 6 ++--- demos/conanfile.py | 2 +- demos/main.cpp | 44 ++++++++++++++++++++++--------- demos/platforms/lpc4078.cpp | 4 +-- demos/platforms/micromod.cpp | 31 ++++++++++++++++++++++ demos/platforms/stm32f103c8.cpp | 6 ++--- demos/resource_list.hpp | 8 +++--- test_package/conanfile.py | 2 +- 10 files changed, 82 insertions(+), 26 deletions(-) create mode 100644 demos/platforms/micromod.cpp diff --git a/conanfile.py b/conanfile.py index afb49a4..9efc429 100644 --- a/conanfile.py +++ b/conanfile.py @@ -26,7 +26,7 @@ class libhal___device___conan(ConanFile): topics = ("__device__", "libhal", "driver") settings = "compiler", "build_type", "os", "arch" - python_requires = "libhal-bootstrap/[^3.0.0]" + python_requires = "libhal-bootstrap/[^4.0.0]" python_requires_extend = "libhal-bootstrap.library" def requirements(self): diff --git a/demos/CMakeLists.txt b/demos/CMakeLists.txt index f01d4f4..462fd3e 100644 --- a/demos/CMakeLists.txt +++ b/demos/CMakeLists.txt @@ -20,6 +20,9 @@ libhal_build_demos( DEMOS __device__ + INCLUDES + . + PACKAGES libhal-__device__ diff --git a/demos/applications/__device__.cpp b/demos/applications/__device__.cpp index 5b0374b..f6529cd 100644 --- a/demos/applications/__device__.cpp +++ b/demos/applications/__device__.cpp @@ -22,9 +22,9 @@ void application(resource_list& p_map) using namespace std::chrono_literals; using namespace hal::literals; - auto& clock = *p_map.clock; - auto& console = *p_map.console; - auto& led = *p_map.led; + auto& clock = *p_map.clock.value(); + auto& console = *p_map.console.value(); + auto& led = *p_map.status_led.value(); hal::print(console, "Demo Application Starting...\n\n"); diff --git a/demos/conanfile.py b/demos/conanfile.py index 785140b..11cd04f 100644 --- a/demos/conanfile.py +++ b/demos/conanfile.py @@ -15,7 +15,7 @@ class demos(ConanFile): - python_requires = "libhal-bootstrap/[^3.0.0]" + python_requires = "libhal-bootstrap/[^4.0.0]" python_requires_extend = "libhal-bootstrap.demo" def requirements(self): diff --git a/demos/main.cpp b/demos/main.cpp index 4e1620b..3f761a1 100644 --- a/demos/main.cpp +++ b/demos/main.cpp @@ -13,21 +13,31 @@ // limitations under the License. #include +#include #include #include -#include "resource_list.hpp" +#include resource_list resources{}; [[noreturn]] void terminate_handler() noexcept { - using namespace std::chrono_literals; - auto& led = *resources.led; - auto& clock = *resources.clock; + if (not resources.status_led && not resources.console) { + // spin here until debugger is connected + while (true) { + continue; + } + } + + // Otherwise, blink the led in a pattern + + auto& led = *resources.status_led.value(); + auto& clock = *resources.clock.value(); while (true) { + using namespace std::chrono_literals; led.level(false); hal::delay(clock, 100ms); led.level(true); @@ -41,17 +51,27 @@ resource_list resources{}; int main() { - // Set terminate routine... - hal::set_terminate(terminate_handler); - try { resources = initialize_platform(); } catch (...) { - // Catch all exceptions preventing terminate from - hal::halt(); + while (true) { + // halt here and wait for a debugger to connect + continue; + } } - application(resources); - resources.reset(); - return 0; + hal::set_terminate(terminate_handler); + + try { + application(resources); + } catch (std::bad_optional_access const& e) { + if (resources.console) { + hal::print(*resources.console.value(), + "A resource required by the application was not available!\n" + "Calling terminate!\n"); + } + } // Allow any other exceptions to terminate the application + + // Terminate if the code reaches this point. + std::terminate(); } diff --git a/demos/platforms/lpc4078.cpp b/demos/platforms/lpc4078.cpp index 720e96b..46770f8 100644 --- a/demos/platforms/lpc4078.cpp +++ b/demos/platforms/lpc4078.cpp @@ -45,9 +45,9 @@ resource_list initialize_platform() static hal::lpc40::output_pin led(1, 10); return { + .reset = []() { hal::cortex_m::reset(); }, .console = &uart0, .clock = &counter, - .led = &led, - .reset = []() { hal::cortex_m::reset(); }, + .status_led = &led, }; } diff --git a/demos/platforms/micromod.cpp b/demos/platforms/micromod.cpp new file mode 100644 index 0000000..eb2b70e --- /dev/null +++ b/demos/platforms/micromod.cpp @@ -0,0 +1,31 @@ +// Copyright 2024 Khalil Estell +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include + +resource_list initialize_platform() +{ + using namespace hal::literals; + + hal::micromod::v1::initialize_platform(); + + return { + .reset = +[]() { hal::micromod::v1::reset(); }, + .console = &hal::micromod::v1::console(hal::buffer<128>), + .clock = &hal::micromod::v1::uptime_clock(), + .status_led = &hal::micromod::v1::led(), + }; +} diff --git a/demos/platforms/stm32f103c8.cpp b/demos/platforms/stm32f103c8.cpp index e8ab5a8..bd8f4ee 100644 --- a/demos/platforms/stm32f103c8.cpp +++ b/demos/platforms/stm32f103c8.cpp @@ -23,7 +23,7 @@ #include #include -#include "../resource_list.hpp" +#include resource_list initialize_platform() { @@ -44,9 +44,9 @@ resource_list initialize_platform() static hal::stm32f1::output_pin led('C', 13); return { + .reset = +[]() { hal::cortex_m::reset(); }, .console = &uart1, .clock = &counter, - .led = &led, - .reset = +[]() { hal::cortex_m::reset(); }, + .status_led = &led, }; } diff --git a/demos/resource_list.hpp b/demos/resource_list.hpp index 13b24f1..2800a9c 100644 --- a/demos/resource_list.hpp +++ b/demos/resource_list.hpp @@ -14,6 +14,8 @@ #pragma once +#include + #include #include #include @@ -21,10 +23,10 @@ struct resource_list { - hal::serial* console; - hal::steady_clock* clock; - hal::output_pin* led; hal::callback reset; + std::optional console; + std::optional clock; + std::optional status_led; // Add more driver interfaces here ... }; diff --git a/test_package/conanfile.py b/test_package/conanfile.py index 830b632..ad581a2 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -17,7 +17,7 @@ class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - python_requires = "libhal-bootstrap/[^2.0.0]" + python_requires = "libhal-bootstrap/[^4.0.0]" python_requires_extend = "libhal-bootstrap.library_test_package" def requirements(self):