📄 base_types.h
字号:
/****h* DE9901/base_types
* FILE NAME
* base_types.h
* COPYRIGHT
* (c) 1996-2005 Mobitex Technology AB - All rights reserved
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * 3. The name Mobitex Technology AB may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY MOBITEX TECHNOLOGY AB "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL MOBITEX TECHNOLOGY AB BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* AUTHOR
* Henrik Harmsen/UZ, MPN/Kjell Westerberg
* HISTORY
* Changes in the file are recorded in this list.
* Ver: Date: Responsible: Comment:
* R1A01 2005-01-17 Kjell Westerberg Approved.
* DESCRIPTION
* Definitions for commonly used types and macros.
*
* The s8, u8, s16, u16, s32, u32 types are all compiler and machine
* independent. They always have the same size and signed/unsigned
* property. (They are defined differently for different compilers
* and architectures).
*
* The native C-style 'int', 'short int' and 'char' are all compiler
* and machine dependent. Their true size and signed/unsigned
* property is determined by the compiler and machine architecture.
*
* Therefore:
* When a variable is needed that has to be a certain length,
* like a 16 or 32 bit counter, use the s8, u8, s16, u16, s32
* and u32 types! Note that this is normally the case, that you
* need to specify exactly what size and signed/unsigned property
* a type has.
*
* When a variable is needed that has to be native C-style 'char'
* or 'int', then use 'char' and 'int' instead of s8 and s32! For
* example, when dealing with C-style strings, they have the type
* (char*), not (s8*) or (u8*). All the standard C-library string
* functions are defined on (char*) pointers.
*
* The normal case is to use the s8, u8, s16.. base types defined
* below.
*
* What signed/unsigned property does the type 'char' have?
* Answer: None.
* There are three types of char:
* 1) char
* 2) unsigned char
* 3) signed char
* ** STRING POINTERS HAVE TYPE (char*) ! NOT (u8*) or (s8*) ! **
* Try passing an (unsigned char*) or (signed char*) to the
* strlen() function in the "acc" compiler. It likes none, it wants
* (char*) and only (char*)...
***/
#include <cyg/infra/cyg_type.h>
#ifndef _BASE_TYPES_H
#define _BASE_TYPES_H
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifdef NULL
#undef NULL
#endif
/* ANSI C allows both "(void*)0" and "0" as definition of NULL.
C++ has a problem with "(void*)0" so we use "0". (see pg. 54
in the C++ programming rules) */
#define NULL 0
/* SIGN(-xxx) = -1, SIGN(0) = 0, SIGN(xxx) = 1 */
#ifndef SIGN
#define SIGN(n) (0 < (n) ? 1 : ((n) < 0 ? -1 : 0))
#endif
#ifndef ABS
#define ABS(n) (0 < (n) ? (n) : -(n))
#endif
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a, b) ((b) < (a) ? (a) : (b))
#endif
/* CLAMP(): make sure the variable x is within the bounds of low...high */
#ifndef CLAMP
#define CLAMP(low, x, high) ((x) < (low) ? (low) : ((high) < (x) ? (high) : (x)))
#endif
/* note: string pointers are (char*), not (u8*) or (s8*) */
typedef unsigned char u8; /* unsigned 8 bit 0 to 255 */
#ifdef __cplusplus
typedef char s8; /* signed 8 bit -128 to 127 */
#else
typedef signed char s8; /* signed 8 bit -128 to 127 */
#endif
typedef unsigned short int u16; /* unsigned 16 bit 0 to 65535 */
typedef signed short int s16; /* signed 16 bit -32768 to 32767 */
typedef unsigned long int u32; /* unsigned 32 bit 0 to 4294967295 */
typedef signed long int s32; /* signed 32 bit -2147483648 to
2147483647 */
typedef unsigned long long u64; /* unsigned 64 bit */
typedef signed long long s64; /* signed 64 bit */
typedef float r32; /* floating point 32 bit
1.18E-38 to 3.4E38 */
typedef double r64; /* floating point 64 bit
1.18E-308 to 3.4E308 */
/* Short boolean type to be used in packed structs */
/* or other places where only a byte shall represent the boolean. */
typedef u8 sbool;
#define PAD1 u8 padding[1];
#define PAD2 u8 padding[2];
#define PAD3 u8 padding[3];
typedef union {
u32 originalLong;
u16 shortArray[2];
u8 charArray[4];
struct {
u16 LSShort;
u16 MSShort;
} rShort;
struct {
u8 LSB;
u8 nextLSB;
u8 nextMSB;
u8 MSB;
} rChar;
} longUnion_t;
typedef union {
u16 originalShort;
u8 charArray[2];
struct {
u8 LSB;
u8 MSB;
} rChar;
} shortUnion_t;
#endif /* _BASE_TYPES_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -