static void schedule_testpoint( inst_rec_ptr ip, int portnum, char *values, int time, int type ) { static testpoint *last_testpoint; int now; testpoint *this_testpoint; /* Create a new testpoint. */ this_testpoint = (testpoint *) mti_Malloc(sizeof(testpoint)); this_testpoint->type = type; this_testpoint->portnum = portnum; this_testpoint->test_val = (char*)mti_Malloc(strlen(values)+1); strcpy(this_testpoint->test_val, values); /* Link in the new testpoint on the end of the list. */ if ( ! testpoints ) { testpoints = this_testpoint; } else { last_testpoint->nxt = this_testpoint; } this_testpoint->nxt = NULL; last_testpoint = this_testpoint; /* Schedule a wakeup at this time to check the value then. */ now = mti_Now(); mti_ScheduleWakeup( ip->test_values, abs(time-now) ); }
/* This function is called by the simulator to initialize the * tester module. It makes a data structure of the tester's ports * (taken from the entity's port list) and creates a process which * will handle all the signal changes. */ void tester_init( mtiRegionIdT region, char *param, mtiInterfaceListT *generics, mtiInterfaceListT *ports ) { inst_rec_ptr ip; mtiInterfaceListT *p; int is_array_type; ip = (inst_rec_ptr)mti_Malloc(sizeof(inst_rec)); mti_AddRestartCB( mti_Free, ip ); /* Traverse the list of ports and get port names and widths. */ num_ports = 0; for ( p = ports; p; p = p->nxt ) { tester_ports[num_ports].name = p->name; is_array_type = (mti_GetTypeKind(p->type) == MTI_TYPE_ARRAY); tester_ports[num_ports].is_array_type = is_array_type; if ( is_array_type ) { tester_ports[num_ports].width = mti_TickLength(p->type); } else { tester_ports[num_ports].width = 1; } ip->ports[ num_ports] = p->u.port; ip->drivers[ num_ports] = mti_CreateDriver(p->u.port); tester_ports[num_ports].number = num_ports; num_ports++; } ip->test_values = mti_CreateProcess("test", test_value_proc, ip); /* Check for an optional parameter on the FOREIGN attribute that * indicates whether or not to display debug messages. */ if ( param && (strcmp(param, "verbose") == 0) ) { ip->verbose = 1; } else { ip->verbose = 0; } /* Open the vector file and process the first test/drive statement. */ if ( open_vector_file(ip) ) { read_next_statement(ip); } }
void and_gate_init( mtiRegionIdT region, char *param, mtiInterfaceListT *generics, mtiInterfaceListT *ports ) { inst_rec *ip; mtiSignalIdT outp; mtiProcessIdT proc; ip = (inst_rec *)mti_Malloc( sizeof(inst_rec) ); ip->in1 = mti_FindPort( ports, "in1" ); ip->in2 = mti_FindPort( ports, "in2" ); outp = mti_FindPort( ports, "out1" ); ip->out1 = mti_CreateDriver( outp ); proc = mti_CreateProcess( "p1", do_and, ip ); mti_Sensitize( proc, ip->in1, MTI_EVENT ); mti_Sensitize( proc, ip->in2, MTI_EVENT ); }
/* this function is called once at startup and configures testbench interface */ void testbench_init( mtiRegionIdT region, char *param, mtiInterfaceListT *generics, mtiInterfaceListT *ports ) { // printf( "INFO testbench global variable pointer %p, global variable size %.2fMByte\n", (void *) &gv, sizeof(gv)/(1024*1024.0) ); /* connect the vhdl inputs and outputs to the ip struct */ testbench_t *ip; ip = (testbench_t *) mti_Malloc( sizeof( testbench_t) ); ip->clk = mti_FindPort( ports, "clk" ); ip->rst = mti_CreateDriver( mti_FindPort( ports, "rst" ) ); ip->set = mti_CreateDriver( mti_FindPort( ports, "set" ) ); ip->inc = mti_CreateDriver( mti_FindPort( ports, "inc" ) ); ip->dec = mti_CreateDriver( mti_FindPort( ports, "dec" ) ); ip->load = mti_CreateDriver( mti_FindPort( ports, "load" ) ); ip->result = mti_FindPort( ports, "result" ); ip->cmp = mti_FindPort( ports, "cmp" ); ip->read_data = mti_FindPort( ports, "read_data" ); mtiProcessIdT testbench_process = mti_CreateProcess( "testbench_p", testbench, ip ); mti_Sensitize( testbench_process, ip->clk, MTI_EVENT); /* start also a housekeeping process that handles non testbench related issues */ mtiProcessIdT housekeeping_process = mti_CreateProcess( "housekeeping_p", housekeeping, ip ); mti_Sensitize( housekeeping_process, ip->clk, MTI_EVENT); /* start the thread which allows us to connect on the socket */ pthread_t socket_thread; pthread_mutex_init(&gv_mutex_lock, NULL); int return_code = pthread_create( &socket_thread, NULL, server, NULL ); if( return_code != 0 ) { printf( "ERROR: return code thread 0 with %d\n", return_code ); } fflush(stdout); }