1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
/*****************************************************************************
Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
more contributor license agreements. See the NOTICE file distributed
with this work for additional information regarding copyright ownership.
Accellera licenses this file to you under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing
permissions and limitations under the License.
*****************************************************************************/
/*****************************************************************************
main.cpp -- This example shows the use of the sc_ttd classes to demonstrate
a communication channel that uses a toggle-toggle handshake.
Original Author: Andy Goodrich, Forte Design Systems, Inc.
*****************************************************************************/
// $Log: main.cpp,v $
// Revision 1.2 2011/08/15 16:43:24 acg
// Torsten Maehne: changes to remove unused argument warnings.
//
// Revision 1.1 2011/06/14 21:25:39 acg
// Andy Goodrich: moved examples from 2.2.1 potential release.
//
// Revision 1.1 2010/08/20 14:14:10 acg
// Andy Goodrich: new example using a toggle-toggle handshake for communication.
//
#include "systemc.h"
#include <iomanip>
#include "sc_ttd.h"
SC_MODULE(DUT)
{
SC_CTOR(DUT)
{
SC_CTHREAD(thread,m_clk.pos());
reset_signal_is(m_reset, false);
}
void thread()
{
sc_uint<8> data[10];
m_input.reset();
m_output.reset();
wait();
for (;;)
{
for ( int outer_i = 0; outer_i < 10; outer_i++ )
{
for ( int inner_i = 0; inner_i < outer_i; inner_i++ )
{
data[inner_i] = m_input.read();
cout << " " << std::setw(3) << data[inner_i]
<< " " << sc_time_stamp() << endl;
}
for ( int inner_i = 0; inner_i < outer_i; inner_i++ )
{
m_output = data[inner_i];
}
}
}
}
sc_in<bool> m_clk;
sc_ttd<sc_uint<8> >::in m_input;
sc_ttd<sc_uint<8> >::out m_output;
sc_in<bool> m_reset;
};
SC_MODULE(TB)
{
SC_CTOR(TB)
{
SC_CTHREAD(consumer,m_clk.pos());
reset_signal_is(m_reset, false);
SC_CTHREAD(producer,m_clk.pos());
reset_signal_is(m_reset, false);
}
void consumer()
{
sc_uint<8> data;
m_from_dut.reset();
wait();
for ( int i = 0; i < 40; i++ )
{
data = m_from_dut.read();
cout << " " << std::setw(3) << data << " "
<< sc_time_stamp() << endl;
}
sc_stop();
}
void producer()
{
sc_uint<8> data;
m_to_dut.reset();
wait();
for ( int i = 0;; i++ )
{
cout << " " << std::setw(3) << i << " "
<< sc_time_stamp() << endl;
data = i;
m_to_dut = data;
if ( i && (i % 6 == 0) ) wait(i);
}
}
sc_in<bool> m_clk;
sc_ttd<sc_uint<8> >::in m_from_dut;
sc_in<bool> m_reset;
sc_ttd<sc_uint<8> >::out m_to_dut;
};
int sc_main(int, char* [])
{
sc_clock clock;
DUT dut("dut");
sc_ttd<sc_uint<8> > dut_to_tb;
sc_signal<bool> reset;
TB tb("tb");
sc_ttd<sc_uint<8> > tb_to_dut;
dut.m_clk(clock);
dut.m_reset(reset);
dut.m_input(tb_to_dut);
dut.m_output(dut_to_tb);
tb.m_clk(clock);
tb.m_reset(reset);
tb.m_from_dut(dut_to_tb);
tb.m_to_dut(tb_to_dut);
cout << "producer dut consumer " << endl;
reset = false;
sc_start(1, SC_NS);
reset = true;
sc_start();
cout << "Program completed" << endl;
return 0;
}
|