Click here to Skip to main content
15,886,052 members
Articles / Mobile Apps

Develop embedded systems based on UML state machines

Rate me:
Please Sign up or sign in to vote.
3.88/5 (9 votes)
1 Jun 2005CPOL3 min read 81.1K   1.3K   37  
This article discovers how to develop and simulate cross-platform embedded systems using the UML State Machine Wizard.
/* =============================================================================
 * Filename:    sme_debug.h
 * 
 * Copyright  Inc
 * All rights reserved.
 * -----------------------------------------------------------------------------
 * General description of this file:
 *
 * State machine engine debug support global header file.
 * -----------------------------------------------------------------------------
 *                               Revision History
 * -----------------------------------------------------------------------------
 * Version   Date      Author          Revision Detail
 * 1.0.0    2004/11/26                 Initial
 * ===========================================================================*/

#ifndef SME_DEBUG_H
#define SME_DEBUG_H

#include "sme.h"

#ifdef __cplusplus   
extern "C" {
#endif

/*****************************************************************************************
*  Diagnostic function prototypes.
******************************************************************************************/
#ifdef _DEBUG
	void SmeTrace(const char * sFormat, ...);
	void SmeAsciiTrace(const char * sFormat, ...);

	typedef void (*SME_OUTPUT_DEBUG_STR_PROC_T)(const SME_CHAR * sDebugStr); 
	SME_OUTPUT_DEBUG_STR_PROC_T	SmeSetOutputDebugStrProc(SME_OUTPUT_DEBUG_STR_PROC_T fnProc);

	#define SME_SET_TRACER(fnTracer)	SmeSetOutputDebugStrProc(fnTracer)

	// ArgList will be a variable argument list.
	#define SME_TRACE  SmeTrace
	#define SME_ASCII_TRACE  SmeAsciiTrace
	// 
	#define SME_ASSERT(BoolExpress)       do { \
	if (!(BoolExpress)) {\
	SME_TRACE("Assertion fails at %s (%d)\n", __FILE__, __LINE__); while(1); \
	}\
	} while(0)

	BOOL OutputDebugStrToDS(SME_CHAR* sDebugStr, int nSizeInByte);
	BOOL StateTrack(struct SME_EVENT_T *pEvent, 
			   struct SME_APP_T *pDestApp, 
			   SME_STATE_T nNewState);

#else /* _DEBUG */
	/*__inline*/ void SmeTrace(const char *sFormat, ...); 
	#define SME_TRACE              1 ? (void)0 : SmeTrace
	#define SME_ASCII_TRACE        1 ? (void)0 : SmeTrace
	#define SME_ASSERT(BoolExpress)
	#define SME_SET_TRACER(fnTracer)
#endif  /* _DEBUG */

/******************************************************************************************
*  Dynamic memory operation function prototypes.
*******************************************************************************************/
typedef BOOL (*SME_ENUM_MEM_CALLBACK_T)(void *pUserData, unsigned int nSize, 
	const char *sFileName, int nLineNumber);

#ifdef _DEBUG
	BOOL SME_DBG_INIT();
	void * SmeMAllocDebug (unsigned int nSize, const char * sFile, int nLine);
	int SmeMFreeDebug (void * pUserData, const char * sFile, int nLine);
	#define SmeMAlloc(nSize)  	SmeMAllocDebug((nSize), __FILE__, __LINE__)
	#define SmeMFree(pUserData)  	SmeMFreeDebug((pUserData), __FILE__, __LINE__)

	enum {
		SME_HOOK_PRE_ALLOC,
		SME_HOOK_POST_ALLOC,
		SME_HOOK_PRE_FREE,
		SME_HOOK_POST_FREE
	};
	typedef unsigned char SME_MEM_OPR_HOOK_TYPE_T;

	typedef int (*SME_MEM_OPR_HOOK_T)(SME_MEM_OPR_HOOK_TYPE_T nAllocType, void *pUserData, unsigned int nSize, 
		const char *sFileName, int nLineNumber);

	SME_MEM_OPR_HOOK_T SME_SET_MEM_OPR_HOOK(SME_MEM_OPR_HOOK_T pMemOprHook);
	BOOL SME_ENUM_MEM(SME_ENUM_MEM_CALLBACK_T fnEnumMemCallBack);
	void SME_DUMP_MEM();
	void SME_ALLOC_MEM_SIZE();

#else
	#define SME_DBG_INIT()
	#define SmeMAlloc(nSize)	SmeMAllocRelease((nSize))
	#define SmeMFree(pUserData)		SmeMFreeRelease((pUserData))

	#define SME_SET_MEM_OPR_HOOK(pMemOprHook)
	#define SME_ENUM_MEM(fnEnumMemCallBack)
	#define SME_DUMP_MEM()
	#define SME_ALLOC_MEM_SIZE()
#endif  /* _DEBUG */

#ifdef __cplusplus
}
#endif 


#endif /* SME_DEBUG_H */

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
China China
Jerome. (Free to speak, free to use.)

Comments and Discussions