Exemplo n.º 1
0
/*
 * Given a path, look the path name up using the PLI,
 * and set it to 'value'.
 */
static int uvm_hdl_set_vlog(char *path, p_vpi_vecval value, PLI_INT32 flag)
{
  static int maxsize = -1;
  vpiHandle r;
  s_vpi_value value_s = { vpiIntVal, { 0 } };
  s_vpi_time  time_s = { vpiSimTime, 0, 0, 0.0 };

  //vpi_printf("uvm_hdl_set_vlog(%s,%0x)\n",path,value[0].aval);

  #ifdef QUESTA
  int result = 0;
  result = uvm_hdl_set_vlog_partsel(path,value,flag);
  if (result < 0)
    return 0;
  if (result == 1)
    return 1;

  if (!strncmp(path,"$root.",6))
    r = vpi_handle_by_name(path+6, 0);
  else
  #endif
  r = vpi_handle_by_name(path, 0);

  if(r == 0)
  {
      vpi_printf((PLI_BYTE8*) "UVM_ERROR: set: unable to locate hdl path (%s)\n",path);
      vpi_printf((PLI_BYTE8*) " Either the name is incorrect, or you may not have PLI/ACC visibility to that name\n");
    return 0;
  }
  else
  {
    if(maxsize == -1) 
        maxsize = uvm_hdl_max_width();

    if (flag == vpiReleaseFlag) {
      //size = vpi_get(vpiSize, r);
      //value_p = (p_vpi_vecval)(malloc(((size-1)/32+1)*8*sizeof(s_vpi_vecval)));
      //value = &value_p;
    }
    value_s.format = vpiVectorVal;
    value_s.value.vector = value;
    vpi_put_value(r, &value_s, &time_s, flag);  
    //if (value_p != NULL)
    //  free(value_p);
    if (value == NULL) {
      value = value_s.value.vector;
    }
  }
#ifndef VCS
  //vpi_release_handle(r);
#endif
  return 1;
}
Exemplo n.º 2
0
int _mon_check_quad() {
    VlVpiHandle vh2 = vpi_handle_by_name((PLI_BYTE8*)"t.quads", NULL);
    CHECK_RESULT_NZ(vh2);

    s_vpi_value v;
    t_vpi_vecval vv[2];
    bzero(&vv,sizeof(vv));

    s_vpi_time t;
    t.type = vpiSimTime;
    t.high = 0;
    t.low = 0;

    VlVpiHandle vhidx2 = vpi_handle_by_index(vh2, 2);
    CHECK_RESULT_NZ(vhidx2);
    VlVpiHandle vhidx3 = vpi_handle_by_index(vh2, 3);
    CHECK_RESULT_NZ(vhidx2);

    v.format = vpiVectorVal;
    v.value.vector = vv;
    v.value.vector[1].aval = 0x12819213UL;
    v.value.vector[0].aval = 0xabd31a1cUL;
    vpi_put_value(vhidx2, &v, &t, vpiNoDelay);

    v.format = vpiVectorVal;
    v.value.vector = vv;
    v.value.vector[1].aval = 0x1c77bb9bUL;
    v.value.vector[0].aval = 0x3784ea09UL;
    vpi_put_value(vhidx3, &v, &t, vpiNoDelay);

    vpi_get_value(vhidx2, &v);
    CHECK_RESULT(v.value.vector[1].aval, 0x12819213UL);
    CHECK_RESULT(v.value.vector[1].bval, 0);

    vpi_get_value(vhidx3, &v);
    CHECK_RESULT(v.value.vector[1].aval, 0x1c77bb9bUL);
    CHECK_RESULT(v.value.vector[1].bval, 0);

    return 0;
}
Exemplo n.º 3
0
static void set_handle_to_value(vpiHandle sig, const char*val)
{
      size_t width = strlen(val);
      size_t vv_count = (width+31)/32;

      s_vpi_value value;

      value.value.vector = calloc(vv_count, sizeof(s_vpi_vecval));
      int idx;
      for (idx = 0 ; idx < width ; idx += 1) {
	    int word = idx / 32;
	    int bit = idx % 32;
	    char src = val[width-idx-1];
	    PLI_INT32 amask = 0;
	    PLI_INT32 bmask = 0;
	    switch (src) {
		case '0':
		  continue;
		case '1':
		  amask = 1;
		  bmask = 0;
		  break;
		case 'x':
		  amask = 1;
		  bmask = 1;
		  break;
		case 'z':
		  amask = 0;
		  bmask = 1;
		  break;
	    }

	    s_vpi_vecval*vp = value.value.vector+word;

	    vp->aval |= amask << bit;
	    vp->bval |= bmask << bit;
      }

      if (vpi_get(vpiSize, sig) != width) {
	    vpi_printf("ERROR: %s is %d bits, got %zu from server\n",
		       vpi_get_str(vpiName, sig), vpi_get(vpiSize, sig), width);
	    vpi_flush();
      }

      assert(vpi_get(vpiSize, sig) == width);
      assert(vpi_get(vpiType, sig) == vpiReg);

      value.format = vpiVectorVal;
      vpi_put_value(sig, &value, 0, vpiNoDelay);

      free(value.value.vector);
}
Exemplo n.º 4
0
static PLI_INT32 sys_fopenrwa_calltf(PLI_BYTE8*name)
{
      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);
      vpiHandle file = vpi_scan(argv);
      s_vpi_value val;
      char *mode;
      unsigned idx, len;

      vpi_free_object(argv);

	/* Get the mode. */
      mode = name + strlen(name) - 1;

	/* Get the filename. */
      val.format = vpiStringVal;
      vpi_get_value(file, &val);

	/* Verify that we have a string and that it is not NULL. */
      if (val.format != vpiStringVal || !*(val.value.str)) {
	    vpi_printf("WARNING: %s:%d: ", vpi_get_str(vpiFile, callh),
	               (int)vpi_get(vpiLineNo, callh));
	    vpi_printf("%s's file name argument is not a valid string.\n",
	                name);
	    return 0;
      }

	/*
	 * Verify that the file name is composed of only printable
	 * characters.
	 */
      len = strlen(val.value.str);
      for (idx = 0; idx < len; idx++) {
	    if (! isprint(val.value.str[idx])) {
		  char msg [64];
		  snprintf(msg, 64, "WARNING: %s:%d:",
		           vpi_get_str(vpiFile, callh),
		           (int)vpi_get(vpiLineNo, callh));
		  vpi_printf("%s %s's file name argument contains non-"
		             "printable characters.\n", msg, name);
		  vpi_printf("%*s \"%s\"\n", (int) strlen(msg), " ", val.value.str);
		  return 0;
	    }
      }

	/* Open the file and return the result. */
      val.format = vpiIntVal;
      val.value.integer = vpi_fopen(val.value.str, mode);
      vpi_put_value(callh, &val, 0, vpiNoDelay);

      return 0;
}
Exemplo n.º 5
0
void set_arg_int(const s_riscyArg *const arg,
                 const int value,
                 const int offset,
                 const int zero_at)
{
    s_vpi_value value_s;
    s_vpi_time time_s;

    value_s.format = vpiIntVal;
    time_s.type = vpiScaledRealTime;
    value_s.value.integer = value;
    if (!offset) {
        vpi_put_value(arg->handle, &value_s, NULL, vpiNoDelay);
    } else {
        time_s.real = offset;
        vpi_put_value(arg->handle, &value_s, &time_s, vpiInertialDelay);
    }
    if (zero_at) {
        time_s.real = zero_at;
        value_s.value.integer = 0;
        vpi_put_value(arg->handle, &value_s, &time_s, vpiInertialDelay);
    }
}
Exemplo n.º 6
0
/*
 * set a handle to a real value
 *
 * user must make sure href can have have a value put into it
 * notice the key to vpi_ processing is to save and pass handles
 */
static void vpiset_to_real(vpiHandle href, double d1)
{
 struct t_vpi_value valrec;
 struct t_vpi_error_info einfotab;

 valrec.format = vpiRealVal;
  valrec.value.real = d1; 
 vpi_put_value(href, &valrec, NULL, vpiNoDelay);
 if (vpi_chk_error(&einfotab))
  {
   vpi_printf("** ERR: vpi_put_value of real error:\n");
   prtvpiemsg(&einfotab);
  }
}
Exemplo n.º 7
0
static PLI_INT32 sys_mti_dist_uniform_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
{
      vpiHandle callh, argv, seed, start, end;
      s_vpi_value val;
      long i_seed, i_start, i_end;

      (void)name; /* Parameter is not used. */

	/* Get the argument handles and convert them. */
      callh = vpi_handle(vpiSysTfCall, 0);
      argv = vpi_iterate(vpiArgument, callh);
      seed = vpi_scan(argv);
      start = vpi_scan(argv);
      end = vpi_scan(argv);

      val.format = vpiIntVal;
      vpi_get_value(seed, &val);
      i_seed = val.value.integer;

      vpi_get_value(start, &val);
      i_start = val.value.integer;

      vpi_get_value(end, &val);
      i_end = val.value.integer;

	/* Calculate and return the result. */
      val.value.integer = mti_dist_uniform(&i_seed, i_start, i_end);
      vpi_put_value(callh, &val, 0, vpiNoDelay);

	/* Return the seed. */
      val.value.integer = i_seed;
      vpi_put_value(seed, &val, 0, vpiNoDelay);

      vpi_free_object(argv);
      return 0;
}
Exemplo n.º 8
0
static PLI_INT32 simbus_poll_calltf(char*my_name)
{
      int poll_state;
      s_vpi_value value;

      vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, sys);

      vpiHandle bus_h = vpi_scan(argv);
      assert(bus_h);

      value.format = vpiIntVal;
      vpi_get_value(bus_h, &value);

      int bus = value.value.integer;
      assert(bus >= 0 && bus < MAX_INSTANCES);

      vpiHandle trig = vpi_scan(argv);
      assert(trig);

      vpi_free_object(argv);

      DEBUG(SIMBUS_DEBUG_CALLS, "Call $poll(%d...)\n", bus);

      poll_state = check_readable(bus);

      value.format = vpiScalarVal;
      value.value.scalar = poll_state? vpi1 : vpi0;
      vpi_put_value(trig, &value, 0, vpiNoDelay);

      if (poll_state == 0) {
	    struct t_cb_data cb_data;
	    struct t_vpi_time cb_time;
	    cb_time.type = vpiSuppressTime;
	    cb_data.reason = cbReadWriteSynch;
	    cb_data.cb_rtn = poll_for_simbus_bus;
	    cb_data.time   = &cb_time;
	    vpi_register_cb(&cb_data);

	    instance_table[bus].trig = trig;

      } else {
	    instance_table[bus].trig = 0;
      }

      DEBUG(SIMBUS_DEBUG_CALLS, "return $poll(%d...)\n", bus);
      return 0;
}
Exemplo n.º 9
0
static PLI_INT32 ivl_method_prev_calltf(PLI_BYTE8*data)
{
      vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, sys);
      vpiHandle arg_enum = vpi_scan(argv);
      vpiHandle arg_item = vpi_scan(argv);
      vpiHandle arg_extra = vpi_scan(argv);

      vpiHandle enum_list = 0;
      vpiHandle memb = 0, prev = 0, last_memb = 0;
      int use_wid = 0;

      s_vpi_value memb_value, item_value;

      assert(arg_extra == 0);

      item_value.format = vpiIntVal;
      vpi_get_value(arg_item, &item_value);

      enum_list = vpi_iterate(vpiMember, arg_enum);
      assert(enum_list);

	/* Search for the current value in the member list. */
      do {
	    prev = memb;
	    memb = vpi_scan(enum_list);
	    if (memb == 0) break;
	    if (use_wid == 0)
		  use_wid = vpi_get(vpiSize, memb);

	    last_memb = memb;
	    memb_value.format = vpiIntVal;
	    vpi_get_value(memb, &memb_value);
      } while (! compare_value_eequal(&memb_value, &item_value, use_wid));

      while (memb) {
	    last_memb = memb;
	    memb = vpi_scan(enum_list);
      }

      if (prev == 0)
	    prev = last_memb;

      vpi_get_value(prev, &memb_value);
      vpi_put_value(sys, &memb_value, 0, vpiNoDelay);

      return 0;
}
Exemplo n.º 10
0
int VpiSignalObjHdl::set_signal_value(std::string &value)
{
    FENTER
    s_vpi_value value_s;

    std::vector<char> writable(value.begin(), value.end());
    writable.push_back('\0');

    value_s.value.str = &writable[0];
    value_s.format = vpiBinStrVal;

    vpi_put_value(GpiObjHdl::get_handle<vpiHandle>(), &value_s, NULL, vpiNoDelay);
    check_vpi_error();

    FEXIT
    return 0;
}
static int sys_fgetc_calltf(char *name)
{
      unsigned int mcd;
      int type;
      s_vpi_value value, rval;
      vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, sys);
      vpiHandle item = vpi_scan(argv);
      FILE *fp;

      if (item == 0) {
	    vpi_printf("%s: mcd parameter missing.\n", name);
	    return 0;
      }

      type = vpi_get(vpiType, item);
      switch (type) {
	    case vpiReg:
	    case vpiRealVal:
	    case vpiIntegerVar:
	      break;
	    default:
	      vpi_printf("ERROR: %s mcd parameter must be of integral", name);
	      vpi_printf(", got vpiType=%d\n", type);
	      vpi_free_object(argv);
	      return 0;
      }

      value.format = vpiIntVal;
      vpi_get_value(item, &value);
      mcd = value.value.integer;

      rval.format = vpiIntVal;

      fp = vpi_get_file(mcd);
      if (!fp || IS_MCD(mcd))
	  rval.value.integer = EOF;
      else
	  rval.value.integer = fgetc(fp);

      vpi_put_value(sys, &rval, 0, vpiNoDelay);

      return 0;
}
Exemplo n.º 12
0
/*
 * Compare the +arguments passed to the simulator with the argument
 * passed to the $test$plusargs. If there is a simulator argument that
 * is like this argument, then return true. Otherwise return false.
 */
static PLI_INT32 sys_test_plusargs_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
{
      s_vpi_value val;
      s_vpi_vlog_info info;
      int idx;
      int flag = 0;
      size_t slen, len;

      (void)name; /* Parameter is not used. */

      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);

      val.format = vpiStringVal;
      vpi_get_value(vpi_scan(argv), &val);
      slen = strlen(val.value.str);

      vpi_get_vlog_info(&info);

	/* Look for a +arg that matches the prefix supplied. */
      for (idx = 0 ;  idx < info.argc ;  idx += 1) {

	      /* Skip arguments that are not +args. */
	    if (info.argv[idx][0] != '+')
		  continue;

	    len = strlen(info.argv[idx]+1);
	    if (len < slen)
		  continue;

	    if (strncmp(val.value.str, info.argv[idx]+1, slen) != 0)
		  continue;

	    flag = 1;
	    break;
      }

      val.format = vpiIntVal;
      val.value.integer = flag;
      vpi_put_value(callh, &val, 0, vpiNoDelay);

      vpi_free_object(argv);
      return 0;
}
Exemplo n.º 13
0
static PLI_INT32 sys_fputc_calltf(PLI_BYTE8*name)
{
      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);
      vpiHandle arg;
      s_vpi_value val;
      PLI_UINT32 fd_mcd;
      FILE *fp;
      unsigned char chr;
      errno = 0;

	/* Get the character. */
      arg = vpi_scan(argv);
      val.format = vpiIntVal;
      vpi_get_value(arg, &val);
      chr = val.value.integer;


	/* Get the file/MC descriptor. */
      arg = vpi_scan(argv);
      vpi_free_object(argv);
      val.format = vpiIntVal;
      vpi_get_value(arg, &val);
      fd_mcd = val.value.integer;

	/* Put the character and return the result. */
      fp = vpi_get_file(fd_mcd);
      val.format = vpiIntVal;
      if (!fp) {
	    vpi_printf("WARNING: %s:%d: ", vpi_get_str(vpiFile, callh),
	               (int)vpi_get(vpiLineNo, callh));
	    vpi_printf("invalid file descriptor (0x%x) given to %s.\n",
	               (unsigned int)fd_mcd, name);
	    errno = EBADF;
	    val.value.integer = EOF;
      } else {
	    val.value.integer = fputc(chr, fp);
	    if (val.value.integer != EOF) val.value.integer = 0;
      }
      vpi_put_value(callh, &val, 0, vpiNoDelay);

      return 0;
}
Exemplo n.º 14
0
static int terminal_calltf(char* user_data){
	QList<quint64>		val;
	
	// retrieve signal values
	{
		vpiHandle	funchandle;
		vpiHandle	arghandle;
		vpiHandle	arg;
		t_vpi_value	argval;
		
		funchandle = vpi_handle(vpiSysTfCall, NULL);
		arghandle = vpi_iterate(vpiArgument, funchandle);
		
		while(arg = vpi_scan(arghandle)){
			argval.format = vpiIntVal;
			vpi_get_value(arg, &argval);
			val.append(argval.value.integer);
		}
	}
	
	// get new values
	procpoll(val);
	
	// assert new signal values
	{
		vpiHandle	funchandle;
		vpiHandle	arghandle;
		vpiHandle	arg;
		t_vpi_value	argval;
		
		funchandle = vpi_handle(vpiSysTfCall, NULL);
		arghandle = vpi_iterate(vpiArgument, funchandle);
		
		for(int i=0; (i<val.length()) && (arg = vpi_scan(arghandle)); ++i){
			argval.format = vpiIntVal;
			argval.value.integer = val[i];
			vpi_put_value(arg, &argval, NULL,vpiNoDelay);
		}
	}
	
	return 0;
}
Exemplo n.º 15
0
static PLI_INT32 sys_deposit_calltf(ICARUS_VPI_CONST PLI_BYTE8 *name)
{
      vpiHandle callh, argv, target, value;
      s_vpi_value val;

      callh = vpi_handle(vpiSysTfCall, 0);
      argv = vpi_iterate(vpiArgument, callh);
      target = vpi_scan(argv);
      assert(target);
      value = vpi_scan(argv);
      assert(value);

      val.format = vpiIntVal;
      vpi_get_value(value, &val);

      vpi_put_value(target, &val, 0, vpiNoDelay);

      vpi_free_object(argv);
      return 0;
}
Exemplo n.º 16
0
static PLI_INT32 sys_clog2_calltf(PLI_BYTE8 *name)
{
      vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
      vpiHandle argv = vpi_iterate(vpiArgument, callh);
      vpiHandle arg;
      s_vpi_value val;
      s_vpi_vecval vec;
      (void) name;  /* Not used! */

	/* Get the argument. */
      arg = vpi_scan(argv);
      vpi_free_object(argv);

      vec = vpip_calc_clog2(arg);

      val.format = vpiVectorVal;
      val.value.vector = &vec;
      vpi_put_value(callh, &val, 0, vpiNoDelay);
      return 0;
}
Exemplo n.º 17
0
int VpiSignalObjHdl::set_signal_value(double value)
{
    FENTER
    s_vpi_value value_s;

    value_s.value.real = value;
    value_s.format = vpiRealVal;

    s_vpi_time vpi_time_s;

    vpi_time_s.type = vpiSimTime;
    vpi_time_s.high = 0;
    vpi_time_s.low  = 0;

    vpi_put_value(GpiObjHdl::get_handle<vpiHandle>(), &value_s, &vpi_time_s, vpiInertialDelay);
    check_vpi_error();

    FEXIT
    return 0;
}
Exemplo n.º 18
0
static PLI_INT32 sys_itor_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
{
    vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
    vpiHandle arg  = (vpiHandle) vpi_get_userdata(callh);
    s_vpi_value value;

    (void)name;  /* Parameter is not used. */

    /* get value */
    value.format = vpiIntVal;
    vpi_get_value(arg, &value);

    /* convert */
    value.value.real = value.value.integer;
    value.format = vpiRealVal;

    /* return converted value */
    vpi_put_value(callh, &value, 0, vpiNoDelay);

    return 0;
}
Exemplo n.º 19
0
// Value related functions
int VpiSignalObjHdl::set_signal_value(long value)
{
    FENTER
    s_vpi_value value_s;

    value_s.value.integer = value;
    value_s.format = vpiIntVal;

    s_vpi_time vpi_time_s;

    vpi_time_s.type = vpiSimTime;
    vpi_time_s.high = 0;
    vpi_time_s.low  = 0;

    // Use Inertial delay to schedule an event, thus behaving like a verilog testbench
    vpi_put_value(GpiObjHdl::get_handle<vpiHandle>(), &value_s, &vpi_time_s, vpiInertialDelay);
    check_vpi_error();

    FEXIT
    return 0;
}
Exemplo n.º 20
0
int _mon_check_getput() {
    VlVpiHandle vh2 = vpi_handle_by_name((PLI_BYTE8*)"t.onebit", NULL);
    CHECK_RESULT_NZ(vh2);

    s_vpi_value v;
    v.format = vpiIntVal;
    vpi_get_value(vh2, &v);
    CHECK_RESULT(v.value.integer, 0);

    s_vpi_time t;
    t.type = vpiSimTime;
    t.high = 0;
    t.low = 0;
    v.value.integer = 1;
    vpi_put_value(vh2, &v, &t, vpiNoDelay);

    vpi_get_value(vh2, &v);
    CHECK_RESULT(v.value.integer, 1);

    return 0;
}
Exemplo n.º 21
0
static void reset_regs(vpiHandle module) {
	vpiHandle reg, i;
	s_vpi_value value;
	int size, j;
	char * charData;

	value.format = vpiBinStrVal;
	i = vpi_iterate(vpiReg, module);

	while (reg = vpi_scan(i)) {
		vpi_get_value(reg, &value);
		charData = value.value.str;
		size = vpi_get(vpiSize, reg);
		for (j = 0; j < size; j++) {
			if (charData[j] == 'x') {
				charData[j] = '0';
			}
		}
		vpi_put_value(reg, &value, NULL, vpiNoDelay);
	}
}
Exemplo n.º 22
0
/*
 * Routine to implement the single argument math functions.
 */
