Skip to content

Commit

Permalink
[board] Implement modm_abandon for AVR boards
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Nov 10, 2024
1 parent d6a9872 commit 6b19ded
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 128 deletions.
8 changes: 4 additions & 4 deletions examples/arduino_nano/printf/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ main()
modm::PeriodicTimer heartbeat(1s);

// <option name="modm:io:with_long_long">yes</option>
serialStream << 32ull << modm::endl;
MODM_LOG_INFO << 32ull << modm::endl;

// <option name="modm:io:with_float">yes</option>
serialStream << 32.0f << modm::endl;
MODM_LOG_INFO << 32.0f << modm::endl;

// <option name="modm:io:with_printf">yes</option>
serialStream.printf("hello %lu %03.3f\n", 32ul, 32.23451);
MODM_LOG_INFO.printf("hello %lu %03.3f\n", 32ul, 32.23451);

uint8_t counter{0};
while (true)
{
if (heartbeat.execute())
{
serialStream << counter++ << modm::endl;
MODM_LOG_INFO << counter++ << modm::endl;
Board::LedD13::toggle();
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/arduino_uno/basic/analog_read_serial/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ main()
// read the input on analog pin 0
int sensorValue = Adc::readChannel(0);
// print analog readout
serialStream << sensorValue << modm::endl;
MODM_LOG_INFO << sensorValue << modm::endl;
}
}
2 changes: 1 addition & 1 deletion examples/arduino_uno/basic/digital_read_serial/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ main()
// read the input pin
bool buttonState = PushButton::read();
// print button state
serialStream << buttonState << modm::endl;
MODM_LOG_INFO << buttonState << modm::endl;
}
}
2 changes: 1 addition & 1 deletion examples/arduino_uno/basic/read_analog_voltage/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ main()
// convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print voltage
serialStream << voltage << "V" << modm::endl;
MODM_LOG_INFO << voltage << "V" << modm::endl;
}
}
35 changes: 5 additions & 30 deletions examples/avr/assert/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,13 @@

using modm::accessor::asFlash;

// Flash support on avr-gcc is so horribly broken.
#define IFS(s) asFlash(PSTR(s))

extern "C" void
modm_abandon(const modm::AssertionInfo &info)
{
serialStream << IFS("Assertion '") << asFlash(info.name) << '\'';
if (info.context != uintptr_t(-1))
serialStream << IFS(" @ ") << (void *)info.context << IFS(" (") << (uint32_t)info.context << IFS(")");
#if MODM_ASSERTION_INFO_HAS_DESCRIPTION
serialStream << IFS(" failed!\n ") << asFlash(info.description) << IFS("\nAbandoning...\n");
#else
serialStream << IFS(" failed!\nAbandoning...\n");
#endif

Leds::setOutput();
while (true) {
Leds::write(1);
modm::delay(20ms);
Leds::write(0);
modm::delay(180ms);
}
}


