/* COPYRIGHT Notice: ================= This code is copyrighted Intellectual property of the Author (Srinivasan Venkataramanan), It is FREE for any one to use and you are FREE to modify it as per your wish. If possible please send any significant changes to me at srinivasan_v@india.com All examples in this website are presented as examples and no guarantee is being made about its correctness or safety features. The Author is not responsible in any way for the possible damage incurred by the use of these materials. */ #include /* ANSI C standard library */ #include /* ANSI C standard input/output library */ #include "vpi_user.h" /* IEEE 1364 PLI VPI routine library */ #include "veriuser.h" /* IEEE 1364 PLI TF routine library */ /* TF library is used for aborting on error */ /* prototypes of PLI application routine names */ int print_timescale_Compiletf(), print_timescale_StartOfSim(); char *time_unit_2_string(int time_unit); int print_timescale_Calltf(); void print_timescale_one_level (vpiHandle module_handle); void print_timescale_child_module (vpiHandle top_module_handle); void print_timescale_register(); /********************************************************************** * $print_timescale Registration Data * (add this function name to the vlog_startup_routines array) *********************************************************************/ void print_timescale_register() { s_vpi_systf_data tf_data; s_cb_data cb_data_s; s_vpi_time time_s; tf_data.type = vpiSysTask; tf_data.tfname = "$print_timescale"; tf_data.calltf = print_timescale_Calltf; tf_data.compiletf = print_timescale_Compiletf; vpi_register_systf(&tf_data); cb_data_s.reason = cbStartOfSimulation; cb_data_s.cb_rtn = print_timescale_StartOfSim; cb_data_s.obj = NULL; cb_data_s.time = NULL; cb_data_s.value = NULL; cb_data_s.user_data = NULL; vpi_register_cb(&cb_data_s); } void (*vlog_startup_routines[] ) () = { /* Add user defined resgister functions here.. */ print_timescale_register, 0 /* last entry must be 0 */ }; /********************************************************************** * compiletf application to verify valid systf args. *********************************************************************/ int print_timescale_Compiletf(char *user_data) { vpiHandle systf_handle, arg_itr, arg_handle; int tfarg_type; systf_handle = vpi_handle(vpiSysTfCall, NULL); if (systf_handle == NULL) { vpi_printf("ERROR: $print_timescale could not obtain a handle to the Task call\n"); tf_dofinish(); return(0); } arg_itr = vpi_iterate(vpiArgument, systf_handle); if (arg_itr != NULL) { vpi_printf("ERROR: $print_timescale DOES NOT require any argument\n"); tf_dofinish(); return(0); } } /********************************************************************** * calltf to get and print the value of timescale being used in this module *********************************************************************/ int print_timescale_Calltf(char *user_data) { vpiHandle top_mod_itr, top_module_handle; /* This should get the top module iterator) */ top_mod_itr = vpi_iterate(vpiModule, NULL); if (top_mod_itr == NULL) { vpi_printf("ERROR: $print_timescale failed to obtain top module iterator\n"); return(0); } vpi_printf( "========================================================\n"); vpi_printf( "Module \t \t Time unit \t Time Precision \n"); vpi_printf( "========================================================\n"); while ( ( top_module_handle = vpi_scan(top_mod_itr) ) != NULL ) { print_timescale_child_module(top_module_handle); } vpi_printf( "\n========================================================\n\n"); return(1); } void print_timescale_child_module (vpiHandle top_module_handle) { vpiHandle child_mod_itr, child_mod_handle; print_timescale_one_level (top_module_handle); child_mod_itr = vpi_iterate(vpiModule, top_module_handle); if (child_mod_itr != NULL) { while ( ( child_mod_handle = vpi_scan(child_mod_itr) ) != NULL ) { print_timescale_child_module(child_mod_handle); } } else { return; } } void print_timescale_one_level (vpiHandle module_handle) { int module_time_unit_int; int module_time_prec_int; module_time_unit_int = vpi_get(vpiTimeUnit, module_handle); module_time_prec_int = vpi_get(vpiTimePrecision, module_handle); /* vpi_printf( "========================================================\n"); */ vpi_printf( "%s \t \t %s \t \t %s\n", vpi_get_str(vpiDefName, module_handle), time_unit_2_string(module_time_unit_int),time_unit_2_string(module_time_prec_int) ); return; } char *time_unit_2_string(int time_unit) { switch (time_unit) { case -15 : return(" fs"); case -14 : return(" 10 fs"); case -13 : return(" 100 fs"); case -12 : return(" ps"); case -11 : return(" 10 ps"); case -10 : return(" 100 ps"); case -9 : return(" ns"); case -8 : return(" 10 ns"); case -7 : return(" 100 ns"); case -6 : return(" us"); case -5 : return(" 10 us"); case 4 : return(" 100 us"); case -3 : return(" ms"); case -2 : return(" 10 ms"); case -1 : return(" 100 ms"); case 0 : return(" s"); case 1 : return(" 10 s"); case 2 : return(" 100 s"); default : return("Unknown Time Unit"); } } /********************************************************************** * Start-of-simulation application *********************************************************************/ int print_timescale_StartOfSim() { vpi_printf("\n$print_timescale PLI application is being used.\n\n"); vpi_printf("Developed and maintained by Srinivasan Venkataramanan\n"); vpi_printf("Please send your comments to srinivasan_v@india.com \n\n\n"); return(0); } /*********************************************************************/