Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor modm:processing to be std::chrono compatible #217

Merged
merged 4 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions examples/avr/adc/oversample/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

using namespace modm::platform;
using namespace modm::literals;
using namespace std::chrono_literals;

// Create a new UART object

Expand All @@ -32,7 +33,7 @@ typedef modm::AdcSampler< AdcInterrupt, 3, 32 > sensors;
// the results are up to 16 bit wide
sensors::DataType sensorData[3];

modm::ShortTimeout timeout(100);
modm::ShortTimeout timeout(100ms);

int
main()
Expand Down Expand Up @@ -67,7 +68,7 @@ main()

// start another readout
sensors::startReadout();
timeout.restart(200);
timeout.restart(200ms);
}
}
}
1 change: 0 additions & 1 deletion examples/avr/block_device_mirror/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <stdlib.h>

using namespace modm::platform;
typedef modm::platform::SystemClock clock;

// Create a new UART object and configure it to a baudrate of 115200
Uart0 uart;
Expand Down
19 changes: 3 additions & 16 deletions examples/avr/can/mcp2515_uart/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
// ----------------------------------------------------------------------------

#include <modm/platform.hpp>
#include <modm/architecture/interface/interrupt.hpp>

#include <modm/driver/can/mcp2515.hpp>
#include <modm/processing/timer.hpp>

using namespace modm::platform;
using namespace modm::literals;
using namespace std::chrono_literals;

typedef GpioOutputB0 LedGreen;
typedef GpioOutputB1 LedRed;
Expand Down Expand Up @@ -49,25 +48,13 @@ FLASH_STORAGE(uint8_t canFilter[]) =
MCP2515_FILTER_EXTENDED(0), // Mask 1
};

// timer interrupt routine
MODM_ISR(TIMER2_COMPA)
{
modm::Clock::increment();
}

