Sunteți pe pagina 1din 3

ECEN 468 ADVANCED DIGITAL SYSTEM DESIGN

HOME WORK - 2
NAME:
SRINIVAS AMBATI
VENKATESH
UIN:
923008575

Date:
Faculty:

02/02/2015
Dr. Jiang Hu

Gas Station Problem:


SC_MODULE(gas_station){
sc_event request1, request2, tank_full;
SC_CTOR(gas_station){
SC_METHOD(attendant);
sensitive << request1 << request2;
dont_initialize();
SC_THREAD(customer1); sensitive << tank_full;
SC_THREAD(customer2);
}
void attendant();
void customer1();
void customer2();
};
void gas_station::customer1(){
while (true) {
wait(SC_ZERO_TIME); tank1 = 0;
do {
request1.notify(); wait(); // Use static sensitivity
} while ( tank1 == 0 );
}
}
void gas_station::attendant(){
if (!filling) {
filling = true; next_trigger(FILL_TIME);
} else {
tank_full.notify(SC_ZERO_TIME);
filling = false;
}
}
1. For the process of customer1( ), please discuss what might be different on the
simulation results between using and without using the wait(SC_ZERO_TIME).

Solution:
Since we have used dont_initialize() for the attendant, At time t=0, the customer1() process
starts.
Wait statement in line 3:
Using wait(sc_zero_time): The customer1() process enters the while loop and waits till the
end of simulation time t=0 after all other processes have finished their part and then
proceeds with the next lines of codes. It functions correctly.
Using wait(): At simulation time t=0, the customer process starts and goes to wait(IDLE)
mode. The only way customer1() process can be started if any value or event in its static

sensitivity list is triggered. In this case, it is the event tank_full. Since the attendant process
has not started, there is no way customer1() process can proceed further. Hence both the
process will be in halt state.
Wait statement in line 5:
Using wait(): Here customer1() sends a notification of request1 and goes to wait() mode. It
will be waiting until the attendant sends a tank_full notification. So it functions correctly.
Using wait(sc_zero_time): After sending the request1 notification to attendant, the
customer1() will wait till the end of that current simulation time t and continues the infinite
while loop. There is a possibility that the customer1() sends the request1 again while the tank
is filling. So this should not be used.
2. For the process of attendant( ), please discuss what might be different on the
simulation results between using tank_full.notify( ) and
tank_full.notify(SC_ZERO_TIME).
Solution:
When the attendant process is in execution, customer1() is in wait state and there is no other
process running. So after the attendant process is triggered again when the tank is full, it will
send tank_full notification to customer1. So using either of the notify statements will not
make any difference in simulation results.
3. Please write a piece of SystemC code for the process of customer2( ). Please note
that there is no static sensitivity for customer2( ).
Solution:
Below is the code for customer2 using a thread process without any static sensitivity. A
infinite while loop is used just like any other thread process. If the attendant is busy filling for
customer1 or customer2 then, customer2 must wait till the tank is filled else, it can notify
request2 and wait for the tank_full notification from attendant.
void gas_station::customer2(){
while (true) {
wait(SC_ZERO_TIME); tank2 = 0;
do {
if(attendant_filling == false)
{
request2.notify();
wait(tank_full); //since there is no static sensitivity, customer has to wait for tank_full
notification
}
else
wait(fill_time);
} while ( tank2 == 0 );
}
}
4. Please rewrite the SystemC code for attendant( ) using thread process without
static sensitivity.
Solution:
Only the main module and attendant code is shown below. Codes for customer1() and
customer2() is same as described above.

The process for attendant is not initialized in the constructor. Since attendant cannot start
filling without any request from the customer. The attendant waits for request1 or request2,
once he gets a request, and if he not busy, then he will start filling the tank and waits for tank
fill time. And then sends a TANK_FULL notification to the customer.
SC_MODULE(gas_station){
sc_event request1, request2, tank_full;
SC_CTOR(gas_station){
SC_THREAD(attendant);
dont_initialize();
SC_THREAD(customer1); sensitive << tank_full;
SC_THREAD(customer2);
}
void attendant();
void customer1();
void customer2();
};
void gas_station::attendant(){
while(true) {
wait(request1 | request2)
if (!filling) {
filling = true; wait(FILL_TIME);
tank_full.notify(SC_ZERO_TIME);
filling = false;
}
}
}

S-ar putea să vă placă și