forked from ARM-software/AVH
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arm_vsi4.py
179 lines (126 loc) · 4.28 KB
/
arm_vsi4.py
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# Copyright (c) 2021 Arm Limited. All rights reserved.
# Virtual Streaming Interface instance 4 Python script
##@addtogroup arm_vsi_py
# @{
#
##@package arm_vsi4
#Documentation for VSI peripherals module.
#
#More details.
import logging
## Set verbosity level
#verbosity = logging.DEBUG
verbosity = logging.ERROR
# [debugging] Verbosity settings
level = { 10: "DEBUG", 20: "INFO", 30: "WARNING", 40: "ERROR" }
logging.basicConfig(format='Py: VSI4: [%(levelname)s]\t%(message)s', level = verbosity)
logging.info("Verbosity level is set to " + level[verbosity])
# IRQ registers
IRQ_Status = 0
# Timer registers
Timer_Control = 0
Timer_Interval = 0
# Timer Control register definitions
Timer_Control_Run_Msk = 1<<0
Timer_Control_Periodic_Msk = 1<<1
Timer_Control_Trig_IRQ_Msk = 1<<2
Timer_Control_Trig_DMA_Msk = 1<<3
# DMA registers
DMA_Control = 0
# DMA Control register definitions
DMA_Control_Enable_Msk = 1<<0
DMA_Control_Direction_Msk = 1<<1
DMA_Control_Direction_P2M = 0<<1
DMA_Control_Direction_M2P = 1<<1
# User registers
Regs = [0] * 64
# Data buffer
Data = bytearray()
## Initialize
def init():
logging.info("Python function init() called")
## Read interrupt request (the VSI IRQ Status Register)
# @return value value read (32-bit)
def rdIRQ():
global IRQ_Status
logging.info("Python function rdIRQ() called")
value = IRQ_Status
logging.debug("Read interrupt request: {}".format(value))
return value
## Write interrupt request (the VSI IRQ Status Register)
# @param value value to write (32-bit)
# @return value value written (32-bit)
def wrIRQ(value):
global IRQ_Status
logging.info("Python function wrIRQ() called")
IRQ_Status = value
logging.debug("Write interrupt request: {}".format(value))
return value
## Write Timer registers (the VSI Timer Registers)
# @param index Timer register index (zero based)
# @param value value to write (32-bit)
# @return value value written (32-bit)
def wrTimer(index, value):
global Timer_Control, Timer_Interval
logging.info("Python function wrTimer() called")
if index == 0:
Timer_Control = value
logging.debug("Write Timer_Control: {}".format(value))
elif index == 1:
Timer_Interval = value
logging.debug("Write Timer_Interval: {}".format(value))
return value
## Timer event (called at Timer Overflow)
def timerEvent():
logging.info("Python function timerEvent() called")
## Write DMA registers (the VSI DMA Registers)
# @param index DMA register index (zero based)
# @param value value to write (32-bit)
# @return value value written (32-bit)
def wrDMA(index, value):
global DMA_Control
logging.info("Python function wrDMA() called")
if index == 0:
DMA_Control = value
logging.debug("Write DMA_Control: {}".format(value))
return value
## Read data from peripheral for DMA P2M transfer (VSI DMA)
# @param size size of data to read (in bytes, multiple of 4)
# @return data data read (bytearray)
def rdDataDMA(size):
global Data
logging.info("Python function rdDataDMA() called")
n = min(len(Data), size)
data = bytearray(size)
data[0:n] = Data[0:n]
logging.debug("Read data ({} bytes)".format(size))
return data
## Write data to peripheral for DMA M2P transfer (VSI DMA)
# @param data data to write (bytearray)
# @param size size of data to write (in bytes, multiple of 4)
def wrDataDMA(data, size):
global Data
logging.info("Python function wrDataDMA() called")
Data = data
logging.debug("Write data ({} bytes)".format(size))
return
## Read user registers (the VSI User Registers)
# @param index user register index (zero based)
# @return value value read (32-bit)
def rdRegs(index):
global Regs
logging.info("Python function rdRegs() called")
value = Regs[index]
logging.debug("Read user register at index {}: {}".format(index, value))
return value
## Write user registers (the VSI User Registers)
# @param index user register index (zero based)
# @param value value to write (32-bit)
# @return value value written (32-bit)
def wrRegs(index, value):
global Regs
logging.info("Python function wrRegs() called")
Regs[index] = value
logging.debug("Write user register at index {}: {}".format(index, value))
return value
## @}