-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[example] Testing multicore clock on RP2040
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <modm/board.hpp> | ||
#include <modm/debug/logger.hpp> | ||
#include <modm/processing.hpp> | ||
#include <mutex> | ||
|
||
// Create an IODeviceWrapper around the Uart Peripheral we want to use | ||
modm::IODeviceWrapper<Uart0, modm::IOBuffer::BlockIfFull> 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<multicore::Mutex> g(log_mutex); | ||
MODM_LOG_ERROR << us << " < " << us_counter << modm::endl; | ||
} | ||
us_counter = us; | ||
|
||
if (tmr.execute()) | ||
{ | ||
Board::LedGreen::set(); | ||
std::lock_guard<multicore::Mutex> g(log_mutex); | ||
MODM_LOG_INFO << "loop: " << counter++ << modm::endl; | ||
} | ||
} | ||
} | ||
|
||
// ---------------------------------------------------------------------------- | ||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
Board::LedGreen::setOutput(); | ||
// initialize Uart0 for MODM_LOG_* | ||
Uart0::connect<GpioOutput0::Tx>(); | ||
Uart0::initialize<Board::SystemClock, 115200_Bd>(); | ||
|
||
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<multicore::Mutex> g(log_mutex); | ||
MODM_LOG_ERROR << us << " < " << us_counter << modm::endl; | ||
} | ||
us_counter = us; | ||
} | ||
|
||
if (tmr.execute()) | ||
{ | ||
Board::LedGreen::reset(); | ||
std::lock_guard<multicore::Mutex> g(log_mutex); | ||
MODM_LOG_INFO << "loop: " << counter++ << modm::endl; | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<library> | ||
<extends>modm:rp-pico</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/rp_pico/mcblink</option> | ||
</options> | ||
<modules> | ||
<module>modm:debug</module> | ||
<module>modm:processing:timer</module> | ||
<module>modm:platform:multicore</module> | ||
<module>modm:platform:uart:0</module> | ||
<module>modm:build:scons</module> | ||
</modules> | ||
</library> |