@@ -24,8 +24,13 @@ static inline uint8_t litex_read8(mem_addr_t addr)
24
24
static inline uint16_t litex_read16 (mem_addr_t addr )
25
25
{
26
26
#if CONFIG_LITEX_CSR_DATA_WIDTH == 8
27
+ #ifdef CONFIG_LITEX_CSR_ORDERING_BIG
27
28
return (sys_read8 (addr ) << 8 )
28
29
| sys_read8 (addr + 0x4 );
30
+ #else
31
+ return sys_read8 (addr )
32
+ | (sys_read8 (addr + 0x4 ) << 8 );
33
+ #endif
29
34
#else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
30
35
return sys_read16 (addr );
31
36
#endif
@@ -34,10 +39,17 @@ static inline uint16_t litex_read16(mem_addr_t addr)
34
39
static inline uint32_t litex_read32 (mem_addr_t addr )
35
40
{
36
41
#if CONFIG_LITEX_CSR_DATA_WIDTH == 8
42
+ #ifdef CONFIG_LITEX_CSR_ORDERING_BIG
37
43
return (sys_read8 (addr ) << 24 )
38
44
| (sys_read8 (addr + 0x4 ) << 16 )
39
45
| (sys_read8 (addr + 0x8 ) << 8 )
40
46
| sys_read8 (addr + 0xc );
47
+ #else
48
+ return sys_read8 (addr )
49
+ | (sys_read8 (addr + 0x4 ) << 8 )
50
+ | (sys_read8 (addr + 0x8 ) << 16 )
51
+ | (sys_read8 (addr + 0xc ) << 24 );
52
+ #endif
41
53
#else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
42
54
return sys_read32 (addr );
43
55
#endif
@@ -46,6 +58,7 @@ static inline uint32_t litex_read32(mem_addr_t addr)
46
58
static inline uint64_t litex_read64 (mem_addr_t addr )
47
59
{
48
60
#if CONFIG_LITEX_CSR_DATA_WIDTH == 8
61
+ #ifdef CONFIG_LITEX_CSR_ORDERING_BIG
49
62
return (((uint64_t )sys_read8 (addr )) << 56 )
50
63
| ((uint64_t )sys_read8 (addr + 0x4 ) << 48 )
51
64
| ((uint64_t )sys_read8 (addr + 0x8 ) << 40 )
@@ -54,8 +67,22 @@ static inline uint64_t litex_read64(mem_addr_t addr)
54
67
| ((uint64_t )sys_read8 (addr + 0x14 ) << 16 )
55
68
| ((uint64_t )sys_read8 (addr + 0x18 ) << 8 )
56
69
| (uint64_t )sys_read8 (addr + 0x1c );
70
+ #else
71
+ return (uint64_t )sys_read8 (addr )
72
+ | ((uint64_t )sys_read8 (addr + 0x4 ) << 8 )
73
+ | ((uint64_t )sys_read8 (addr + 0x8 ) << 16 )
74
+ | ((uint64_t )sys_read8 (addr + 0xc ) << 24 )
75
+ | ((uint64_t )sys_read8 (addr + 0x10 ) << 32 )
76
+ | ((uint64_t )sys_read8 (addr + 0x14 ) << 40 )
77
+ | ((uint64_t )sys_read8 (addr + 0x18 ) << 48 )
78
+ | ((uint64_t )sys_read8 (addr + 0x1c ) << 56 );
79
+ #endif
57
80
#else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
81
+ #ifdef CONFIG_LITEX_CSR_ORDERING_BIG
58
82
return ((uint64_t )sys_read32 (addr ) << 32 ) | (uint64_t )sys_read32 (addr + 0x4 );
83
+ #else
84
+ return sys_read64 (addr );
85
+ #endif
59
86
#endif
60
87
}
61
88
@@ -67,8 +94,13 @@ static inline void litex_write8(uint8_t value, mem_addr_t addr)
67
94
static inline void litex_write16 (uint16_t value , mem_addr_t addr )
68
95
{
69
96
#if CONFIG_LITEX_CSR_DATA_WIDTH == 8
97
+ #ifdef CONFIG_LITEX_CSR_ORDERING_BIG
70
98
sys_write8 (value >> 8 , addr );
71
99
sys_write8 (value , addr + 0x4 );
100
+ #else
101
+ sys_write8 (value , addr );
102
+ sys_write8 (value >> 8 , addr + 0x4 );
103
+ #endif
72
104
#else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
73
105
sys_write16 (value , addr );
74
106
#endif
@@ -77,10 +109,17 @@ static inline void litex_write16(uint16_t value, mem_addr_t addr)
77
109
static inline void litex_write32 (uint32_t value , mem_addr_t addr )
78
110
{
79
111
#if CONFIG_LITEX_CSR_DATA_WIDTH == 8
112
+ #ifdef CONFIG_LITEX_CSR_ORDERING_BIG
80
113
sys_write8 (value >> 24 , addr );
81
114
sys_write8 (value >> 16 , addr + 0x4 );
82
115
sys_write8 (value >> 8 , addr + 0x8 );
83
116
sys_write8 (value , addr + 0xC );
117
+ #else
118
+ sys_write8 (value , addr );
119
+ sys_write8 (value >> 8 , addr + 0x4 );
120
+ sys_write8 (value >> 16 , addr + 0x8 );
121
+ sys_write8 (value >> 24 , addr + 0xC );
122
+ #endif
84
123
#else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
85
124
sys_write32 (value , addr );
86
125
#endif
@@ -89,6 +128,7 @@ static inline void litex_write32(uint32_t value, mem_addr_t addr)
89
128
static inline void litex_write64 (uint64_t value , mem_addr_t addr )
90
129
{
91
130
#if CONFIG_LITEX_CSR_DATA_WIDTH == 8
131
+ #ifdef CONFIG_LITEX_CSR_ORDERING_BIG
92
132
sys_write8 (value >> 56 , addr );
93
133
sys_write8 (value >> 48 , addr + 0x4 );
94
134
sys_write8 (value >> 40 , addr + 0x8 );
@@ -97,9 +137,23 @@ static inline void litex_write64(uint64_t value, mem_addr_t addr)
97
137
sys_write8 (value >> 16 , addr + 0x14 );
98
138
sys_write8 (value >> 8 , addr + 0x18 );
99
139
sys_write8 (value , addr + 0x1C );
140
+ #else
141
+ sys_write8 (value , addr );
142
+ sys_write8 (value >> 8 , addr + 0x4 );
143
+ sys_write8 (value >> 16 , addr + 0x8 );
144
+ sys_write8 (value >> 24 , addr + 0xC );
145
+ sys_write8 (value >> 32 , addr + 0x10 );
146
+ sys_write8 (value >> 40 , addr + 0x14 );
147
+ sys_write8 (value >> 48 , addr + 0x18 );
148
+ sys_write8 (value >> 56 , addr + 0x1C );
149
+ #endif
100
150
#else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
151
+ #ifdef CONFIG_LITEX_CSR_ORDERING_BIG
101
152
sys_write32 (value >> 32 , addr );
102
153
sys_write32 (value , addr + 0x4 );
154
+ #else
155
+ sys_write64 (value , addr );
156
+ #endif
103
157
#endif /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
104
158
}
105
159
0 commit comments