static modm::Abandonment
test_assertion_handler(const modm::AssertionInfo &info)
{
serialStream << IFS("#1: '") << asFlash(info.name) << IFS("'!") << modm::endl;
MODM_LOG_INFO << IFSS("#1: '") << asFlash(info.name) << IFSS("'!") << modm::endl;
// The strings are located in FLASH!!!
if (strncmp_P("io.", info.name, 3) == 0) {
serialStream << IFS("Ignoring assertion!") << modm::endl;
MODM_LOG_INFO << IFSS("Ignoring assertion!") << modm::endl;
return modm::Abandonment::Ignore;
}
return modm::Abandonment::DontCare;
Expand All @@ -55,15 +30,15 @@ MODM_ASSERTION_HANDLER(test_assertion_handler);
static modm::Abandonment
test_assertion_handler2(const modm::AssertionInfo &info)
{
serialStream << IFS("#2: '") << asFlash(info.name) << IFS("'!") << modm::endl;
MODM_LOG_INFO << IFSS("#2: '") << asFlash(info.name) << IFSS("'!") << modm::endl;
return modm::Abandonment::DontCare;
}
MODM_ASSERTION_HANDLER(test_assertion_handler2);

static modm::Abandonment
test_assertion_handler3(const modm::AssertionInfo &info)
{
serialStream << IFS("#3: '") << asFlash(info.name) << IFS("'!") << modm::endl;
MODM_LOG_INFO << IFSS("#3: '") << asFlash(info.name) << IFSS("'!") << modm::endl;
return modm::Abandonment::DontCare;
}
MODM_ASSERTION_HANDLER(test_assertion_handler3);
Expand All @@ -74,7 +49,7 @@ int main()
{
Board::initialize();
Leds::setOutput();
serialStream << IFS("Starting test...\n");
MODM_LOG_INFO << IFSS("Starting test...\n");

// only fails for debug builds, but is ignored anyways
modm_assert_continue_fail(false, "io.tx",
Expand Down
46 changes: 23 additions & 23 deletions examples/avr/ports/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ struct DebugGpioPort : public Port
static void dumpShifts()
{
for (int ii=0; ii<7; ii++) {
serialStream << char(ii+'A') << " {";
MODM_LOG_INFO << char(ii+'A') << " {";
for (int jj=0; jj<Port::width; jj++) {
const auto p = Port::shift_masks[ii][jj];
serialStream << " ";
if (p >= 0) { serialStream << p; }
else { serialStream << " "; }
serialStream << " ";
if (jj != Port::width - 1) { serialStream << ","; }
MODM_LOG_INFO << " ";
if (p >= 0) { MODM_LOG_INFO << p; }
else { MODM_LOG_INFO << " "; }
MODM_LOG_INFO << " ";
if (jj != Port::width - 1) { MODM_LOG_INFO << ","; }
}
serialStream << "}" << modm::endl;
MODM_LOG_INFO << "}" << modm::endl;
}
}

static void dumpMasks()
{
for (int ii=0; ii<7; ii++) {
serialStream << char(ii+'A') << " " << modm::bin << Port::mask(ii) << modm::endl;
MODM_LOG_INFO << char(ii+'A') << " " << modm::bin << Port::mask(ii) << modm::endl;
}
serialStream << modm::endl;
MODM_LOG_INFO << modm::endl;
for (int ii=0; ii<7; ii++) {
serialStream << char(ii+'A') << " " << modm::bin << Port::inverted(ii) << modm::endl;
MODM_LOG_INFO << char(ii+'A') << " " << modm::bin << Port::inverted(ii) << modm::endl;
}
}
};
Expand All @@ -64,23 +64,23 @@ int main()
static_assert(PinGroup3::number_of_ports == 1);
static_assert(PinGroup4::number_of_ports == 1);

DebugGpioPort<PinGroup>::dumpMasks(); serialStream << modm::endl;
DebugGpioPort<PinGroup2>::dumpMasks(); serialStream << modm::endl;
DebugGpioPort<PinGroup3>::dumpMasks(); serialStream << modm::endl;
DebugGpioPort<PinGroup4>::dumpMasks(); serialStream << modm::endl;
DebugGpioPort<PinGroup>::dumpMasks(); MODM_LOG_INFO << modm::endl;
DebugGpioPort<PinGroup2>::dumpMasks(); MODM_LOG_INFO << modm::endl;
DebugGpioPort<PinGroup3>::dumpMasks(); MODM_LOG_INFO << modm::endl;
DebugGpioPort<PinGroup4>::dumpMasks(); MODM_LOG_INFO << modm::endl;

DebugGpioPort<PinGroup>::dumpShifts(); serialStream << modm::endl;
DebugGpioPort<PinGroup2>::dumpShifts(); serialStream << modm::endl;
DebugGpioPort<PinGroup>::dumpShifts(); MODM_LOG_INFO << modm::endl;
DebugGpioPort<PinGroup2>::dumpShifts(); MODM_LOG_INFO << modm::endl;

PinGroup2::setInput(); serialStream << modm::bin << PinGroup2::read() << modm::endl;
PinGroup3::setInput(); serialStream << modm::bin << PinGroup3::read() << modm::endl;
PinGroup4::setInput(); serialStream << modm::bin << PinGroup4::read() << modm::endl;
serialStream << modm::endl;
PinGroup2::setInput(); MODM_LOG_INFO << modm::bin << PinGroup2::read() << modm::endl;
PinGroup3::setInput(); MODM_LOG_INFO << modm::bin << PinGroup3::read() << modm::endl;
PinGroup4::setInput(); MODM_LOG_INFO << modm::bin << PinGroup4::read() << modm::endl;
MODM_LOG_INFO << modm::endl;

PinGroup::setOutput(modm::Gpio::High); modm::delay(1s);

const auto fn_report = []() {
serialStream << modm::bin << PinGroup::read() << modm::endl; modm::delay(200ms);
MODM_LOG_INFO << modm::bin << PinGroup::read() << modm::endl; modm::delay(200ms);
};

while (true)
Expand All @@ -91,14 +91,14 @@ int main()
PinGroup::write(0b00111); fn_report();
PinGroup::write(0b01111); fn_report();
PinGroup::write(0b11111); fn_report();
serialStream << modm::endl;
MODM_LOG_INFO << modm::endl;

PinGroup::reset();
Pin0::set(); fn_report();
Pin1::set(); fn_report();
Pin2::set(); fn_report();
Pin3::set(); fn_report();
serialStream << modm::endl;
MODM_LOG_INFO << modm::endl;

// while (true);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/avr/qmc5883l/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ main()
<< modm::endl;
} else
{
serialStream << "readDataBlocking(): Error: " << uint8_t(I2cMaster::getErrorState())
<< modm::endl;
MODM_LOG_INFO << "readDataBlocking(): Error: " << uint8_t(I2cMaster::getErrorState())
<< modm::endl;
}
}
}
Expand Down
15 changes: 0 additions & 15 deletions src/modm/board/al_avreb_can/board_serial.cpp

