Jump to content
mladia

Binding ports and starting function

Recommended Posts

I am working on a bigger projects for simulation of a computer architecture. I have provided the a minimal example


int sc_main():

sc_signal<bool> task_finished[ 16 ]
std::vector< PipelineLeon* > pipelines( 16 , NULL );
for( vector< cpu_spec >::iterator it = cpu_list->begin(); cpu_list->end() != it; ++it ) {
	//init pipeline
  	//...
  	pipeline->task_finished( task_finished[ it->cpu_index ]);
}
TaskSchedulerTemplate* task_scheduler = create_new_scheduler("Task-Scheduler", &pipelines);
pipeline_leon.h:

class PipelineLeon : public sc_core::sc_module
{
public:
  	TaskSchedulerTemplate *task_scheduler
	sc_out <bool> task_finished;
	SC_HAS_PROCESS( PipelineLeon );
	finish_syscall( int exit_state );
}

      
pipeline_leon.cpp:

//gets called sometime during the simulation
void PipelineLeon::finish_syscall( int exit_state )
{
	task_schdeduler->trigger();
	task_finished->write(true);
}
task_scheduler.h:

class TaskSchedulerTemplate : public sc_core::sc_module
{
public:
	sc_in<bool> * task_finished;
	SC_HAS_PROCESS( TaskSchedulerTemplate );
	task_finished_action();
	TaskSchedulerTemplate( sc_module_name name,  std::vector<PipelineLeon*> * pipelines);
	inline virtual void trigger() { trigger_task_scheduler.notify( SC_ZERO_TIME );
	sc_event_queue trigger_task_scheduler;
	schedule_task();
}
// calling basically TaskSchedulerTemplate
TaskSchedulerTemplate* create_new_scheduler( sc_module_name name, std::vector <PipelineLeon*> * _pipelines );

          
task_scheduler.cpp:
          
TaskSchedulerTemplate::TaskSchedulerTemplate(sc_module_name name, std::vector<PipelineLeon*> * _pipelines)
    : sc_module(name), pipelines(_pipelines)
{
	SC_METHOD( schedule_task );
	sensitive << trigger_task_scheduler;
	dont_initialize();
      
	task_finished = new sc_in <bool> [number_of_pipelines];
	for (vector<PipelineLeon*>::iterator pipeline = pipelines->begin() ; pipeline != pipelines->end() ; pipeline++ ){
		task_finished[ (*pipeline)->get_cpu_index() ]( (*pipeline)->task_finished ); 
	}
        
	SC_METHOD(task_finished_action);
	for (int i = 0; i< number_of_pipelines; i++) {
		sensitive << task_finished[i].pos();
	}
	dont_initialize();
}

There are more pipelines and every one of them has this port task_finished, which is connected in the task_scheduler. Everything compiles properly.
The problem is that the method task_finished_action does not get called at all, when finish_syscall is executed. What am I missing. This should work like that, right?

Share this post


Link to post
Share on other sites

You should not use new on arrays as this does not call the constructors. So instead of

	sc_in<bool> * task_finished;

You should use

	sc_vector< sc_in<bool> > task_finished;

and the constructor should the look like

TaskSchedulerTemplate::TaskSchedulerTemplate(sc_module_name name, std::vector<PipelineLeon*> * _pipelines)
    : sc_module(name), task_finished("task_finished", number_of_pipelines), pipelines(_pipelines)
{
	SC_METHOD( schedule_task );
	sensitive << trigger_task_scheduler;
	dont_initialize();
      
	for (vector<PipelineLeon*>::iterator pipeline = pipelines->begin() ; pipeline != pipelines->end() ; pipeline++ ){
		task_finished[ (*pipeline)->get_cpu_index() ]( (*pipeline)->task_finished ); 
	}
        
	SC_METHOD(task_finished_action);
	for (int i = 0; i< number_of_pipelines; i++) {
		sensitive << task_finished[i].pos();
	}
	dont_initialize();
}

sc_vector ensure that the constuctors of the sc_port are called properly.

Moreover I would not bing the task_finished signals of the _pipeline vector in the constructor, this limits the reuse and the clarity of the design intent. So I suggest to move the for-loop to sc_main and remove the second constructor argument to TaskSchedulerTemplate::TaskSchedulerTemplate.

BR

 

-Eyck

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...