Piconomic Logo www.piconomic.co.za

common.h : Common definitions
[/general : General utility files & modules]

Definition of standard types, boolean, scope and utility macros. More...

Defines

#define NULL   0
 NULL pointer.

Standard types



typedef uint8_t u8_t
 unsigned 8-bit value (0 to 255)
typedef int8_t s8_t
 signed 8-bit value (-128 to +127)
typedef uint16_t u16_t
 unsigned 16-bit value (0 to 65535)
typedef int16_t s16_t
 signed 16-bit value (-32768 to 32767)
typedef uint32_t u32_t
 unsigned 32-bit value (0 to 4294967296)
typedef int32_t s32_t
 signed 32-bit value (-2147483648 to +2147483647)

Boolean type



#define bool_t   bool
#define TRUE   true

Type size and sign macros

Source: "Catching Integer Overflows in C"



#define TYPE_IS_SIGNED(type)   ((type)-1 < 1)
 Test if a type is signed or unsigned.
#define MIN_OF_TYPE(type)   (TYPE_IS_SIGNED(type)?__MIN_SIGNED(type):(type)0)
 Return the minimum of a type.
#define MAX_OF_TYPE(type)   ((type)~MIN_OF_TYPE(type))
 Return the maximum of a type.

Concatenation macros



#define CONCAT(x, y)   _CONCAT(x, y)
 Recursive token concatenation macro.

Bit manipulation macros useful to manipulate Port IO pins



#define BIT_SET_HI(var, bit)   {var |=(1<<bit);}
 Macro to set a bit (1).
#define BIT_SET_LO(var, bit)   {var &= ~(1<<bit);}
 Macro to clear a bit (0).
#define BIT_TOGGLE(var, bit)   {if(var&(1<<bit)) {var &= ~(1<<bit);} else {var |=(1<<bit);}}
 Macro to toggle a bit.
#define BIT_IS_HI(var, bit)   ((var&(1<<bit)) != 0)
 Macro to test if a bit is set (1?).
#define BIT_IS_LO(var, bit)   ((var&(1<<bit)) == 0)
 Macro to test if a bit is cleared (0?).
#define LOOP_UNTIL_BIT_IS_HI(var, bit)   while(BIT_IS_LO(var,bit)) {;}
 Macro to wait until a bit is set.
#define LOOP_UNTIL_BIT_IS_LO(var, bit)   while(BIT_IS_HI(var,bit)) {;}
 Macro to wait until a bit is cleared.

Byte macros



#define U16_HI8(data)   ((u8_t)((data>>8)&0xff))
 Macro to extract the high 8 bits of a 16-bit value (Most Significant Byte).
#define U16_LO8(data)   ((u8_t)(data&0xff))
 Macro to extract the low 8 bits of a 16-bit value (Least Significant Byte).
#define U32_HI8(data)   ((u8_t)((data>>24)&0xff))
 Macro to extract the high 8 bits (bits 31..24) of a 32-bit value.
#define U32_MH8(data)   ((u8_t)((data>>16)&0xff))
 Macro to extract the medium high 8 bits (bits 23..16) of a 32-bit value.
#define U32_ML8(data)   ((u8_t)((data>>8)&0xff))
 Macro to extract the medium low 8 bits (bits 15..8) of a 32-bit value.
#define U32_LO8(data)   ((u8_t)(data&0xff))
 Macro to extract the low 8 bits (bits 7..0) of a 32-bit value.

General utility macros



#define DIV_ROUND(dividend, divisor)   (((dividend+((divisor)>>1))/(divisor)))
 Macro to calculate division with rounding to nearest integer value.
#define DIV_ROUNDUP(dividend, divisor)   (((dividend+((divisor)-1))/(divisor)))
 Macro to calculate division with rounding to nearest integer value.
#define BOUND(value, min, max)   (((value)>=(min))&&((value)<=(max)))
 Macro to check if a value is within bounds (min <= value <= max ?).
#define ARRAY_LENGTH(array)   (sizeof(array)/sizeof((array)[0]))
 Macro to calculate the length of an array.
#define VAL_IS_PWR_OF_TWO(value)   (((value)&((value)-1)) == 0)
 Macro to see if a value is a power of two.

Detailed Description

File: common.h


Define Documentation

#define MIN_OF_TYPE ( type   )     (TYPE_IS_SIGNED(type)?__MIN_SIGNED(type):(type)0)

For an unsigned type it is zero. For a signed type this is the largest negative value

Definition at line 133 of file common.h.

#define CONCAT ( x,
 )     _CONCAT(x, y)
Example:
 #define XY       123456
 #define TOKEN1   X
 #define TOKEN2   Y
 #define TOKEN1_2 CONCAT(X,Y)

CONCAT(X,Y) is expanded by the C preprocessor to the macro XY, which is expanded to 123456.

Definition at line 159 of file common.h.

#define DIV_ROUND ( dividend,
divisor   )     (((dividend+((divisor)>>1))/(divisor)))

Warning: This macro will only work correctly if (dividend >= 0)

Definition at line 214 of file common.h.

Referenced by systmr_init(), uart1_init(), and uart2_init().

#define DIV_ROUNDUP ( dividend,
divisor   )     (((dividend+((divisor)-1))/(divisor)))

Warning: This macro will only work correctly if (dividend >= 0)

Definition at line 221 of file common.h.

Generated on Fri Aug 13 16:50:38 2010 for Piconomic Firmware Library by doxygen 1.6.3