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  circ48.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( circ48 )
4112855Sgabeblack@google.com{
4212855Sgabeblack@google.com    SC_HAS_PROCESS( circ48 );
4312855Sgabeblack@google.com
4412855Sgabeblack@google.com    sc_in_clk clk;
4512855Sgabeblack@google.com
4612855Sgabeblack@google.com    sc_in<bool>         reset;
4712855Sgabeblack@google.com    sc_in<bool>         x_ok;
4812855Sgabeblack@google.com    sc_in<bool>         y_ok;
4912855Sgabeblack@google.com    sc_out<bool>        out_wr;
5012855Sgabeblack@google.com    sc_out<bool>        out_sel;
5112855Sgabeblack@google.com    sc_out<bool_vector> out_xy;
5212855Sgabeblack@google.com    sc_out<bool_vector> diffs;
5312855Sgabeblack@google.com
5412855Sgabeblack@google.com    void entry();
5512855Sgabeblack@google.com
5612855Sgabeblack@google.com    circ48( sc_module_name         name_,
5712855Sgabeblack@google.com	    const sc_clock&        clk_,
5812855Sgabeblack@google.com	    const sc_signal<bool>& reset_,
5912855Sgabeblack@google.com	    const sc_signal<bool>& x_ok_,
6012855Sgabeblack@google.com	    const sc_signal<bool>& y_ok_,
6112855Sgabeblack@google.com	    sc_signal<bool>&       out_wr_,
6212855Sgabeblack@google.com	    sc_signal<bool>&       out_sel_,
6312855Sgabeblack@google.com	    signal_bool_vector&    out_xy_,
6412855Sgabeblack@google.com	    signal_bool_vector&    diffs_ )
6512855Sgabeblack@google.com	: sc_module( name_ )
6612855Sgabeblack@google.com    {
6712855Sgabeblack@google.com          clk( clk_ );
6812855Sgabeblack@google.com	  reset( reset_ );
6912855Sgabeblack@google.com	  x_ok( x_ok_ );
7012855Sgabeblack@google.com	  y_ok( y_ok_ );
7112855Sgabeblack@google.com	  out_wr( out_wr_ );
7212855Sgabeblack@google.com	  out_sel( out_sel_ );
7312855Sgabeblack@google.com	  out_xy( out_xy_ );
7412855Sgabeblack@google.com	  diffs( diffs_ );
7512855Sgabeblack@google.com	SC_CTHREAD( entry, clk.pos() );
7612855Sgabeblack@google.com	reset_signal_is(reset,true);
7712855Sgabeblack@google.com    }
7812855Sgabeblack@google.com};
7912855Sgabeblack@google.com
8012855Sgabeblack@google.com
8112855Sgabeblack@google.com/*****************************************************************************/
8212855Sgabeblack@google.com/**									    **/
8312855Sgabeblack@google.com/**  This function is the "clean" behavior (i.e. not written with synthesis **/
8412855Sgabeblack@google.com/**  or implementation in mind.  This is a circle generator, that uses an   **/
8512855Sgabeblack@google.com/**  algorithmic, interpolating technique.  Origin of circle is fixed to    **/
8612855Sgabeblack@google.com/**  point (0,0) 							    **/
8712855Sgabeblack@google.com/**  NOTE:  Extra WAIT at end for VGB (requires waits after signal assign)  **/
8812855Sgabeblack@google.com/**									    **/
8912855Sgabeblack@google.com/*****************************************************************************/
9012855Sgabeblack@google.com
9112855Sgabeblack@google.comvoid
9212855Sgabeblack@google.comcirc48::entry()
9312855Sgabeblack@google.com{
9412855Sgabeblack@google.com    sc_signed x(4);
9512855Sgabeblack@google.com    sc_signed y(4);
9612855Sgabeblack@google.com    sc_signed x_end(4);
9712855Sgabeblack@google.com    sc_signed y_end(4);
9812855Sgabeblack@google.com    sc_signed diff(8);
9912855Sgabeblack@google.com    bool first;
10012855Sgabeblack@google.com
10112855Sgabeblack@google.com    // reset initialization
10212855Sgabeblack@google.com
10312855Sgabeblack@google.com    out_wr.write( 0 );		// Initialize at time zero ????
10412855Sgabeblack@google.com    out_sel.write( 0 );
10512855Sgabeblack@google.com
10612855Sgabeblack@google.com    // setup counter-clockwise circle generation
10712855Sgabeblack@google.com
10812855Sgabeblack@google.com    while(true) {  // Reset_loop
10912855Sgabeblack@google.com	x_end = 4;
11012855Sgabeblack@google.com	x = x_end;
11112855Sgabeblack@google.com	diff = 0;
11212855Sgabeblack@google.com	diffs.write(diff);
11312855Sgabeblack@google.com	y_end = 4;
11412855Sgabeblack@google.com	y = y_end;
11512855Sgabeblack@google.com	first = true;
11612855Sgabeblack@google.com	wait();
11712855Sgabeblack@google.com
11812855Sgabeblack@google.com        // perform counter-clockwise circle generation
11912855Sgabeblack@google.com
12012855Sgabeblack@google.com	while(first || (x != x_end) || (y != y_end)) {  // Main_loop
12112855Sgabeblack@google.com	    first = false;
12212855Sgabeblack@google.com	    diff = diff + 1;
12312855Sgabeblack@google.com
12412855Sgabeblack@google.com	    if (diff > 1) {
12512855Sgabeblack@google.com		if ((x >= 0) && (y >= 0)) {
12612855Sgabeblack@google.com		    diff = diff - x - x;
12712855Sgabeblack@google.com		    x = x - 1;
12812855Sgabeblack@google.com		}
12912855Sgabeblack@google.com		else { // else_1_begin
13012855Sgabeblack@google.com		    if ((x < 0) && (y >= 0)) {
13112855Sgabeblack@google.com			diff = diff - y - y;
13212855Sgabeblack@google.com			y = y - 1;
13312855Sgabeblack@google.com		    }
13412855Sgabeblack@google.com		    else { // else_2_begin
13512855Sgabeblack@google.com			if ((x < 0) && (y < 0)) {
13612855Sgabeblack@google.com			    diff = diff + x + x;
13712855Sgabeblack@google.com			    x = x + 1;
13812855Sgabeblack@google.com			}
13912855Sgabeblack@google.com			else {
14012855Sgabeblack@google.com			    diff = diff + y + y;
14112855Sgabeblack@google.com			    y = y + 1;
14212855Sgabeblack@google.com			}
14312855Sgabeblack@google.com		    } // else_2_end
14412855Sgabeblack@google.com		} // else_1_end
14512855Sgabeblack@google.com	    }
14612855Sgabeblack@google.com	    else {
14712855Sgabeblack@google.com		if ((x >= 0) && (y >= 0)) {
14812855Sgabeblack@google.com		    diff = diff + y + y;
14912855Sgabeblack@google.com		    y = y + 1;
15012855Sgabeblack@google.com		}
15112855Sgabeblack@google.com		else { // else_3_begin
15212855Sgabeblack@google.com		    if ((x < 0) && (y >= 0)) {
15312855Sgabeblack@google.com			diff = diff - x - x;
15412855Sgabeblack@google.com			x = x - 1;
15512855Sgabeblack@google.com		    }
15612855Sgabeblack@google.com		    else { // else_4_begin
15712855Sgabeblack@google.com			if ((x < 0) && (y < 0)) {
15812855Sgabeblack@google.com			    diff = diff - y - y;
15912855Sgabeblack@google.com			    y = y - 1;
16012855Sgabeblack@google.com			}
16112855Sgabeblack@google.com			else {
16212855Sgabeblack@google.com			    diff = x + x;
16312855Sgabeblack@google.com			    x = x + 1;
16412855Sgabeblack@google.com			}
16512855Sgabeblack@google.com		    } // else_4_end
16612855Sgabeblack@google.com		} // else_3_end
16712855Sgabeblack@google.com	    }
16812855Sgabeblack@google.com
16912855Sgabeblack@google.com            // send the intermediate x value to port
17012855Sgabeblack@google.com
17112855Sgabeblack@google.com	    out_sel.write(0);	// Select x
17212855Sgabeblack@google.com	    out_wr.write(1);	// Output ready signal
17312855Sgabeblack@google.com	    out_xy.write(x);
17412855Sgabeblack@google.com	    diffs.write(diff);
17512855Sgabeblack@google.com	    wait();
17612855Sgabeblack@google.com
17712855Sgabeblack@google.com            // handshake x..
17812855Sgabeblack@google.com
17912855Sgabeblack@google.com	    do { wait(); } while (x_ok == 0);
18012855Sgabeblack@google.com	    out_wr.write(0);
18112855Sgabeblack@google.com	    wait();
18212855Sgabeblack@google.com
18312855Sgabeblack@google.com            // send the intermediate y value to port
18412855Sgabeblack@google.com
18512855Sgabeblack@google.com	    out_sel.write(1);	// Select y
18612855Sgabeblack@google.com	    out_wr.write(1);	// Output ready signal
18712855Sgabeblack@google.com	    out_xy.write(y);
18812855Sgabeblack@google.com	    wait();
18912855Sgabeblack@google.com
19012855Sgabeblack@google.com            // handshake y..
19112855Sgabeblack@google.com
19212855Sgabeblack@google.com	    do { wait(); } while (y_ok == 0);
19312855Sgabeblack@google.com	    out_wr.write(0);
19412855Sgabeblack@google.com	    wait();
19512855Sgabeblack@google.com	}  // End of Main_loop
19612855Sgabeblack@google.com    }  // End of Reset_loop
19712855Sgabeblack@google.com}
198