test08.cpp revision 12855:588919e0e4aa
15584Snate@binkert.org/*****************************************************************************
25584Snate@binkert.org
35584Snate@binkert.org  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
45584Snate@binkert.org  more contributor license agreements.  See the NOTICE file distributed
55584Snate@binkert.org  with this work for additional information regarding copyright ownership.
65584Snate@binkert.org  Accellera licenses this file to you under the Apache License, Version 2.0
75584Snate@binkert.org  (the "License"); you may not use this file except in compliance with the
85584Snate@binkert.org  License.  You may obtain a copy of the License at
95584Snate@binkert.org
105584Snate@binkert.org    http://www.apache.org/licenses/LICENSE-2.0
115584Snate@binkert.org
125584Snate@binkert.org  Unless required by applicable law or agreed to in writing, software
135584Snate@binkert.org  distributed under the License is distributed on an "AS IS" BASIS,
145584Snate@binkert.org  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
155584Snate@binkert.org  implied.  See the License for the specific language governing
165584Snate@binkert.org  permissions and limitations under the License.
175584Snate@binkert.org
185584Snate@binkert.org *****************************************************************************/
195584Snate@binkert.org
205584Snate@binkert.org/*****************************************************************************
215584Snate@binkert.org
225584Snate@binkert.org  test08.cpp -- Test for sc_spawn during update phase, including after stop.
235584Snate@binkert.org
245584Snate@binkert.org  Original Author: Andy Goodrich
255584Snate@binkert.org
265584Snate@binkert.org *****************************************************************************/
275584Snate@binkert.org
285584Snate@binkert.org/*****************************************************************************
295584Snate@binkert.org
305584Snate@binkert.org  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
315584Snate@binkert.org  changes you are making here.
325584Snate@binkert.org
335584Snate@binkert.org      Name, Affiliation, Date:
345584Snate@binkert.org  Description of Modification:
355584Snate@binkert.org
365584Snate@binkert.org *****************************************************************************/
375584Snate@binkert.org// $Log: test08.cpp,v $
385584Snate@binkert.org// Revision 1.4  2011/02/20 13:43:44  acg
395584Snate@binkert.org//  Andy Goodrich: updates for IEEE 1666 2011.
405584Snate@binkert.org//
415584Snate@binkert.org// Revision 1.3  2011/02/18 21:11:07  acg
425584Snate@binkert.org//  Philipp A. Hartmann: rename ABC class to eliminate class with wingdi.h.
435584Snate@binkert.org//
445584Snate@binkert.org// Revision 1.2  2011/02/01 17:17:40  acg
455584Snate@binkert.org//  Andy Goodrich: update of copyright notice, added visible CVS logging.
465584Snate@binkert.org//
475584Snate@binkert.org
485584Snate@binkert.org#define SC_INCLUDE_DYNAMIC_PROCESSES
49#include "systemc.h"
50
51class prim_channel : public sc_prim_channel {
52  public:
53  	prim_channel(const char* name = sc_gen_unique_name("prim_channel") )
54	    : sc_prim_channel(name)
55	{}
56	void thread()
57	{
58		cout << "thread here..." << endl;
59	}
60	void update()
61	{
62		cout << "update called..." << endl;
63		sc_spawn( sc_bind(&prim_channel::thread,this),
64		          sc_gen_unique_name("thread"));
65	}
66	void write( int i )
67	{
68		request_update();
69	}
70};
71
72SC_MODULE(DUT)
73{
74	SC_CTOR(DUT)
75	{
76		SC_CTHREAD(thread,m_clk.pos());
77	}
78	void thread()
79	{
80		for (;;)
81		{
82			wait();
83			m_chan.write(0);
84			wait();
85			m_chan.write(0);
86			sc_stop();
87		}
88	}
89	sc_in<bool>  m_clk;
90	prim_channel m_chan;
91};
92int sc_main(int argc, char* argv[])
93{
94	sc_clock        clock;
95	DUT             dut("dut");
96
97	dut.m_clk(clock);
98
99	sc_start(10, SC_NS);
100
101	cout << "Program completed" << endl;
102	return 0;
103}
104