static PLI_INT32 va_single_argument_calltf(ICARUS_VPI_CONST PLI_BYTE8 *ud)
{
    vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
    s_vpi_value val;
    va_single_t* fun_data;

    (void) ud;  /* Not used! */

    /* Retrieve the function and argument data. */
    fun_data = vpi_get_userdata(callh);

    /* Calculate the result */
    val.format = vpiRealVal;
    vpi_get_value(fun_data->arg, &val);
    val.value.real = (fun_data->func)(val.value.real);

    /* Return the result */
    vpi_put_value(callh, &val, 0, vpiNoDelay);

    return 0;
}
Exemplo n.º 23
0
/*
 * Routine to return a character value (implements %c).
 *
 * Return: 1 for a match, 0 for no match/variable and -1 for a
 *         suppressed match. No variable is fatal.
 */
static int scan_format_char(vpiHandle callh, vpiHandle argv,
                            struct byte_source *src, unsigned width,
                            unsigned suppress_flag, PLI_BYTE8 *name)
{
      vpiHandle arg;
      s_vpi_value val;
      int ch;

	/* If we are being asked for no digits then return a match fail. */
      if (width == 0) return 0;

	/* Get the character to return. */
      ch = byte_getc(src);

	/* Nothing was matched. */
      if (ch == EOF) return 0;

	/* If this match is being suppressed then return after consuming
	 * the character and report that no arguments were used. */
      if (suppress_flag) return -1;

	/* We must have a variable to put the character value into. */
      arg = vpi_scan(argv);
      if (! arg) {
	    vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
	               (int)vpi_get(vpiLineNo, callh));
	    vpi_printf("%s() ran out of variables for %%c format code.", name);
	    vpi_control(vpiFinish, 1);
	    return 0;
      }

	/* Put the character into the variable. */
      val.format = vpiIntVal;
      val.value.integer = ch;
      vpi_put_value(arg, &val, 0, vpiNoDelay);

	/* We always consume one variable if it is available. */
      return 1;
}
Exemplo n.º 24
0
static PLI_INT32 PLIbook_PowCalltf(PLI_BYTE8 *user_data)
#endif
{
  s_vpi_value value_s;
  vpiHandle   systf_handle, arg_itr, arg_handle;
  PLI_INT32   base, expo;
  double      result;

  (void)user_data;  /* Parameter is not used. */

  //vpi_printf("\n$my_pow PLI calltf function.\n\n");

  systf_handle = vpi_handle(vpiSysTfCall, NULL);
  arg_itr = vpi_iterate(vpiArgument, systf_handle);
  if (arg_itr == NULL) {
    vpi_printf("ERROR: $my_pow failed to obtain systf arg handles\n");
    return(0);
  }

  /* read base from systf arg 1 (compiletf has already verified) */
  arg_handle = vpi_scan(arg_itr);
  value_s.format = vpiIntVal;
  vpi_get_value(arg_handle, &value_s);
  base = value_s.value.integer;

  /* read exponent from systf arg 2 (compiletf has already verified) */
  arg_handle = vpi_scan(arg_itr);
  vpi_free_object(arg_itr); /* not calling scan until returns null */
  vpi_get_value(arg_handle, &value_s);
  expo = value_s.value.integer;

  /* calculate result of base to power of exponent */
  result = pow( (double)base, (double)expo );

  /* write result to simulation as return value $my_pow */
  value_s.value.integer = (PLI_INT32)result;
  vpi_put_value(systf_handle, &value_s, NULL, vpiNoDelay);
  return(0);
}
Exemplo n.º 25
0
/*
 * The pattern here is get the current vector, load the new bits on
 * top of the old ones and then put the modified vector. We need the
 * "get" first so that if we run out of bits in the file we keep the
 * original ones.
 */
