1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

OP-36 PIOS_DEBUG_Assert() function

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@307 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
FredericG 2010-03-14 10:20:27 +00:00 committed by FredericG
parent a30f682a1e
commit 7bd573f043
2 changed files with 23 additions and 0 deletions

View File

@ -29,6 +29,8 @@
/* Project Includes */
#include "pios.h"
// Global variables
const uint8_t* PIOS_DEBUG_AssertMsg = (uint8_t*)"ASSERT FAILED";
/* Private Function Prototypes */
@ -84,4 +86,16 @@ void PIOS_DEBUG_PinLow(uint8_t Pin)
#endif // PIOS_ENABLE_DEBUG_PINS
}
/**
* Report a serious error and halt
*/
void PIOS_DEBUG_Panic(const uint8_t* msg)
{
register int *lr asm ("lr"); // Link-register holds the PC of the caller
PIOS_COM_SendFormattedStringNonBlocking(COM_DEBUG_USART, "\r%s @0x%x\r", msg, lr);
// Stay put
while(1);
}

View File

@ -26,8 +26,17 @@
#ifndef PIOS_DEBUG_H
#define PIOS_DEBUG_H
extern const uint8_t* PIOS_DEBUG_AssertMsg;
void PIOS_DEBUG_Init(void);
void PIOS_DEBUG_PinHigh(uint8_t pin);
void PIOS_DEBUG_PinLow(uint8_t pin);
void PIOS_DEBUG_Panic(const uint8_t* msg);
#ifdef DEBUG
#define PIOS_DEBUG_Assert(test) if (!(test)) PIOS_DEBUG_Panic(PIOS_DEBUG_AssertMsg);
#else
#define PIOS_DEBUG_Assert(test)
#endif
#endif /* PIOS_DEBUG_H */