|
|
import os
|
|
|
os.system('clear') # on linux / os x
|
|
|
|
|
|
import numpy as np
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
from test_fft.register_addresses import *
|
|
|
|
|
|
import test_fft.read_flags as flg
|
|
|
import test_fft.data_generator as dtgn
|
|
|
import test_fft.print_custom as prnt
|
|
|
import test_fft.read_data as rdata
|
|
|
|
|
|
prnt.print_custom( '*' )
|
|
|
prnt.print_custom( '*' )
|
|
|
prnt.print_custom( '*' )
|
|
|
prnt.print_custom( '*' )
|
|
|
prnt.print_custom( '*' )
|
|
|
|
|
|
######################
|
|
|
# GET DATA FROM RECORD
|
|
|
#storageDirectory = '/home/paul/data/2014_06_24/'
|
|
|
#day = '2014_6_24-'
|
|
|
#hour = '9_0_3'
|
|
|
#suffix = '.data'
|
|
|
|
|
|
#typeOfData = '_SBM1_CWF_'
|
|
|
#cwf_f1 = np.genfromtxt( storageDirectory + day + hour + typeOfData + 'F1' + suffix,
|
|
|
# skip_header = 1)
|
|
|
cwf_f1 = np.zeros( 1000 )
|
|
|
|
|
|
#################
|
|
|
# BUILD WAVEFORMS
|
|
|
nbSamples = 256
|
|
|
nbComponentsPerMatrix = 15
|
|
|
nbFrequencyBins = 128
|
|
|
#wfrm0 = getWaveFromRecord( cwf_f1, nbSamples, 0, columnV )
|
|
|
#wfrm1 = getWaveFromRecord( cwf_f1, nbSamples, 0, columnE1 )
|
|
|
#wfrm2 = getWaveFromRecord( cwf_f1, nbSamples, 0, columnE2 )
|
|
|
#wfrm3 = getWaveFromRecord( cwf_f1, nbSamples, 0, columnB1 )
|
|
|
#wfrm4 = getWaveFromRecord( cwf_f1, nbSamples, 0, columnB2 )
|
|
|
wfrm0 = dtgn.sineWave( 256, 10, 1000 )
|
|
|
wfrm1 = dtgn.sineWave( 256, 10, 1000 )
|
|
|
wfrm2 = dtgn.sineWave( 256, 20, 1000 )
|
|
|
wfrm3 = dtgn.sineWave( 256, 20, 1000 )
|
|
|
wfrm4 = dtgn.sineWave( 256, 50, 1000 )
|
|
|
|
|
|
################
|
|
|
# BUILD THE DATA
|
|
|
dataToWrite0 = dtgn.generateDataToWrite( nbSamples, wfrm0, wfrm1 )
|
|
|
dataToWrite1 = dtgn.generateDataToWrite( nbSamples, wfrm2, wfrm3 )
|
|
|
dataToWrite2 = dtgn.generateDataToWrite( nbSamples, wfrm4, np.zeros( nbSamples ) )
|
|
|
|
|
|
########################
|
|
|
# WRITE WAVEFORM IN FIFO
|
|
|
prnt.print_custom( "1) write waveforms in FIFOs: " + str(len(dataToWrite0)) + " samples" )
|
|
|
prnt.print_reg_sm( FFT_SM_MEM_OUT_SM_CTRL )
|
|
|
|
|
|
for k in range(nbSamples):
|
|
|
RMAPPlugin0.Write( FFT_FIFO_F2_1_0, [dataToWrite0[k]] )
|
|
|
RMAPPlugin0.Write( FFT_FIFO_F2_3_2, [dataToWrite1[k]] )
|
|
|
RMAPPlugin0.Write( FFT_FIFO_F2_4, [dataToWrite2[k]] )
|
|
|
# write only the FIFO F2
|
|
|
RMAPPlugin0.Write( FFT_FIFO_F2_WEN, [0xffffffe0] )
|
|
|
|
|
|
prnt.print_custom( "1) data written in FIFOs" )
|
|
|
|
|
|
################
|
|
|
# SM FIRST READ
|
|
|
prnt.print_custom( "======= SM FIRST READ" )
|
|
|
|
|
|
components = []
|
|
|
|
|
|
flg.wait_for_FIFO_0_or_1_Full( FFT_SM_MEM_OUT_SM_CTRL )
|
|
|
|
|
|
if flg.is_MEM_OUT_SM_Full_FIFO_0( FFT_SM_MEM_OUT_SM_CTRL ):
|
|
|
address_MEM_OUT_SM = FFT_SM_MEM_OUT_SM_1
|
|
|
fifo_to_wait_for = 0
|
|
|
elif flg.is_MEM_OUT_SM_Full_FIFO_1( FFT_SM_MEM_OUT_SM_CTRL ):
|
|
|
address_MEM_OUT_SM = FFT_SM_MEM_OUT_SM_0
|
|
|
fifo_to_wait_for = 1
|
|
|
|
|
|
for component in range(nbComponentsPerMatrix):
|
|
|
prnt.print_custom( "==== component = " + str( component )
|
|
|
+ ", read @ " + hex(address_MEM_OUT_SM & 0xffffffff) )
|
|
|
prnt.print_reg_sm( FFT_SM_MEM_OUT_SM_CTRL )
|
|
|
currentComp_re = np.zeros( nbFrequencyBins )
|
|
|
currentComp_im = np.zeros( nbFrequencyBins )
|
|
|
if (component == 0) | (component == 12):
|
|
|
flg.wait_for_FIFO_Full( fifo_to_wait_for, FFT_SM_MEM_OUT_SM_CTRL )
|
|
|
currentComp_re = rdata.read_SM_Re( nbFrequencyBins, address_MEM_OUT_SM )
|
|
|
components.append( currentComp_re )
|
|
|
elif (component == 5) | (component == 9):
|
|
|
flg.wait_for_FIFO_Full( fifo_to_wait_for, FFT_SM_MEM_OUT_SM_CTRL )
|
|
|
currentComp_re = rdata.read_SM_Re( nbFrequencyBins, address_MEM_OUT_SM )
|
|
|
components.append( currentComp_re )
|
|
|
elif (component == 1) | (component == 3) | (component == 7):
|
|
|
currentComp_re, currentComp_im = rdata.read_SM_Re_Im( nbFrequencyBins, address_MEM_OUT_SM )
|
|
|
components.append( currentComp_re )
|
|
|
components.append( currentComp_im )
|
|
|
flg.wait_for_FIFO_Full( fifo_to_wait_for, FFT_SM_MEM_OUT_SM_CTRL )
|
|
|
elif (component == 2) | (component == 6) | (component == 10):
|
|
|
currentComp_re, currentComp_im = rdata.read_SM_Re_Im( nbFrequencyBins, address_MEM_OUT_SM )
|
|
|
components.append( currentComp_re )
|
|
|
components.append( currentComp_im )
|
|
|
flg.wait_for_FIFO_Full( fifo_to_wait_for, FFT_SM_MEM_OUT_SM_CTRL )
|
|
|
elif (component == 4) | (component == 8):
|
|
|
currentComp_re, currentComp_im = rdata.read_SM_Re_Im( nbFrequencyBins, address_MEM_OUT_SM )
|
|
|
components.append( currentComp_re )
|
|
|
components.append( currentComp_im )
|
|
|
elif (component == 11) | (component == 13):
|
|
|
currentComp_re, currentComp_im = rdata.read_SM_Re_Im( nbFrequencyBins, address_MEM_OUT_SM )
|
|
|
components.append( currentComp_re )
|
|
|
components.append( currentComp_im )
|
|
|
elif (component == 14):
|
|
|
currentComp_re = rdata.read_SM_Re( nbFrequencyBins, address_MEM_OUT_SM )
|
|
|
components.append( currentComp_re )
|
|
|
else:
|
|
|
prnt.print_custom( "unexpected value for component" )
|
|
|
# change FIFO
|
|
|
if address_MEM_OUT_SM == FFT_SM_MEM_OUT_SM_0:
|
|
|
address_MEM_OUT_SM = FFT_SM_MEM_OUT_SM_1
|
|
|
fifo_to_wait_for = 0
|
|
|
elif address_MEM_OUT_SM == FFT_SM_MEM_OUT_SM_1:
|
|
|
address_MEM_OUT_SM = FFT_SM_MEM_OUT_SM_0
|
|
|
fifo_to_wait_for = 1
|
|
|
|
|
|
prnt.print_custom( "======= READ COMPLETE" )
|
|
|
|
|
|
prnt.print_reg_sm( FFT_SM_MEM_OUT_SM_CTRL )
|
|
|
|
|
|
# PLOT SM
|
|
|
|
|
|
plt.figure( 1 )
|
|
|
plt.subplot(231)
|
|
|
plt.plot(wfrm0, 'b')
|
|
|
plt.subplot(232)
|
|
|
plt.plot(wfrm1, 'g')
|
|
|
plt.plot(wfrm1, '.')
|
|
|
plt.subplot(233)
|
|
|
plt.plot(wfrm2, 'r')
|
|
|
plt.plot(wfrm2, '.')
|
|
|
plt.subplot(234)
|
|
|
plt.plot(wfrm3, 'c')
|
|
|
plt.subplot(235)
|
|
|
plt.plot(wfrm4, 'm')
|
|
|
|
|
|
plt.figure( 2 )
|
|
|
|
|
|
plt.subplot(231)
|
|
|
plt.plot(components[0], label='0')
|
|
|
plt.plot(components[1], label='1')
|
|
|
plt.plot(components[2], label='2')
|
|
|
plt.plot(components[3], label='3')
|
|
|
plt.legend(loc='upper right')
|
|
|
|
|
|
plt.subplot(232)
|
|
|
plt.plot(components[4], label='4')
|
|
|
plt.plot(components[5], label='5')
|
|
|
plt.plot(components[6], label='6')
|
|
|
plt.plot(components[7], label='7')
|
|
|
plt.legend(loc='upper right')
|
|
|
|
|
|
plt.subplot(233)
|
|
|
plt.plot(components[8], label='8')
|
|
|
plt.plot(components[9], label='9')
|
|
|
plt.plot(components[10], label='10')
|
|
|
plt.plot(components[11], label='11')
|
|
|
plt.legend(loc='upper right')
|
|
|
|
|
|
plt.subplot(234)
|
|
|
plt.plot(components[12], label='12')
|
|
|
plt.plot(components[13], label='13')
|
|
|
plt.plot(components[14], label='14')
|
|
|
plt.plot(components[15], label='15')
|
|
|
plt.legend(loc='upper right')
|
|
|
|
|
|
plt.subplot(235)
|
|
|
plt.plot(components[16], label='16')
|
|
|
plt.plot(components[17], label='17')
|
|
|
plt.plot(components[18], label='18')
|
|
|
plt.plot(components[19], label='19')
|
|
|
plt.legend(loc='upper right')
|
|
|
|
|
|
plt.subplot(236)
|
|
|
plt.plot(components[20], label='20')
|
|
|
plt.plot(components[21], label='21')
|
|
|
plt.plot(components[22], label='22')
|
|
|
plt.plot(components[23], label='23')
|
|
|
plt.plot(components[24], label='24')
|
|
|
plt.legend(loc='upper right')
|
|
|
|
|
|
plt.show()
|