|
16 | 16 | BUILD_ASSERT(CONFIG_LITEX_CSR_DATA_WIDTH == 8 || CONFIG_LITEX_CSR_DATA_WIDTH == 32,
|
17 | 17 | "CONFIG_LITEX_CSR_DATA_WIDTH must be 8 or 32 bits");
|
18 | 18 |
|
| 19 | +#define LITEX_CSR_DW_BYTES (CONFIG_LITEX_CSR_DATA_WIDTH/8) |
| 20 | +#define LITEX_CSR_OFFSET_BYTES 4 |
| 21 | + |
| 22 | +static inline size_t litex_num_subregs(size_t csr_bytes) |
| 23 | +{ |
| 24 | + return (csr_bytes - 1) / LITEX_CSR_DW_BYTES + 1; |
| 25 | +} |
| 26 | + |
19 | 27 | static inline uint8_t litex_read8(mem_addr_t addr)
|
20 | 28 | {
|
21 | 29 | return sys_read8(addr);
|
@@ -198,6 +206,34 @@ static inline uint32_t litex_read(mem_addr_t addr, uint32_t size)
|
198 | 206 | }
|
199 | 207 | }
|
200 | 208 |
|
| 209 | +static inline void litex_write32_array(mem_addr_t addr, uint32_t *buf, size_t cnt) |
| 210 | +{ |
| 211 | + size_t i; |
| 212 | + |
| 213 | + for (i = 0; i < cnt; i++) { |
| 214 | +#ifdef CONFIG_LITEX_CSR_ORDERING_BIG |
| 215 | + litex_write32(buf[cnt - 1 - i], addr); |
| 216 | +#else |
| 217 | + litex_write32(buf[i], addr); |
| 218 | +#endif |
| 219 | + addr += litex_num_subregs(sizeof(uint32_t)) * LITEX_CSR_OFFSET_BYTES; |
| 220 | + } |
| 221 | +} |
| 222 | + |
| 223 | +static inline void litex_read32_array(mem_addr_t addr, uint32_t *buf, size_t cnt) |
| 224 | +{ |
| 225 | + size_t i; |
| 226 | + |
| 227 | + for (i = 0; i < cnt; i++) { |
| 228 | +#ifdef CONFIG_LITEX_CSR_ORDERING_BIG |
| 229 | + buf[cnt - 1 - i] = litex_read32(addr); |
| 230 | +#else |
| 231 | + buf[i] = litex_read32(addr); |
| 232 | +#endif |
| 233 | + addr += litex_num_subregs(sizeof(uint32_t)) * LITEX_CSR_OFFSET_BYTES; |
| 234 | + } |
| 235 | +} |
| 236 | + |
201 | 237 | #endif /* _ASMLANGUAGE */
|
202 | 238 |
|
203 | 239 | #endif /* __RISCV32_LITEX_VEXRISCV_SOC_H_ */
|
0 commit comments