First Checkin. Woohoo!

git-svn-id: http://cexception.svn.sourceforge.net/svnroot/cexception/trunk@1 50f63946-2846-0410-8d77-f904c773002e
This commit is contained in:
mvandervoord
2008-02-21 01:38:49 +00:00
commit 87838b85bc
7 changed files with 651 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
#include "Exception.h"
volatile EXCEPTION_FRAME_T ExceptionFrames[EXCEPTION_NUM_ID];
//------------------------------------------------------------------------------------------
// ThrowDetailed
//------------------------------------------------------------------------------------------
//
// PARAMETERS: None
//
// DESCRIPTION: throws a software exception with details
//
// RETURNS: None
//
//------------------------------------------------------------------------------------------
void ThrowDetailed(unsigned int ExceptionID, unsigned int Details)
{
MY_FRAME.Exception = ExceptionID;
MY_FRAME.Details = Details;
longjmp(*MY_FRAME.pFrame, 1);
}
//------------------------------------------------------------------------------------------
// Rethrow
//------------------------------------------------------------------------------------------
//
// PARAMETERS: None
//
// DESCRIPTION: rethrows a software exception that has already been thrown
//
// RETURNS: None
//
//------------------------------------------------------------------------------------------
void Rethrow()
{
longjmp(*MY_FRAME.pFrame, 1);
}
+43
View File
@@ -0,0 +1,43 @@
#ifndef _EXCEPTION_H
#define _EXCEPTION_H
#include <setjmp.h>
#include "ExceptionConfig.h"
//exception frame structures
typedef struct {
jmp_buf* pFrame;
volatile unsigned int Exception;
volatile unsigned int Details;
} EXCEPTION_FRAME_T;
extern volatile EXCEPTION_FRAME_T ExceptionFrames[];
#define MY_FRAME (ExceptionFrames[EXCEPTION_GET_ID()])
#define MY_FRAME_FAST (ExceptionFrames[MY_ID])
#define EXCEPTION_ID (MY_FRAME.Exception)
#define EXCEPTION_DETAILS (MY_FRAME.Details)
#define Try \
{ \
jmp_buf *PrevFrame, NewFrame; \
PrevFrame = MY_FRAME.pFrame; \
unsigned int MY_ID = EXCEPTION_GET_ID(); \
MY_FRAME_FAST.pFrame = &NewFrame; \
MY_FRAME_FAST.Details = 0; \
MY_FRAME_FAST.Exception = EXCEPTION_NONE; \
if (setjmp(NewFrame) == 0) { \
if (&PrevFrame)
#define Catch \
else { } \
MY_FRAME_FAST.Exception = EXCEPTION_NONE; \
} \
MY_FRAME_FAST.pFrame = PrevFrame; \
} \
if (MY_FRAME.Exception != EXCEPTION_NONE)
#define Throw(id) ThrowDetailed(id, __LINE__)
void ThrowDetailed(unsigned int ExceptionID, unsigned int Details);
void Rethrow(void);
#endif // _EXCEPTION_H
+26
View File
@@ -0,0 +1,26 @@
#ifndef _EXCEPTION_CONFIG_H
#define _EXCEPTION_CONFIG_H
//#define EXCEPTION_MULTI_STACK
#define EXCEPTION_NONE (0x5A5A5A5A)
//if using multistack support and not currently running a test, must include multistack support
#undef EXCEPTION_INCLUDE_MULTI_STACK_SUPPORT
#ifndef TEST
#ifdef EXCEPTION_MULTI_STACK
#define EXCEPTION_INCLUDE_MULTI_STACK_SUPPORT
#endif
#endif
//define the method of automatically looking up the current frame index (mappable from task ID if the task ID's are consecutive)
// The example below supports the Quadros OS in Multi-Stack Mode. Most RTOS will support a similar function call.
#ifdef EXCEPTION_INCLUDE_MULTI_STACK_SUPPORT
#include "OSAPI.h"
#define EXCEPTION_GET_ID() (KS_GetTaskID())
#define EXCEPTION_NUM_ID (NTASKS + 1)
#else
#define EXCEPTION_GET_ID() (0) //use the first index always because there is only one anyway
#define EXCEPTION_NUM_ID (1) //there is only the one stack
#endif
#endif //_EXCEPTION_CONFIG_H