Exemple #1
0
int VpiCbHdl::cleanup_callback(void)
{
    if (m_state == GPI_FREE)
        return 0;

    /* If the one-time callback has not come back then
     * remove it, it is has then free it. The remove is done
     * internally */

    if (m_state == GPI_PRIMED) {
        if (!m_obj_hdl) {
            LOG_CRITICAL("VPI: passed a NULL pointer : ABORTING");
        }

        if (!(vpi_remove_cb(get_handle<vpiHandle>()))) {
            LOG_CRITICAL("VPI: unbale to remove callback : ABORTING");
        }

        check_vpi_error();
    } else {
#ifndef MODELSIM
        /* This is disabled for now, causes a small leak going to put back in */
        if (!(vpi_free_object(get_handle<vpiHandle>()))) {
            LOG_CRITICAL("VPI: unbale to free handle : ABORTING");
        }
#endif
    }


    m_obj_hdl = NULL;
    m_state = GPI_FREE;

    return 0;
}
Exemple #2
0
int VpiValueCbHdl::cleanup_callback(void)
{
    if (m_state == GPI_FREE)
        return 0;

    /* This is a recurring callback so just remove when
     * not wanted */
    if (!(vpi_remove_cb(get_handle<vpiHandle>()))) {
        LOG_CRITICAL("VPI: unbale to remove callback : ABORTING");
    }

    m_obj_hdl = NULL;
    m_state = GPI_FREE;
    return 0;
}
int _mon_check_callbacks() {
    t_cb_data cb_data;
    cb_data.reason = cbEndOfSimulation;
    cb_data.cb_rtn = NULL;
    cb_data.user_data = 0;
    cb_data.value = NULL;

    vpiHandle vh = vpi_register_cb(&cb_data);
    CHECK_RESULT_NZ(vh);

    PLI_INT32 status = vpi_remove_cb(vh);
    CHECK_RESULT_NZ(status);

    return 0;
}
Exemple #4
0
static PLI_INT32
Callback(s_cb_data *data)
{
    s_vpi_time t;
    static int count = 0;

    t.type = vpiScaledRealTime;
    vpi_get_time(0, &t);

    vpi_printf("Callback @ %.1f\n", t.real);

    if (count>1) {
	vpi_printf("vpi_remove_cb returned %d @ %.1f\n",
	    (int)vpi_remove_cb(Handle), t.real);
    }

    count++;

    return 0;
}
int _mon_check_putget_str(p_cb_data cb_data) {
    static VlVpiHandle cb;
    static struct {
        VlVpiHandle scope, sig, rfr, check, verbose;
        char str[128+1];          // char per bit plus null terminator
        int type;                 // value type in .str
        union {
            PLI_INT32    integer;
            s_vpi_vecval vector[4];
        } value;                 // reference
    } data[129];
    if (cb_data) {
        // this is the callback
        static unsigned int seed = 1;
        s_vpi_time t;
        t.type = vpiSimTime;
        t.high = 0;
        t.low = 0;
        for (int i=2; i<=128; i++) {
            static s_vpi_value v;
            int words = (i+31)>>5;
            TEST_MSG("========== %d ==========\n", i);
            if (callback_count_strs) {
                // check persistance
                if (data[i].type) {
                    v.format = data[i].type;
                } else {
                    static PLI_INT32 vals[] = {vpiBinStrVal, vpiOctStrVal, vpiHexStrVal, vpiDecStrVal};
                    v.format = vals[rand_r(&seed) % ((words>2)?3:4)];
                    TEST_MSG("new format %d\n", v.format);
                }
                vpi_get_value(data[i].sig, &v);
                TEST_MSG("%s\n", v.value.str);
                if (data[i].type) {
                    CHECK_RESULT_CSTR(v.value.str, data[i].str);
                } else {
                    data[i].type = v.format;
                    strcpy(data[i].str, v.value.str);
                }
            }

            // check for corruption
            v.format = (words==1)?vpiIntVal:vpiVectorVal;
            vpi_get_value(data[i].sig, &v);
            if (v.format == vpiIntVal) {
                TEST_MSG("%08x %08x\n", v.value.integer, data[i].value.integer);
                CHECK_RESULT(v.value.integer, data[i].value.integer);
            } else {
                for (int k=0; k < words; k++) {
                    TEST_MSG("%d %08x %08x\n", k, v.value.vector[k].aval, data[i].value.vector[k].aval);
                    CHECK_RESULT_HEX(v.value.vector[k].aval, data[i].value.vector[k].aval);
                }
            }

            if (callback_count_strs & 7) {
                // put same value back - checking encoding/decoding equivalent
                v.format = data[i].type;
                v.value.str = data[i].str;
                vpi_put_value(data[i].sig, &v, &t, vpiNoDelay);
                v.format = vpiIntVal;
                v.value.integer = 1;
                //vpi_put_value(data[i].verbose, &v, &t, vpiNoDelay);
                vpi_put_value(data[i].check, &v, &t, vpiNoDelay);
            } else {
                // stick a new random value in
                unsigned int mask = ((i&31)?(1<<(i&31)):0)-1;
                if (words == 1) {
                    v.value.integer = rand_r(&seed);
                    data[i].value.integer = v.value.integer &= mask;
                    v.format = vpiIntVal;
                    TEST_MSG("new value %08x\n", data[i].value.integer);
                } else {
                    TEST_MSG("new value\n");
                    for (int j=0; j<4; j++) {
                        data[i].value.vector[j].aval = rand_r(&seed);
                        if (j==(words-1)) {
                            data[i].value.vector[j].aval &= mask;
                        }
                        TEST_MSG(" %08x\n", data[i].value.vector[j].aval);
                    }
                    v.value.vector = data[i].value.vector;
                    v.format = vpiVectorVal;
                }
                vpi_put_value(data[i].sig, &v, &t, vpiNoDelay);
                vpi_put_value(data[i].rfr, &v, &t, vpiNoDelay);
            }
            if ((callback_count_strs & 1) == 0) data[i].type = 0;
        }
        if (++callback_count_strs == callback_count_strs_max) {
            int success = vpi_remove_cb(cb);
            CHECK_RESULT_NZ(success);
        };
    } else {
        // setup and install
        for (int i=1; i<=128; i++) {