tb.h revision 12855:588919e0e4aa
1/***************************************************************************** 2 3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 4 more contributor license agreements. See the NOTICE file distributed 5 with this work for additional information regarding copyright ownership. 6 Accellera licenses this file to you under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with the 8 License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 implied. See the License for the specific language governing 16 permissions and limitations under the License. 17 18 *****************************************************************************/ 19 20/***************************************************************************** 21 22 tb.h -- 23 24 Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 25 26 *****************************************************************************/ 27 28/***************************************************************************** 29 30 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 31 changes you are making here. 32 33 Name, Affiliation, Date: 34 Description of Modification: 35 36 *****************************************************************************/ 37 38#include "common.h" 39 40SC_MODULE( testbench ) 41{ 42 SC_HAS_PROCESS( testbench ); 43 44 sc_in_clk clk; 45 46 sc_out<bool> reset; 47 sc_out<bool> x_ok; 48 sc_out<bool> y_ok; 49 sc_in<bool> data_ready; 50 sc_in<bool> select_xy; 51 sc_in<bool_vector> coord_xy; 52 53 void entry(); 54 55 testbench( sc_module_name name_, 56 const sc_clock& clk_, 57 sc_signal<bool>& reset_, 58 sc_signal<bool>& x_ok_, 59 sc_signal<bool>& y_ok_, 60 const sc_signal<bool>& data_ready_, 61 const sc_signal<bool>& select_xy_, 62 const signal_bool_vector& coord_xy_ ) 63 : sc_module( name_ ) 64 { 65 clk( clk_ ); 66 reset( reset_ ); 67 x_ok( x_ok_ ); 68 y_ok( y_ok_ ); 69 data_ready( data_ready_ ); 70 select_xy( select_xy_ ); 71 coord_xy( coord_xy_ ); 72 SC_CTHREAD( entry, clk.neg() ); 73 } 74}; 75 76sc_bv<16> mem[17]; 77 78void 79testbench::entry() 80{ 81 bool_vector x_coord; 82 bool_vector y_coord; 83 int x_flag = 0; 84 int y_flag = 0; 85 int i; // Counter variable 86 int x = 0; // Memory location of x_coord 87 int y = 1; // Memory location of y_coord 88 89 // reset initialization 90 91 reset.write(1); 92 x_ok.write(0); 93 y_ok.write(0); 94 wait(); 95 reset.write(0); 96 wait(); 97 98 // fill display memory with zeros 99 100 for (i = 1; i < 17; i++) 101 mem[i] = 0; 102 103 // capture of (x,y) coordinates 104 105 while(true) { 106 107 // wait for new x or y coordinate to be calculated 108 109 do { wait(); } while (data_ready == 0); 110 111 // capture x coordinate 112 113 if(select_xy.read() == 0) { 114 x_coord = coord_xy.read(); 115 x_flag = x_flag + 1; 116 x_ok.write(1); 117 } 118 119 // capture y coordinate 120 121 if(select_xy.read() == 1) { 122 y_coord = coord_xy.read(); 123 y_flag = y_flag + 1; 124 y_ok.write(1); 125 } 126 127 wait(); 128 x_ok.write(0); 129 y_ok.write(0); 130 131 // debug display of coordinate sets 132 /* 133 if (x_flag == y_flag) { 134 cout << " Coordinate Set #" << x_flag 135 << " X = " << x_coord.to_int() 136 << " Y = " << y_coord.to_int() 137 << endl; 138 } 139 */ 140 141 // conversion of x coordinate values to memory column locations 142 143 if (x_coord.to_int() == -8) x = 15; 144 if (x_coord.to_int() == -7) x = 14; 145 if (x_coord.to_int() == -6) x = 13; 146 if (x_coord.to_int() == -5) x = 12; 147 if (x_coord.to_int() == -4) x = 11; 148 if (x_coord.to_int() == -3) x = 10; 149 if (x_coord.to_int() == -2) x = 9; 150 if (x_coord.to_int() == -1) x = 8; 151 if (x_coord.to_int() == 0) x = 7; 152 if (x_coord.to_int() == 1) x = 6; 153 if (x_coord.to_int() == 2) x = 5; 154 if (x_coord.to_int() == 3) x = 4; 155 if (x_coord.to_int() == 4) x = 3; 156 if (x_coord.to_int() == 5) x = 2; 157 if (x_coord.to_int() == 6) x = 1; 158 if (x_coord.to_int() == 7) x = 0; 159 160 // conversion of y coordinate values to memory row locations 161 162 if (y_coord.to_int() == -8) y = 16; 163 if (y_coord.to_int() == -7) y = 15; 164 if (y_coord.to_int() == -6) y = 14; 165 if (y_coord.to_int() == -5) y = 13; 166 if (y_coord.to_int() == -4) y = 12; 167 if (y_coord.to_int() == -3) y = 11; 168 if (y_coord.to_int() == -2) y = 10; 169 if (y_coord.to_int() == -1) y = 9; 170 if (y_coord.to_int() == 0) y = 8; 171 if (y_coord.to_int() == 1) y = 7; 172 if (y_coord.to_int() == 2) y = 6; 173 if (y_coord.to_int() == 3) y = 5; 174 if (y_coord.to_int() == 4) y = 4; 175 if (y_coord.to_int() == 5) y = 3; 176 if (y_coord.to_int() == 6) y = 2; 177 if (y_coord.to_int() == 7) y = 1; 178 179 // turn bit high in memory for calculated coordinate 180 181 mem[y][x] = 1; 182 183 // stop simulation after 100 coordinates 184 185 if (y_flag == 100) break; 186 187 } // End of while loop 188 189 cout << "\n\t FINAL MEMORY VALUES" << endl; 190 191 for (i = 1; i < 17; i++) 192 cout << "Memory Location " << i 193 << " : \t" << mem[i] << endl; 194 195 sc_stop(); 196} 197