Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

[wip] xpcc error model using assertions #185

Merged
merged 8 commits into from
Nov 16, 2016
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
4 changes: 4 additions & 0 deletions examples/avr/assert/SConstruct
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# path to the xpcc root directory
xpccpath = '../../..'
# execute the common SConstruct file
execfile(xpccpath + '/scons/SConstruct')
92 changes: 92 additions & 0 deletions examples/avr/assert/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// coding: utf-8
/* Copyright (c) 2016, Roboterclub Aachen e.V.
* All Rights Reserved.
*
* The file is part of the xpcc library and is released under the 3-clause BSD
* license. See the file `LICENSE` for the full license governing this code.
*/
// ----------------------------------------------------------------------------

#include <xpcc/architecture/platform.hpp>
#include <avr/pgmspace.h>

using xpcc::accessor::asFlash;

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

@salkinium salkinium Sep 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AVR is pretty cool, but this Flash f-up is pretty unforgiveable. This should be solved at a compiler level, not a user application level though.


#define XPCC_CAN_MODULE_NAME "can"
#define XPCC_IOBUFFER_MODULE_NAME "iobuffer"
#define XPCC_UART_MODULE_NAME "uart"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are supposed to be declared by the module, perhaps overwriteable?


extern "C" void
xpcc_abandon(const char * module,
const char * location,
const char * failure)
{
serialStream << IFS("Assertion '")
<< asFlash(module) << '.'
<< asFlash(location) << '.'
<< asFlash(failure)
<< IFS("' failed! Abandoning.") << xpcc::endl;

Leds::setOutput();
while(1) {
Leds::write(1);
xpcc::delayMilliseconds(20);
Leds::write(0);
xpcc::delayMilliseconds(180);
}
}

static xpcc::Abandonment
test_assertion_handler(const char * module,
const char * /* location */,
const char * /* failure */)
{
serialStream << IFS("#1: '") << asFlash(module) << IFS("'!") << xpcc::endl;
// The strings are located in FLASH!!!
if (strcmp_P(module, PSTR(XPCC_IOBUFFER_MODULE_NAME)) == 0)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit sucky, if your application should be portable between AVR and Cortex-M. But I see not other way than to place the strings into Flash, since this feature is supposed to be used on ATtinys too.

return xpcc::Abandonment::Ignore;
return xpcc::Abandonment::DontCare;
}
XPCC_ASSERTION_HANDLER(test_assertion_handler);

static xpcc::Abandonment
test_assertion_handler2(const char * /* module */,
const char * location,
const char * /* failure */)
{
serialStream << IFS("#2: '") << asFlash(location) << IFS("'!") << xpcc::endl;
return xpcc::Abandonment::DontCare;
}
XPCC_ASSERTION_HANDLER(test_assertion_handler2);

static xpcc::Abandonment
test_assertion_handler3(const char * /* module */,
const char * /* location */,
const char * failure)
{
serialStream << IFS("#3: '") << asFlash(failure) << IFS("'!") << xpcc::endl;
return xpcc::Abandonment::DontCare;
}
XPCC_ASSERTION_HANDLER(test_assertion_handler3);

// ----------------------------------------------------------------------------
int main()
{
Board::initialize();
Leds::setOutput();

xpcc_assert(true, XPCC_CAN_MODULE_NAME, "init", "timeout");

xpcc_assert_debug(false, XPCC_IOBUFFER_MODULE_NAME, "tx", "full");

xpcc_assert(false, XPCC_UART_MODULE_NAME, "init", "mode");

while (1)
{
Led3::toggle();
xpcc::delayMilliseconds(500);
}
}
3 changes: 3 additions & 0 deletions examples/avr/assert/project.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build]
board = al_avreb_can
buildpath = ${xpccpath}/build/avr/${name}
4 changes: 4 additions & 0 deletions examples/linux/assert/SConstruct
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# path to the xpcc root directory
xpccpath = '../../..'
# execute the common SConstruct file
execfile(xpccpath + '/scons/SConstruct')
29 changes: 29 additions & 0 deletions examples/linux/assert/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <xpcc/architecture/platform.hpp>

