mirror of
https://github.com/throwtheswitch/cexception.git
synced 2026-10-05 08:17:21 +00:00
cleaned up order of inclusion and testability
git-svn-id: http://cexception.svn.sourceforge.net/svnroot/cexception/trunk@3 50f63946-2846-0410-8d77-f904c773002e
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
#ifndef _CEXCEPTION_H
|
||||
#define _CEXCEPTION_H
|
||||
|
||||
#include <setjmp.h>
|
||||
|
||||
#ifndef EXCEPTION_NONE
|
||||
#define EXCEPTION_NONE (0x5A5A5A5A)
|
||||
#endif
|
||||
|
||||
#ifndef EXCEPTION_NUM_ID
|
||||
#define EXCEPTION_NUM_ID (1) //there is only the one stack by default
|
||||
#endif
|
||||
|
||||
#ifndef EXCEPTION_GET_ID
|
||||
#define EXCEPTION_GET_ID (0) //use the first index always because there is only one anyway
|
||||
#endif
|
||||
|
||||
//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; \
|
||||
unsigned int MY_ID = EXCEPTION_GET_ID; \
|
||||
PrevFrame = MY_FRAME.pFrame; \
|
||||
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 // _CEXCEPTION_H
|
||||
+16
-36
@@ -1,43 +1,23 @@
|
||||
#ifndef _EXCEPTION_H
|
||||
#define _EXCEPTION_H
|
||||
|
||||
#include <setjmp.h>
|
||||
#include "ExceptionConfig.h"
|
||||
// Define the reserved value representing NO EXCEPTION
|
||||
#define EXCEPTION_NONE (0x5A5A5A5A)
|
||||
|
||||
//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[];
|
||||
// Multi-Tasking environments will need a couple of macros defined to make this library
|
||||
// properly handle multiple exception stacks. You will need to include and required
|
||||
// definitions, then define the following macros:
|
||||
// EXCEPTION_GET_ID - returns the id of the current task indexed 0 to (numtasks - 1)
|
||||
// EXCEPTION_NUM_ID - returns the number of tasks that might be returned
|
||||
//
|
||||
// For example, Quadros might include the following implementation:
|
||||
#ifndef TEST
|
||||
#include "OSAPI.h"
|
||||
#define EXCEPTION_GET_ID() (KS_GetTaskID())
|
||||
#define EXCEPTION_NUM_ID (NTASKS + 1)
|
||||
#endif
|
||||
|
||||
#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; \
|
||||
unsigned int MY_ID = EXCEPTION_GET_ID(); \
|
||||
PrevFrame = MY_FRAME.pFrame; \
|
||||
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);
|
||||
// INCLUDE THE ACTUAL CEXCEPTION LIBRARY
|
||||
#include "CException.h"
|
||||
|
||||
#endif // _EXCEPTION_H
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user