-
Notifications
You must be signed in to change notification settings - Fork 3
Add zp_assert #12
base: main
Are you sure you want to change the base?
Add zp_assert #12
Changes from all commits
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,11 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <projectDescription> | ||
| <name>ZeroPilot-SW-3</name> | ||
| <comment></comment> | ||
| <projects> | ||
| </projects> | ||
| <buildSpec> | ||
| </buildSpec> | ||
| <natures> | ||
| </natures> | ||
| </projectDescription> | ||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||
| #pragma once | ||||
|
Contributor
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. Pragma once is the same as the include guards directly below. We use include guards throughout our project so I would stick to that
Suggested change
|
||||
|
|
||||
| #ifndef ZP_ASSERT_H | ||||
| #define ZP_ASSERT_H | ||||
|
|
||||
| #include <stdint.h> | ||||
|
|
||||
| typedef struct sAssertInfo { | ||||
| uint64_t pc; | ||||
| uint64_t lr; | ||||
| } sAssertInfo; | ||||
|
Contributor
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. What do PC and lr stand for? Can we expand their abbreviations? |
||||
|
|
||||
| void store_assert(const uint64_t *pc, const uint64_t *lr); | ||||
|
|
||||
| #define GET_LR() __builtin_return_address(0) | ||||
| //#define GET_PC(_a) __asm volatile ("mov %0, pc" : "=r" (_a)) // Comment out this for ARM | ||||
| #define GET_PC(_a) __asm volatile("1: lea 1b(%%rip), %0;": "=a"(pc)); // Comment this for x86 | ||||
|
Contributor
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. I think it would be preferable to use some form of
Contributor
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. What does this assembly do? A comment could be useful to explain it here |
||||
|
|
||||
| #define MY_ASSERT_RECORD() \ | ||||
| do { \ | ||||
| void *pc = NULL; \ | ||||
| GET_PC(pc); \ | ||||
| const void *lr = GET_LR(); \ | ||||
| store_assert(pc, lr); \ | ||||
| } while (0) | ||||
|
|
||||
| void zp_assert(bool expr); | ||||
|
|
||||
| #endif | ||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #include "zp_assert.h" | ||
|
|
||
| static sAssertInfo g_assert_info; | ||
|
|
||
| void store_assert(const uint64_t *pc, const uint64_t *lr) { | ||
| g_assert_info.pc = pc; | ||
| g_assert_info.lr = lr; | ||
| } | ||
|
|
||
| void zp_assert(bool expr) { | ||
| if (!expr) { | ||
| //#warning This should call the los hardfault handler, or something more appropriate | ||
|
Contributor
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. If we assert, we should probably also set all motors to 0 throttle. Can you think of any other safety related functions that should be performed in the event if an assert? |
||
| while (1) { | ||
| MY_ASSERT_RECORD(); | ||
|
Contributor
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. Why are we using macros instead of normal functions? |
||
| } | ||
| } | ||
| } | ||
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 think we want to avoid commiting .project files