📄 comdef.h
字号:
PARAMETERS
ray array to receive the 2 bytes from 'val'
val word to break into 2 bytes and put into 'ray'
DEPENDENCIES
None
RETURN VALUE
None
SIDE EFFECTS
None
===========================================================================*/
#define FLOPW( ray, val ) \
(ray)[0] = ((val) / 256); \
(ray)[1] = ((val) & 0xFF)
/*===========================================================================
MACRO B_PTR
MACRO W_PTR
DESCRIPTION
Casts the address of a specified variable as a pointer to byte/word,
allowing byte/word-wise access, e.g.
W_PTR ( xyz )[ 2 ] = 0x1234; -or- B_PTR ( xyz )[ 2 ] = 0xFF;
PARAMETERS
var the datum to get a word pointer to
DEPENDENCIES
None
RETURN VALUE
Word pointer to var
SIDE EFFECTS
None
===========================================================================*/
#define B_PTR( var ) ( (byte *) (void *) &(var) )
#define W_PTR( var ) ( (word *) (void *) &(var) )
/*===========================================================================
MACRO WORD_LO
MACRO WORD_HI
DESCRIPTION
Take a word and extract the least-significant or most-significant byte.
PARAMETERS
xxx word to extract the Low/High from
DEPENDENCIES
None
RETURN VALUE
WORD_LO Least significant byte of xxx.
WORD_HI Most significant byte of xxx.
SIDE EFFECTS
None
===========================================================================*/
#define WORD_LO(xxx) ((byte) ((word)(xxx) & 255))
#define WORD_HI(xxx) \
/*lint -e572 */ ((byte) ((word)(xxx) >> 8)) /*lint +e572 */
/*===========================================================================
MACRO RND8
DESCRIPTION
RND8 rounds a number up to the nearest multiple of 8.
PARAMETERS
x Number to be rounded up
DEPENDENCIES
None
RETURN VALUE
x rounded up to the nearest multiple of 8.
SIDE EFFECTS
None
===========================================================================*/
#define RND8( x ) ((((x) + 7) / 8 ) * 8 )
/*===========================================================================
MACRO INTLOCK / INTFREE
DESCRIPTION
INTLOCK Saves current interrupt state on stack then disables interrupts.
Used in conjunction with INTFREE.
INTFREE Restores previous interrupt state from stack. Used in conjunction
with INTLOCK.
PARAMETERS
None
DEPENDENCIES
The stack level when INTFREE is called must be as it was just after INTLOCK
was called. The Microsoft C compiler does not always pop the stack after a
subroutine call, but instead waits to do a 'big' pop after several calls.
This causes these macros to fail. Do not place subroutine calls between
these macros. Use INTLOCK/FREE_SAV in those cases.
RETURN VALUE
None
SIDE EFFECTS
INTLOCK turn off interrupts
INTFREE restore the interrupt mask saved previously
===========================================================================*/
#if defined PC_EMULATOR_H && !defined T_REXNT
#error code not present
#elif defined T_WINNT
#error code not present
#elif !defined _ARM_ASM_
// #include "rex.h"
// #define INTLOCK( ) { dword sav = rex_int_lock();
// #define INTFREE( ) if(!sav) (void)rex_int_free();}
#endif
/*===========================================================================
MACRO INTLOCK_SAV / INTFREE_SAV
DESCRIPTION
INTLOCK_SAV Saves current interrupt state in specified variable sav_var
then disables interrupts. Used in conjunction with INTFREE_SAV.
INTFREE_SAV Restores previous interrupt state from specified variable
sav_var. Used in conjunction with INTLOCK_SAV.
PARAMETERS
sav_var Current flags register, including interrupt status
DEPENDENCIES
None.
RETURN VALUE
None
SIDE EFFECTS
INTLOCK_SAV turn off interrupts
INTFREE_SAV restore the interrupt mask saved previously
===========================================================================*/
#ifdef _lint /* get lint to 'know' the parameter is accessed */
#define INTLOCK_SAV(sav_var) (sav_var = 1)
#define INTFREE_SAV(sav_var) (sav_var = sav_var + 1)
#else
#if defined PC_EMULATOR_H && !defined T_REXNT
#error code not present
#elif defined T_WINNT
#error code not present
#elif !defined _ARM_ASM_
// #include "rex.h"
// #define INTLOCK_SAV( sav_var ) sav_var = rex_int_lock()
// #define INTFREE_SAV( sav_var ) if(!sav_var) rex_int_free()
#endif
#endif /* END if _lint */
/*===========================================================================
MACRO UPCASE
DESCRIPTION
Convert a character to uppercase, the character does not have to
be printable or a letter.
PARAMETERS
c Character to be converted
DEPENDENCIES
'c' is referenced multiple times, and should remain the same value
each time it is evaluated.
RETURN VALUE
Uppercase equivalent of the character parameter
SIDE EFFECTS
None
===========================================================================*/
#define UPCASE( c ) ( ((c) >= 'a' && (c) <= 'z') ? ((c) - 0x20) : (c) )
/*===========================================================================
MACRO DECCHK
MACRO HEXCHK
DESCRIPTION
These character attribute macros are similar to the standard 'C' macros
(isdec and ishex), but do not rely on the character attributes table used
by Microsoft 'C'.
PARAMETERS
c Character to be examined
DEPENDENCIES
None
RETURN VALUE
DECCHK True if the character is a decimal digit, else False
HEXCHK True if the chacters is a hexidecimal digit, else False
SIDE EFFECTS
None
===========================================================================*/
#define DECCHK( c ) ((c) >= '0' && (c) <= '9')
#define HEXCHK( c ) ( ((c) >= '0' && (c) <= '9') ||\
((c) >= 'A' && (c) <= 'F') ||\
((c) >= 'a' && (c) <= 'f') )
/*===========================================================================
MACRO INC_SAT
DESCRIPTION
Increment a value, but saturate it at its maximum positive value, do not
let it wrap back to 0 (unsigned) or negative (signed).
PARAMETERS
val value to be incremented with saturation
DEPENDENCIES
None
RETURN VALUE
val
SIDE EFFECTS
val is updated to the new value
===========================================================================*/
#define INC_SAT( val ) (val = ((val)+1 > (val)) ? (val)+1 : (val))
/*===========================================================================
MACRO ARR_SIZE
DESCRIPTION
Return the number of elements in an array.
PARAMETERS
a array name
DEPENDENCIES
None
RETURN VALUE
Number of elements in array a
SIDE EFFECTS
None.
===========================================================================*/
#define ARR_SIZE( a ) ( sizeof( (a) ) / sizeof( (a[0]) ) )
/*===========================================================================
MACRO MOD_BY_POWER_OF_TWO
Will calculate x % y, where x is a non-negative integer and
y is a power of 2 from 2^0..2^32.
Will work for 2^0, 2^1, 2^2, 2^3, 2^4, ... 2^32
ie. 1, 2, 4, 8, 16, ... 4294967296
===========================================================================*/
#define MOD_BY_POWER_OF_TWO( val, mod_by ) \
( (dword)(val) & (dword)((mod_by)-1) )
/* -------------------------------------------------------------------------
** Debug Declarations
** ------------------------------------------------------------------------- */
/* Define 'SHOW_STAT' in order to view static's as globals
** (e.g. cl /DSHOW_STAT foo.c) If 'SHOW_STAT' is not defined,
** it gets defined as 'static'
*/
#ifdef LOCAL
#undef LOCAL
#endif
#ifdef SHOW_STAT
#define LOCAL
#else
#define LOCAL static
#endif
/*===========================================================================
FUNCTION DECLARATIONS
===========================================================================*/
/*===========================================================================
FUNCTION inp, outp, inpw, outpw, inpdw, outpdw
DESCRIPTION
IN/OUT port macros for byte and word ports, typically inlined by compilers
which support these routines
PARAMETERS
inp( xx_addr )
inpw( xx_addr )
inpdw( xx_addr )
outp( xx_addr, xx_byte_val )
outpw( xx_addr, xx_word_val )
outpdw( xx_addr, xx_dword_val )
xx_addr - Address of port to read or write (may be memory mapped)
xx_byte_val - 8 bit value to write
xx_word_val - 16 bit value to write
xx_dword_val - 32 bit value to write
DEPENDENCIES
None
RETURN VALUE
inp/inpw/inpdw: the byte, word or dword read from the given address
outp/outpw/outpdw: the byte, word or dword written to the given address
SIDE EFFECTS
None.
===========================================================================*/
#ifdef PC_EMULATOR_H
/* For PC emulation, include a header which defines inp/outp/inpw/outpw
** with the semantics above
*/
#define PC_EMULATOR_IO
#include PC_EMULATOR_H
#undef PC_EMULATOR_IO
#else
/* ARM based targets use memory mapped i/o, so the inp/outp calls are
** macroized to access memory directly
*/
#define inp(port) (*((volatile byte *) (port)))
#define inpw(port) (*((volatile word *) (port)))
#define inpdw(port) (*((volatile dword *)(port)))
#define outp(port, val) (*((volatile byte *) (port)) = ((byte) (val)))
#define outpw(port, val) (*((volatile word *) (port)) = ((word) (val)))
#define outpdw(port, val) (*((volatile dword *) (port)) = ((dword) (val)))
#endif
/*===========================================================================
FUNCTION enable, disable
DESCRIPTION
Interrupt enable and disable routines. Enable should cause the CPU to
allow interrupts and disable should cause the CPU to disallow
interrupts
PARAMETERS
None
DEPENDENCIES
None
RETURN VALUE
None
SIDE EFFECTS
None.
===========================================================================*/
#ifndef T_WINNT
/* ARM has no such definition, so we provide one here to enable/disable
** interrupts
*/
#define _disable() (void)rex_int_lock()
#define _enable() (void)rex_int_free()
#endif
#endif /* SWIG */
#endif /* COMDEF_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -