⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vpi_utilities.c

📁 pli_handbook_examples_pc verilog hdl 与C的接口的典型例子
💻 C
📖 第 1 页 / 共 2 页
字号:


/**********************************************************************
 * PLIbook_getarg_realval_vpi()
 * Return the value of a system task/function argument as a double.
 * Similar to acc_fetch_tfarg()
 *********************************************************************/
double PLIbook_getarg_realval_vpi(int argNum)
{
  vpiHandle arg_h;
  s_vpi_value argVal;
  #ifdef PLIbookDebug
    s_vpi_error_info err;  /* structure for error handling */
  #endif
 
  arg_h = PLIbook_getarg_handle_vpi(argNum);
  if (arg_h == NULL) {
    vpi_printf("ERROR: PLIbook_getarg_realval_vpi() could not obtain arg handle\n");
    return(0);
  }
  argVal.format = vpiRealVal;
  vpi_get_value(arg_h, &argVal);
  #ifdef PLIbookDebug /* if error, generate verbose debug message */
    if (vpi_chk_error(&err)) {
      vpi_printf("ERROR: PLIbook_getarg_realval_vpi() could not obtain arg value\n");
      vpi_printf("File %s, Line %d: %s\n",
                 err.file, err.line, err.message);
      return(0.0);
    }
  #endif

  return(argVal.value.real);
}


/**********************************************************************
 * PLIbook_getarg_stringval_vpi()
 * Return the value of a system task/function argument as a string.
 * Similar to acc_fetch_tfarg_str()
 *********************************************************************/
char *PLIbook_getarg_stringval_vpi(int argNum)
{
  vpiHandle arg_h;
  s_vpi_value argVal;
  #ifdef PLIbookDebug
    s_vpi_error_info err;  /* structure for error handling */
  #endif
 
  arg_h = PLIbook_getarg_handle_vpi(argNum);
  if (arg_h == NULL) {
    vpi_printf("ERROR: PLIbook_getarg_stringval_vpi() could not obtain arg handle\n");
    return(0);
  }
  argVal.format = vpiStringVal;
  vpi_get_value(arg_h, &argVal);
  #ifdef PLIbookDebug /* if error, generate verbose debug message */
    if (vpi_chk_error(&err)) {
      vpi_printf("ERROR: PLIbook_getarg_stringval_vpi() could not obtain arg value\n");
      vpi_printf("File %s, Line %d: %s\n",
                 err.file, err.line, err.message);
      return("");
    }
  #endif

  return(argVal.value.str);
}


/**********************************************************************
 * PLIbook_vpi_get_str()
 * Return the string property of an object.  Works like vpi_get_str()
 * except that it traps a null return and converts it to a null string
 *********************************************************************/
char *PLIbook_vpi_get_str(int type, vpiHandle obj_h)
{
  char *temp;

  temp = vpi_get_str(type, obj_h);
  if (temp != NULL)
    return(temp);
  else
    return("");
}


/**********************************************************************
 * PLIbook_set_vpiworkarea()
 *   Stores a data value in the work area for a specific system
 *   task/function instance.  Similar to tf_setworkarea().
 *
 *   This routine automatically allocates a work area that is specific
 *   to an instance of a system task or system function. The work area
 *   is created using a simple LIFO stack so that a work area can be 
 *   allocated for any number of system task/function instances. Only
 *   one work area per task/function instance will be allocated.
 * 
 *   The work area stores a char* pointer in its data field. The data
 *   can be retrieved using PLIbook_set_vpiworkarea().
 *********************************************************************/

/* Work area structure definition */
typedef struct PLIbook_vpiworkarea *PLIbook_vpiworkarea_p;
typedef struct PLIbook_vpiworkarea {
  vpiHandle systf_h; /* shows which systf instance owns this space */
  char *data;        /* data to be stored in workarea */
  PLIbook_vpiworkarea_p next_workarea;
} PLIbook_vpiworkarea_s;


/* allocate a global stack pointer */
static PLIbook_vpiworkarea_p PLIbook_vpiworkarea_stack = NULL; 


void PLIbook_set_vpiworkarea(vpiHandle systf_h, char *data)
{
  PLIbook_vpiworkarea_p workarea = PLIbook_vpiworkarea_stack;

  /* locate the workarea in the stack for this task instance */
  while (workarea && (workarea->systf_h != systf_h))
    workarea = workarea->next_workarea;
    
  /* if no work area found for this task instance, create one */
  if (workarea == NULL) { 
    workarea =
          (PLIbook_vpiworkarea_p)malloc(sizeof(PLIbook_vpiworkarea_s));
    workarea->systf_h = systf_h;    /* set owner of this workarea */
    if (PLIbook_vpiworkarea_stack == NULL) {
      /* work area stack doesn't exist yet, create first location */
      workarea->next_workarea = NULL;
      PLIbook_vpiworkarea_stack = workarea;
    }
    else {
      workarea->next_workarea = PLIbook_vpiworkarea_stack;
      PLIbook_vpiworkarea_stack = workarea;
    }
  }

  /* store data in the work area */
  workarea->data = data;
  return;
}


/**********************************************************************
 * PLIbook_get_vpiworkarea()
 *   Returns the data stored in the work area for a specific system
 *   task/function instance. Similar to tf_getworkarea().  A NULL is
 *   returned if unsuccessful.
 *********************************************************************/
char *PLIbook_get_vpiworkarea(vpiHandle systf_h)
{
  PLIbook_vpiworkarea_p  workarea;

  /* locate the workarea in the stack for this task instance */
  workarea = PLIbook_vpiworkarea_stack;
  while (workarea && (workarea->systf_h != systf_h))
    workarea = workarea->next_workarea;
  if (workarea == NULL) {
    #ifdef PLIbookDebug  /* generate verbose debug message */
      vpi_printf("Warning: workarea not found for this task instance\n");
    #endif
    return(NULL);
  }
  return(workarea->data);
}


/**********************************************************************
 * PLIbook_fetch_type_str_vpi()
 * Return the string name of a VPI constant.
 * Similar to acc_fetch_type_string()
 *********************************************************************/
