📄 read_4state_value_tf.c
字号:
/**********************************************************************
* $read_4state_value example -- C source code using TF/ACC PLI routines
*
* C source to illustrate reading 4-state logic values into C integers.
* The signals in Verilog to be read can be a vector of any bit size
* (including scalar).
*
* For the book, "The Verilog PLI Handbook" by Stuart Sutherland
* Book copyright 1999, Kluwer Academic Publishers, Norwell, MA, USA
* Contact: www.wkap.il
* Example copyright 1998, Sutherland HDL Inc, Portland, Oregon, USA
* Contact: www.sutherland.com or (503) 692-0898
*
* Usage:
* ------
*
* Syntax: $read_4state_value(<signal>);
*
* Example:
* reg [0:39] data;
* initial $read_4state_value(data);
*
* Routine definitions for a veriusertfs array:
* /* routine prototypes -/
* extern int PLIbook_Read4stateValue_checktf(),
* PLIbook_Read4stateValue_calltf(),
* PLIbook_Read4stateValue_misctf();
* /* table entries -/
* {usertask, /* type of PLI routine -/
* 0, /* user_data value -/
* PLIbook_Read4stateValue_checktf, /* checktf routine -/
* 0, /* sizetf routine -/
* PLIbook_Read4stateValue_calltf, /* calltf routine -/
* PLIbook_Read4stateValue_misctf, /* misctf routine -/
* "$read_4state_value", /* system task/function name -/
* 1 /* forward reference = true -/
* },
*********************************************************************/
#include "veriuser.h" /* IEEE 1364 PLI TF routine library */
/**********************************************************************
* checktf routine
*********************************************************************/
int PLIbook_Read4stateValue_checktf()
{
if (tf_nump() != 1)
tf_error("Usage error: $read_4state_value(<signal>);");
return(0);
}
/**********************************************************************
* misctf routine
*
* The misctf routine is used to call tf_exprinfo() at the
* beginning of simulation, so that the memory allocated by
* tf_exprinfo() is only allocated one time for each instance of
* $read_4state_value.
*********************************************************************/
int PLIbook_Read4stateValue_misctf(int user_data, int reason)
{
p_tfexprinfo info_p; /* pointer to structure for tf_exprinfo() */
p_vecval val_array; /* pointer to value array in info struct */
int i;
if (reason != REASON_ENDOFCOMPILE)
return(0); /* exit now if this is not the start of simulation */
/* allocte memory for an s_tfexprinfo structure */
info_p = (p_tfexprinfo)malloc(sizeof(s_tfexprinfo));
tf_exprinfo(1, info_p); /* read expression info for arg 1 */
tf_setworkarea((char *)info_p); /* save info pointer in workarea */
io_printf("Expression info:\n");
switch (info_p->expr_type) {
case TF_NULLPARAM: io_printf(" type = TF_NULLPARAM\n"); break;
case TF_STRING: io_printf(" type = TF_STRING\n"); break;
case TF_READONLY: io_printf(" type = TF_READONLY\n"); break;
case TF_READONLYREAL: io_printf(" type = TF_READONLYREAL\n"); break;
case TF_READWRITE: io_printf(" type = TF_READWRITE\n"); break;
case TF_READWRITEREAL: io_printf(" type = TF_READWRITEREAL\n"); break;
case TF_RWBITSELECT: io_printf(" type = TF_RWBITSELECT\n"); break;
case TF_RWPARTSELECT: io_printf(" type = TF_RWPARTSELECT\n"); break;
case TF_RWMEMSELECT: io_printf(" type = TF_RWMEMSELECT\n"); break;
default: io_printf(" type is unknown (%d)\n", info_p->expr_type);
}
io_printf(" ngroups = %d\n", info_p->expr_ngroups);
io_printf(" vector size = %d\n", info_p->expr_vec_size);
io_printf(" sign = %d\n", info_p->expr_sign);
io_printf(" LHS select = %d\n", info_p->expr_lhs_select);
io_printf(" RHS select = %d\n", info_p->expr_rhs_select);
switch (info_p->expr_type) {
case TF_STRING:
io_printf(" string value = %s\n", info_p->expr_string); break;
case TF_READONLYREAL:
case TF_READWRITEREAL:
io_printf(" real value = %f\n", info_p->real_value); break;
case TF_READONLY:
case TF_READWRITE:
case TF_RWBITSELECT:
case TF_RWPARTSELECT:
case TF_RWMEMSELECT:
val_array = info_p->expr_value_p;
io_printf(" vector value (in hex):\n");
for (i=0; i<info_p->expr_ngroups; i++) {
io_printf(" avalbits[%d] = %x\n", i, val_array[i].avalbits);
io_printf(" bvalbits[%d] = %x\n", i, val_array[i].bvalbits);
}
break;
}
io_printf("\n\n");
return(0);
}
/**********************************************************************
* calltf routine
*********************************************************************/
int PLIbook_Read4stateValue_calltf()
{
p_tfexprinfo info_p; /* pointer to structure for tf_exprinfo() */
p_vecval val_array; /* pointer to value array in info struct */
int i;
info_p = (p_tfexprinfo)tf_getworkarea(); /* retrieve info pointer */
tf_evaluatep(1); /* re-read value of arg 1 */
switch (info_p->expr_type) {
case TF_STRING:
io_printf(" string value = %s\n", info_p->expr_string); break;
case TF_READONLYREAL:
case TF_READWRITEREAL:
io_printf(" real value = %f\n", info_p->real_value); break;
case TF_READONLY:
case TF_READWRITE:
case TF_RWBITSELECT:
case TF_RWPARTSELECT:
case TF_RWMEMSELECT:
val_array = info_p->expr_value_p;
io_printf(" vector value (in hex):\n");
for (i=0; i<info_p->expr_ngroups; i++) {
io_printf(" avalbits[%d] = %x\n", i, val_array[i].avalbits);
io_printf(" bvalbits[%d] = %x\n", i, val_array[i].bvalbits);
}
break;
}
io_printf("\n");
return(0);
}
/*********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -