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

[wip] xpcc error model using assertions #185

merged 8 commits into from
Nov 16, 2016

Conversation

salkinium
Copy link
Member

@salkinium salkinium commented Sep 15, 2016

I'm working on adding a universal error model to xpcc via assertions that can be modified by the user application.

The principle is described here in detail and was inspired by trying to find a solution to #114.

Note that this is very much WIP, and none of the interfaces are finalized. I plan to write a blog post about this for additional concept documentation.
I made the decision to have three fields, so that people are not tempted just to put a human readable string in there, which would defeat the purpose of the handlers.

Also see this alternate implementation with binary errors. It's not very useful.

cc @ekiwi @dergraaf @strongly-typed


using namespace xpcc::at90;

namespace Board
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add more detailed information about the board, e.g. including a link to the documentation?

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.

{
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.


#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?

@@ -75,6 +75,7 @@
#define EXTERN_FLASH_STORAGE_STRING(s) extern const char s[]

#define INLINE_FLASH_STORAGE_STRING(s) ((const char *)(s))
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know what I was smoking when I thought that INLINE_FLASH_STORAGE_STRING("Hello World!") was an acceptable length for a macro to be used inline.

@@ -31,7 +31,7 @@

# -----------------------------------------------------------------------------
def avrdude_flash(env, source, eeprom_source='', alias='avrdude_program'):
actionString = '$AVRDUDE -p $AVRDUDE_DEVICE -c $AVRDUDE_PROGRAMMER -P $AVRDUDE_PORT $AVRDUDE_OPTIONS -U flash:w:'
actionString = '$AVRDUDE -V -p $AVRDUDE_DEVICE -c $AVRDUDE_PROGRAMMER -P $AVRDUDE_PORT $AVRDUDE_OPTIONS -U flash:w:'
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe we should add a avrdude.verify={true, false} to project.cfg?

#endif

#define xpcc_assert(condition, module, location, failure) \
xpcc_assert_evaluate((condition), INLINE_FLASH_STORAGE_STRING(module "\0" location "\0" failure));
Copy link
Member Author

Choose a reason for hiding this comment

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

The reason why I chose to put this all into one string is that only one address needs to be loaded into registers. This should make assertions a lot less costly on AVRs, since only 3 registers (2 on ARM) need to be written (one for bool, two for address).

.xpcc_assertion : AT( ADDR(.text) + SIZEOF(.text) + SIZEOF(.data))
{
. = ALIGN(2);
__assertion_table_start = . + SIZEOF(.data);
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 an issue of VMA vs. LMA. This is placed physically after data into Flash, but virtually after flash. ld is not really well documented, so maybe I just don't know any better. But the end result is the same anyways.

KEEP(*(.assertion))
__assertion_table_end = .;
. = ALIGN (4);

Copy link
Member Author

Choose a reason for hiding this comment

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

Snippets like these should be deduplicated.

@salkinium
Copy link
Member Author

salkinium commented Nov 16, 2016

Any further review comments by the usual suspects (cc @ekiwi @dergraaf @strongly-typed)?

@ekiwi
Copy link
Member

ekiwi commented Nov 16, 2016

Any further review comments by the usual suspects

Well I am opposed to the use of strings for this purpose. However, if no one else objects, I think you should merge.

@salkinium
Copy link
Member Author

Well I am opposed to the use of strings for this purpose.

What is your alternative? (this is mine).

@ekiwi
Copy link
Member

ekiwi commented Nov 16, 2016

What is your alternative?

I don't have one which is why I won't object to merging this even though I do not necessarily like this solution.

@salkinium salkinium merged commit 50bc064 into roboterclubaachen:develop Nov 16, 2016
@salkinium salkinium deleted the feature/xpcc_assertion_handlers branch November 16, 2016 23:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants