fh_def.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * This file is part of FH8620 BSP for RT-Thread distribution.
  3. *
  4. * Copyright (c) 2016 Shanghai Fullhan Microelectronics Co., Ltd.
  5. * All rights reserved
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * Visit http://www.fullhan.com to get contact with Fullhan.
  22. *
  23. * Change Logs:
  24. * Date Author Notes
  25. */
  26. #ifndef FH_DEF_H_
  27. #define FH_DEF_H_
  28. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  29. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  30. typedef char SINT8;
  31. typedef short SINT16;
  32. typedef int SINT32;
  33. typedef long long SINT64;
  34. typedef unsigned char UINT8;
  35. typedef unsigned short UINT16;
  36. typedef unsigned int UINT32;
  37. typedef unsigned long long UINT64;
  38. #ifndef TYPE_DEFINED
  39. typedef unsigned char uchar;
  40. typedef signed char int8;
  41. typedef unsigned char uint8;
  42. typedef signed short int16;
  43. typedef unsigned short uint16;
  44. typedef signed int int32;
  45. typedef unsigned int uint32;
  46. typedef signed long long int64;
  47. typedef unsigned long long uint64;
  48. typedef float ieee_single;
  49. typedef double ieee_double;
  50. typedef unsigned long boolean;
  51. #define TYPE_DEFINED
  52. #endif
  53. #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  54. #define reg_read(addr) (*((volatile UINT32 *)(addr)))
  55. #define reg_write(addr,value) (*(volatile UINT32 *)(addr)=(value))
  56. #define GET_REG(addr) reg_read(addr)
  57. #define SET_REG(addr,value) reg_write(addr,value)
  58. #define SET_REG_M(addr,value,mask) reg_write(addr,(reg_read(addr)&(~(mask)))|((value)&(mask)))
  59. #define SET_REG_B(addr,element,highbit,lowbit) SET_REG_M((addr),((element)<<(lowbit)),(((1<<((highbit)-(lowbit)+1))-1)<<(lowbit)))
  60. #define GET_REG8(addr) (*((volatile UINT8 *)(addr)))
  61. #define SET_REG8(addr,value) (*(volatile UINT8 *)(addr)=(value))
  62. #define read_reg(addr) (*((volatile uint32 *)(addr)))
  63. #define write_reg(addr, reg) (*((volatile uint32 *)(addr))) = (uint32)(reg)
  64. #define inw(addr) (*((volatile uint32 *)(addr)))
  65. #define outw(addr, reg) (*((volatile uint32 *)(addr))) = (uint32)(reg)
  66. #ifndef BIT
  67. #define BIT(nr) (1UL << (nr))
  68. #endif
  69. typedef volatile const unsigned int RoReg; /**< Read only 32-bit register (volatile const unsigned int) */
  70. typedef volatile unsigned int WoReg; /**< Write only 32-bit register (volatile unsigned int) */
  71. typedef volatile unsigned int RwReg; /**< Read-Write 32-bit register (volatile unsigned int) */
  72. #endif /* FH_DEF_H_ */