Skip to content
Snippets Groups Projects
Commit 8008ef14 authored by Reinier van der Walle's avatar Reinier van der Walle
Browse files

initial commit

parent 28989cf2
No related branches found
No related tags found
No related merge requests found
#! /usr/bin/env python
###############################################################################
#
# Copyright (C) 2012
# ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
"""Test case for the bf_unit entity.
Description:
This testcase is used in conjunction with the tb_bf_unit.vhd file.
Generics for the VHDL testbench are passed to modelsim to configure the
current simulation.
To observe the VHDL signals in the wave window modelsim needs to be
started manually and then c_start_modelsim must be set to 0 and the generics
also must be set manually.
NOTE: Use c_write_bg, c_write_bf_weights and c_write_bf_ss_wide to en- or disable
the time-consuming writes to the mm-interface. WHen disabled, be sure to
have the according .hex files in place. The .hex files can be generated
with the bf_unit.py script.
BEWARE: If the hex files change due to different script settings, then it is
necessary to run the script again to ensure that Modelsim starts with the
latest hex files.
Usage:
> python tc_bf_unit.py --unb 0 --fn 0 --sim
"""
###############################################################################
# System imports
import test_case
import node_io
import sys
import pi_diag_data_buffer
import pi_stagiair_wave_gen
from tools import *
from common import *
import csv
import cmath
###############################################################################
# Debug control
c_debug_print = False
# Create a test case object
tc = test_case.Testcase('TB - ', '')
tc.append_log(3, '>>>')
tc.append_log(1, '>>> Title : Test bench for wave_gen' )
tc.append_log(3, '>>>')
tc.append_log(3, '')
tc.set_result('PASSED')
###############################################################################
c_size = 2048
c_filename = 'values.csv'
# Create access object for nodes
io = node_io.NodeIO(tc.nodeImages, tc.base_ip)
# Create databuffer instances
db = pi_diag_data_buffer.PiDiagDataBuffer(tc, io, instanceName = '', nofStreams=1, ramSizePerStream=c_size)
wg = pi_stagiair_wave_gen.PiWaveGen(tc, io, nof_inst=1)
def listToCsv(fileName = 'default.csv', overwrite = False, value_list = []):
header = None
if overwrite:
ofile = open(fileName, "w")
header = ['real', 'imag', 'abs', 'phase']
else:
ofile = open(fileName, "a")
writer = csv.writer(ofile, delimiter=',', quoting=csv.QUOTE_NONE)
if not header == None:
writer.writerow(header)
for value in value_list:
if type(value) == complex:
row_list = [value.real, value.imag, abs(value), cmath.phase(value)]
else:
row_list = [value]
writer.writerow(row_list)
if __name__ == "__main__":
wg.write(registers=[('gain_sel', 16)])
wg.write(registers=[('wave_sel', 0)])
wg.write(registers=[('enable', 1)])
do_until_ge(db.read_nof_words, ms_retry=1000, val=c_size, s_timeout=3600)
wg.write(registers=[('enable', 0)])
val_list = flatten(db.read_data_buffer(streamNr=0, n=c_size, radix='dec', width=8, nofColumns=1))
listToCsv(fileName = c_filename, overwrite = True, value_list = val_list)
for i in range(1,5):
wg.write(registers=[('wave_sel', i)])
wg.write(registers=[('enable', 1)])
do_until_ge(db.read_nof_words, ms_retry=1000, val=c_size, s_timeout=3600)
wg.write(registers=[('enable', 0)])
val_list = flatten(db.read_data_buffer(streamNr=0, n=c_size, radix='dec', width=8, nofColumns=1))
listToCsv(fileName = c_filename, overwrite = False, value_list = val_list)
###############################################################################
# End
tc.set_section_id('')
tc.append_log(3, '')
tc.append_log(3, '>>>')
tc.append_log(0, '>>> Test bench result: %s' % tc.get_result())
tc.append_log(3, '>>>')
sys.exit(tc.get_result())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment