# HG changeset patch # User paul # Date 2014-07-22 14:24:04 # Node ID 0cad6347e2657233b905c1d469151751cf8217c4 # Parent 80993ec2f9f20dcdea5ee35bc20df2ac116d8054 sources reorganized imports are done in a better way a few renaming also diff --git a/lfr_emulator.sublime-workspace b/lfr_emulator.sublime-workspace --- a/lfr_emulator.sublime-workspace +++ b/lfr_emulator.sublime-workspace @@ -4,6 +4,10 @@ "selected_items": [ [ + "nb", + "nbFrequencyBins" + ], + [ "fi", "fifo_to_wait_for" ], @@ -172,23 +176,31 @@ "buffers": [ { - "file": "test_fft/test_sm_mini_lfr.py", + "file": "test_fft/test_sm_only.py", "settings": { - "buffer_size": 5847, + "buffer_size": 6506, "line_ending": "Unix" } }, { - "file": "test_fft/test_sm_functions.py", + "file": "test_fft/test_sm_only_functions.py", "settings": { - "buffer_size": 3914, + "buffer_size": 2151, "line_ending": "Unix" } }, { - "file": "test_fft/register_addresses_fft_test.py", + "file": "test_fft/test_sm_only_register_addresses.py", + "settings": + { + "buffer_size": 391, + "line_ending": "Unix" + } + }, + { + "file": "test_fft/test_fft_register_addresses.py", "settings": { "buffer_size": 873, @@ -220,9 +232,18 @@ }, "file_history": [ + "/opt/LFR_EMULATOR/test_fft/test_sm_only_register_addresses.py", + "/opt/LFR_EMULATOR/test_fft/test_sm_only_functions.py", + "/opt/LFR_EMULATOR/test_fft/test_sm_functions.py", + "/opt/LFR_EMULATOR/test_fft/test_fft_register_addresses.py", + "/opt/LFR_EMULATOR/test_fft/test_fft_only.py", + "/opt/LFR_EMULATOR/test_fft/test_fft_functions.py", + "/opt/LFR_EMULATOR/test_fft/test_fft.py", + "/opt/LFR_EMULATOR/test_fft/general_functions.py", + "/opt/LFR_EMULATOR/test_fft/test_sm.py", + "/opt/LFR_EMULATOR/test_fft/register_addresses_fft_test.py", "/opt/LFR_EMULATOR/test_fft/fft_test_functions.py", "/opt/LFR_EMULATOR/test_fft/test_fft_mini_lfr.py", - "/opt/LFR_EMULATOR/test_fft/register_addresses_fft_test.py", "/opt/LFR_EMULATOR/test_fft/functions_evaluations.py", "/opt/LFR_EMULATOR/SRC/processing_chain.py", "/opt/LFR_EMULATOR/main.py", @@ -301,18 +322,18 @@ [ { "buffer": 0, - "file": "test_fft/test_sm_mini_lfr.py", + "file": "test_fft/test_sm_only.py", "settings": { - "buffer_size": 5847, + "buffer_size": 6506, "regions": { }, "selection": [ [ - 5847, - 5847 + 3548, + 3548 ] ], "settings": @@ -321,25 +342,25 @@ "translate_tabs_to_spaces": false }, "translation.x": 0.0, - "translation.y": 1640.0, + "translation.y": 0.0, "zoom_level": 1.0 }, "type": "text" }, { "buffer": 1, - "file": "test_fft/test_sm_functions.py", + "file": "test_fft/test_sm_only_functions.py", "settings": { - "buffer_size": 3914, + "buffer_size": 2151, "regions": { }, "selection": [ [ - 2764, - 2764 + 1314, + 1314 ] ], "settings": @@ -348,14 +369,40 @@ "translate_tabs_to_spaces": false }, "translation.x": 0.0, - "translation.y": 1404.0, + "translation.y": 324.0, "zoom_level": 1.0 }, "type": "text" }, { "buffer": 2, - "file": "test_fft/register_addresses_fft_test.py", + "file": "test_fft/test_sm_only_register_addresses.py", + "settings": + { + "buffer_size": 391, + "regions": + { + }, + "selection": + [ + [ + 297, + 297 + ] + ], + "settings": + { + "syntax": "Packages/Python/Python.tmLanguage" + }, + "translation.x": 0.0, + "translation.y": 0.0, + "zoom_level": 1.0 + }, + "type": "text" + }, + { + "buffer": 3, + "file": "test_fft/test_fft_register_addresses.py", "settings": { "buffer_size": 873, @@ -365,8 +412,8 @@ "selection": [ [ - 703, - 703 + 0, + 0 ] ], "settings": @@ -374,7 +421,7 @@ "syntax": "Packages/Python/Python.tmLanguage" }, "translation.x": 0.0, - "translation.y": 108.0, + "translation.y": 0.0, "zoom_level": 1.0 }, "type": "text" @@ -388,7 +435,7 @@ }, "input": { - "height": 0.0 + "height": 34.0 }, "layout": { diff --git a/test_fft/data_generator.py b/test_fft/data_generator.py new file mode 100644 --- /dev/null +++ b/test_fft/data_generator.py @@ -0,0 +1,62 @@ +import numpy as np + +def getWaveFromRecord( cwf, bufferSize, offset, column ): + yVector = cwf[(0+offset):(bufferSize+offset), column] + return yVector + +def sineWave( bufferSize, nbPeriod, amplitude): + deltaX = nbPeriod * 2 * np.pi / bufferSize + xVector = np.arange( bufferSize ) * deltaX + yVector = np.int16( amplitude * np.sin( xVector ) ) + return yVector + +def continuous( bufferSize, value ): + tmpVector = np.empty( bufferSize ) + tmpVector.fill( value ) + yVector = np.int16( tmpVector ) + return yVector + +def step( bufferSize, value ): + tmpVector = np.zeros( bufferSize ) + for k in range( bufferSize / 2 ): + tmpVector[ bufferSize / 2 + k ] = value + yVector = np.int16( tmpVector ) + return yVector + +def dirac( bufferSize, value, position=0 ): + tmpVector = np.zeros( bufferSize ) + if position < bufferSize: + tmpVector[position] = value + yVector = np.int16( tmpVector ) + return yVector + +def generateDataToWrite( bufferSize, wfrm0, wfrm1 ): + dataVector = [] + for k in range(bufferSize): + dataVector.append( + ( (np.int16(wfrm1[k]) & 0xffff ) << 16) + | (np.int16(wfrm0[k]) & 0xffff ) + ) + return dataVector + +def convertToSigned16Bits( dataToConvert ): + dataInInt16 = np.int16( dataToConvert ) + if dataInInt16 < 32768: + val = dataInInt16 + else: + val = dataInInt16 - 65536 + return val + +def convertVectorToSigned16Bits( bufferSize, dataBuffer ): + dataBufferConverted = np.zeros( bufferSize ) + for k in range( bufferSize ): + dataBufferConverted[k] = convertToSigned16Bits( dataBuffer[k] ) + return dataBufferConverted + +def convertToSigned8Bits( dataToConvert ): + dataInInt16 = np.int8( dataToConvert ) + if dataInInt16 < 8: + val = dataInInt16 + else: + val = dataInInt16 - 16 + return val diff --git a/test_fft/fft_test_functions.py b/test_fft/fft_test_functions.py deleted file mode 100644 --- a/test_fft/fft_test_functions.py +++ /dev/null @@ -1,95 +0,0 @@ -import numpy as np - -from test_fft.register_addresses_fft_test import * - -from __main__ import RMAPPlugin0 - -def getWaveFromRecord( cwf, bufferSize, offset, column ): - yVector = cwf[(0+offset):(bufferSize+offset), column] - return yVector - -def sineWave( bufferSize, nbPeriod, amplitude): - deltaX = nbPeriod * 2 * np.pi / bufferSize - xVector = np.arange( bufferSize ) * deltaX - yVector = np.int16( amplitude * np.sin( xVector ) ) - return yVector - -def continuous( bufferSize, value ): - tmpVector = np.empty( bufferSize ) - tmpVector.fill( value ) - yVector = np.int16( tmpVector ) - return yVector - -def step( bufferSize, value ): - tmpVector = np.zeros( bufferSize ) - for k in range( bufferSize / 2 ): - tmpVector[ bufferSize / 2 + k ] = value - yVector = np.int16( tmpVector ) - return yVector - -def dirac( bufferSize, value ): - tmpVector = np.zeros( bufferSize ) - tmpVector[0] = value - yVector = np.int16( tmpVector ) - return yVector - -def generateDataToWrite( bufferSize, wfrm0, wfrm1 ): - dataVector = [] - for k in range(bufferSize): - dataVector.append( - ( (np.int16(wfrm1[k]) & 0xffff ) << 16) - | (np.int16(wfrm0[k]) & 0xffff ) - ) - return dataVector - -def print_reg_fft( ): - fft_reg = RMAPPlugin0.Read( address_CTRL, 1) - out_ren = (fft_reg[0] & 0x0000001f) - out_reuse = (fft_reg[0] & 0x000003e0) >> 5 - out_locked = (fft_reg[0] & 0x00007c00) >> 10 - MEM_IN_SM_Full = (fft_reg[0] & 0x000f8000) >> 15 - MEM_IN_SM_Empty = (fft_reg[0] & 0x01f00000) >> 20 - print "out_ren = " + bin( out_ren ) \ - + ", out_reuse = " + bin( out_reuse ) \ - + ", out_locked = " + bin( out_locked ) \ - + ", MEM_IN_SM_Full = " + bin( MEM_IN_SM_Full ) \ - + ", MEM_IN_SM_Empty = " + bin( MEM_IN_SM_Empty ) - RMAPPlugin0.ProcessPendingEvents() - -def print_custom( value ): - print value - RMAPPlugin0.ProcessPendingEvents() - -def is_MEM_IN_SM_Emty( ): - ret = 0 - fft_reg = RMAPPlugin0.Read( address_CTRL, 1) - MEM_IN_SM_Empty = (fft_reg[0] & 0x01f00000) >> 20 - if MEM_IN_SM_Empty == 0x1f: - ret = 1 - return ret - -def out_locked_AND_out_reuse_AND_out_ren( ): - # reuse => 0111 1111 1111 1111 - RMAPPlugin0.Write( address_CTRL, [0x00007fff] ) - -def convertToSigned16Bits( dataToConvert ): - dataInInt16 = np.int16( dataToConvert ) - if dataInInt16 < 32768: - val = dataInInt16 - else: - val = dataInInt16 - 65536 - return val - -def convertVectorToSigned16Bits( bufferSize, dataBuffer ): - dataBufferConverted = np.zeros( bufferSize ) - for k in range( bufferSize ): - dataBufferConverted[k] = convertToSigned16Bits( dataBuffer[k] ) - return dataBufferConverted - -def convertToSigned8Bits( dataToConvert ): - dataInInt16 = np.int8( dataToConvert ) - if dataInInt16 < 8: - val = dataInInt16 - else: - val = dataInInt16 - 16 - return val diff --git a/test_fft/fft_test_functions.pyc b/test_fft/fft_test_functions.pyc deleted file mode 100644 index 508a55ef93c95832a934dd1bf5027854ba9bfb1f..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 GIT binary patch literal 0 Hc$@> 5 + out_locked = (fft_reg[0] & 0x00007c00) >> 10 + MEM_IN_SM_Full = (fft_reg[0] & 0x000f8000) >> 15 + MEM_IN_SM_Empty = (fft_reg[0] & 0x01f00000) >> 20 + print "out_ren = " + bin( out_ren ) \ + + ", out_reuse = " + bin( out_reuse ) \ + + ", out_locked = " + bin( out_locked ) \ + + ", MEM_IN_SM_Full = " + bin( MEM_IN_SM_Full ) \ + + ", MEM_IN_SM_Empty = " + bin( MEM_IN_SM_Empty ) + RMAPPlugin0.ProcessPendingEvents() + +def print_reg_sm( address ): + sm_reg = RMAPPlugin0.Read( address, 1) + out_ren = (sm_reg[0] & 0x00000003) + MEM_OUT_SM_Full = (sm_reg[0] & 0x0000000c) >> 2 + MEM_OUT_SM_Empty = (sm_reg[0] & 0x00000030) >> 4 + MEM_OUT_SM_Full_s= (sm_reg[0] & 0x00000040) >> 6 + print "sm_reg = " + bin( sm_reg[0] & 0x7f ) \ + + ", MEM_OUT_SM_Full_s = " + bin( MEM_OUT_SM_Full_s ) \ + + ", MEM_OUT_SM_Empty = " + bin( MEM_OUT_SM_Empty ) \ + + ", MEM_OUT_SM_Full = " + bin( MEM_OUT_SM_Full ) \ + + ", out_ren = " + bin( out_ren ) + RMAPPlugin0.ProcessPendingEvents() + +def print_reg_sm_only_MEM_IN_CTRL( address ): + sm_reg = RMAPPlugin0.Read( address, 1) + out_wen = (sm_reg[0] & 0x0000001f) + MEM_IN_SM_Full = (sm_reg[0] & 0x000003e0) >> 5 + MEM_IN_SM_Empty = (sm_reg[0] & 0x00007c00) >> 10 + MEM_IN_SM_Locked = (sm_reg[0] & 0x000f8000) >> 15 + print "MEM_IN_SM = " + bin( sm_reg[0] & 0xfffff ) \ + + ", Locked = " + bin( MEM_IN_SM_Locked ) \ + + ", Empty = " + bin( MEM_IN_SM_Empty ) \ + + ", Full = " + bin( MEM_IN_SM_Full ) \ + + ", wen = " + bin( out_wen ) + RMAPPlugin0.ProcessPendingEvents() + +def print_reg_sm_only_MEM_OUT_CTRL( address ): + sm_reg = RMAPPlugin0.Read( address, 1) + MEM_IN_SM_Empty = (sm_reg[0] & 0x00000030) >> 4 + MEM_IN_SM_Full = (sm_reg[0] & 0x0000000c) >> 2 + out_ren = (sm_reg[0] & 0x00000003) + print "MEM_OUT_SM = " + bin( sm_reg[0] & 0x3f ) \ + + ", Empty = " + bin( MEM_IN_SM_Empty ) \ + + ", Full = " + bin( MEM_IN_SM_Full ) \ + + ", ren = " + bin( out_ren ) + RMAPPlugin0.ProcessPendingEvents() diff --git a/test_fft/read_data.py b/test_fft/read_data.py new file mode 100644 --- /dev/null +++ b/test_fft/read_data.py @@ -0,0 +1,80 @@ +import numpy as np + +from __main__ import RMAPPlugin0 + +from test_fft.register_addresses import * +import test_fft.print_custom as prnt + +def read_SM_Re( nbFrequencyBins, address_MEM_OUT_SM ): + currentComp_re = np.zeros( nbFrequencyBins ) + if address_MEM_OUT_SM == FFT_SM_MEM_OUT_SM_0: + mask_REN = mask_REN_FIFO_0 + elif address_MEM_OUT_SM == FFT_SM_MEM_OUT_SM_1: + mask_REN = mask_REN_FIFO_1 + else: + prnt.print_custom( "ERR *** read_SM_Re *** unexpected address_MEM_OUT_SM" ) + for frequencyBin in range(nbFrequencyBins): + # read Re + RMAPPlugin0.Write( FFT_SM_MEM_OUT_SM_CTRL, [mask_REN] ) + val = RMAPPlugin0.Read( address_MEM_OUT_SM, 1) + currentComp_re[frequencyBin] = val[0] + RMAPPlugin0.ProcessPendingEvents() + return currentComp_re + +def read_SM_Re_Im( nbFrequencyBins, address_MEM_OUT_SM ): + currentComp_re = np.zeros( nbFrequencyBins ) + currentComp_im = np.zeros( nbFrequencyBins ) + if address_MEM_OUT_SM == FFT_SM_MEM_OUT_SM_0: + mask_REN = mask_REN_FIFO_0 + elif address_MEM_OUT_SM == FFT_SM_MEM_OUT_SM_1: + mask_REN = mask_REN_FIFO_1 + else: + prnt.print_custom( "ERR *** read_SM_Re_Im *** unexpected address_MEM_OUT_SM" ) + for frequencyBin in range(nbFrequencyBins): + # read Re + RMAPPlugin0.Write( FFT_SM_MEM_OUT_SM_CTRL, [mask_REN] ) + val = RMAPPlugin0.Read( address_MEM_OUT_SM, 1) + currentComp_re[frequencyBin] = val[0] + # read Im + RMAPPlugin0.Write( FFT_SM_MEM_OUT_SM_CTRL, [mask_REN] ) + val = RMAPPlugin0.Read( address_MEM_OUT_SM, 1) + currentComp_im[frequencyBin] = val[0] + RMAPPlugin0.ProcessPendingEvents() + return (currentComp_re, currentComp_im) + +def read_SM_ONLY_Re( nbFrequencyBins, address_MEM_OUT_SM ): + currentComp_re = np.zeros( nbFrequencyBins ) + if address_MEM_OUT_SM == SM_ONLY_MEM_OUT_SM_0: + mask_REN = mask_REN_FIFO_0 + elif address_MEM_OUT_SM == SM_ONLY_MEM_OUT_SM_1: + mask_REN = mask_REN_FIFO_1 + else: + prnt.print_custom( "ERR *** read_SM_ONLY_Re *** unexpected address_MEM_OUT_SM" ) + for frequencyBin in range(nbFrequencyBins): + # read Re + RMAPPlugin0.Write( SM_ONLY_MEM_OUT_CTRL, [mask_REN] ) + val = RMAPPlugin0.Read( address_MEM_OUT_SM, 1) + currentComp_re[frequencyBin] = val[0] + RMAPPlugin0.ProcessPendingEvents() + return currentComp_re + +def read_SM_ONLY_Re_Im( nbFrequencyBins, address_MEM_OUT_SM ): + currentComp_re = np.zeros( nbFrequencyBins ) + currentComp_im = np.zeros( nbFrequencyBins ) + if address_MEM_OUT_SM == SM_ONLY_MEM_OUT_SM_0: + mask_REN = mask_REN_FIFO_0 + elif address_MEM_OUT_SM == SM_ONLY_MEM_OUT_SM_1: + mask_REN = mask_REN_FIFO_1 + else: + prnt.print_custom( "ERR *** read_SM_ONLY_Re_Im *** unexpected address_MEM_OUT_SM" ) + for frequencyBin in range(nbFrequencyBins): + # read Re + RMAPPlugin0.Write( SM_ONLY_MEM_OUT_CTRL, [mask_REN] ) + val = RMAPPlugin0.Read( address_MEM_OUT_SM, 1) + currentComp_re[frequencyBin] = val[0] + # read Im + RMAPPlugin0.Write( SM_ONLY_MEM_OUT_CTRL, [mask_REN] ) + val = RMAPPlugin0.Read( address_MEM_OUT_SM, 1) + currentComp_im[frequencyBin] = val[0] + RMAPPlugin0.ProcessPendingEvents() + return (currentComp_re, currentComp_im) diff --git a/test_fft/read_flags.py b/test_fft/read_flags.py new file mode 100644 --- /dev/null +++ b/test_fft/read_flags.py @@ -0,0 +1,90 @@ +import numpy as np + +from __main__ import RMAPPlugin0 + +from test_fft.register_addresses import * +import test_fft.print_custom as prnt + +def is_MEM_IN_SM_Emty( address ): + ret = 0 + fft_reg = RMAPPlugin0.Read( address, 1) + MEM_IN_SM_Empty = (fft_reg[0] & 0x01f00000) >> 20 + if MEM_IN_SM_Empty == 0x1f: + ret = 1 + return ret + +def out_locked_AND_out_reuse_AND_out_ren( address ): + # reuse => 0111 1111 1111 1111 + RMAPPlugin0.Write( address, [0x00007fff] ) + +#================================== +#================================== + +def is_MEM_OUT_SM_Empty( address ): + ret = 0 + sm_reg = RMAPPlugin0.Read( address, 1) + MEM_OUT_SM_Empty = (sm_reg[0] & 0x00000030) >> 4 + if MEM_OUT_SM_Empty == 0x3: + ret = 1 + return ret + +def is_MEM_OUT_SM_Full( address ): + ret = 0 + sm_reg = RMAPPlugin0.Read( address, 1) + MEM_OUT_SM_Full = (sm_reg[0] & 0x0000000c) >> 2 + if MEM_OUT_SM_Full != 0x0: + ret = 1 + return ret + +def is_MEM_OUT_SM_Full_FIFO_0( address ): + ret = 0 + sm_reg = RMAPPlugin0.Read( address, 1) + MEM_OUT_SM_Full = (sm_reg[0] & 0x00000004) >> 2 + if MEM_OUT_SM_Full == 0x01: + ret = 1 + return ret + +def is_MEM_OUT_SM_Full_FIFO_1( address ): + ret = 0 + sm_reg = RMAPPlugin0.Read( address, 1) + MEM_OUT_SM_Full = (sm_reg[0] & 0x00000008) >> 3 + if MEM_OUT_SM_Full == 0x01: + ret = 1 + return ret + +def wait_for_FIFO_0_Full( address ): + counter = 0 + while ( is_MEM_OUT_SM_Full_FIFO_0( address ) == 0 ): + prnt.print_custom( "FIFO_0 not full " + str(counter) ) + counter = counter + 1 + if counter == 10: + break + +def wait_for_FIFO_1_Full( address ): + counter = 0 + while ( is_MEM_OUT_SM_Full_FIFO_1( address ) == 0 ): + prnt.print_custom( "FIFO_1 not full " + str(counter)) + counter = counter + 1 + if counter == 10: + break + +def wait_for_FIFO_Full( fifo, address ): + if fifo == 0: + wait_for_FIFO_0_Full( address ) + elif fifo == 1: + wait_for_FIFO_1_Full( address ) + else: + prnt.print_custom( "ERR *** wait_for_FIFO_Full *** unexpted value for parameter [fifo]" ) + +def wait_for_FIFO_0_or_1_Full( address ): + counter = 0 + sm_reg = RMAPPlugin0.Read( address, 1) + MEM_OUT_SM_Full = (sm_reg[0] & 0x0000000c) >> 2 + while ( MEM_OUT_SM_Full == 0 ): + prnt.print_custom( "FIFO 0 or 1 not full " + str(counter)) + counter = counter + 1 + if counter == 10: + break + sm_reg = RMAPPlugin0.Read( address, 1) + MEM_OUT_SM_Full = (sm_reg[0] & 0x0000000c) >> 2 + RMAPPlugin0.ProcessPendingEvents() diff --git a/test_fft/register_addresses.py b/test_fft/register_addresses.py new file mode 100644 --- /dev/null +++ b/test_fft/register_addresses.py @@ -0,0 +1,58 @@ +#============================ +# ADRESSES FOR THE FFT MODULE +# FIFO F0 +FFT_FIFO_F0_1_0 = 0x80000f00 +FFT_FIFO_F0_3_2 = 0x80000f04 +FFT_FIFO_F0_4 = 0x80000f08 +FFT_FIFO_F0_WEN = 0x80000f0c +# FIFO F1 +FFT_FIFO_F1_1_0 = 0x80000f10 +FFT_FIFO_F1_3_2 = 0x80000f14 +FFT_FIFO_F1_4 = 0x80000f18 +FFT_FIFO_F1_WEN = 0x80000f1c +# FIFO F2 +FFT_FIFO_F2_1_0 = 0x80000f20 +FFT_FIFO_F2_3_2 = 0x80000f24 +FFT_FIFO_F2_4 = 0x80000f28 +FFT_FIFO_F2_WEN = 0x80000f2c + +FFT_MEM_IN_SM_0 = 0x80000f30 +FFT_MEM_IN_SM_1 = 0x80000f34 +FFT_MEM_IN_SM_2 = 0x80000f38 +FFT_MEM_IN_SM_3 = 0x80000f3c +FFT_MEM_IN_SM_4 = 0x80000f40 + +FFT_CTRL = 0x80000f44 + +#================================ +# ADDRESSES FOR THE FFT_SM DESIGN +FFT_SM_MEM_OUT_SM_0 = 0x80000f30 +FFT_SM_MEM_OUT_SM_1 = 0x80000f34 +FFT_SM_MEM_OUT_SM_CTRL = 0x80000f38 + +#================================= +# ADDRESSES FOR THE SM_ONLY DESIGN +SM_ONLY_MEM_IN_SM_0 = 0x80000f00 +SM_ONLY_MEM_IN_SM_1 = 0x80000f04 +SM_ONLY_MEM_IN_SM_2 = 0x80000f08 +SM_ONLY_MEM_IN_SM_3 = 0x80000f0c +SM_ONLY_MEM_IN_SM_4 = 0x80000f10 + +SM_ONLY_MEM_IN_SM_CTRL = 0x80000f14 + +SM_ONLY_MEM_OUT_SM_0 = 0x80000f18 +SM_ONLY_MEM_OUT_SM_1 = 0x80000f1c + +SM_ONLY_MEM_OUT_CTRL = 0x80000f20 + +#====================== +# GENERAL USE CONSTANTS +mask_REN_FIFO_0 = 0xfffffffe # 1110 +mask_REN_FIFO_1 = 0xfffffffd # 1101 +# +columnV = 1 +columnE1 = 2 +columnE2 = 3 +columnB1 = 4 +columnB2 = 5 +columnB3 = 6 \ No newline at end of file diff --git a/test_fft/register_addresses_fft_test.py b/test_fft/register_addresses_fft_test.py deleted file mode 100644 --- a/test_fft/register_addresses_fft_test.py +++ /dev/null @@ -1,39 +0,0 @@ -# FIFO F0 -address_FIFO_F0_1_0 = 0x80000f00 -address_FIFO_F0_3_2 = 0x80000f04 -address_FIFO_F0_4 = 0x80000f08 -address_FIFO_F0_WEN = 0x80000f0c -# FIFO F1 -address_FIFO_F1_1_0 = 0x80000f10 -address_FIFO_F1_3_2 = 0x80000f14 -address_FIFO_F1_4 = 0x80000f18 -address_FIFO_F1_WEN = 0x80000f1c -# FIFO F2 -address_FIFO_F2_1_0 = 0x80000f20 -address_FIFO_F2_3_2 = 0x80000f24 -address_FIFO_F2_4 = 0x80000f28 -address_FIFO_F2_WEN = 0x80000f2c - -address_MEM_IN_SM_0 = 0x80000f30 -address_MEM_IN_SM_1 = 0x80000f34 -address_MEM_IN_SM_2 = 0x80000f38 -address_MEM_IN_SM_3 = 0x80000f3c -address_MEM_IN_SM_4 = 0x80000f40 - -address_CTRL = 0x80000f44 - -address_MEM_OUT_SM_0= 0x80000f30 -address_MEM_OUT_SM_1= 0x80000f34 - -mask_REN_FIFO_0 = 0xfffffffe # 1110 -mask_REN_FIFO_1 = 0xfffffffd # 1101 - -address_CTRL_SM = 0x80000f38 - -# -columnV = 1 -columnE1 = 2 -columnE2 = 3 -columnB1 = 4 -columnB2 = 5 -columnB3 = 6 \ No newline at end of file diff --git a/test_fft/register_addresses_fft_test.pyc b/test_fft/register_addresses_fft_test.pyc deleted file mode 100644 index 0ee4abc27a6302a286a7397ddadffa94376844e7..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 GIT binary patch literal 0 Hc$@ 0111 1100 0001 1111 -RMAPPlugin0.Write( address_CTRL, [0x00007c1f] ) - -# wait for SM_Full -fft_reg = RMAPPlugin0.Read( address_CTRL, 1) -while (fft_reg[0] & 0x000f8000) == 0: - print_custom( "SM not full" ) - fft_reg = RMAPPlugin0.Read( address_CTRL, 1) - -print_reg_fft( ) - -################ -# FFT FIRST READ -print_custom( "======= FIRST READ" ) -fft0_re = np.zeros( nbSamples ) -fft0_im = np.zeros( nbSamples ) -fft1_re = np.zeros( nbSamples ) -fft1_im = np.zeros( nbSamples ) -fft2_re = np.zeros( nbSamples ) -fft2_im = np.zeros( nbSamples ) -fft3_re = np.zeros( nbSamples ) -fft3_im = np.zeros( nbSamples ) -fft4_re = np.zeros( nbSamples ) -fft4_im = np.zeros( nbSamples ) - -for k in range(128): - # read enable => 0111 1100 0000 0000 - RMAPPlugin0.Write( address_CTRL, [0x00007c00] ) - val = RMAPPlugin0.Read( address_MEM_IN_SM_0, 1) - fft0_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff ) - fft0_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) - val = RMAPPlugin0.Read( address_MEM_IN_SM_1, 1) - fft1_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff ) - fft1_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) - val = RMAPPlugin0.Read( address_MEM_IN_SM_2, 1) - fft2_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff ) - fft2_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) - val = RMAPPlugin0.Read( address_MEM_IN_SM_3, 1) - fft3_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff ) - fft3_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) - val = RMAPPlugin0.Read( address_MEM_IN_SM_4, 1) - fft4_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff ) - fft4_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) - if is_MEM_IN_SM_Emty( ) == 1: - print_custom( "k = " + str( k ) ) - -fft0 = fft0_re * fft0_re + fft0_im * fft0_im -fft1 = fft1_re * fft1_re + fft1_im * fft1_im -fft2 = fft2_re * fft2_re + fft2_im * fft2_im -fft3 = fft3_re * fft3_re + fft3_im * fft3_im -fft4 = fft4_re * fft4_re + fft4_im * fft4_im - -####### -# REUSE -print_custom( "======= REUSE" ) -out_locked_AND_out_reuse_AND_out_ren() -print_reg_fft( ) - -print_custom( "read data in fft FIFOs" ) -fft0_re = np.zeros( nbSamples ) -fft0_im = np.zeros( nbSamples ) -fft1_re = np.zeros( nbSamples ) -fft1_im = np.zeros( nbSamples ) -fft2_re = np.zeros( nbSamples ) -fft2_im = np.zeros( nbSamples ) -fft3_re = np.zeros( nbSamples ) -fft3_im = np.zeros( nbSamples ) -fft4_re = np.zeros( nbSamples ) -fft4_im = np.zeros( nbSamples ) - -for k in range(128): - # read enable => 0111 1100 0000 0000 - val = RMAPPlugin0.Read( address_MEM_IN_SM_0, 1) - fft0_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff ) - fft0_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) - val = RMAPPlugin0.Read( address_MEM_IN_SM_1, 1) - fft1_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff ) - fft1_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) - val = RMAPPlugin0.Read( address_MEM_IN_SM_2, 1) - fft2_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff ) - fft2_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) - val = RMAPPlugin0.Read( address_MEM_IN_SM_3, 1) - fft3_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff ) - fft3_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) - val = RMAPPlugin0.Read( address_MEM_IN_SM_4, 1) - fft4_re[k] = convertToSigned16Bits( val[0] & 0x0000ffff ) - fft4_im[k] = convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) - RMAPPlugin0.Write( address_CTRL, [0x00007c00] ) - if is_MEM_IN_SM_Emty( ) == 1: - print_custom( "k = " + str( k ) ) - -fft0_b = fft0_re * fft0_re + fft0_im * fft0_im -fft1_b = fft1_re * fft1_re + fft1_im * fft1_im -fft2_b = fft2_re * fft2_re + fft2_im * fft2_im -fft3_b = fft3_re * fft3_re + fft3_im * fft3_im -fft4_b = fft4_re * fft4_re + fft4_im * fft4_im - -print_custom( "data read in fft FIFOs" ) - -print_reg_fft( ) - -#unlock FIFOs => 0000 0000 0001 1111 -RMAPPlugin0.Write( address_CTRL, [0x0000001f] ) - -print_reg_fft( ) - -# PLOT FFT - -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(311) -plt.plot(fft0_re) -plt.plot(fft1_re) -plt.plot(fft2_re) -plt.plot(fft3_re) -plt.plot(fft4_re) - -plt.subplot(312) -plt.plot(fft0_im) -plt.plot(fft1_im) -plt.plot(fft2_im) -plt.plot(fft3_im) -plt.plot(fft4_im) - -plt.subplot(313) -plt.plot(fft0_re * fft0_re + fft0_im * fft0_im, 'b') -plt.plot(fft1_re * fft1_re + fft1_im * fft1_im, 'g') -plt.plot(fft2_re * fft2_re + fft2_im * fft2_im, 'r') -plt.plot(fft3_re * fft3_re + fft3_im * fft3_im, 'c') -plt.plot(fft4_re * fft4_re + fft4_im * fft4_im, 'm') - -plt.figure( 3 ) -plt.subplot(231) -plt.plot(fft0[0:255], 'b') -plt.subplot(232) -plt.plot(fft1[0:255], 'g') -plt.subplot(233) -plt.plot(fft2[0:255], 'r') -plt.subplot(234) -plt.plot(fft3[0:255], 'c') -plt.subplot(235) -plt.plot(fft4[0:255], 'm') - -plt.figure( 4 ) -plt.subplot(231) -plt.plot(fft0_b[0:255], 'b') -plt.subplot(232) -plt.plot(fft1_b[0:255], 'g') -plt.subplot(233) -plt.plot(fft2_b[0:255], 'r') -plt.subplot(234) -plt.plot(fft3_b[0:255], 'c') -plt.subplot(235) -plt.plot(fft4_b[0:255], 'm') - -plt.show() \ No newline at end of file diff --git a/test_fft/test_fft_only.py b/test_fft/test_fft_only.py new file mode 100644 --- /dev/null +++ b/test_fft/test_fft_only.py @@ -0,0 +1,241 @@ +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 +#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( nbSamples, 10, 1000 ) +wfrm1 = dtgn.dirac( nbSamples, 1000 ) +wfrm2 = dtgn.step( nbSamples, 1000 ) +wfrm3 = dtgn.continuous( nbSamples, 100 ) +wfrm4 = dtgn.continuous( nbSamples, 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_reg_fft( FFT_CTRL ) + +prnt.print_custom( "1) write waveforms in FIFOs: " + str(len(dataToWrite0)) + " samples" ) + +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" ) + +prnt.print_reg_fft( FFT_CTRL ) + +# LOCK FIFOs => 0111 1100 0001 1111 +RMAPPlugin0.Write( FFT_CTRL, [0x00007c1f] ) + +# wait for SM_Full +fft_reg = RMAPPlugin0.Read( FFT_CTRL, 1) +counter = 0 +while (fft_reg[0] & 0x000f8000) == 0: + prnt.print_custom( "SM not full" ) + counter = counter + 1 + if counter == 10: + break + fft_reg = RMAPPlugin0.Read( FFT_CTRL, 1) + +prnt.print_reg_fft( FFT_CTRL ) + +################ +# FFT FIRST READ +prnt.print_custom( "======= FIRST READ" ) +fft0_re = np.zeros( nbSamples ) +fft0_im = np.zeros( nbSamples ) +fft1_re = np.zeros( nbSamples ) +fft1_im = np.zeros( nbSamples ) +fft2_re = np.zeros( nbSamples ) +fft2_im = np.zeros( nbSamples ) +fft3_re = np.zeros( nbSamples ) +fft3_im = np.zeros( nbSamples ) +fft4_re = np.zeros( nbSamples ) +fft4_im = np.zeros( nbSamples ) + +for k in range(128): + # read enable => 0111 1100 0000 0000 + RMAPPlugin0.Write( FFT_CTRL, [0x00007c00] ) + val = RMAPPlugin0.Read( FFT_MEM_IN_SM_0, 1) + fft0_re[k] = dtgn.convertToSigned16Bits( val[0] & 0x0000ffff ) + fft0_im[k] = dtgn.convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) + val = RMAPPlugin0.Read( FFT_MEM_IN_SM_1, 1) + fft1_re[k] = dtgn.convertToSigned16Bits( val[0] & 0x0000ffff ) + fft1_im[k] = dtgn.convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) + val = RMAPPlugin0.Read( FFT_MEM_IN_SM_2, 1) + fft2_re[k] = dtgn.convertToSigned16Bits( val[0] & 0x0000ffff ) + fft2_im[k] = dtgn.convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) + val = RMAPPlugin0.Read( FFT_MEM_IN_SM_3, 1) + fft3_re[k] = dtgn.convertToSigned16Bits( val[0] & 0x0000ffff ) + fft3_im[k] = dtgn.convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) + val = RMAPPlugin0.Read( FFT_MEM_IN_SM_4, 1) + fft4_re[k] = dtgn.convertToSigned16Bits( val[0] & 0x0000ffff ) + fft4_im[k] = dtgn.convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) + if flg.is_MEM_IN_SM_Emty( FFT_CTRL ) == 1: + prnt.print_custom( "k = " + str( k ) ) + +fft0 = fft0_re * fft0_re + fft0_im * fft0_im +fft1 = fft1_re * fft1_re + fft1_im * fft1_im +fft2 = fft2_re * fft2_re + fft2_im * fft2_im +fft3 = fft3_re * fft3_re + fft3_im * fft3_im +fft4 = fft4_re * fft4_re + fft4_im * fft4_im + +####### +# REUSE +prnt.print_custom( "======= REUSE" ) +flg.out_locked_AND_out_reuse_AND_out_ren( FFT_CTRL ) +prnt.print_reg_fft( FFT_CTRL ) + +prnt.print_custom( "read data in fft FIFOs" ) +fft0_re = np.zeros( nbSamples ) +fft0_im = np.zeros( nbSamples ) +fft1_re = np.zeros( nbSamples ) +fft1_im = np.zeros( nbSamples ) +fft2_re = np.zeros( nbSamples ) +fft2_im = np.zeros( nbSamples ) +fft3_re = np.zeros( nbSamples ) +fft3_im = np.zeros( nbSamples ) +fft4_re = np.zeros( nbSamples ) +fft4_im = np.zeros( nbSamples ) + +for k in range(128): + # read enable => 0111 1100 0000 0000 + val = RMAPPlugin0.Read( FFT_MEM_IN_SM_0, 1) + fft0_re[k] = dtgn.convertToSigned16Bits( val[0] & 0x0000ffff ) + fft0_im[k] = dtgn.convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) + val = RMAPPlugin0.Read( FFT_MEM_IN_SM_1, 1) + fft1_re[k] = dtgn.convertToSigned16Bits( val[0] & 0x0000ffff ) + fft1_im[k] = dtgn.convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) + val = RMAPPlugin0.Read( FFT_MEM_IN_SM_2, 1) + fft2_re[k] = dtgn.convertToSigned16Bits( val[0] & 0x0000ffff ) + fft2_im[k] = dtgn.convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) + val = RMAPPlugin0.Read( FFT_MEM_IN_SM_3, 1) + fft3_re[k] = dtgn.convertToSigned16Bits( val[0] & 0x0000ffff ) + fft3_im[k] = dtgn.convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) + val = RMAPPlugin0.Read( FFT_MEM_IN_SM_4, 1) + fft4_re[k] = dtgn.convertToSigned16Bits( val[0] & 0x0000ffff ) + fft4_im[k] = dtgn.convertToSigned16Bits( ( (val[0] & 0xffff0000) >> 16 ) ) + RMAPPlugin0.Write( FFT_CTRL, [0x00007c00] ) + if flg.is_MEM_IN_SM_Emty( FFT_CTRL ) == 1: + prnt.print_custom( "k = " + str( k ) ) + +fft0_b = fft0_re * fft0_re + fft0_im * fft0_im +fft1_b = fft1_re * fft1_re + fft1_im * fft1_im +fft2_b = fft2_re * fft2_re + fft2_im * fft2_im +fft3_b = fft3_re * fft3_re + fft3_im * fft3_im +fft4_b = fft4_re * fft4_re + fft4_im * fft4_im + +prnt.print_custom( "data read in fft FIFOs" ) + +prnt.print_reg_fft( FFT_CTRL ) + +#unlock FIFOs => 0000 0000 0001 1111 +RMAPPlugin0.Write( FFT_CTRL, [0x0000001f] ) + +prnt.print_reg_fft( FFT_CTRL ) + +# PLOT FFT + +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(311) +plt.plot(fft0_re) +plt.plot(fft1_re) +plt.plot(fft2_re) +plt.plot(fft3_re) +plt.plot(fft4_re) + +plt.subplot(312) +plt.plot(fft0_im) +plt.plot(fft1_im) +plt.plot(fft2_im) +plt.plot(fft3_im) +plt.plot(fft4_im) + +plt.subplot(313) +plt.plot(fft0_re * fft0_re + fft0_im * fft0_im, 'b') +plt.plot(fft1_re * fft1_re + fft1_im * fft1_im, 'g') +plt.plot(fft2_re * fft2_re + fft2_im * fft2_im, 'r') +plt.plot(fft3_re * fft3_re + fft3_im * fft3_im, 'c') +plt.plot(fft4_re * fft4_re + fft4_im * fft4_im, 'm') + +plt.figure( 3 ) +plt.subplot(231) +plt.plot(fft0[0:255], 'b') +plt.subplot(232) +plt.plot(fft1[0:255], 'g') +plt.subplot(233) +plt.plot(fft2[0:255], 'r') +plt.subplot(234) +plt.plot(fft3[0:255], 'c') +plt.subplot(235) +plt.plot(fft4[0:255], 'm') + +plt.figure( 4 ) +plt.subplot(231) +plt.plot(fft0_b[0:255], 'b') +plt.subplot(232) +plt.plot(fft1_b[0:255], 'g') +plt.subplot(233) +plt.plot(fft2_b[0:255], 'r') +plt.subplot(234) +plt.plot(fft3_b[0:255], 'c') +plt.subplot(235) +plt.plot(fft4_b[0:255], 'm') + +plt.show() \ No newline at end of file diff --git a/test_fft/test_fft_sm.py b/test_fft/test_fft_sm.py new file mode 100644 --- /dev/null +++ b/test_fft/test_fft_sm.py @@ -0,0 +1,193 @@ +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() \ No newline at end of file diff --git a/test_fft/test_sm_functions.py b/test_fft/test_sm_functions.py deleted file mode 100644 --- a/test_fft/test_sm_functions.py +++ /dev/null @@ -1,128 +0,0 @@ -import numpy as np - -from test_fft.register_addresses_fft_test import * - -from __main__ import RMAPPlugin0 - -def print_custom( value ): - print value - RMAPPlugin0.ProcessPendingEvents() - -def read_SM_Re( nbFrequencyBins, address_MEM_OUT_SM ): - currentComp_re = np.zeros( nbFrequencyBins ) - if address_MEM_OUT_SM == address_MEM_OUT_SM_0: - mask_REN = mask_REN_FIFO_0 - elif address_MEM_OUT_SM == address_MEM_OUT_SM_1: - mask_REN = mask_REN_FIFO_1 - else: - print_custom( "ERR *** read_SM_Re *** unexpected address_MEM_OUT_SM" ) - for frequencyBin in range(nbFrequencyBins): - # read Re - RMAPPlugin0.Write( address_CTRL_SM, [mask_REN] ) - val = RMAPPlugin0.Read( address_MEM_OUT_SM, 1) - currentComp_re[frequencyBin] = val[0] - RMAPPlugin0.ProcessPendingEvents() - return currentComp_re - -def read_SM_Re_Im( nbFrequencyBins, address_MEM_OUT_SM ): - currentComp_re = np.zeros( nbFrequencyBins ) - currentComp_im = np.zeros( nbFrequencyBins ) - if address_MEM_OUT_SM == address_MEM_OUT_SM_0: - mask_REN = mask_REN_FIFO_0 - elif address_MEM_OUT_SM == address_MEM_OUT_SM_1: - mask_REN = mask_REN_FIFO_1 - else: - print_custom( "ERR *** read_SM_Re_Im *** unexpected address_MEM_OUT_SM" ) - for frequencyBin in range(nbFrequencyBins): - # read Re - RMAPPlugin0.Write( address_CTRL_SM, [mask_REN] ) - val = RMAPPlugin0.Read( address_MEM_OUT_SM, 1) - currentComp_re[frequencyBin] = val[0] - # read Im - RMAPPlugin0.Write( address_CTRL_SM, [mask_REN] ) - val = RMAPPlugin0.Read( address_MEM_OUT_SM, 1) - currentComp_im[frequencyBin] = val[0] - RMAPPlugin0.ProcessPendingEvents() - return (currentComp_re, currentComp_im) - -def is_MEM_OUT_SM_Empty( ): - ret = 0 - sm_reg = RMAPPlugin0.Read( address_CTRL_SM, 1) - MEM_OUT_SM_Empty = (sm_reg[0] & 0x00000030) >> 4 - if MEM_OUT_SM_Empty == 0x3: - ret = 1 - return ret - -def is_MEM_OUT_SM_Full( ): - ret = 0 - sm_reg = RMAPPlugin0.Read( address_CTRL_SM, 1) - MEM_OUT_SM_Full = (sm_reg[0] & 0x0000000c) >> 2 - if MEM_OUT_SM_Full != 0x0: - ret = 1 - return ret - -def is_MEM_OUT_SM_Full_FIFO_0( ): - ret = 0 - sm_reg = RMAPPlugin0.Read( address_CTRL_SM, 1) - MEM_OUT_SM_Full = (sm_reg[0] & 0x00000004) >> 2 - if MEM_OUT_SM_Full == 0x01: - ret = 1 - return ret - -def is_MEM_OUT_SM_Full_FIFO_1( ): - ret = 0 - sm_reg = RMAPPlugin0.Read( address_CTRL_SM, 1) - MEM_OUT_SM_Full = (sm_reg[0] & 0x00000008) >> 3 - if MEM_OUT_SM_Full == 0x01: - ret = 1 - return ret - -def wait_for_FIFO_0_Full(): - counter = 0 - while ( is_MEM_OUT_SM_Full_FIFO_0() == 0 ): - print_custom( "FIFO_0 not full " + str(counter) ) - counter = counter + 1 - if counter == 10: - break - -def wait_for_FIFO_1_Full(): - counter = 0 - while ( is_MEM_OUT_SM_Full_FIFO_1() == 0 ): - print_custom( "FIFO_1 not full " + str(counter)) - counter = counter + 1 - if counter == 10: - break - -def wait_for_FIFO_Full( fifo ): - if fifo == 0: - wait_for_FIFO_0_Full() - elif fifo == 1: - wait_for_FIFO_1_Full() - else: - print_custom( "ERR *** wait_for_FIFO_Full *** unexpted value for parameter [fifo]" ) - -def wait_for_FIFO_0_or_1_Full(): - counter = 0 - sm_reg = RMAPPlugin0.Read( address_CTRL_SM, 1) - MEM_OUT_SM_Full = (sm_reg[0] & 0x0000000c) >> 2 - while ( MEM_OUT_SM_Full == 0 ): - print_custom( "FIFO 0 or 1 not full " + str(counter)) - counter = counter + 1 - if counter == 10: - break - sm_reg = RMAPPlugin0.Read( address_CTRL_SM, 1) - MEM_OUT_SM_Full = (sm_reg[0] & 0x0000000c) >> 2 - RMAPPlugin0.ProcessPendingEvents() - -def print_reg_sm( ): - sm_reg = RMAPPlugin0.Read( address_CTRL_SM, 1) - out_ren = (sm_reg[0] & 0x00000003) - MEM_OUT_SM_Full = (sm_reg[0] & 0x0000000c) >> 2 - MEM_OUT_SM_Empty = (sm_reg[0] & 0x00000030) >> 4 - MEM_OUT_SM_Full_s= (sm_reg[0] & 0x00000040) >> 6 - print "sm_reg = " + bin( sm_reg[0] & 0x7f ) \ - + ", out_ren = " + bin( out_ren ) \ - + ", MEM_OUT_SM_Full = " + bin( MEM_OUT_SM_Full ) \ - + ", MEM_OUT_SM_Empty = " + bin( MEM_OUT_SM_Empty ) \ - + ", MEM_OUT_SM_Full_s = " + bin( MEM_OUT_SM_Full_s ) - RMAPPlugin0.ProcessPendingEvents() \ No newline at end of file diff --git a/test_fft/test_sm_mini_lfr.py b/test_fft/test_sm_mini_lfr.py deleted file mode 100644 --- a/test_fft/test_sm_mini_lfr.py +++ /dev/null @@ -1,190 +0,0 @@ -import os -os.system('clear') # on linux / os x - -import numpy as np -import matplotlib.pyplot as plt - -from test_fft.register_addresses_fft_test import * -from test_fft.fft_test_functions import * -from test_fft.test_sm_functions import * - -print_custom( '*' ) -print_custom( '*' ) -print_custom( '*' ) -print_custom( '*' ) -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 = sineWave( 256, 10, 1000 ) -wfrm1 = sineWave( 256, 10, 1000 ) -wfrm2 = sineWave( 256, 20, 1000 ) -wfrm3 = sineWave( 256, 20, 1000 ) -wfrm4 = sineWave( 256, 50, 1000 ) - -################ -# BUILD THE DATA -dataToWrite0 = generateDataToWrite( nbSamples, wfrm0, wfrm1 ) -dataToWrite1 = generateDataToWrite( nbSamples, wfrm2, wfrm3 ) -dataToWrite2 = generateDataToWrite( nbSamples, wfrm4, np.zeros( nbSamples ) ) - -######################## -# WRITE WAVEFORM IN FIFO -print_custom( "1) write waveforms in FIFOs: " + str(len(dataToWrite0)) + " samples" ) -print_reg_sm( ) - -for k in range(nbSamples): - RMAPPlugin0.Write( address_FIFO_F2_1_0, [dataToWrite0[k]] ) - RMAPPlugin0.Write( address_FIFO_F2_3_2, [dataToWrite1[k]] ) - RMAPPlugin0.Write( address_FIFO_F2_4, [dataToWrite2[k]] ) - # write only the FIFO F2 - RMAPPlugin0.Write( address_FIFO_F2_WEN, [0xffffffe0] ) - -print_custom( "1) data written in FIFOs" ) - -################ -# SM FIRST READ -print_custom( "======= SM FIRST READ" ) - -components = [] - -wait_for_FIFO_0_or_1_Full() - -if is_MEM_OUT_SM_Full_FIFO_0( ): - address_MEM_OUT_SM = address_MEM_OUT_SM_1 - fifo_to_wait_for = 0 -elif is_MEM_OUT_SM_Full_FIFO_1( ): - address_MEM_OUT_SM = address_MEM_OUT_SM_0 - fifo_to_wait_for = 1 - -for component in range(nbComponentsPerMatrix): - print_custom( "==== component = " + str( component ) - + ", read @" + hex(address_MEM_OUT_SM & 0xffffffff) ) - print_reg_sm( ) - currentComp_re = np.zeros( nbFrequencyBins ) - currentComp_im = np.zeros( nbFrequencyBins ) - if (component == 0) | (component == 12): - wait_for_FIFO_Full( fifo_to_wait_for ) - currentComp_re = read_SM_Re( nbFrequencyBins, address_MEM_OUT_SM ) - components.append( currentComp_re ) - elif (component == 5) | (component == 9): - wait_for_FIFO_Full( fifo_to_wait_for ) - currentComp_re = read_SM_Re( nbFrequencyBins, address_MEM_OUT_SM ) - components.append( currentComp_re ) - elif (component == 1) | (component == 3) | (component == 7): - currentComp_re, currentComp_im = read_SM_Re_Im( nbFrequencyBins, address_MEM_OUT_SM ) - components.append( currentComp_re ) - components.append( currentComp_im ) - wait_for_FIFO_Full( fifo_to_wait_for ) - elif (component == 2) | (component == 6) | (component == 10): - currentComp_re, currentComp_im = read_SM_Re_Im( nbFrequencyBins, address_MEM_OUT_SM ) - components.append( currentComp_re ) - components.append( currentComp_im ) - wait_for_FIFO_Full( fifo_to_wait_for ) - elif (component == 4) | (component == 8): - currentComp_re, currentComp_im = 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 = read_SM_Re_Im( nbFrequencyBins, address_MEM_OUT_SM ) - components.append( currentComp_re ) - components.append( currentComp_im ) - elif (component == 14): - currentComp_re = read_SM_Re( nbFrequencyBins, address_MEM_OUT_SM ) - components.append( currentComp_re ) - else: - print_custom( "unexpected value for component" ) - # change FIFO - if address_MEM_OUT_SM == address_MEM_OUT_SM_0: - address_MEM_OUT_SM = address_MEM_OUT_SM_1 - fifo_to_wait_for = 0 - elif address_MEM_OUT_SM == address_MEM_OUT_SM_1: - address_MEM_OUT_SM = address_MEM_OUT_SM_0 - fifo_to_wait_for = 1 - -print_custom( "======= READ COMPLETE" ) - -print_reg_sm( ) - -# 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() \ No newline at end of file diff --git a/test_fft/test_sm_only.py b/test_fft/test_sm_only.py new file mode 100644 --- /dev/null +++ b/test_fft/test_sm_only.py @@ -0,0 +1,218 @@ +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( '*' ) + +############ +# BUILD DATA +nbSamples = 256 +nbComponentsPerMatrix = 15 +nbFrequencyBins = 128 +re_0 = dtgn.sineWave( nbFrequencyBins, 10, 10 ) +im_0 = dtgn.sineWave( nbFrequencyBins, 10, 10 ) +dataToWrite_0 = dtgn.generateDataToWrite( nbFrequencyBins, re_0, im_0 ) +re_1 = dtgn.sineWave( nbFrequencyBins, 10, 20 ) +im_1 = dtgn.sineWave( nbFrequencyBins, 10, 20 ) +dataToWrite_1 = dtgn.generateDataToWrite( nbFrequencyBins, re_1, im_1 ) +re_2 = dtgn.sineWave( nbFrequencyBins, 10, 30 ) +im_2 = dtgn.sineWave( nbFrequencyBins, 10, 30 ) +dataToWrite_2 = dtgn.generateDataToWrite( nbFrequencyBins, re_2, im_2 ) +re_3 = dtgn.sineWave( nbFrequencyBins, 10, 40 ) +im_3 = dtgn.sineWave( nbFrequencyBins, 10, 40 ) +dataToWrite_3 = dtgn.generateDataToWrite( nbFrequencyBins, re_3, im_3 ) +re_4 = dtgn.sineWave( nbFrequencyBins, 10, 50 ) +im_4 = dtgn.sineWave( nbFrequencyBins, 10, 50 ) +dataToWrite_4 = dtgn.generateDataToWrite( nbFrequencyBins, re_4, im_4 ) + +re_0 = dtgn.step( nbFrequencyBins, 10 ) +im_0 = dtgn.continuous( nbFrequencyBins, 10 ) +dataToWrite_0 = dtgn.generateDataToWrite( nbFrequencyBins, re_0, im_0 ) +re_1 = dtgn.step( nbFrequencyBins, 20 ) +im_1 = dtgn.continuous( nbFrequencyBins, 20 ) +dataToWrite_1 = dtgn.generateDataToWrite( nbFrequencyBins, re_1, im_1 ) +re_2 = dtgn.step( nbFrequencyBins, 30 ) +im_2 = dtgn.continuous( nbFrequencyBins, 30 ) +dataToWrite_2 = dtgn.generateDataToWrite( nbFrequencyBins, re_2, im_2 ) +re_3 = dtgn.step( nbFrequencyBins, 40 ) +im_3 = dtgn.continuous( nbFrequencyBins, 40 ) +dataToWrite_3 = dtgn.generateDataToWrite( nbFrequencyBins, re_3, im_3 ) +re_4 = dtgn.step( nbFrequencyBins, 50 ) +im_4 = dtgn.continuous( nbFrequencyBins, 50 ) +dataToWrite_4 = dtgn.generateDataToWrite( nbFrequencyBins, re_4, im_4 ) + +diracPosition = 60 +re_0 = dtgn.dirac( nbFrequencyBins, 10, diracPosition ) +im_0 = dtgn.dirac( nbFrequencyBins, 10, diracPosition ) +dataToWrite_0 = dtgn.generateDataToWrite( nbFrequencyBins, re_0, im_0 ) +re_1 = dtgn.dirac( nbFrequencyBins, 20, diracPosition ) +im_1 = dtgn.dirac( nbFrequencyBins, 20, diracPosition ) +dataToWrite_1 = dtgn.generateDataToWrite( nbFrequencyBins, re_1, im_1 ) +re_2 = dtgn.dirac( nbFrequencyBins, 30, diracPosition ) +im_2 = dtgn.dirac( nbFrequencyBins, 30, diracPosition ) +dataToWrite_2 = dtgn.generateDataToWrite( nbFrequencyBins, re_2, im_2 ) +re_3 = dtgn.dirac( nbFrequencyBins, 40, diracPosition ) +im_3 = dtgn.dirac( nbFrequencyBins, 40, diracPosition ) +dataToWrite_3 = dtgn.generateDataToWrite( nbFrequencyBins, re_3, im_3 ) +re_4 = dtgn.dirac( nbFrequencyBins, 50, diracPosition ) +im_4 = dtgn.dirac( nbFrequencyBins, 50, diracPosition ) +dataToWrite_4 = dtgn.generateDataToWrite( nbFrequencyBins, re_4, im_4 ) + +######################## +# WRITE WAVEFORM IN FIFO +prnt.print_reg_sm_only_MEM_IN_CTRL( SM_ONLY_MEM_IN_SM_CTRL ) +prnt.print_reg_sm_only_MEM_OUT_CTRL( SM_ONLY_MEM_OUT_CTRL ) +prnt.print_custom( "1) write data in SM_MEM_IN: " + str(len(dataToWrite_0)) + " bins" ) + +for k in range(nbFrequencyBins): + RMAPPlugin0.Write( SM_ONLY_MEM_IN_SM_0, [dataToWrite_0[k]] ) + RMAPPlugin0.Write( SM_ONLY_MEM_IN_SM_1, [dataToWrite_1[k]] ) + RMAPPlugin0.Write( SM_ONLY_MEM_IN_SM_2, [dataToWrite_2[k]] ) + RMAPPlugin0.Write( SM_ONLY_MEM_IN_SM_3, [dataToWrite_3[k]] ) + RMAPPlugin0.Write( SM_ONLY_MEM_IN_SM_4, [dataToWrite_4[k]] ) + RMAPPlugin0.Write( SM_ONLY_MEM_IN_SM_CTRL, [0xffffffe0] ) + +prnt.print_custom( "1) data written in SM_MEM_IN" ) +prnt.print_reg_sm_only_MEM_IN_CTRL( SM_ONLY_MEM_IN_SM_CTRL ) +prnt.print_reg_sm_only_MEM_OUT_CTRL( SM_ONLY_MEM_OUT_CTRL ) + +################ +# SM FIRST READ +prnt.print_custom( "======= SM FIRST READ" ) + +components = [] + +flg.wait_for_FIFO_0_or_1_Full( SM_ONLY_MEM_OUT_CTRL ) + +if flg.is_MEM_OUT_SM_Full_FIFO_0( SM_ONLY_MEM_OUT_CTRL ): + address_MEM_OUT_SM = SM_ONLY_MEM_OUT_SM_1 + fifo_to_wait_for = 0 +elif flg.is_MEM_OUT_SM_Full_FIFO_1( SM_ONLY_MEM_OUT_CTRL ): + address_MEM_OUT_SM = SM_ONLY_MEM_OUT_SM_0 + fifo_to_wait_for = 1 +else: + prnt.print_custom("oups, FIFO_0 and FIFO_1 are not full, this is unexpected") + +for component in range(nbComponentsPerMatrix): + prnt.print_custom( "==== component = " + str( component ) + + ", read @ " + hex(address_MEM_OUT_SM & 0xffffffff) ) + prnt.print_reg_sm_only_MEM_IN_CTRL( SM_ONLY_MEM_IN_SM_CTRL ) + prnt.print_reg_sm_only_MEM_OUT_CTRL( SM_ONLY_MEM_OUT_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, SM_ONLY_MEM_OUT_CTRL ) + currentComp_re = rdata.read_SM_ONLY_Re( nbFrequencyBins, address_MEM_OUT_SM ) + components.append( currentComp_re ) + elif (component == 5) | (component == 9): + flg.wait_for_FIFO_Full( fifo_to_wait_for, SM_ONLY_MEM_OUT_CTRL ) + currentComp_re = rdata.read_SM_ONLY_Re( nbFrequencyBins, address_MEM_OUT_SM ) + components.append( currentComp_re ) + elif (component == 1) | (component == 3) | (component == 7): + currentComp_re, currentComp_im = rdata.read_SM_ONLY_Re_Im( nbFrequencyBins, address_MEM_OUT_SM ) + components.append( currentComp_re ) + components.append( currentComp_im ) + flg.wait_for_FIFO_Full( fifo_to_wait_for, SM_ONLY_MEM_OUT_CTRL ) + elif (component == 2) | (component == 6) | (component == 10): + currentComp_re, currentComp_im = rdata.read_SM_ONLY_Re_Im( nbFrequencyBins, address_MEM_OUT_SM ) + components.append( currentComp_re ) + components.append( currentComp_im ) + flg.wait_for_FIFO_Full( fifo_to_wait_for, SM_ONLY_MEM_OUT_CTRL ) + elif (component == 4) | (component == 8): + currentComp_re, currentComp_im = rdata.read_SM_ONLY_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_ONLY_Re_Im( nbFrequencyBins, address_MEM_OUT_SM ) + components.append( currentComp_re ) + components.append( currentComp_im ) + elif (component == 14): + currentComp_re = rdata.read_SM_ONLY_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 == SM_ONLY_MEM_OUT_SM_0: + address_MEM_OUT_SM = SM_ONLY_MEM_OUT_SM_1 + fifo_to_wait_for = 0 + elif address_MEM_OUT_SM == SM_ONLY_MEM_OUT_SM_1: + address_MEM_OUT_SM = SM_ONLY_MEM_OUT_SM_0 + fifo_to_wait_for = 1 + +prnt.print_custom( "======= READ COMPLETE" ) + +prnt.print_reg_sm_only_MEM_IN_CTRL( SM_ONLY_MEM_IN_SM_CTRL ) +prnt.print_reg_sm_only_MEM_OUT_CTRL( SM_ONLY_MEM_OUT_CTRL ) + +# PLOT SM + +plt.figure( 1 ) +plt.subplot(231) +plt.plot(re_0, 'b') +plt.subplot(232) +plt.plot(re_1, 'g') +plt.plot(re_1, '.') +plt.subplot(233) +plt.plot(re_2, 'r') +plt.plot(re_2, '.') +plt.subplot(234) +plt.plot(re_3, 'c') +plt.subplot(235) +plt.plot(re_4, '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() \ No newline at end of file