Skip to content

Commit

Permalink
Made Python logging to use getLogger(__name__) (#22)
Browse files Browse the repository at this point in the history
More differentiation in logging was required in parallel execution of VSI scripts, when using them with AVH Corellium models out of python C libs.
  • Loading branch information
vovamarch authored Dec 6, 2024
1 parent 8e572c2 commit 6df80d4
Show file tree
Hide file tree
Showing 19 changed files with 503 additions and 441 deletions.
73 changes: 38 additions & 35 deletions interface/audio/python/arm_vsi0.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2021-2022 Arm Limited. All rights reserved.
# Copyright (c) 2021-2024 Arm Limited. All rights reserved.

# Virtual Streaming Interface instance 0 Python script: Audio Input

Expand All @@ -13,15 +13,18 @@
import logging
import wave

logger = logging.getLogger(__name__)

## Set verbosity level
#verbosity = logging.DEBUG
#verbosity = logging.INFO
#verbosity = logging.WARNING
verbosity = logging.ERROR

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


# IRQ registers
Expand Down Expand Up @@ -65,52 +68,52 @@
# @param name name of WAVE file to open
def openWAVE(name):
global WAVE
logging.info("Open WAVE file (read mode): {}".format(name))
logger.info("Open WAVE file (read mode): {}".format(name))
WAVE = wave.open(name, 'rb')
logging.info(" Number of channels: {}".format(WAVE.getnchannels()))
logging.info(" Sample bits: {}".format(WAVE.getsampwidth() * 8))
logging.info(" Sample rate: {}".format(WAVE.getframerate()))
logging.info(" Number of frames: {}".format(WAVE.getnframes()))
logger.info(" Number of channels: {}".format(WAVE.getnchannels()))
logger.info(" Sample bits: {}".format(WAVE.getsampwidth() * 8))
logger.info(" Sample rate: {}".format(WAVE.getframerate()))
logger.info(" Number of frames: {}".format(WAVE.getnframes()))

## Read WAVE frames (global WAVE object) into global AudioFrames object
# @param n number of frames to read
# @return frames frames read
def readWAVE(n):
global WAVE
logging.info("Read WAVE frames")
logger.info("Read WAVE frames")
frames = WAVE.readframes(n)
return frames

## Close WAVE file (global WAVE object)
def closeWAVE():
global WAVE
logging.info("Close WAVE file")
logger.info("Close WAVE file")
WAVE.close()


## Load audio frames into global Data buffer
# @param block_size size of block to load (in bytes)
def loadAudioFrames(block_size):
global Data
logging.info("Load audio frames into data buffer")
logger.info("Load audio frames into data buffer")
frame_size = CHANNELS * ((SAMPLE_BITS + 7) // 8)
frames_max = block_size // frame_size
Data = readWAVE(frames_max)


## Initialize
def init():
logging.info("Python function init() called")
logger.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")
logger.info("Python function rdIRQ() called")

value = IRQ_Status
logging.debug("Read interrupt request: {}".format(value))
logger.debug("Read interrupt request: {}".format(value))

return value

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

IRQ_Status = value
logging.debug("Write interrupt request: {}".format(value))
logger.debug("Write interrupt request: {}".format(value))

return value

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

if index == 0:
Timer_Control = value
logging.debug("Write Timer_Control: {}".format(value))
logger.debug("Write Timer_Control: {}".format(value))
elif index == 1:
Timer_Interval = value
logging.debug("Write Timer_Interval: {}".format(value))
logger.debug("Write Timer_Interval: {}".format(value))

return value


## Timer event (called at Timer Overflow)
def timerEvent():
logging.info("Python function timerEvent() called")
logger.info("Python function timerEvent() called")


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

if index == 0:
DMA_Control = value
logging.debug("Write DMA_Control: {}".format(value))
logger.debug("Write DMA_Control: {}".format(value))

return value

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

loadAudioFrames(size)

n = min(len(Data), size)
data = bytearray(size)
data[0:n] = Data[0:n]
logging.debug("Read data ({} bytes)".format(size))
logger.debug("Read data ({} bytes)".format(size))

return data

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

Data = data
logging.debug("Write data ({} bytes)".format(size))
logger.debug("Write data ({} bytes)".format(size))

return

Expand All @@ -202,10 +205,10 @@ def wrCONTROL(value):
global CONTROL
if ((value ^ CONTROL) & CONTROL_ENABLE_Msk) != 0:
if (value & CONTROL_ENABLE_Msk) != 0:
logging.info("Enable Receiver")
logger.info("Enable Receiver")
openWAVE('test.wav')
else:
logging.info("Disable Receiver")
logger.info("Disable Receiver")
closeWAVE()
CONTROL = value

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

## Write SAMPLE_BITS register (user register)
# @param value value to write (32-bit)
def wrSAMPLE_BITS(value):
global SAMPLE_BITS
SAMPLE_BITS = value
logging.info("Sample bits: {}".format(value))
logger.info("Sample bits: {}".format(value))

## Write SAMPLE_RATE register (user register)
# @param value value to write (32-bit)
def wrSAMPLE_RATE(value):
global SAMPLE_RATE
SAMPLE_RATE = value
logging.info("Sample rate: {}".format(value))
logger.info("Sample rate: {}".format(value))


## 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")
logger.info("Python function rdRegs() called")

value = Regs[index]
logging.debug("Read user register at index {}: {}".format(index, value))
logger.debug("Read user register at index {}: {}".format(index, value))

return value

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

if index == 0:
wrCONTROL(value)
Expand All @@ -262,7 +265,7 @@ def wrRegs(index, value):
wrSAMPLE_RATE(value)

Regs[index] = value
logging.debug("Write user register at index {}: {}".format(index, value))
logger.debug("Write user register at index {}: {}".format(index, value))

return value

Expand Down
Loading

0 comments on commit 6df80d4

Please sign in to comment.