112855Sgabeblack@google.com/***************************************************************************** 212855Sgabeblack@google.com 312855Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412855Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 512855Sgabeblack@google.com with this work for additional information regarding copyright ownership. 612855Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 712855Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 812855Sgabeblack@google.com License. You may obtain a copy of the License at 912855Sgabeblack@google.com 1012855Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1112855Sgabeblack@google.com 1212855Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1312855Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1412855Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512855Sgabeblack@google.com implied. See the License for the specific language governing 1612855Sgabeblack@google.com permissions and limitations under the License. 1712855Sgabeblack@google.com 1812855Sgabeblack@google.com *****************************************************************************/ 1912855Sgabeblack@google.com 2012855Sgabeblack@google.com/***************************************************************************** 2112855Sgabeblack@google.com 2212855Sgabeblack@google.com tb.h -- 2312855Sgabeblack@google.com 2412855Sgabeblack@google.com Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 2512855Sgabeblack@google.com 2612855Sgabeblack@google.com *****************************************************************************/ 2712855Sgabeblack@google.com 2812855Sgabeblack@google.com/***************************************************************************** 2912855Sgabeblack@google.com 3012855Sgabeblack@google.com MODIFICATION LOG - modifiers, enter your name, affiliation, date and 3112855Sgabeblack@google.com changes you are making here. 3212855Sgabeblack@google.com 3312855Sgabeblack@google.com Name, Affiliation, Date: 3412855Sgabeblack@google.com Description of Modification: 3512855Sgabeblack@google.com 3612855Sgabeblack@google.com *****************************************************************************/ 3712855Sgabeblack@google.com 3812855Sgabeblack@google.com#include "common.h" 3912855Sgabeblack@google.com 4012855Sgabeblack@google.comSC_MODULE( testbench ) 4112855Sgabeblack@google.com{ 4212855Sgabeblack@google.com SC_HAS_PROCESS( testbench ); 4312855Sgabeblack@google.com 4412855Sgabeblack@google.com sc_in_clk clk; 4512855Sgabeblack@google.com 4612855Sgabeblack@google.com sc_out<bool> reset; 4712855Sgabeblack@google.com sc_out<bool> x_ok; 4812855Sgabeblack@google.com sc_out<bool> y_ok; 4912855Sgabeblack@google.com sc_in<bool> data_ready; 5012855Sgabeblack@google.com sc_in<bool> select_xy; 5112855Sgabeblack@google.com sc_in<bool_vector> coord_xy; 5212855Sgabeblack@google.com 5312855Sgabeblack@google.com void entry(); 5412855Sgabeblack@google.com 5512855Sgabeblack@google.com testbench( sc_module_name name_, 5612855Sgabeblack@google.com const sc_clock& clk_, 5712855Sgabeblack@google.com sc_signal<bool>& reset_, 5812855Sgabeblack@google.com sc_signal<bool>& x_ok_, 5912855Sgabeblack@google.com sc_signal<bool>& y_ok_, 6012855Sgabeblack@google.com const sc_signal<bool>& data_ready_, 6112855Sgabeblack@google.com const sc_signal<bool>& select_xy_, 6212855Sgabeblack@google.com const signal_bool_vector& coord_xy_ ) 6312855Sgabeblack@google.com : sc_module( name_ ) 6412855Sgabeblack@google.com { 6512855Sgabeblack@google.com clk( clk_ ); 6612855Sgabeblack@google.com reset( reset_ ); 6712855Sgabeblack@google.com x_ok( x_ok_ ); 6812855Sgabeblack@google.com y_ok( y_ok_ ); 6912855Sgabeblack@google.com data_ready( data_ready_ ); 7012855Sgabeblack@google.com select_xy( select_xy_ ); 7112855Sgabeblack@google.com coord_xy( coord_xy_ ); 7212855Sgabeblack@google.com SC_CTHREAD( entry, clk.neg() ); 7312855Sgabeblack@google.com } 7412855Sgabeblack@google.com}; 7512855Sgabeblack@google.com 7612855Sgabeblack@google.comsc_bv<16> mem[17]; 7712855Sgabeblack@google.com 7812855Sgabeblack@google.comvoid 7912855Sgabeblack@google.comtestbench::entry() 8012855Sgabeblack@google.com{ 8112855Sgabeblack@google.com bool_vector x_coord; 8212855Sgabeblack@google.com bool_vector y_coord; 8312855Sgabeblack@google.com int x_flag = 0; 8412855Sgabeblack@google.com int y_flag = 0; 8512855Sgabeblack@google.com int i; // Counter variable 8612855Sgabeblack@google.com int x = 0; // Memory location of x_coord 8712855Sgabeblack@google.com int y = 1; // Memory location of y_coord 8812855Sgabeblack@google.com 8912855Sgabeblack@google.com // reset initialization 9012855Sgabeblack@google.com 9112855Sgabeblack@google.com reset.write(1); 9212855Sgabeblack@google.com x_ok.write(0); 9312855Sgabeblack@google.com y_ok.write(0); 9412855Sgabeblack@google.com wait(); 9512855Sgabeblack@google.com reset.write(0); 9612855Sgabeblack@google.com wait(); 9712855Sgabeblack@google.com 9812855Sgabeblack@google.com // fill display memory with zeros 9912855Sgabeblack@google.com 10012855Sgabeblack@google.com for (i = 1; i < 17; i++) 10112855Sgabeblack@google.com mem[i] = 0; 10212855Sgabeblack@google.com 10312855Sgabeblack@google.com // capture of (x,y) coordinates 10412855Sgabeblack@google.com 10512855Sgabeblack@google.com while(true) { 10612855Sgabeblack@google.com 10712855Sgabeblack@google.com // wait for new x or y coordinate to be calculated 10812855Sgabeblack@google.com 10912855Sgabeblack@google.com do { wait(); } while (data_ready == 0); 11012855Sgabeblack@google.com 11112855Sgabeblack@google.com // capture x coordinate 11212855Sgabeblack@google.com 11312855Sgabeblack@google.com if(select_xy.read() == 0) { 11412855Sgabeblack@google.com x_coord = coord_xy.read(); 11512855Sgabeblack@google.com x_flag = x_flag + 1; 11612855Sgabeblack@google.com x_ok.write(1); 11712855Sgabeblack@google.com } 11812855Sgabeblack@google.com 11912855Sgabeblack@google.com // capture y coordinate 12012855Sgabeblack@google.com 12112855Sgabeblack@google.com if(select_xy.read() == 1) { 12212855Sgabeblack@google.com y_coord = coord_xy.read(); 12312855Sgabeblack@google.com y_flag = y_flag + 1; 12412855Sgabeblack@google.com y_ok.write(1); 12512855Sgabeblack@google.com } 12612855Sgabeblack@google.com 12712855Sgabeblack@google.com wait(); 12812855Sgabeblack@google.com x_ok.write(0); 12912855Sgabeblack@google.com y_ok.write(0); 13012855Sgabeblack@google.com 13112855Sgabeblack@google.com // debug display of coordinate sets 13212855Sgabeblack@google.com /* 13312855Sgabeblack@google.com if (x_flag == y_flag) { 13412855Sgabeblack@google.com cout << " Coordinate Set #" << x_flag 13512855Sgabeblack@google.com << " X = " << x_coord.to_int() 13612855Sgabeblack@google.com << " Y = " << y_coord.to_int() 13712855Sgabeblack@google.com << endl; 13812855Sgabeblack@google.com } 13912855Sgabeblack@google.com */ 14012855Sgabeblack@google.com 14112855Sgabeblack@google.com // conversion of x coordinate values to memory column locations 14212855Sgabeblack@google.com 14312855Sgabeblack@google.com if (x_coord.to_int() == -8) x = 15; 14412855Sgabeblack@google.com if (x_coord.to_int() == -7) x = 14; 14512855Sgabeblack@google.com if (x_coord.to_int() == -6) x = 13; 14612855Sgabeblack@google.com if (x_coord.to_int() == -5) x = 12; 14712855Sgabeblack@google.com if (x_coord.to_int() == -4) x = 11; 14812855Sgabeblack@google.com if (x_coord.to_int() == -3) x = 10; 14912855Sgabeblack@google.com if (x_coord.to_int() == -2) x = 9; 15012855Sgabeblack@google.com if (x_coord.to_int() == -1) x = 8; 15112855Sgabeblack@google.com if (x_coord.to_int() == 0) x = 7; 15212855Sgabeblack@google.com if (x_coord.to_int() == 1) x = 6; 15312855Sgabeblack@google.com if (x_coord.to_int() == 2) x = 5; 15412855Sgabeblack@google.com if (x_coord.to_int() == 3) x = 4; 15512855Sgabeblack@google.com if (x_coord.to_int() == 4) x = 3; 15612855Sgabeblack@google.com if (x_coord.to_int() == 5) x = 2; 15712855Sgabeblack@google.com if (x_coord.to_int() == 6) x = 1; 15812855Sgabeblack@google.com if (x_coord.to_int() == 7) x = 0; 15912855Sgabeblack@google.com 16012855Sgabeblack@google.com // conversion of y coordinate values to memory row locations 16112855Sgabeblack@google.com 16212855Sgabeblack@google.com if (y_coord.to_int() == -8) y = 16; 16312855Sgabeblack@google.com if (y_coord.to_int() == -7) y = 15; 16412855Sgabeblack@google.com if (y_coord.to_int() == -6) y = 14; 16512855Sgabeblack@google.com if (y_coord.to_int() == -5) y = 13; 16612855Sgabeblack@google.com if (y_coord.to_int() == -4) y = 12; 16712855Sgabeblack@google.com if (y_coord.to_int() == -3) y = 11; 16812855Sgabeblack@google.com if (y_coord.to_int() == -2) y = 10; 16912855Sgabeblack@google.com if (y_coord.to_int() == -1) y = 9; 17012855Sgabeblack@google.com if (y_coord.to_int() == 0) y = 8; 17112855Sgabeblack@google.com if (y_coord.to_int() == 1) y = 7; 17212855Sgabeblack@google.com if (y_coord.to_int() == 2) y = 6; 17312855Sgabeblack@google.com if (y_coord.to_int() == 3) y = 5; 17412855Sgabeblack@google.com if (y_coord.to_int() == 4) y = 4; 17512855Sgabeblack@google.com if (y_coord.to_int() == 5) y = 3; 17612855Sgabeblack@google.com if (y_coord.to_int() == 6) y = 2; 17712855Sgabeblack@google.com if (y_coord.to_int() == 7) y = 1; 17812855Sgabeblack@google.com 17912855Sgabeblack@google.com // turn bit high in memory for calculated coordinate 18012855Sgabeblack@google.com 18112855Sgabeblack@google.com mem[y][x] = 1; 18212855Sgabeblack@google.com 18312855Sgabeblack@google.com // stop simulation after 100 coordinates 18412855Sgabeblack@google.com 18512855Sgabeblack@google.com if (y_flag == 100) break; 18612855Sgabeblack@google.com 18712855Sgabeblack@google.com } // End of while loop 18812855Sgabeblack@google.com 18912855Sgabeblack@google.com cout << "\n\t FINAL MEMORY VALUES" << endl; 19012855Sgabeblack@google.com 19112855Sgabeblack@google.com for (i = 1; i < 17; i++) 19212855Sgabeblack@google.com cout << "Memory Location " << i 19312855Sgabeblack@google.com << " : \t" << mem[i] << endl; 19412855Sgabeblack@google.com 19512855Sgabeblack@google.com sc_stop(); 19612855Sgabeblack@google.com} 197