This file was deleted.

5 changes: 5 additions & 0 deletions src/modm/board/al_avreb_can/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def prepare(module, options):

def build(env):
env.outbasepath = "modm/src/modm/board"
env.substitutions = {
"with_logger": True,
"with_assert": env.has_module(":architecture:assert")
}
env.template("../board.cpp.in", "board.cpp")
env.copy('.')
env.collect(":build:default.avrdude.port", "usb");
env.collect(":build:default.avrdude.programmer", "avrispmkII");
8 changes: 7 additions & 1 deletion src/modm/board/arduino_nano/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ def prepare(module, options):
return True

def build(env):
env.outbasepath = "modm/src/modm/"
env.outbasepath = "modm/src/modm/board"
env.substitutions = {
"with_logger": True,
"with_assert": env.has_module(":architecture:assert")
}
env.template("../board.cpp.in", "board.cpp")
env.outbasepath = "modm/src/modm"
env.copy(localpath("../arduino_uno"), "board")
env.collect(":build:default.avrdude.programmer", "arduino");
env.collect(":build:default.avrdude.baudrate", "115200");
22 changes: 0 additions & 22 deletions src/modm/board/arduino_uno/board_serial.cpp

This file was deleted.

5 changes: 5 additions & 0 deletions src/modm/board/arduino_uno/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ def prepare(module, options):

def build(env):
env.outbasepath = "modm/src/modm/board"
env.substitutions = {
"with_logger": True,
"with_assert": env.has_module(":architecture:assert")
}
env.template("../board.cpp.in", "board.cpp")
env.copy('.')
env.collect(":build:default.avrdude.programmer", "arduino");
env.collect(":build:default.avrdude.baudrate", "115200");
11 changes: 6 additions & 5 deletions src/modm/board/board.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "board.hpp"
#include <modm/architecture/interface/delay.hpp>
#include <modm/architecture/interface/accessor.hpp>
%% if with_assert
#include <modm/architecture/interface/assert.hpp>
%% endif
Expand All @@ -37,15 +38,15 @@ modm_extern_c void
modm_abandon(const modm::AssertionInfo &info)
{
%% if with_logger
MODM_LOG_ERROR << "Assertion '" << info.name << "'";
MODM_LOG_ERROR << IFSS("Assertion '") << modm::accessor::asFlash(info.name) << IFSS("'");
if (info.context != uintptr_t(-1)) {
MODM_LOG_ERROR << " @ " << (void *) info.context <<
" (" << (uint32_t) info.context << ")";
MODM_LOG_ERROR << IFSS(" @ ") << (void *) info.context <<
IFSS(" (") << (uint32_t) info.context << IFSS(")");
}
#if MODM_ASSERTION_INFO_HAS_DESCRIPTION
MODM_LOG_ERROR << " failed!\n " << info.description << "\nAbandoning...\n";
MODM_LOG_ERROR << IFSS(" failed!\n ") << modm::accessor::asFlash(info.description) << IFSS("\nAbandoning...\n");
#else
MODM_LOG_ERROR << " failed!\nAbandoning...\n";
MODM_LOG_ERROR << IFSS(" failed!\nAbandoning...\n");
#endif
%% else
(void)info;
Expand Down
22 changes: 0 additions & 22 deletions src/modm/board/mega_2560_pro/board_serial.cpp

This file was deleted.

5 changes: 5 additions & 0 deletions src/modm/board/mega_2560_pro/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ def prepare(module, options):

def build(env):
env.outbasepath = "modm/src/modm/board"
env.substitutions = {
"with_logger": True,
"with_assert": env.has_module(":architecture:assert")
}
env.template("../board.cpp.in", "board.cpp")
env.copy('.')
env.collect(":build:default.avrdude.programmer", "stk500v2");
env.collect(":build:default.avrdude.baudrate", "115200");
Expand Down
2 changes: 1 addition & 1 deletion src/modm/board/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def init(module):

def prepare(module, options):
# The modm_abandon function uses delay functions
module.depends(":architecture:delay", ":architecture:assert")
module.depends(":architecture:delay", ":architecture:assert", ":architecture:accessor")

return True

Expand Down

0 comments on commit 6b19ded

Please sign in to comment.