char *PLIbook_fetch_type_str_vpi(int type)
{
  switch (type) {
    case  vpiAlways         : return("vpiAlways");
    case  vpiAssignStmt     : return("vpiAssignStmt");
    case  vpiAssignment     : return("vpiAssignment");
    case  vpiBegin          : return("vpiBegin");
    case  vpiCase           : return("vpiCase");
    case  vpiCaseItem       : return("vpiCaseItem");
    case  vpiConstant       : return("vpiConstant");
    case  vpiContAssign     : return("vpiContAssign");
    case  vpiDeassign       : return("vpiDeassign");
    case  vpiDefParam       : return("vpiDefParam");
    case  vpiDelayControl   : return("vpiDelayControl");
    case  vpiDisable        : return("vpiDisable");
    case  vpiEventControl   : return("vpiEventControl");
    case  vpiEventStmt      : return("vpiEventStmt");
    case  vpiFor            : return("vpiFor");
    case  vpiForce          : return("vpiForce");
    case  vpiForever        : return("vpiForever");
    case  vpiFork           : return("vpiFork");
    case  vpiFuncCall       : return("vpiFuncCall");
    case  vpiFunction       : return("vpiFunction");
    case  vpiGate           : return("vpiGate");
    case  vpiIf             : return("vpiIf");
    case  vpiIfElse         : return("vpiIfElse");
    case  vpiInitial        : return("vpiInitial");
    case  vpiIntegerVar     : return("vpiIntegerVar");
    case  vpiInterModPath   : return("vpiInterModPath");
    case  vpiIterator       : return("vpiIterator");
    case  vpiIODecl         : return("vpiIODecl");
    case  vpiMemory         : return("vpiMemory");
    case  vpiMemoryWord     : return("vpiMemoryWord");
    case  vpiModPath        : return("vpiModPath");
    case  vpiModule         : return("vpiModule");
    case  vpiNamedBegin     : return("vpiNamedBegin");
    case  vpiNamedEvent     : return("vpiNamedEvent");
    case  vpiNamedFork      : return("vpiNamedFork");
    case  vpiNet            : return("vpiNet");
    case  vpiNetBit         : return("vpiNetBit");
    case  vpiNullStmt       : return("vpiNullStmt");
    case  vpiOperation      : return("vpiOperation");
    case  vpiParamAssign    : return("vpiParamAssign");
    case  vpiParameter      : return("vpiParameter");
    case  vpiPartSelect     : return("vpiPartSelect");
    case  vpiPathTerm       : return("vpiPathTerm");
    case  vpiPort           : return("vpiPort");
    case  vpiPortBit        : return("vpiPortBit");
    case  vpiPrimTerm       : return("vpiPrimTerm");
    case  vpiRealVar        : return("vpiRealVar");
    case  vpiReg            : return("vpiReg");
    case  vpiRegBit         : return("vpiRegBit");
    case  vpiRelease        : return("vpiRelease");
    case  vpiRepeat         : return("vpiRepeat");
    case  vpiRepeatControl  : return("vpiRepeatControl");
    case  vpiSchedEvent     : return("vpiSchedEvent");
    case  vpiSpecParam      : return("vpiSpecParam");
    case  vpiSwitch         : return("vpiSwitch");
    case  vpiSysFuncCall    : return("vpiSysFuncCall");
    case  vpiSysTaskCall    : return("vpiSysTaskCall");
    case  vpiTableEntry     : return("vpiTableEntry");
    case  vpiTask           : return("vpiTask");
    case  vpiTaskCall       : return("vpiTaskCall");
    case  vpiTchk           : return("vpiTchk");
    case  vpiTchkTerm       : return("vpiTchkTerm");
    case  vpiTimeVar        : return("vpiTimeVar");
    case  vpiTimeQueue      : return("vpiTimeQueue");
    case  vpiUdp            : return("vpiUdp");
    case  vpiUdpDefn        : return("vpiUdpDefn");
    case  vpiUserSystf      : return("vpiUserSystf");
    case  vpiVarSelect      : return("vpiVarSelect");
    case  vpiWait           : return("vpiWait");
    case  vpiWhile          : return("vpiWhile");
    case  vpiCondition      : return("vpiCondition");
    case  vpiDelay          : return("vpiDelay");
    case  vpiElseStmt       : return("vpiElseStmt");
    case  vpiForIncStmt     : return("vpiForIncStmt");
    case  vpiForInitStmt    : return("vpiForInitStmt");
    case  vpiHighConn       : return("vpiHighConn");
    case  vpiLhs            : return("vpiLhs");
    case  vpiIndex          : return("vpiIndex");
    case  vpiLeftRange      : return("vpiLeftRange");
    case  vpiLowConn        : return("vpiLowConn");
    case  vpiParent         : return("vpiParent");
    case  vpiRhs            : return("vpiRhs");
    case  vpiRightRange     : return("vpiRightRange");
    case  vpiScope          : return("vpiScope");
    case  vpiSysTfCall      : return("vpiSysTfCall");
    case  vpiTchkDataTerm   : return("vpiTchkDataTerm");
    case  vpiTchkNotifier   : return("vpiTchkNotifier");
    case  vpiTchkRefTerm    : return("vpiTchkRefTerm");
    case  vpiArgument       : return("vpiArgument");
    case  vpiBit            : return("vpiBit");
    case  vpiDriver         : return("vpiDriver");
    case  vpiInternalScope  : return("vpiInternalScope");
    case  vpiLoad           : return("vpiLoad");
    case  vpiModDataPathIn  : return("vpiModDataPathIn");
    case  vpiModPathIn      : return("vpiModPathIn");
    case  vpiModPathOut     : return("vpiModPathOut");
    case  vpiOperand        : return("vpiOperand");
    case  vpiPortInst       : return("vpiPortInst");
    case  vpiProcess        : return("vpiProcess");
    case  vpiVariables      : return("vpiVariables");
    case  vpiUse            : return("vpiUse");
    case  vpiExpr           : return("vpiExpr");
    case  vpiPrimitive      : return("vpiPrimitive");
    case  vpiStmt           : return("vpiStmt");
    
  /* Additional constants defined in Verilog-XL's vpi_user_cds.h */
  /***  
    case  vpiAttribute      : return("vpiAttribute");
    case  vpiCallback       : return("vpiCallback");
    case  vpiPorts          : return("vpiPorts");
    case  vpiTaskFunc       : return("vpiTaskFunc");
  ***/
    
    default                 : return("UNDEFINED TYPE");
  }
}
/*********************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -