Skip to content

Commit

Permalink
updated some user script to match the bridge changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaooooo committed Nov 7, 2018
1 parent 67c22f8 commit 4009b8d
Show file tree
Hide file tree
Showing 5 changed files with 256 additions and 193 deletions.
84 changes: 51 additions & 33 deletions examples/freeRTOS-examples/test_applications/test_KWS/i2s.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,56 @@
import time

def i2s(bridge):
print ("i2s.py execution on-going")
addrWavOutHead = os.popen("riscv32-unknown-elf-nm test |grep -w 'i2s_out_header$'").read()
addrWavOutHead = (addrWavOutHead.split())[0]

while (1) :
time.sleep(1)
input("Press return to start sound acquisition:")
recReady = int(("0x"+addrWavOutHead), 16) + 8
bridge.write_32(recReady, 0)

micReady = int(("0x"+addrWavOutHead), 16) + 12
bridge.write_32(micReady, 1)

recReady = int(("0x"+addrWavOutHead), 16) + 8
WavOutFlag = bridge.read_32(recReady)
while ( int(WavOutFlag) == 0 ):
time.sleep(1)
recReady = int(("0x"+addrWavOutHead), 16) + 8
WavOutFlag = bridge.read_32(recReady)
print ("py: waiting recReady")

l2Addr = int(("0x"+addrWavOutHead), 16)
addrWav = bridge.read_32(l2Addr)
size = int(("0x"+addrWavOutHead), 16) + 4
WavSize = bridge.read_32(size)

with open("wavOut.wav", 'wb') as waveOut:
print ("py: now download", WavSize, "bytes")
for byte in bridge.read(addrWav, WavSize):
waveOut.write(byte)

waveOut.closed
class state:
addrWavOutHead = 0
initialized = False
started = False
recReady = False

def init_state():
state.started = False
state.recReady = False

def do_i2s():
if not state.initialized:
print ("i2s.py execution on-going")
addrHead = os.popen("riscv32-unknown-elf-nm test |grep -w 'i2s_out_header$'").read()
state.addrWavOutHead = (addrHead.split())[0]
state.initialized = True
return 3000000

if not state.started:
input("Press return to start sound acquisition:")
micReady = int(("0x"+state.addrWavOutHead), 16) + 12
bridge.write_32(micReady, 1)
state.started = True
return 0

if not state.recReady:
recReady = int(("0x"+state.addrWavOutHead), 16) + 8
WavOutFlag = bridge.read_32(recReady)
if (int(WavOutFlag) == 0):
return 1000000
else:
l2Addr = int(("0x"+state.addrWavOutHead), 16)
addrWav = bridge.read_32(l2Addr)
size = int(("0x"+state.addrWavOutHead), 16) + 4
WavSize = bridge.read_32(size)
with open("wavOut.wav", 'wb') as waveOut:
print ("py: now download", WavSize, "bytes")
for byte in bridge.read(addrWav, WavSize):
waveOut.write(byte)

waveOut.close()
recReady = int(("0x"+state.addrWavOutHead), 16) + 8
bridge.write_32(recReady, 0)
os.system("if [ ! -f ../../../waveOut.wav ]; then ln -s BUILD/GAP8/GCC_RISCV/wavOut.wav ../../../wavOut.wav 1>/dev/null 2>/dev/null; fi")

print(".wav have been saved")
init_state()
return 1000000

bridge.script_cb = bridge.timer_cb_typ(do_i2s)
bridge.module.bridge_loop_timeout(bridge.script_cb, 100000)

os.system("if [ ! -f ../../../waveOut.wav ]; then ln -s BUILD/GAP8/GCC_RISCV/wavOut.wav ../../../wavOut.wav 1>/dev/null 2>/dev/null; fi")
time.sleep(1)
84 changes: 52 additions & 32 deletions examples/freeRTOS-examples/test_driver/test_SAI/i2s.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,57 @@
import time

def i2s(bridge):
print ("i2s.py execution on-going")
addrWavOutHead = os.popen("riscv32-unknown-elf-nm test |grep -w 'I2sOutHeader$'").read()
addrWavOutHead = (addrWavOutHead.split())[0]

time.sleep(3)
input("Press return to start sound acquisition:")
class state:
addrWavOutHead = 0
initialized = False
started = False
recReady = False

def init_state():
state.started = False
state.recReady = False

def do_i2s():
if not state.initialized:
print ("i2s.py execution on-going")
addrHead = os.popen("riscv32-unknown-elf-nm test |grep -w 'I2sOutHeader$'").read()
state.addrWavOutHead = (addrHead.split())[0]
state.initialized = True
return 3000000

if not state.started:
input("Press return to start sound acquisition:")
micReady = int(("0x"+state.addrWavOutHead), 16) + 12
bridge.write_32(micReady, 1)
state.started = True
return 0

if not state.recReady:
recReady = int(("0x"+state.addrWavOutHead), 16) + 8
WavOutFlag = bridge.read_32(recReady)
if (int(WavOutFlag) == 0):
print ("py: waiting recReady ")
return 1000000
else:
l2Addr = int(("0x"+state.addrWavOutHead), 16)
addrWav = bridge.read_32(l2Addr)
size = int(("0x"+state.addrWavOutHead), 16) + 4
WavSize = bridge.read_32(size)
with open("wavOut.wav", 'wb') as waveOut:
print ("py: now download", WavSize, "bytes")
for byte in bridge.read(addrWav, WavSize):
waveOut.write(byte)

waveOut.close()
recReady = int(("0x"+state.addrWavOutHead), 16) + 8
bridge.write_32(recReady, 0)
os.system("if [ ! -f ../../../waveOut.wav ]; then ln -s BUILD/GAP8/GCC_RISCV/wavOut.wav ../../../wavOut.wav 1>/dev/null 2>/dev/null; fi")

print(".wav have been saved")
init_state()
return 1000000

bridge.script_cb = bridge.timer_cb_typ(do_i2s)
bridge.module.bridge_loop_timeout(bridge.script_cb, 100000)

micReady = int(("0x"+addrWavOutHead), 16) + 12
bridge.write_32(micReady, 1)

recReady = int(("0x"+addrWavOutHead), 16) + 8
WavOutFlag = bridge.read_32(recReady)
while ( int(WavOutFlag) == 0 ):
time.sleep(1)
recReady = int(("0x"+addrWavOutHead), 16) + 8
WavOutFlag = bridge.read_32(recReady)
print ("py: waiting recReady")

l2Addr = int(("0x"+addrWavOutHead), 16)
addrWav = bridge.read_32(l2Addr)
size = int(("0x"+addrWavOutHead), 16) + 4
WavSize = bridge.read_32(size)

with open("wavOut.wav", 'wb') as waveOut:
print ("py: now download", WavSize, "bytes")
for byte in bridge.read(addrWav, WavSize):
waveOut.write(byte)

waveOut.closed

recReady = int(("0x"+addrWavOutHead), 16) + 8
bridge.write_32(recReady, 0)

os.system("if [ ! -f ../../../waveOut.wav ]; then ln -s BUILD/GAP8/GCC_RISCV/wavOut.wav ../../../wavOut.wav 1>/dev/null 2>/dev/null; fi")
78 changes: 49 additions & 29 deletions examples/mbed-examples/test_application/test_KWS/i2s.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,56 @@
import time

def i2s(bridge):
print ("i2s.py execution on-going")
addrWavOutHead = os.popen("riscv32-unknown-elf-nm test |grep -w 'i2s_out_header$'").read()
addrWavOutHead = (addrWavOutHead.split())[0]

while (1) :
time.sleep(1)
input("Press return to start sound acquisition:")
recReady = int(("0x"+addrWavOutHead), 16) + 8
bridge.write_32(recReady, 0)

micReady = int(("0x"+addrWavOutHead), 16) + 12
bridge.write_32(micReady, 1)

recReady = int(("0x"+addrWavOutHead), 16) + 8
WavOutFlag = bridge.read_32(recReady)
while ( int(WavOutFlag) == 0 ):
time.sleep(1)
recReady = int(("0x"+addrWavOutHead), 16) + 8

class state:
addrWavOutHead = 0
initialized = False
started = False
recReady = False

def init_state():
state.started = False
state.recReady = False

def do_i2s():
if not state.initialized:
print ("i2s.py execution on-going")
addrHead = os.popen("riscv32-unknown-elf-nm test |grep -w 'i2s_out_header$'").read()
state.addrWavOutHead = (addrHead.split())[0]
state.initialized = True
return 3000000

if not state.started:
input("Press return to start sound acquisition:")
micReady = int(("0x"+state.addrWavOutHead), 16) + 12
bridge.write_32(micReady, 1)
state.started = True
return 0

if not state.recReady:
recReady = int(("0x"+state.addrWavOutHead), 16) + 8
WavOutFlag = bridge.read_32(recReady)
if (int(WavOutFlag) == 0):
return 1000000
else:
l2Addr = int(("0x"+state.addrWavOutHead), 16)
addrWav = bridge.read_32(l2Addr)
size = int(("0x"+state.addrWavOutHead), 16) + 4
WavSize = bridge.read_32(size)
with open("wavOut.wav", 'wb') as waveOut:
print ("py: now download", WavSize, "bytes")
for byte in bridge.read(addrWav, WavSize):
waveOut.write(byte)

waveOut.close()
recReady = int(("0x"+state.addrWavOutHead), 16) + 8
bridge.write_32(recReady, 0)
os.system("if [ ! -f ../../../waveOut.wav ]; then ln -s BUILD/GAP8/GCC_RISCV/wavOut.wav ../../../wavOut.wav 1>/dev/null 2>/dev/null; fi")

l2Addr = int(("0x"+addrWavOutHead), 16)
addrWav = bridge.read_32(l2Addr)
size = int(("0x"+addrWavOutHead), 16) + 4
WavSize = bridge.read_32(size)
print(".wav have been saved")
init_state()
return 1000000

# with open("wavOut.wav", 'wb') as waveOut:
# print ("py: now download", WavSize, "bytes")
# for byte in bridge.read(addrWav, WavSize):
# waveOut.write(byte)
# waveOut.closed
bridge.script_cb = bridge.timer_cb_typ(do_i2s)
bridge.module.bridge_loop_timeout(bridge.script_cb, 100000)

os.system("if [ ! -f ../../../waveOut.wav ]; then ln -s BUILD/GAP8/GCC_RISCV/wavOut.wav ../../../wavOut.wav 1>/dev/null 2>/dev/null; fi")
time.sleep(1)
84 changes: 52 additions & 32 deletions examples/mbed-examples/test_driver/test_I2S/i2s.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,57 @@
import time

def i2s(bridge):
print ("i2s.py execution on-going")
addrWavOutHead = os.popen("riscv32-unknown-elf-nm test |grep -w 'I2sOutHeader$'").read()
addrWavOutHead = (addrWavOutHead.split())[0]

time.sleep(3)
input("Press return to start sound acquisition:")
class state:
addrWavOutHead = 0
initialized = False
started = False
recReady = False

def init_state():
state.started = False
state.recReady = False

def do_i2s():
if not state.initialized:
print ("i2s.py execution on-going")
addrHead = os.popen("riscv32-unknown-elf-nm test |grep -w 'I2sOutHeader$'").read()
state.addrWavOutHead = (addrHead.split())[0]
state.initialized = True
return 3000000

if not state.started:
input("Press return to start sound acquisition:")
micReady = int(("0x"+state.addrWavOutHead), 16) + 12
bridge.write_32(micReady, 1)
state.started = True
return 0

if not state.recReady:
recReady = int(("0x"+state.addrWavOutHead), 16) + 8
WavOutFlag = bridge.read_32(recReady)
if (int(WavOutFlag) == 0):
print ("py: waiting recReady ")
return 1000000
else:
l2Addr = int(("0x"+state.addrWavOutHead), 16)
addrWav = bridge.read_32(l2Addr)
size = int(("0x"+state.addrWavOutHead), 16) + 4
WavSize = bridge.read_32(size)
with open("wavOut.wav", 'wb') as waveOut:
print ("py: now download", WavSize, "bytes")
for byte in bridge.read(addrWav, WavSize):
waveOut.write(byte)

waveOut.close()
recReady = int(("0x"+state.addrWavOutHead), 16) + 8
bridge.write_32(recReady, 0)
os.system("if [ ! -f ../../../waveOut.wav ]; then ln -s BUILD/GAP8/GCC_RISCV/wavOut.wav ../../../wavOut.wav 1>/dev/null 2>/dev/null; fi")

print(".wav have been saved")
init_state()
return 1000000

bridge.script_cb = bridge.timer_cb_typ(do_i2s)
bridge.module.bridge_loop_timeout(bridge.script_cb, 100000)

micReady = int(("0x"+addrWavOutHead), 16) + 12
bridge.write_32(micReady, 1)

recReady = int(("0x"+addrWavOutHead), 16) + 8
WavOutFlag = bridge.read_32(recReady)
while ( int(WavOutFlag) == 0 ):
time.sleep(1)
recReady = int(("0x"+addrWavOutHead), 16) + 8
WavOutFlag = bridge.read_32(recReady)
print ("py: waiting recReady")

l2Addr = int(("0x"+addrWavOutHead), 16)
addrWav = bridge.read_32(l2Addr)
size = int(("0x"+addrWavOutHead), 16) + 4
WavSize = bridge.read_32(size)

with open("wavOut.wav", 'wb') as waveOut:
print ("py: now download", WavSize, "bytes")
for byte in bridge.read(addrWav, WavSize):
waveOut.write(byte)

waveOut.closed

recReady = int(("0x"+addrWavOutHead), 16) + 8
bridge.write_32(recReady, 0)

os.system("if [ ! -f ../../../waveOut.wav ]; then ln -s BUILD/GAP8/GCC_RISCV/wavOut.wav ../../../wavOut.wav 1>/dev/null 2>/dev/null; fi")
Loading

0 comments on commit 4009b8d

Please sign in to comment.