Skip to content

Commit 56bf288

Browse files
maass-hamburgcfriedt
authored andcommitted
soc: litex: add array functions to soc.h
adds functions to read and write arrays to the soc.h file. Signed-off-by: Fin Maaß <[email protected]>
1 parent 5a0fba3 commit 56bf288

File tree

1 file changed

+36
-0
lines changed
  • soc/litex/litex_vexriscv

1 file changed

+36
-0
lines changed

soc/litex/litex_vexriscv/soc.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
BUILD_ASSERT(CONFIG_LITEX_CSR_DATA_WIDTH == 8 || CONFIG_LITEX_CSR_DATA_WIDTH == 32,
1717
"CONFIG_LITEX_CSR_DATA_WIDTH must be 8 or 32 bits");
1818

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+
1927
static inline uint8_t litex_read8(mem_addr_t addr)
2028
{
2129
return sys_read8(addr);
@@ -198,6 +206,34 @@ static inline uint32_t litex_read(mem_addr_t addr, uint32_t size)
198206
}
199207
}
200208

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+
201237
#endif /* _ASMLANGUAGE */
202238

203239
#endif /* __RISCV32_LITEX_VEXRISCV_SOC_H_ */

0 commit comments

Comments
 (0)