diff --git a/examples/rp_pico/mcblink/main.cpp b/examples/rp_pico/mcblink/main.cpp new file mode 100644 index 0000000000..3e18f46680 --- /dev/null +++ b/examples/rp_pico/mcblink/main.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2023, Niklas Hauser + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +// ---------------------------------------------------------------------------- + +#include +#include +#include +#include + +// Create an IODeviceWrapper around the Uart Peripheral we want to use +modm::IODeviceWrapper loggerDevice; +modm::log::Logger modm::log::info(loggerDevice); +modm::log::Logger modm::log::error(loggerDevice); + +multicore::Mutex log_mutex; +uint32_t counter{}; + +void +core1_main() +{ + modm::PrecisePeriodicTimer tmr(0.100990s); + uint32_t us_counter{}; + + while (true) + { + const uint32_t us = modm::PreciseClock::now().time_since_epoch().count(); + if (us < us_counter) + { + std::lock_guard g(log_mutex); + MODM_LOG_ERROR << us << " < " << us_counter << modm::endl; + } + us_counter = us; + + if (tmr.execute()) + { + Board::LedGreen::set(); + std::lock_guard g(log_mutex); + MODM_LOG_INFO << "loop: " << counter++ << modm::endl; + } + } +} + +// ---------------------------------------------------------------------------- +int +main() +{ + Board::initialize(); + Board::LedGreen::setOutput(); + // initialize Uart0 for MODM_LOG_* + Uart0::connect(); + Uart0::initialize(); + + multicore::Core1::run(core1_main); + + modm::PrecisePeriodicTimer tmr(0.1002284s); + uint32_t us_counter{}; + + while (true) + { + { + const uint32_t us = modm::PreciseClock::now().time_since_epoch().count(); + if (us < us_counter) + { + std::lock_guard g(log_mutex); + MODM_LOG_ERROR << us << " < " << us_counter << modm::endl; + } + us_counter = us; + } + + if (tmr.execute()) + { + Board::LedGreen::reset(); + std::lock_guard g(log_mutex); + MODM_LOG_INFO << "loop: " << counter++ << modm::endl; + } + } + + return 0; +} diff --git a/examples/rp_pico/mcblink/project.xml b/examples/rp_pico/mcblink/project.xml new file mode 100644 index 0000000000..63577e34c2 --- /dev/null +++ b/examples/rp_pico/mcblink/project.xml @@ -0,0 +1,13 @@ + + modm:rp-pico + + + + + modm:debug + modm:processing:timer + modm:platform:multicore + modm:platform:uart:0 + modm:build:scons + +