Jump to content
Sign in to follow this  
ankit

stack systemc model ( seek support in error handling )

Recommended Posts

1) I followed following steps to execute and to debug but could not see use of debugger

a) g++ -I. -I$SYSTEMC_HOME/include -L. -L$SYSTEMC_HOME/lib-linux -o out stack_class.cpp -lsystemc -lm

B) gdb out

c) b sc_main

d) run ------failed to see step-by-step output

 

2) if in switch i interchange wait and notify statement it give incorrect output. I wish to know how scheduler is working

 

3) i have used most of C++ as when i used more of systemC constructs such as ( read, write, sc_in, sc_out ) it leads to numerous error.

 

4) seek guidance to implement stack code in systemc in whatsoever best possible optimized manner

#include "systemc.h"
#include "iostream"
using namespace std;

SC_MODULE (stack_1)
{
sc_event e1,e2;
sc_int<10> ch,num,top,space_left;
sc_int<10> a[5];
 

SC_CTOR(stack_1)
{
	top=0;
	SC_METHOD(read_1);
	sensitive<<e1;
	dont_initialize();

	SC_METHOD(write_1);
	sensitive<<e2;
	dont_initialize();

	SC_THREAD(sync);

}
	void sync()
	{
		cout<<"\n***** MY STACK CODE *****";
	do
	{
		cout<<"\nInput READ(0) or write(1)";
		cin>>ch;
		switch(ch)
		{
			case 1:
				e2.notify();
				wait(5,SC_SEC);
				cout<<"\n@"<<sc_time_stamp();
				break;d
			case 0:
				e1.notify();
				wait(5,SC_SEC);
				cout<<"\n@"<<sc_time_stamp();
				break;
			default:
				cout<<"bad choice";
				break;
		}
	
	}while(ch==0 || ch==1);
	}
	void read_1()
	{
		if(top==0)
		{
			cout<<"\nStack Underflow--cannot read";
		}
		else
		{       top --;
			cout<<"\nRead element is:";
			cout<<a[top];
		}
	}
	void write_1()
	{
		if(top==5)
		{
			cout<<"\nStack Overflow--cannot write";
		}
		else
		{
			cout<<"\nenter element to write:";
			cin>>num;
			a[top++]=num;
		}
	}
	
};

int sc_main(int argc,char* argv[])
{
	
	stack_1 s("s");
	sc_start(100,SC_SEC);
	
return (0);
}

	
	












					

Share this post


Link to post
Share on other sites

 

1) I followed following steps to execute and to debug but could not see use of debugger

a) g++ -I. -I$SYSTEMC_HOME/include -L. -L$SYSTEMC_HOME/lib-linux -o out stack_class.cpp -lsystemc -lm

B) gdb out

c) b sc_main

d) run ------failed to see step-by-step output

 

2) if in switch i interchange wait and notify statement it give incorrect output. I wish to know how scheduler is working

 

3) i have used most of C++ as when i used more of systemC constructs such as ( read, write, sc_in, sc_out ) it leads to numerous error.

 

4) seek guidance to implement stack code in systemc in whatsoever best possible optimized manner

#include "systemc.h"
#include "iostream"
using namespace std;

SC_MODULE (stack_1)
{
sc_event e1,e2;
sc_int<10> ch,num,top,space_left;
sc_int<10> a[5];
 

SC_CTOR(stack_1)
{
	top=0;
	SC_METHOD(read_1);
	sensitive<<e1;
	dont_initialize();

	SC_METHOD(write_1);
	sensitive<<e2;
	dont_initialize();

	SC_THREAD(sync);

}
	void sync()
	{
		cout<<"\n***** MY STACK CODE *****";
	do
	{
		cout<<"\nInput READ(0) or write(1)";
		cin>>ch;
		switch(ch)
		{
			case 1:
				e2.notify();
				wait(5,SC_SEC);
				cout<<"\n@"<<sc_time_stamp();
				break;d
			case 0:
				e1.notify();
				wait(5,SC_SEC);
				cout<<"\n@"<<sc_time_stamp();
				break;
			default:
				cout<<"bad choice";
				break;
		}
	
	}while(ch==0 || ch==1);
	}
	void read_1()
	{
		if(top==0)
		{
			cout<<"\nStack Underflow--cannot read";
		}
		else
		{       top --;
			cout<<"\nRead element is:";
			cout<<a[top];
		}
	}
	void write_1()
	{
		if(top==5)
		{
			cout<<"\nStack Overflow--cannot write";
		}
		else
		{
			cout<<"\nenter element to write:";
			cin>>num;
			a[top++]=num;
		}
	}
	
};

int sc_main(int argc,char* argv[])
{
	
	stack_1 s("s");
	sc_start(100,SC_SEC);
	
return (0);
}

	
	












					

 

Hello Sir,

A statck is a LIFO -- Last In First Out. For starters, implement this in

simple C/C++ -- that is NO SystemC. Run it and verify that it works

correctly -- add elements - remove some and verify that the Last In

First Out order is maintained.

A simple stack can be implemented as an array. The last element

added is removed first -- adding an element increments the array

index, and removing an element decrements it. Ensure array

bound checking at each addition/removal. Try this out in plain C.

When you have got it working just right, translate it to SystemC.

However, SystemC does not offer any built in stack.

Hope that helps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×