Skip to content
This repository was archived by the owner on Feb 5, 2024. It is now read-only.
Open
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
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Contributor Author

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

<projectDescription>
<name>ZeroPilot-SW-3</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
29 changes: 29 additions & 0 deletions Common/Inc/zp_assert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
#pragma once


#ifndef ZP_ASSERT_H
#define ZP_ASSERT_H

#include <stdint.h>

typedef struct sAssertInfo {
uint64_t pc;
uint64_t lr;
} sAssertInfo;
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would be preferable to use some form of #ifdef to determine what platform we are building for and use that to choose the line that is defined.
Not sure but there might be a compiler extension that will give us this info for free.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
17 changes: 17 additions & 0 deletions Common/Src/zp_assert.c
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why are we using macros instead of normal functions?

}
}
}