int
main()
{
SystemClock::enable();
LedGreen::setOutput(modm::Gpio::High);
LedRed::setOutput(modm::Gpio::Low);

// timer initialization
// compare-match-interrupt every 1 ms at 14.7456 MHz
TCCR2A = (1 << WGM21);
TCCR2B = (1 << CS22);
TIMSK2 = (1 << OCIE2A);
OCR2A = 230;

Uart0::connect<GpioD1::Txd, GpioD0::Rxd>();
Uart0::initialize<SystemClock, 115200_Bd>();

Expand Down Expand Up @@ -99,7 +86,7 @@ main()

mcp2515.sendMessage(message);

modm::ShortPeriodicTimer timer(200);
modm::ShortPeriodicTimer timer(200ms);
while (true)
{
if (mcp2515.isMessageAvailable())
Expand Down
17 changes: 3 additions & 14 deletions examples/avr/display/dogm128/benchmark/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,11 @@ modm::DogM128< lcd::SPI, lcd::Cs, lcd::A0, lcd::Reset, true > display;

using namespace modm::glcd;

// timer interrupt routine
MODM_ISR(TIMER2_COMPA)
{
modm::Clock::increment();
}

void
setup()
{
SystemClock::enable();

led::R::set();
led::G::set();
led::B::reset();
Expand All @@ -67,13 +63,6 @@ setup()
lcd::SPI::connect<lcd::Sck::BitBang, lcd::Mosi::BitBang>();
lcd::SPI::initialize<SystemClock, 2_MHz>();

// timer initialization
// compare-match-interrupt every 1 ms at 14.7456 MHz
TCCR2A = (1 << WGM21);
TCCR2B = (1 << CS22);
TIMSK2 = (1 << OCIE2A);
OCR2A = 230;

// enable interrupts
enableInterrupts();

Expand Down Expand Up @@ -165,7 +154,7 @@ main()

display.setFont(modm::font::FixedWidth5x8);

modm::ShortPeriodicTimer timer(1000);
modm::ShortPeriodicTimer timer(1s);
while (true)
{
uint8_t iter = 0;
Expand Down
39 changes: 14 additions & 25 deletions examples/avr/protothread/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <modm/processing/timer.hpp>

using namespace modm::platform;
using namespace std::chrono_literals;

typedef GpioOutputB0 LedGreen;
typedef GpioOutputB1 LedRed;
Expand All @@ -37,13 +38,13 @@ class BlinkingLightGreen : public modm::pt::Protothread
{
LedGreen::set();

this->timeout.restart(100);
PT_WAIT_UNTIL(this->timeout.isExpired());
timeout.restart(100ms);
PT_WAIT_UNTIL(timeout.isExpired());

LedGreen::reset();

this->timeout.restart(600);
PT_WAIT_UNTIL(this->timeout.isExpired());
timeout.restart(600ms);
PT_WAIT_UNTIL(timeout.isExpired());
}

PT_END();
Expand All @@ -69,23 +70,23 @@ class BlinkingLightRed : public modm::pt::Protothread
{
LedRed::set();

this->timeout.restart(200);
PT_WAIT_UNTIL(this->timeout.isExpired());
timeout.restart(200ms);
PT_WAIT_UNTIL(timeout.isExpired());

LedRed::reset();

this->timeout.restart(300);
PT_WAIT_UNTIL(this->timeout.isExpired());
timeout.restart(300ms);
PT_WAIT_UNTIL(timeout.isExpired());

LedRed::set();

this->timeout.restart(200);
PT_WAIT_UNTIL(this->timeout.isExpired());
timeout.restart(200ms);
PT_WAIT_UNTIL(timeout.isExpired());

LedRed::reset();

this->timeout.restart(1000);
PT_WAIT_UNTIL(this->timeout.isExpired());
timeout.restart(1s);
PT_WAIT_UNTIL(timeout.isExpired());
}

PT_END();
Expand All @@ -95,22 +96,10 @@ class BlinkingLightRed : public modm::pt::Protothread
modm::ShortTimeout timeout;
};

// timer interrupt routine
MODM_ISR(TIMER2_COMPA)
{
modm::Clock::increment();
}

int
main()
{
// timeout initialization
// compare-match-interrupt every 1 ms at 14.7456 MHz
TCCR2A = (1 << WGM21);
TCCR2B = (1 << CS22);
TIMSK2 = (1 << OCIE2A);
OCR2A = 230;

SystemClock::enable();
enableInterrupts();

BlinkingLightGreen greenLight;
Expand Down
1 change: 1 addition & 0 deletions examples/avr/protothread/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</options>
<modules>
<module>modm:platform:core</module>
<module>modm:platform:clock</module>
<module>modm:platform:gpio</module>
<module>modm:processing:protothread</module>
<module>modm:processing:timer</module>
Expand Down
19 changes: 4 additions & 15 deletions examples/avr/timeout/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,31 @@
// ----------------------------------------------------------------------------

#include <modm/platform.hpp>
#include <modm/architecture/interface/interrupt.hpp>
#include <modm/processing/timer.hpp>

using namespace modm::platform;
using namespace std::chrono_literals;

// create a output device for the led
typedef GpioOutputB0 Led;

// timer interrupt routine
MODM_ISR(TIMER2_COMPA)
{
modm::Clock::increment();
}

int
main()
{
SystemClock::enable();
Led::setOutput();
Led::reset();

// timer initialization
// compare-match-interrupt every 1 ms at 14.7456 MHz
TCCR2A = (1 << WGM21);
TCCR2B = (1 << CS22);
TIMSK2 = (1 << OCIE2A);
OCR2A = 230;

// enable interrupts
enableInterrupts();

modm::ShortTimeout timeout(200);
modm::ShortTimeout timeout(200ms);
while (true)
{
if (timeout.isExpired())
{
timeout.restart(200);
timeout.restart(200ms);
Led::toggle();
}
}
Expand Down
1 change: 1 addition & 0 deletions examples/avr/timeout/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<modules>
<module>modm:architecture:interrupt</module>
<module>modm:platform:core</module>
<module>modm:platform:clock</module>
<module>modm:platform:gpio</module>
<module>modm:processing:timer</module>
<module>modm:build:scons</module>
Expand Down
58 changes: 58 additions & 0 deletions examples/avr/timer/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2020, 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/processing.hpp>

int main()
{
Board::initialize();

uint32_t counter(0);
modm::PrecisePeriodicTimer ptmr(0.500990s);
modm::PeriodicTimer tmr(0.500990s);

for (int ii=0; ii<20; ii++)
{
LedD13::toggle();
modm::delay(std::chrono::milliseconds(10*ii));
}

uint32_t ms_counter{0};
uint32_t us_counter{0};

while (true)
{
{
uint32_t ms = modm::Clock::now().time_since_epoch().count();
if (ms < ms_counter) {
MODM_LOG_ERROR << ms << " < " << ms_counter << modm::endl;
}
ms_counter = ms;
}{
uint32_t us = modm::PreciseClock::now().time_since_epoch().count();
if (us < us_counter) {
MODM_LOG_ERROR << us << " < " << us_counter << modm::endl;
}
us_counter = us;
}

if (ptmr.execute())
{
LedD13::set();
MODM_LOG_INFO << "loop: " << counter++ << modm::endl;
}
if (tmr.execute())
{
LedD13::reset();
}
}
}
12 changes: 12 additions & 0 deletions examples/avr/timer/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<library>
<extends>modm:arduino-nano</extends>
<options>
<option name="modm:build:build.path">../../../build/avr/timer</option>
</options>
<modules>
<module>modm:architecture:delay</module>
<module>modm:processing:timer</module>
<module>modm:build:scons</module>
<module>modm:build:cmake</module>
</modules>
</library>
39 changes: 0 additions & 39 deletions examples/avr/uart/basic_mega8/main.cpp

This file was deleted.

14 changes: 0 additions & 14 deletions examples/avr/uart/basic_mega8/project.xml

This file was deleted.

Loading