-
Notifications
You must be signed in to change notification settings - Fork 1
Erick Assertion Handler #95
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
base: dev
Are you sure you want to change the base?
Changes from all commits
256e183
5d345a6
8468e90
d228ccf
3d99efa
f44ae4c
f6392e4
3a4dc75
f16d093
78db09a
d0c4dd4
b40ca16
8d96584
ab19948
ebb9dce
2e1c8ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // | ||
| // AssertionHandler.h | ||
| // micromouse-xcode | ||
| // | ||
| // Created by Erick Sanchez on 4/20/16. | ||
| // Copyright © 2016 Erick Sanchez. All rights reserved. | ||
| // | ||
|
|
||
| #ifndef AssertionHandler_h | ||
| #define AssertionHandler_h | ||
|
|
||
| #include "Logger.h" | ||
| #include "Memory.h" | ||
| #include <assert.h> | ||
|
|
||
| #ifdef __MK20DX256__ // Teensy Compile | ||
|
|
||
| inline static void logError( int code ) { | ||
| //Read and increment to the next error state, as well as validate to loop back to 1 if incremented to 21 | ||
| int intNextIndex = Micromouse::Memory::read(Micromouse::ERROR_MEMORY) +1; | ||
| intNextIndex = intNextIndex > 20 ? 1 : intNextIndex; | ||
|
|
||
| //Find next state address and save code as well as the most recent error state in ERROR_MEMORY | ||
| int intNextStateAddress = Micromouse::ERROR_MEMORY +intNextIndex * 4; | ||
| Micromouse::Memory::write( intNextStateAddress, code); | ||
| Micromouse::Memory::write( Micromouse::ERROR_MEMORY, intNextIndex); | ||
|
|
||
| } | ||
|
|
||
| inline static void printErrorCodes() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does it need to be inline?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmmm, beats the hell out of me, i thought i had to, does it need to be static? i would say no huh
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, it can just be a regular global function |
||
| for (int error = 0; error <= 11; error += 1) { | ||
| int address = Micromouse::ERROR_MEMORY; | ||
| log(INFO) << Micromouse::Memory::read((error * 4) +address); | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| //Prints to concole using Logger(..) << code and metadata of the assertion | ||
| #define assertion(condition,code) \ | ||
| ( \ | ||
| (__builtin_expect(!(condition), 0) ? (void)(logError(code)) : (void)0) \ | ||
| ) | ||
|
|
||
| #else | ||
|
|
||
| //Prints to concole using the definition of assert(e) declared in assert.h | ||
| #define assertion(condition,code) \ | ||
| ( \ | ||
| (__builtin_expect(!(condition), 0) ? __assert_rtn(__func__, __FILE__, __LINE__, #condition) : (void)0) \ | ||
| ) | ||
|
|
||
| #endif | ||
|
|
||
| #endif /* AssertionHandler_h */ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a function here that dumps all the errors in memory to the serial port using log()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, you mean read all the codes and output them to the serial port?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't tell if i did it right :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite, look at logger.h for proper use
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about now???
plus i can't tell why i can't call to this
inlinemethod anywhere in the project :P