-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathmain.cpp
More file actions
86 lines (74 loc) · 2.08 KB
/
main.cpp
File metadata and controls
86 lines (74 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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;
}