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