always @(posedge clk)
begin
// Connect the Master
$simMaster(AM,AS,WRITE,IACK,LWORD,DS0,DS1,AB,DB,SYSRESET,DTACK,BERR);
// Connect the Slave
//simSlave slave(.clk(clk),.Write(WRITE),.DTACK(DTACK),.AB(AB),.DB(DB));
// Define the ON and OFF time of clock
#define PERIOD 5
extern int clkGen();
extern int clkInit();
extern int clkReactive (int data, int reason, int paramvc);
// Data structure
struct clkData {
int clk;
int clkCnt;
};
struct clkData *data;
// Main routine which toggles the clock
int clkGen ()
{
acc_initialize();
// Get the stored workarea
data = ( struct clkData * )tf_igetworkarea(tf_getinstance());
if (data->clkCnt == PERIOD)
{
data->clk = (data->clk == 0) ? 1 : 0;
data->clkCnt = 0;
io_printf("%d Current clk = %d\n",tf_gettime(), data->clk);
// Drive the clock signal in HDL
tf_putp (1, data->clk);
}
else
{
data->clkCnt ++;
}
tf_setdelay(1);
acc_close();
return 0;
}
// checktf() routine
// This function inits the objects and also stores the object in workarea
int clkInit()
{
acc_initialize();
data = ( struct clkData * )malloc( sizeof( struct clkData ) );
data->clkCnt = 0;
data->clk = 0;
tf_setworkarea(data);
acc_close();
return 0;
}
// misctf() routine
// This routine is called after 1 tick
int clkReactive (int data, int reason, int paramvc)
{
acc_initialize();
// if callback reason is reactive, then call clkGen function
if (reason == reason_reactivate)
{
clkGen();
// Set the callback delay to 1 tick
}
acc_close();
return 0;
}
// Data structure
typedef struct myMaster
{
handle WRITE;
handle SYSRESET;
int error;
int error_time;
int numCount;
int indexCount;
int state;
int write_value;
int sysreset_value;
int regAdd[10];
} myMaster_s,*myMaster_p;