fio.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright : (C) 2022 Phytium Information Technology, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is OPEN SOURCE software: you can redistribute it and/or modify it
  6. * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
  7. * either version 1.0 of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
  10. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. * See the Phytium Public License for more details.
  12. *
  13. *
  14. * FilePath: fio.h
  15. * Date: 2021-04-07 09:53:07
  16. * LastEditTime: 2022-02-18 08:24:01
  17. * Description:  This files is for general reigster io functions
  18. *
  19. * Modify History:
  20. * Ver   Who        Date         Changes
  21. * ----- ------     --------    --------------------------------------
  22. */
  23. #ifndef FT_IO_H
  24. #define FT_IO_H
  25. #ifdef __cplusplus
  26. extern "C"
  27. {
  28. #endif
  29. #include "ftypes.h"
  30. static _INLINE u8 FtIn8(uintptr addr)
  31. {
  32. return *(volatile u8 *)addr;
  33. }
  34. static _INLINE u16 FtIn16(uintptr addr)
  35. {
  36. return *(volatile u16 *)addr;
  37. }
  38. static _INLINE u32 FtIn32(uintptr addr)
  39. {
  40. return *(volatile u32 *)addr;
  41. }
  42. static _INLINE u64 FtIn64(uintptr addr)
  43. {
  44. return *(volatile u64 *)addr;
  45. }
  46. static _INLINE void FtOut8(uintptr addr, u8 value)
  47. {
  48. volatile u8 *local_addr = (volatile u8 *)addr;
  49. *local_addr = value;
  50. }
  51. static _INLINE void FtOut16(uintptr addr, u16 value)
  52. {
  53. volatile u16 *local_addr = (volatile u16 *)addr;
  54. *local_addr = value;
  55. }
  56. static _INLINE void FtOut32(uintptr addr, u32 value)
  57. {
  58. volatile u32 *local_addr = (volatile u32 *)addr;
  59. *local_addr = value;
  60. }
  61. static _INLINE void FtOut64(uintptr addr, u64 value)
  62. {
  63. volatile u64 *local_addr = (volatile u64 *)addr;
  64. *local_addr = value;
  65. }
  66. static _INLINE void FtSetBit32(uintptr addr, u32 value)
  67. {
  68. volatile u32 last_value;
  69. last_value = FtIn32(addr);
  70. last_value |= value;
  71. FtOut32(addr, last_value);
  72. }
  73. static _INLINE void FtClearBit32(uintptr addr, u32 value)
  74. {
  75. volatile u32 last_value;
  76. last_value = FtIn32(addr);
  77. last_value &= ~value;
  78. FtOut32(addr, last_value);
  79. }
  80. static _INLINE void FtToggleBit32(uintptr addr, u32 toggle_pos)
  81. {
  82. volatile u32 value;
  83. value = FtIn32(addr);
  84. value ^= (1 << toggle_pos);
  85. FtOut32(addr, value);
  86. }
  87. static _INLINE u16 FtEndianSwap16(u16 data)
  88. {
  89. return (u16)(((data & 0xFF00U) >> 8U) | ((data & 0x00FFU) << 8U));
  90. }
  91. #define FT_WRITE32(_reg, _val) (*(volatile uint32_t *)&_reg = _val)
  92. #define FT_READ32(_reg) (*(volatile uint32_t *)&_reg)
  93. #ifdef __cplusplus
  94. }
  95. #endif
  96. #endif // !