13
13
#ifndef _ASMLANGUAGE
14
14
/* CSR access helpers */
15
15
16
+ BUILD_ASSERT (CONFIG_LITEX_CSR_DATA_WIDTH == 8 || CONFIG_LITEX_CSR_DATA_WIDTH == 32 ,
17
+ "CONFIG_LITEX_CSR_DATA_WIDTH must be 8 or 32 bits" );
18
+
16
19
static inline uint8_t litex_read8 (mem_addr_t addr )
17
20
{
18
- #if CONFIG_LITEX_CSR_DATA_WIDTH >= 8
19
21
return sys_read8 (addr );
20
- #else
21
- #error CSR data width less than 8
22
- #endif
23
22
}
24
23
25
24
static inline uint16_t litex_read16 (mem_addr_t addr )
26
25
{
27
26
#if CONFIG_LITEX_CSR_DATA_WIDTH == 8
28
27
return (sys_read8 (addr ) << 8 )
29
28
| sys_read8 (addr + 0x4 );
30
- #elif CONFIG_LITEX_CSR_DATA_WIDTH >= 16
29
+ #else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
31
30
return sys_read16 (addr );
32
- #else
33
- #error Unsupported CSR data width
34
31
#endif
35
32
}
36
33
@@ -41,10 +38,8 @@ static inline uint32_t litex_read32(mem_addr_t addr)
41
38
| (sys_read8 (addr + 0x4 ) << 16 )
42
39
| (sys_read8 (addr + 0x8 ) << 8 )
43
40
| sys_read8 (addr + 0xc );
44
- #elif CONFIG_LITEX_CSR_DATA_WIDTH >= 32
41
+ #else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
45
42
return sys_read32 (addr );
46
- #else
47
- #error Unsupported CSR data width
48
43
#endif
49
44
}
50
45
@@ -59,33 +54,23 @@ static inline uint64_t litex_read64(mem_addr_t addr)
59
54
| ((uint64_t )sys_read8 (addr + 0x14 ) << 16 )
60
55
| ((uint64_t )sys_read8 (addr + 0x18 ) << 8 )
61
56
| (uint64_t )sys_read8 (addr + 0x1c );
62
- #elif CONFIG_LITEX_CSR_DATA_WIDTH == 32
57
+ #else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
63
58
return ((uint64_t )sys_read32 (addr ) << 32 ) | (uint64_t )sys_read32 (addr + 0x4 );
64
- #elif CONFIG_LITEX_CSR_DATA_WIDTH >= 64
65
- return sys_read64 (addr );
66
- #else
67
- #error Unsupported CSR data width
68
59
#endif
69
60
}
70
61
71
62
static inline void litex_write8 (uint8_t value , mem_addr_t addr )
72
63
{
73
- #if CONFIG_LITEX_CSR_DATA_WIDTH >= 8
74
64
sys_write8 (value , addr );
75
- #else
76
- #error CSR data width less than 8
77
- #endif
78
65
}
79
66
80
67
static inline void litex_write16 (uint16_t value , mem_addr_t addr )
81
68
{
82
69
#if CONFIG_LITEX_CSR_DATA_WIDTH == 8
83
70
sys_write8 (value >> 8 , addr );
84
71
sys_write8 (value , addr + 0x4 );
85
- #elif CONFIG_LITEX_CSR_DATA_WIDTH >= 16
72
+ #else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
86
73
sys_write16 (value , addr );
87
- #else
88
- #error Unsupported CSR data width
89
74
#endif
90
75
}
91
76
@@ -96,10 +81,8 @@ static inline void litex_write32(uint32_t value, mem_addr_t addr)
96
81
sys_write8 (value >> 16 , addr + 0x4 );
97
82
sys_write8 (value >> 8 , addr + 0x8 );
98
83
sys_write8 (value , addr + 0xC );
99
- #elif CONFIG_LITEX_CSR_DATA_WIDTH >= 32
84
+ #else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
100
85
sys_write32 (value , addr );
101
- #else
102
- #error Unsupported CSR data width
103
86
#endif
104
87
}
105
88
@@ -114,14 +97,10 @@ static inline void litex_write64(uint64_t value, mem_addr_t addr)
114
97
sys_write8 (value >> 16 , addr + 0x14 );
115
98
sys_write8 (value >> 8 , addr + 0x18 );
116
99
sys_write8 (value , addr + 0x1C );
117
- #elif CONFIG_LITEX_CSR_DATA_WIDTH == 32
100
+ #else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
118
101
sys_write32 (value >> 32 , addr );
119
102
sys_write32 (value , addr + 0x4 );
120
- #elif CONFIG_LITEX_CSR_DATA_WIDTH >= 64
121
- sys_write64 (value , addr );
122
- #else
123
- #error Unsupported CSR data width
124
- #endif
103
+ #endif /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
125
104
}
126
105
127
106
/*
0 commit comments