|
|
|
|
systemc-forum - Re: [systemc-forum] Help on parameterizing sc_methods/sc_threads number
|
Message Thread:
Previous |
Next
|
- To: Daniele Bortolotti <bobo.drugo@xxxxxxxxx>
- From: david.long@xxxxxxxxxx
- Date: Wed, 13 Jan 2010 12:19:24 +0000
- Cc: systemc-forum@xxxxxxxxxxxxxxxxx
- Send Email to systemc-forum@lists.systemc.org:
- Send new message
- Reply to this message
|
Hi Daniele,
Unfortunately you cannot pass arguments to a process registered with the
SC_THREAD macro (which is the only way to create threads in versions of
SystemC earlier than 2.1).
A work-around that you should be able to use for your problem is to
declare an index counter variable as a module member and then use that to
initialise a local index variable as each thread starts, e.g. here is part
of one of an example that did something similar (in SystemC 2.0.1)
template <int size=8>
SC_MODULE(mon)
{
// ports
sc_in<int> P1[size];
void do_mon_thread()
{
int proc_no = n_proc++;
cout << sc_time_stamp() << ": P1[" << proc_no << "] = " <<
P1[proc_no].read() << endl;
while (true)
{
wait(P1[proc_no].value_changed_event());
cout << sc_time_stamp() << ": P1[" << proc_no << "] = " <<
P1[proc_no].read() << endl;
}
} SC_CTOR(mon):n_proc(0)
{
for (int i=0; i<size; i++) {
SC_THREAD(do_mon_thread);
}
}
private:
int n_proc;
};
Hope that helps!
Regards,
Dave
--
Dr David Long
Senior Consultant
Doulos - Developing Design Know-how
VHDL * Verilog * SystemVerilog * SystemC * PSL * Perl * Tcl/Tk * Project
Services
Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24 1AW,
UK
Tel: + 44 (0)1425 471223 Email:
david.long@xxxxxxxxxx
Fax: +44 (0)1425 471573 http://www.doulos.com
--------------------------------------------------------------------------------
This message may contain personal views which are not the views of
Doulos, unless specifically stated.
<systemc-forum@xxxxxxxxxxxxxxxxx> wrote on 13/01/2010 09:41:50:
> From:
>
> Daniele Bortolotti <bobo.drugo@xxxxxxxxx>
>
> To:
>
> david.long@xxxxxxxxxx
>
> Cc:
>
> systemc-forum@xxxxxxxxxxxxxxxxx
>
> Date:
>
> 13/01/2010 09:42
>
> Subject:
>
> Re: [systemc-forum] Help on parameterizing sc_methods/sc_threads number
>
> Sent by:
>
> <systemc-forum@xxxxxxxxxxxxxxxxx>
>
> Hi David,
>
> thanks for your prompt reply.
> I am very interested in your solution about the creation of dynamic
> processes (sc_spawn etc ...) but I am bound to version 2.0.1 of
> SystemC that does not implement dynamic processes. So is there some
> other way? Maybe some C++ trick ? :-)
>
> I tried the solution suggested by sr raksha but when I use a loop
> for binding sc_threads to functions I can't pass an index argument
> (I hope I'm wrong but the compiler complains about that).
>
> Thanks for your help.
>
> Best Regards
> Daniele
>
> 2010/1/11 <david.long@xxxxxxxxxx>
> Hi Daniele,
>
> To parameterise your code, you should use "dynamic processes",
> rather than the "static processes" (i.e. processes created using the
> SC_THREAD macro) that you are currently using. The function that
> defines a dynamic process can take arguments (e.g. to specify the
> port index for a polling thread) - you are not allowed to do this
> with static processes. The dynamic processes can be created within
> your module constructor by calling sc_spawn (it is also legal to
> create dynamic processes after a module has been constructed but I
> don't think you need to do that in this case).
>
> Your code could look something like this:
>
> #define SC_INCLUDE_DYNAMIC_PROCESSES
>
> SC_MODULE(THREED_xbar)
> ...
> // prototypes
> void req_polling(int index);
> ...
>
> THREED_xbar(sc_module_name nm, ...) : ...
> sc_spawn_options options;
> options.set_sensitivity(clock.pos());
> for (int index = 0; index < N; index++) {
> sc_spawn( sc_bind
> (&THREED_xbar::req_polling,this,index),sc_gen_unique_name
> ("req_polling"),&options);
> }
>
> ... //etc
> }
> };
>
> Hope that's enough detail to give you the idea!
>
> Regards,
> Dave
>
> --
> Dr David Long
> Senior Consultant
>
> Doulos - Developing Design Know-how
> VHDL * Verilog * SystemVerilog * SystemC * PSL * Perl * Tcl/Tk *
> Project Services
>
> Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24
1AW, UK
> Tel: + 44 (0)1425 471223 Email:
david.long@xxxxxxxxxx
>
> Fax: +44 (0)1425 471573 http://www.doulos.com
>
>
--------------------------------------------------------------------------------
> Doulos Ltd is registered in England and Wales with company no. 3723454
> Its registered office is 4 Brackley Close, Bournemouth International
Airport,
> Christchurch, BH23 6SE, UK.
>
> This message (and associated files) may contain information that is
> confidential,
> proprietary, privileged, or subject to copyright. It is intended
> solely for the use
> of the individual to whom it is addressed and others authorised to
> receive it. If
> you have received this email in error, please notify the sender and
delete all
> copies. This message may contain personal views which are not the views
of
> Doulos, unless specifically stated.
>
>
> <systemc-forum@xxxxxxxxxxxxxxxxx> wrote on 10/01/2010 15:16:30:
>
> > From:
> >
> > Daniele Bortolotti <bobo.drugo@xxxxxxxxx>
> >
> > To:
> >
> > systemc-forum@xxxxxxxxxxxxxxxxx
> >
> > Date:
> >
> > 10/01/2010 15:17
> >
> > Subject:
> >
> > [systemc-forum] Help on parameterizing sc_methods/sc_threads number
> >
> > Sent by:
> >
> > <systemc-forum@xxxxxxxxxxxxxxxxx>
> >
> > Hi everybody!
> >
> > I'm modelling a crossbar ( interconnect matrix ) for my MSc final
> > project, I just need it to be 2:2 ( 2 inputs and 2 outputs ) and
> > that's already done. Besides I'd like to make it a parameterized
module
> > xbar_N:M with N inputs (from masters) and M outputs (to slaves) and
> > I'd like to reuse/extend what I've already coded.
> >
> > There are three types of sc_thread in my model : one for polling
> > masters' requests, an arbiter for scheduling, grants and for
> > connecting input ports to output ports, and a simple finite state
> > machine for "talking" with each slave memory.
> >
> > So I need N polling threads and M fsm threads....but I don't know
> > how to do that.
> >
> > Is there any way I can declare and define a variable number of
> > threads? Maybe a loop?
> >
> > Here's some of the code from the xbar_2:2.h file :
> >
> > SC_MODULE(THREED_xbar)
> > {
> > sc_in<bool> clock;
> > // other ports ....
> >
> > public:
> > // various signals ....
> >
> > // prototypes
> > void req0_polling();
> > void req1_polling();
> > void arbiter();
> > void fsm0();
> > void fsm1();
> > SC_HAS_PROCESS(THREED_xbar);
> > THREED_xbar(sc_module_name nm,
> > unsigned char ID,
> > unsigned long int noc_start_add,
> > unsigned long int noc_end_add,
> > unsigned char delay,
> > sc_trace_file *tf,
> > bool tracing) :
> > sc_module(nm),
> > ID(ID),
> > noc_start_add(noc_start_add),
> > noc_end_add(noc_end_add),
> > delay(delay) {
> >
> > SC_THREAD(req0_polling);
> > sensitive << clock.pos();
> > SC_THREAD(req1_polling);
> > sensitive << clock.pos();
> > SC_THREAD(arbiter);
> > sensitive << clock.neg();
> > SC_THREAD(fsm0);
> > sensitive << clock.pos();
> > SC_THREAD(fsm1);
> > sensitive << clock.pos();
> > }
> > }
> > }
> >
> > and in the xbar_2:2.cpp file I've something like this
> >
> > void THREED_xbar::req0_polling( ) {
> > while(true) {
> > .....
> > wait();
> > }
> > }
> >
> > void THREED_xbar::req1_polling( ) {
> > while(true) {
> > .......
> > wait();
> > }
> > }
> >
> > void THREED_xbar::arbiter( ) {
> > while(true) {
> > .......
> > wait();
> > }
> > }
> >
> > void THREED_xbar::fsm0( ) {
> > while(true) {
> > .......
> > wait();
> > }
> > }
> >
> > void THREED_xbar::fsm1( ) {
> > while(true) {
> > .......
> > wait();
> > }
> > }
> >
> > req0_polling and req1_polling have exactly the same code except for
> > an index (the core ID)
> > so I suppose there's a way to parameterize this code (the same for
> > fsm0 and fsm1).
> >
> > any suggestion is welcome!!!
> >
> > thanks and regards
> > -daniele-
|
|