1 /*
2  * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0.
5  *
6  * @Date: 2021-04-07 09:53:07
7  * @LastEditTime: 2021-04-07 15:29:06
8  * @Description:  This files is for general reigster io functions
9  *
10  * @Modify History:
11  *  Ver   Who        Date         Changes
12  * ----- ------     --------    --------------------------------------
13  */
14 
15 #ifndef FT_IO_H
16 #define FT_IO_H
17 
18 #ifdef __cplusplus
19 extern "C"
20 {
21 #endif
22 
23 #include "ft_types.h"
24 
25 #if defined(__GNUC__) || defined(__ICCARM__) || defined(__MICROBLAZE__)
26 #define INLINE inline
27 #else
28 #define INLINE __inline
29 #endif
30 
31     /**
32      * @name: Ft_in8
33      * @msg:  Read byte value
34      * @in param {UINTPTR}: Addr 需要读取的地址
35      * @return {u8} Byte Value
36      */
Ft_in8(FT_IN UINTPTR Addr)37     static INLINE u8 Ft_in8(FT_IN UINTPTR Addr)
38     {
39         return *(volatile u8 *)Addr;
40     }
41 
42     /**
43      * @name: Ft_in16
44      * @msg:  Read half-word value
45      * @in param {UINTPTR}: Addr 需要读取的地址
46      * @return {u16} Half-word Value
47      */
Ft_in16(FT_IN UINTPTR Addr)48     static INLINE u16 Ft_in16(FT_IN UINTPTR Addr)
49     {
50         return *(volatile u16 *)Addr;
51     }
52 
53     /**
54      * @name: Ft_in32
55      * @msg:  Read word value
56      * @in param {UINTPTR}: Addr 需要读取的地址
57      * @return {u16} Word Value
58      */
Ft_in32(FT_IN UINTPTR Addr)59     static INLINE u32 Ft_in32(FT_IN UINTPTR Addr)
60     {
61         return *(volatile u32 *)Addr;
62     }
63 
64     /**
65      * @name: Ft_in64
66      * @msg:  Read u64 value
67      * @in param {UINTPTR}: Addr 需要读取的地址
68      * @return {u16} u64 Value
69      */
Ft_in64(FT_IN UINTPTR Addr)70     static INLINE u64 Ft_in64(FT_IN UINTPTR Addr)
71     {
72         return *(volatile u64 *)Addr;
73     }
74 
75     /**
76      * @name: Ft_out8
77      * @msg:  write byte value
78      * @in param {UINTPTR}: Addr 需要写入的地址
79      * @in param {u8}: Need write value
80      * @return {*}
81      */
Ft_out8(FT_IN UINTPTR Addr,FT_IN u8 Value)82     static INLINE void Ft_out8(FT_IN UINTPTR Addr, FT_IN u8 Value)
83     {
84         volatile u8 *LocalAddr = (volatile u8 *)Addr;
85         *LocalAddr = Value;
86     }
87 
88     /**
89      * @name: Ft_out16
90      * @msg: write half-word value
91      * @in param {UINTPTR}: Addr 需要写入的地址
92      * @in param {u16}: Need write value
93      * @return {*}
94      */
Ft_out16(FT_IN UINTPTR Addr,FT_IN u16 Value)95     static INLINE void Ft_out16(FT_IN UINTPTR Addr, FT_IN u16 Value)
96     {
97         volatile u16 *LocalAddr = (volatile u16 *)Addr;
98         *LocalAddr = Value;
99     }
100 
101     /**
102      * @name: Ft_out32
103      * @msg: write half-word value
104      * @in param {UINTPTR}: Addr 需要写入的地址
105      * @in param {u32}: Need write value
106      * @return {*}
107      */
Ft_out32(FT_IN UINTPTR Addr,FT_IN u32 Value)108     static INLINE void Ft_out32(FT_IN UINTPTR Addr, FT_IN u32 Value)
109     {
110         volatile u32 *LocalAddr = (volatile u32 *)Addr;
111         *LocalAddr = Value;
112     }
113 
114     /**
115      * @name: Ft_out64
116      * @msg: write u64 value
117      * @in param {UINTPTR}: Addr 需要写入的地址
118      * @in param {u64}: Need write value
119      * @return {*}
120      */
Ft_out64(FT_IN UINTPTR Addr,FT_IN u64 Value)121     static INLINE void Ft_out64(FT_IN UINTPTR Addr, FT_IN u64 Value)
122     {
123         volatile u64 *LocalAddr = (volatile u64 *)Addr;
124         *LocalAddr = Value;
125     }
126 
127     /**
128      * @name: Ft_setBit32
129      * @msg:
130      * @in param {FT_INUINTPTR} addr
131      * @in param {FT_INu32} offset
132      * @in param {FT_INu32} value
133      */
Ft_setBit32(FT_IN UINTPTR addr,FT_IN u32 value)134     static INLINE void Ft_setBit32(FT_IN UINTPTR addr, FT_IN u32 value)
135     {
136         u32 lastValue;
137         lastValue = Ft_in32(addr);
138         lastValue |= value;
139         Ft_out32(addr, lastValue);
140     }
141 
142     /**
143      * @name: Ft_clearBit32
144      * @msg:
145      * @in param:
146      * @inout param:
147      * @out param:
148      * @return {*}
149      * @param {FT_INUINTPTR} addr
150      * @param {FT_INu32} value
151      */
Ft_clearBit32(FT_IN UINTPTR addr,FT_IN u32 value)152     static INLINE void Ft_clearBit32(FT_IN UINTPTR addr, FT_IN u32 value)
153     {
154         u32 lastValue;
155         lastValue = Ft_in32(addr);
156         lastValue &= ~value;
157         Ft_out32(addr, lastValue);
158     }
159 
160 #ifdef __cplusplus
161 }
162 #endif
163 
164 #endif // !
165