static unsigned fread_word(FILE *fp, vpiHandle word,
                           unsigned words, unsigned bpe, s_vpi_vecval *vector)
{
      unsigned rtn, clr_mask, bnum;
      int bidx, byte;
      s_vpi_value val;
      struct t_vpi_vecval *cur = &vector[words-1];

      rtn = 0;

	/* Get the current bits from the register and copy them to
	 * my local vector. */
      val.format = vpiVectorVal;
      vpi_get_value(word, &val);
      for (bidx = 0; bidx < words; bidx += 1) {
	    vector[bidx].aval = val.value.vector[bidx].aval;
	    vector[bidx].bval = val.value.vector[bidx].bval;
      }

	/* Copy the bytes to the local vector MSByte first. */
      for (bidx = bpe-1; bidx >= 0; bidx -= 1) {
	    byte = fgetc(fp);
	    if (byte == EOF) break;
	      /* Clear the current byte and load the new value. */
	    bnum = bidx % 4;
	    clr_mask = ~(0xff << bnum*8);
	    cur->aval &= clr_mask;
	    cur->bval &= clr_mask;
	    cur->aval |= byte << bnum*8;
	    rtn += 1;
	    if (bnum == 0) cur -= 1;
      }

	/* Put the updated bits into the register. */
      val.value.vector = vector;
      vpi_put_value(word, &val, 0, vpiNoDelay);

      return rtn;
}
Exemplo n.º 26
0
/*
 * Routine to return a floating point value (implements %e, %f and %g).
 *
 * Return: 1 for a match, 0 for no match/variable and -1 for a
 *         suppressed match. No variable is fatal.
 */
