Skip to content

Commit 6df80d4

Browse files
authored
Made Python logging to use getLogger(__name__) (#22)
More differentiation in logging was required in parallel execution of VSI scripts, when using them with AVH Corellium models out of python C libs.
1 parent 8e572c2 commit 6df80d4

File tree

19 files changed

+503
-441
lines changed

19 files changed

+503
-441
lines changed

interface/audio/python/arm_vsi0.py

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2021-2022 Arm Limited. All rights reserved.
1+
# Copyright (c) 2021-2024 Arm Limited. All rights reserved.
22

33
# Virtual Streaming Interface instance 0 Python script: Audio Input
44

@@ -13,15 +13,18 @@
1313
import logging
1414
import wave
1515

16+
logger = logging.getLogger(__name__)
1617

1718
## Set verbosity level
1819
#verbosity = logging.DEBUG
20+
#verbosity = logging.INFO
21+
#verbosity = logging.WARNING
1922
verbosity = logging.ERROR
2023

2124
# [debugging] Verbosity settings
2225
level = { 10: "DEBUG", 20: "INFO", 30: "WARNING", 40: "ERROR" }
23-
logging.basicConfig(format='Py: VSI0: [%(levelname)s]\t%(message)s', level = verbosity)
24-
logging.info("Verbosity level is set to " + level[verbosity])
26+
logging.basicConfig(format='Py: %(name)s : [%(levelname)s]\t%(message)s', level = verbosity)
27+
logger.info("Verbosity level is set to " + level[verbosity])
2528

2629

2730
# IRQ registers
@@ -65,52 +68,52 @@
6568
# @param name name of WAVE file to open
6669
def openWAVE(name):
6770
global WAVE
68-
logging.info("Open WAVE file (read mode): {}".format(name))
71+
logger.info("Open WAVE file (read mode): {}".format(name))
6972
WAVE = wave.open(name, 'rb')
70-
logging.info(" Number of channels: {}".format(WAVE.getnchannels()))
71-
logging.info(" Sample bits: {}".format(WAVE.getsampwidth() * 8))
72-
logging.info(" Sample rate: {}".format(WAVE.getframerate()))
73-
logging.info(" Number of frames: {}".format(WAVE.getnframes()))
73+
logger.info(" Number of channels: {}".format(WAVE.getnchannels()))
74+
logger.info(" Sample bits: {}".format(WAVE.getsampwidth() * 8))
75+
logger.info(" Sample rate: {}".format(WAVE.getframerate()))
76+
logger.info(" Number of frames: {}".format(WAVE.getnframes()))
7477

7578
## Read WAVE frames (global WAVE object) into global AudioFrames object
7679
# @param n number of frames to read
7780
# @return frames frames read
7881
def readWAVE(n):
7982
global WAVE
80-
logging.info("Read WAVE frames")
83+
logger.info("Read WAVE frames")
8184
frames = WAVE.readframes(n)
8285
return frames
8386

8487
## Close WAVE file (global WAVE object)
8588
def closeWAVE():
8689
global WAVE
87-
logging.info("Close WAVE file")
90+
logger.info("Close WAVE file")
8891
WAVE.close()
8992

9093

9194
## Load audio frames into global Data buffer
9295
# @param block_size size of block to load (in bytes)
9396
def loadAudioFrames(block_size):
9497
global Data
95-
logging.info("Load audio frames into data buffer")
98+
logger.info("Load audio frames into data buffer")
9699
frame_size = CHANNELS * ((SAMPLE_BITS + 7) // 8)
97100
frames_max = block_size // frame_size
98101
Data = readWAVE(frames_max)
99102

100103

101104
## Initialize
102105
def init():
103-
logging.info("Python function init() called")
106+
logger.info("Python function init() called")
104107

105108

106109
## Read interrupt request (the VSI IRQ Status Register)
107110
# @return value value read (32-bit)
108111
def rdIRQ():
109112
global IRQ_Status
110-
logging.info("Python function rdIRQ() called")
113+
logger.info("Python function rdIRQ() called")
111114

112115
value = IRQ_Status
113-
logging.debug("Read interrupt request: {}".format(value))
116+
logger.debug("Read interrupt request: {}".format(value))
114117

115118
return value
116119

@@ -120,10 +123,10 @@ def rdIRQ():
120123
# @return value value written (32-bit)
121124
def wrIRQ(value):
122125
global IRQ_Status
123-
logging.info("Python function wrIRQ() called")
126+
logger.info("Python function wrIRQ() called")
124127

125128
IRQ_Status = value
126-
logging.debug("Write interrupt request: {}".format(value))
129+
logger.debug("Write interrupt request: {}".format(value))
127130

128131
return value
129132

@@ -134,21 +137,21 @@ def wrIRQ(value):
134137
# @return value value written (32-bit)
135138
def wrTimer(index, value):
136139
global Timer_Control, Timer_Interval
137-
logging.info("Python function wrTimer() called")
140+
logger.info("Python function wrTimer() called")
138141

139142
if index == 0:
140143
Timer_Control = value
141-
logging.debug("Write Timer_Control: {}".format(value))
144+
logger.debug("Write Timer_Control: {}".format(value))
142145
elif index == 1:
143146
Timer_Interval = value
144-
logging.debug("Write Timer_Interval: {}".format(value))
147+
logger.debug("Write Timer_Interval: {}".format(value))
145148

146149
return value
147150

148151

149152
## Timer event (called at Timer Overflow)
150153
def timerEvent():
151-
logging.info("Python function timerEvent() called")
154+
logger.info("Python function timerEvent() called")
152155

153156

154157
## Write DMA registers (the VSI DMA Registers)
@@ -157,11 +160,11 @@ def timerEvent():
157160
# @return value value written (32-bit)
158161
def wrDMA(index, value):
159162
global DMA_Control
160-
logging.info("Python function wrDMA() called")
163+
logger.info("Python function wrDMA() called")
161164

162165
if index == 0:
163166
DMA_Control = value
164-
logging.debug("Write DMA_Control: {}".format(value))
167+
logger.debug("Write DMA_Control: {}".format(value))
165168

166169
return value
167170

@@ -171,14 +174,14 @@ def wrDMA(index, value):
171174
# @return data data read (bytearray)
172175
def rdDataDMA(size):
173176
global Data
174-
logging.info("Python function rdDataDMA() called")
177+
logger.info("Python function rdDataDMA() called")
175178

176179
loadAudioFrames(size)
177180

178181
n = min(len(Data), size)
179182
data = bytearray(size)
180183
data[0:n] = Data[0:n]
181-
logging.debug("Read data ({} bytes)".format(size))
184+
logger.debug("Read data ({} bytes)".format(size))
182185

183186
return data
184187

@@ -188,10 +191,10 @@ def rdDataDMA(size):
188191
# @param size size of data to write (in bytes, multiple of 4)
189192
def wrDataDMA(data, size):
190193
global Data
191-
logging.info("Python function wrDataDMA() called")
194+
logger.info("Python function wrDataDMA() called")
192195

193196
Data = data
194-
logging.debug("Write data ({} bytes)".format(size))
197+
logger.debug("Write data ({} bytes)".format(size))
195198

196199
return
197200

@@ -202,10 +205,10 @@ def wrCONTROL(value):
202205
global CONTROL
203206
if ((value ^ CONTROL) & CONTROL_ENABLE_Msk) != 0:
204207
if (value & CONTROL_ENABLE_Msk) != 0:
205-
logging.info("Enable Receiver")
208+
logger.info("Enable Receiver")
206209
openWAVE('test.wav')
207210
else:
208-
logging.info("Disable Receiver")
211+
logger.info("Disable Receiver")
209212
closeWAVE()
210213
CONTROL = value
211214

@@ -214,32 +217,32 @@ def wrCONTROL(value):
214217
def wrCHANNELS(value):
215218
global CHANNELS
216219
CHANNELS = value
217-
logging.info("Number of channels: {}".format(value))
220+
logger.info("Number of channels: {}".format(value))
218221

219222
## Write SAMPLE_BITS register (user register)
220223
# @param value value to write (32-bit)
221224
def wrSAMPLE_BITS(value):
222225
global SAMPLE_BITS
223226
SAMPLE_BITS = value
224-
logging.info("Sample bits: {}".format(value))
227+
logger.info("Sample bits: {}".format(value))
225228

226229
## Write SAMPLE_RATE register (user register)
227230
# @param value value to write (32-bit)
228231
def wrSAMPLE_RATE(value):
229232
global SAMPLE_RATE
230233
SAMPLE_RATE = value
231-
logging.info("Sample rate: {}".format(value))
234+
logger.info("Sample rate: {}".format(value))
232235

233236

234237
## Read user registers (the VSI User Registers)
235238
# @param index user register index (zero based)
236239
# @return value value read (32-bit)
237240
def rdRegs(index):
238241
global Regs
239-
logging.info("Python function rdRegs() called")
242+
logger.info("Python function rdRegs() called")
240243

241244
value = Regs[index]
242-
logging.debug("Read user register at index {}: {}".format(index, value))
245+
logger.debug("Read user register at index {}: {}".format(index, value))
243246

244247
return value
245248

@@ -250,7 +253,7 @@ def rdRegs(index):
250253
# @return value value written (32-bit)
251254
def wrRegs(index, value):
252255
global Regs
253-
logging.info("Python function wrRegs() called")
256+
logger.info("Python function wrRegs() called")
254257

255258
if index == 0:
256259
wrCONTROL(value)
@@ -262,7 +265,7 @@ def wrRegs(index, value):
262265
wrSAMPLE_RATE(value)
263266

264267
Regs[index] = value
265-
logging.debug("Write user register at index {}: {}".format(index, value))
268+
logger.debug("Write user register at index {}: {}".format(index, value))
266269

267270
return value
268271

0 commit comments

Comments
 (0)