Skip to content

Commit 0a21405

Browse files
maass-hamburgcfriedt
authored andcommitted
soc: litex: check CONFIG_LITEX_CSR_DATA_WIDTH
Litex only supports CONFIG_LITEX_CSR_DATA_WIDTH with 8 and 32 bit, enforce it here too. Signed-off-by: Fin Maaß <[email protected]>
1 parent 456bfbf commit 0a21405

File tree

1 file changed

+10
-31
lines changed
  • soc/litex/litex_vexriscv

1 file changed

+10
-31
lines changed

soc/litex/litex_vexriscv/soc.h

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,21 @@
1313
#ifndef _ASMLANGUAGE
1414
/* CSR access helpers */
1515

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+
1619
static inline uint8_t litex_read8(mem_addr_t addr)
1720
{
18-
#if CONFIG_LITEX_CSR_DATA_WIDTH >= 8
1921
return sys_read8(addr);
20-
#else
21-
#error CSR data width less than 8
22-
#endif
2322
}
2423

2524
static inline uint16_t litex_read16(mem_addr_t addr)
2625
{
2726
#if CONFIG_LITEX_CSR_DATA_WIDTH == 8
2827
return (sys_read8(addr) << 8)
2928
| sys_read8(addr + 0x4);
30-
#elif CONFIG_LITEX_CSR_DATA_WIDTH >= 16
29+
#else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
3130
return sys_read16(addr);
32-
#else
33-
#error Unsupported CSR data width
3431
#endif
3532
}
3633

@@ -41,10 +38,8 @@ static inline uint32_t litex_read32(mem_addr_t addr)
4138
| (sys_read8(addr + 0x4) << 16)
4239
| (sys_read8(addr + 0x8) << 8)
4340
| sys_read8(addr + 0xc);
44-
#elif CONFIG_LITEX_CSR_DATA_WIDTH >= 32
41+
#else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
4542
return sys_read32(addr);
46-
#else
47-
#error Unsupported CSR data width
4843
#endif
4944
}
5045

@@ -59,33 +54,23 @@ static inline uint64_t litex_read64(mem_addr_t addr)
5954
| ((uint64_t)sys_read8(addr + 0x14) << 16)
6055
| ((uint64_t)sys_read8(addr + 0x18) << 8)
6156
| (uint64_t)sys_read8(addr + 0x1c);
62-
#elif CONFIG_LITEX_CSR_DATA_WIDTH == 32
57+
#else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
6358
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
6859
#endif
6960
}
7061

7162
static inline void litex_write8(uint8_t value, mem_addr_t addr)
7263
{
73-
#if CONFIG_LITEX_CSR_DATA_WIDTH >= 8
7464
sys_write8(value, addr);
75-
#else
76-
#error CSR data width less than 8
77-
#endif
7865
}
7966

8067
static inline void litex_write16(uint16_t value, mem_addr_t addr)
8168
{
8269
#if CONFIG_LITEX_CSR_DATA_WIDTH == 8
8370
sys_write8(value >> 8, addr);
8471
sys_write8(value, addr + 0x4);
85-
#elif CONFIG_LITEX_CSR_DATA_WIDTH >= 16
72+
#else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
8673
sys_write16(value, addr);
87-
#else
88-
#error Unsupported CSR data width
8974
#endif
9075
}
9176

@@ -96,10 +81,8 @@ static inline void litex_write32(uint32_t value, mem_addr_t addr)
9681
sys_write8(value >> 16, addr + 0x4);
9782
sys_write8(value >> 8, addr + 0x8);
9883
sys_write8(value, addr + 0xC);
99-
#elif CONFIG_LITEX_CSR_DATA_WIDTH >= 32
84+
#else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
10085
sys_write32(value, addr);
101-
#else
102-
#error Unsupported CSR data width
10386
#endif
10487
}
10588

@@ -114,14 +97,10 @@ static inline void litex_write64(uint64_t value, mem_addr_t addr)
11497
sys_write8(value >> 16, addr + 0x14);
11598
sys_write8(value >> 8, addr + 0x18);
11699
sys_write8(value, addr + 0x1C);
117-
#elif CONFIG_LITEX_CSR_DATA_WIDTH == 32
100+
#else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
118101
sys_write32(value >> 32, addr);
119102
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 */
125104
}
126105

127106
/*

0 commit comments

Comments
 (0)