static int scan_format_float(vpiHandle callh, vpiHandle argv,
                             struct byte_source *src, unsigned width,
                             unsigned suppress_flag, PLI_BYTE8 *name,
                             char code)
{
      vpiHandle arg;
      int match;
      s_vpi_value val;
      double result;

	/* Get the real value. */
      result = get_float(src, width, &match);

	/* Nothing was matched. */
      if (match == 0) return 0;

	/* If this match is being suppressed then return after consuming
	 * the digits and report that no arguments were used. */
      if (suppress_flag) return -1;

	/* We must have a variable to put the double value into. */
      arg = vpi_scan(argv);
      if (! arg) {
	    vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
	               (int)vpi_get(vpiLineNo, callh));
	    vpi_printf("%s() ran out of variables for %%%c format code.",
	               name, code);
	    vpi_control(vpiFinish, 1);
	    return 0;
      }

	/* Put the value into the variable. */
      val.format = vpiRealVal;
      val.value.real = result;
      vpi_put_value(arg, &val, 0, vpiNoDelay);

	/* We always consume one variable if it is available. */
      return 1;
}
Exemplo n.º 27
0
static PLI_INT32 ivlh_attribute_event_calltf(ICARUS_VPI_CONST PLI_BYTE8*data)
{
      event_type_t type = (event_type_t) data;
      vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
      struct t_vpi_value rval;
      struct monitor_data*mon;

      rval.format = vpiScalarVal;

      mon = (struct monitor_data*) (vpi_get_userdata(sys));

      if (mon->last_event.type == 0) {
	    rval.value.scalar = vpi0;

      } else {
	    struct t_vpi_time tnow;
	    tnow.type = vpiSimTime;
	    vpi_get_time(0, &tnow);

	    rval.value.scalar = vpi1;

	    // Detect if change occured in this moment
	    if (mon->last_event.high != tnow.high)
		  rval.value.scalar = vpi0;
	    if (mon->last_event.low != tnow.low)
		  rval.value.scalar = vpi0;

	    // Determine the edge, if required
	    if (type == RISING_EDGE && mon->last_value.value.scalar != vpi1)
		  rval.value.scalar = vpi0;
	    else if (type == FALLING_EDGE && mon->last_value.value.scalar != vpi0)
		  rval.value.scalar = vpi0;
      }

      vpi_put_value(sys, &rval, 0, vpiNoDelay);

      return 0;
}
Exemplo n.º 28
0
int readUnsignedHalf_calltf(char *user_data)
{
  int data;
  vpiHandle systf_handle, arg_iterator, arg_handle, reg_handle;
  s_vpi_value current_value;
  s_vpi_value value_s;
  //unsigned long long instruction;


  /* obtain a handle to the system task instance. */
  systf_handle  = vpi_handle(vpiSysTfCall, 0);

  /* obtain handle to system task argument. */
  arg_iterator  = vpi_iterate(vpiArgument, systf_handle);
  reg_handle    = vpi_scan(arg_iterator);

  /* free iterator memory */
  vpi_free_object(arg_iterator);

  /* read current value */
  current_value.format = vpiIntVal;  /* read value as a integer */
  vpi_get_value(reg_handle, &current_value);

 

  data = (int) VMEM[0]->read_unsigned_half(current_value.value.integer);
  data = (data & 0x0000FFFF);
  //vpi_printf("Data read \t%x\n",data);

  value_s.format    = vpiIntVal;
  value_s.value.integer = data;

  
  vpi_put_value(systf_handle, &value_s, 0, vpiNoDelay);

 
  return(0);    
}
Exemplo n.º 29
0
static PLI_INT32
EndOfCompile(s_cb_data *data)
{
    vpiHandle hand;
    s_vpi_time timerec = { vpiSimTime, 0, 0, 0 };
    s_vpi_value val;
    int i;

    (void)data;  /* Parameter is not used. */

    hand = vpi_handle_by_name("test.r", 0);
    assert(hand);

    // Get current state
    val.format = vpiIntVal;
    vpi_get_value(hand, &val);

    // Add a few transitions
    for (i = 0; i < 6; i++) {

	if (i < 3) {
	    // delay 10+i time units
	    timerec.low = 1000 * (i + 1);
	} else {
	    timerec.type = vpiScaledRealTime;
	    timerec.low = 0;
	    timerec.real = 10000.0 * (i+1);
	}

	// Toggle state
	val.value.integer ^= 1;

	// Put new state
	vpi_put_value(hand, &val, &timerec, vpiPureTransportDelay);
    }

    return 0;
}
Exemplo n.º 30
0
int vpi_input_str(PLI_BYTE8 *d) {

	vpiHandle systfref, argh, argsiter;
	s_vpi_value v;
	systfref = vpi_handle(vpiSysTfCall, NULL);
	argsiter = vpi_iterate(vpiArgument, systfref);
	argh = vpi_scan(argsiter);
	
	if (!argh) {
		vpi_printf("$VPI: missing parameter\n");
		return 0;
	}
	
	v.format = vpiIntVal;
	vpi_get_value(argh, &v);
	
	vpi_printf("VPI: %d\n", v.value.integer);
	// vpi_put_value(systfref, &v, NULL, vpiNoDelay);
	vpi_put_value(systfref, &v, NULL, vpiNoDelay);


	return 0;
}