#define XPCC_CAN_MODULE_NAME "can"
#define XPCC_IOBUFFER_MODULE_NAME "iobuffer"
#define XPCC_UART_MODULE_NAME "uart"

static xpcc::Abandonment
test_assertion_handler(const char * module,
const char * location,
const char * failure)
{
if (strcmp(module, XPCC_IOBUFFER_MODULE_NAME) == 0)
return xpcc::Abandonment::Ignore;
return xpcc::Abandonment::DontCare;
}
XPCC_ASSERTION_HANDLER(test_assertion_handler);

// ----------------------------------------------------------------------------
int
main()
{
xpcc_assert(true, XPCC_CAN_MODULE_NAME, "init", "timeout");

xpcc_assert_debug(false, XPCC_IOBUFFER_MODULE_NAME, "tx", "full");

xpcc_assert(false, XPCC_UART_MODULE_NAME, "init", "mode");

return 0;
}
3 changes: 3 additions & 0 deletions examples/linux/assert/project.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build]
device = hosted
buildpath = ${xpccpath}/build/linux/${name}
4 changes: 4 additions & 0 deletions examples/stm32f469_discovery/assert/SConstruct
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# path to the xpcc root directory
xpccpath = '../../..'
# execute the common SConstruct file
execfile(xpccpath + '/scons/SConstruct')
56 changes: 56 additions & 0 deletions examples/stm32f469_discovery/assert/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <xpcc/architecture/platform.hpp>

#define XPCC_CAN_MODULE_NAME "can"
#define XPCC_IOBUFFER_MODULE_NAME "iobuffer"
#define XPCC_UART_MODULE_NAME "uart"

using namespace Board;

extern "C" void xpcc_abandon(const char * module,
const char * location,
const char * failure)
{
XPCC_LOG_ERROR << "Assertion '"
<< module << "." << location << "." << failure
<< "' failed! Abandoning." << xpcc::endl;

LedGreen::setOutput();
while(1) {
LedBlue::set();
xpcc::delayMilliseconds(20);
LedBlue::reset();
xpcc::delayMilliseconds(180);
}
}

static xpcc::Abandonment
test_assertion_handler(const char * module,
const char * /* location */,
const char * /* failure */)
{
if (strcmp(module, XPCC_IOBUFFER_MODULE_NAME) == 0)
return xpcc::Abandonment::Ignore;
return xpcc::Abandonment::DontCare;
}
XPCC_ASSERTION_HANDLER(test_assertion_handler);

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

xpcc_assert(true, XPCC_CAN_MODULE_NAME, "init", "timeout");

xpcc_assert_debug(false, XPCC_IOBUFFER_MODULE_NAME, "tx", "full");

xpcc_assert(false, XPCC_UART_MODULE_NAME, "init", "mode");

while(1)
{
LedRed::toggle();
xpcc::delayMilliseconds(500);
}

return 0;
}
3 changes: 3 additions & 0 deletions examples/stm32f469_discovery/assert/project.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build]
board = stm32f469_discovery
buildpath = ${xpccpath}/build/stm32f469_discovery/${name}
1 change: 1 addition & 0 deletions scons/site_tools/avr.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def generate(env, **kw):
"-mmcu=$AVR_DEVICE",
"-Wl,--relax",
"-Wl,--gc-sections",
"-Wl,-T,${XPCC_ROOTPATH}/src/xpcc/architecture/platform/driver/core/avr/linkerscript.ld",
# "-Wl,-Map=${TARGET.base}.map,--cref",
# "-Wl,-u,vfprintf -lprintf_flt" # enable float support for vfprinft
]
Expand Down
1 change: 1 addition & 0 deletions src/xpcc/architecture/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,6 @@ class Peripheral
#include "interface/i2c.hpp"
#include "interface/register.hpp"
#include "interface/memory.hpp"
#include "interface/assert.hpp"

#endif // XPCC_INTERFACE_HPP
Loading