/
picorv_dma_hal.h
86 lines (71 loc) · 2.12 KB
/
picorv_dma_hal.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef PICORV_DMA_HAL_H
#define PICORV_DMA_HAL_H
#include <assert.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* PicoRV DMA hardware access layer.
*/
#define PICORV_BASE 0x10002000
//Program Memory Base Address and size
#define PICORV_PROG_MEM_BASE PICORV_BASE
#define PICORV_PROG_SIZE_BYTES 4096
//System Registers Base Address.
#define PICORV_SYS_REG_BASE (PICORV_BASE+0x1000)
//Host Interface Registers Base Address.
#define PICORV_HIR_REG_BASE (PICORV_SYS_REG_BASE + 16*4)
//Output IRQ system register offset
#define PICORV_SYS_REG_IRQ_OUT 0
//Input IRQ system register offset
#define PICORV_SYS_REG_IRQ_IN 1
//Control system register offsset
#define PICORV_SYS_REG_CTRL 2
//Host Interface register offsets
#define PICORV_HIR_0 0
#define PICORV_HIR_1 1
#define PICORV_HIR_2 2
#define PICORV_HIR_3 3
#define PICORV_HIR_4 4
#define PICORV_HIR_5 5
#define PICORV_HIR_6 6
#define PICORV_HIR_7 7
#define PICORV_HIR_8 8
#define PICORV_HIR_9 9
#define PICORV_HIR_10 10
#define PICORV_HIR_11 11
#define PICORV_HIR_12 12
#define PICORV_HIR_13 13
#define PICORV_HIR_14 14
#define PICORV_HIR_15 15
//Write to System Register
inline void picorv_sys_reg_wr(unsigned reg_offset, unsigned val)
{
assert(reg_offset <= PICORV_SYS_REG_CTRL);
((unsigned volatile *)(PICORV_SYS_REG_BASE))[reg_offset] = val;
}
//Read from System Register
inline unsigned picorv_sys_reg_rd(unsigned reg_offset)
{
assert(reg_offset <= PICORV_SYS_REG_CTRL);
return ((unsigned volatile *)(PICORV_SYS_REG_BASE))[reg_offset];
}
//Write to Host Interface Register
inline void picorv_hir_reg_wr(unsigned hir_reg_offset, unsigned val)
{
assert(hir_reg_offset <= PICORV_HIR_15);
((unsigned volatile *)(PICORV_HIR_REG_BASE))[hir_reg_offset] = val;
}
//Read from Host Interface Register
inline unsigned picorv_hir_reg_rd(unsigned hir_reg_offset)
{
assert(hir_reg_offset <= PICORV_HIR_15);
return ((unsigned volatile *)(PICORV_HIR_REG_BASE))[hir_reg_offset];
}
//Load a PicoRV program into Program Memory.
//progLen must be a multiple of 4 and <= PICORV_PROG_SIZE_BYTES.
void picorv_load_program(unsigned char *progData, unsigned progLen);
#ifdef __cplusplus
}
#endif
#endif //PICORV_DMA_HAL_H