type.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. // File name : type.h
  3. // Version : V0.1
  4. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. #ifndef _TYPES_H
  6. #define _TYPES_H
  7. typedef unsigned char BOOLEAN;
  8. typedef unsigned char UINT8;
  9. typedef signed char INT8;
  10. typedef unsigned short int UINT16;
  11. typedef signed short int INT16;
  12. typedef unsigned int UINT32;
  13. typedef signed int INT32;
  14. typedef float FP32;
  15. typedef double FP64;
  16. typedef unsigned long ULONG;
  17. typedef signed long LONG;
  18. typedef char TCHAR ;
  19. typedef unsigned char TBYTE ;
  20. typedef unsigned int TWORD ;
  21. typedef unsigned long TDWORD;
  22. typedef unsigned char BOOL;
  23. #define __I volatile const /*!< Defines 'read only' permissions */
  24. #define __O volatile /*!< Defines 'write only' permissions */
  25. #define __IO volatile /*!< Defines 'read / write' permissions */
  26. #define BIT0 (1<<0)
  27. #define BIT1 (1<<1)
  28. #define BIT2 (1<<2)
  29. #define BIT3 (1<<3)
  30. #define BIT4 (1<<4)
  31. #define BIT5 (1<<5)
  32. #define BIT6 (1<<6)
  33. #define BIT7 (1<<7)
  34. #define BIT8 (1<<8)
  35. #define BIT9 (1<<9)
  36. #define BIT11 (1<<11)
  37. #ifndef U32
  38. typedef unsigned int U32;
  39. #endif
  40. #ifndef U16
  41. typedef unsigned short int U16;
  42. #endif
  43. #ifndef U8
  44. typedef unsigned char U8;
  45. #endif
  46. #ifndef Uint32
  47. typedef unsigned int Uint32;
  48. #endif
  49. #ifndef Uint16
  50. typedef unsigned short int Uint16;
  51. #endif
  52. #ifndef Uint8
  53. typedef unsigned char Uint8;
  54. #endif
  55. #ifndef uchar
  56. #define uchar unsigned char
  57. #endif
  58. #ifndef uint
  59. #define uint unsigned int
  60. #endif
  61. #ifndef ushort
  62. #define ushort unsigned short
  63. #endif
  64. #ifndef ulong
  65. #define ulong unsigned long
  66. #endif
  67. typedef unsigned char u8;
  68. typedef signed char s8;
  69. typedef unsigned short int u16;
  70. typedef signed short int s16;
  71. typedef unsigned int u32;
  72. typedef signed int s32;
  73. typedef unsigned long int u64;
  74. typedef signed long int s64;
  75. typedef unsigned int const uc32; /* Read Only */
  76. typedef unsigned short int const uc16; /* Read Only */
  77. typedef unsigned char const uc8; /* Read Only */
  78. typedef volatile unsigned int vu32;
  79. typedef volatile unsigned short int vu16;
  80. typedef volatile unsigned char vu8;
  81. typedef volatile unsigned int const vuc32; /* Read Only */
  82. typedef volatile unsigned short int const vuc16; /* Read Only */
  83. typedef volatile unsigned char const vuc8; /* Read Only */
  84. typedef unsigned char bool_t;
  85. typedef enum {FALSE = 0, TRUE = !FALSE} bool;
  86. typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus;
  87. typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
  88. #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
  89. /* Bit_SET and Bit_RESET enumeration -----------------------------------------*/
  90. typedef enum
  91. { Bit_RESET = 0,
  92. Bit_SET
  93. }BitAction;
  94. #define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET))
  95. #define GPIO_INPUT 0
  96. #define GPIO_OUTPUT 1
  97. #define IS_GPIO_DIR_BIT(BIT) (((BIT) == GPIO_INPUT) || \
  98. ((BIT) == GPIO_OUTPUT))
  99. #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
  100. #define _U 0x01 /* upper */
  101. #define _L 0x02 /* lower */
  102. #define _D 0x04 /* digit */
  103. #define _C 0x08 /* cntrl */
  104. #define _P 0x10 /* punct */
  105. #define _S 0x20 /* white space (space/lf/tab) */
  106. #define _X 0x40 /* hex digit */
  107. #define _SP 0x80 /* hard space (0x20) */
  108. extern unsigned char _ctype[];
  109. extern char _ctmp;
  110. #define isalnum(c) ((_ctype+1)[c]&(_U|_L|_D))
  111. #define isalpha(c) ((_ctype+1)[c]&(_U|_L))
  112. #define iscntrl(c) ((_ctype+1)[c]&(_C))
  113. #define isdigit(c) ((_ctype+1)[c]&(_D))
  114. #define isgraph(c) ((_ctype+1)[c]&(_P|_U|_L|_D))
  115. #define islower(c) ((_ctype+1)[c]&(_L))
  116. #define isprint(c) ((_ctype+1)[c]&(_P|_U|_L|_D|_SP))
  117. #define ispunct(c) ((_ctype+1)[c]&(_P))
  118. #define isspace(c) ((_ctype+1)[c]&(_S))
  119. #define isupper(c) ((_ctype+1)[c]&(_U))
  120. #define isxdigit(c) ((_ctype+1)[c]&(_D|_X))
  121. #define isascii(c) (((unsigned) c)<=0x7f)
  122. #define toascii(c) (((unsigned) c)&0x7f)
  123. #define tolower(c) (_ctmp=c,isupper(_ctmp)?_ctmp-('A'-'a'):_ctmp)
  124. #define toupper(c) (_ctmp=c,islower(_ctmp)?_ctmp-('a'-'A'):_ctmp)
  125. #endif
  126. /* end of types.h */