Exemple #1
0
// Value related functions
int VhpiLogicSignalObjHdl::set_signal_value(long value)
{
    switch (m_value.format) {
        case vhpiEnumVal:
        case vhpiLogicVal: {
            m_value.value.enumv = value ? vhpi1 : vhpi0;
            break;
        }

        case vhpiEnumVecVal:
        case vhpiLogicVecVal: {
            int i;
            for (i=0; i<m_num_elems; i++)
                m_value.value.enumvs[m_num_elems-i-1] = value&(1<<i) ? vhpi1 : vhpi0;

            m_value.numElems = m_num_elems;
            break;
        }

        default: {
            LOG_ERROR("VHPI: Unable to set a std_logic signal with a raw value");
            return -1;
        }
    }

    if (vhpi_put_value(GpiObjHdl::get_handle<vhpiHandleT>(), &m_value, vhpiDepositPropagate)) {
        check_vhpi_error();
        return -1;
    }

    return 0;
}
Exemple #2
0
const char* VhpiSignalObjHdl::get_signal_value_binstr(void)
{
    vhpi_get_value(GpiObjHdl::get_handle<vhpiHandleT>(), &m_binvalue);
    check_vhpi_error();

    return m_binvalue.value.str;
}
Exemple #3
0
// Value related functions
int VhpiSignalObjHdl::set_signal_value(int value)
{
    switch (m_value.format) {
        case vhpiEnumVal:
        case vhpiLogicVal: {
            m_value.value.enumv = value ? vhpi1 : vhpi0;
            break;
        }

        case vhpiEnumVecVal:
        case vhpiLogicVecVal: {
            unsigned int i;
            for (i=0; i<m_size; i++)
                m_value.value.enumvs[m_size-i-1] = value&(1<<i) ? vhpi1 : vhpi0;

            break;
        }

        default: {
            LOG_CRITICAL("VHPI type of object has changed at runtime: ABORTING");
        }
    }
    vhpi_put_value(GpiObjHdl::get_handle<vhpiHandleT>(), &m_value, vhpiForcePropagate);
    check_vhpi_error();
    return 0;
}
Exemple #4
0
int VhpiCbHdl::arm_callback(void)
{
    int ret = 0;
    vhpiStateT cbState;

    if (m_state == GPI_PRIMED)
        return 0;

    /* Do we already have a handle, if so and it is disabled then
       just re-enable it */

    if (get_handle<vhpiHandleT>()) {
        cbState = (vhpiStateT)vhpi_get(vhpiStateP, get_handle<vhpiHandleT>());
        if (vhpiDisable == cbState) {
            if (vhpi_enable_cb(get_handle<vhpiHandleT>())) {
                check_vhpi_error();
                goto error;
            }
        }
    } else {

        vhpiHandleT new_hdl = vhpi_register_cb(&cb_data, vhpiReturnCb);

        if (!new_hdl) {
            check_vhpi_error();
            LOG_ERROR("VHPI: Unable to register callback a handle for VHPI type %s(%d)",
                         m_impl->reason_to_string(cb_data.reason), cb_data.reason);
            goto error;
        }

        cbState = (vhpiStateT)vhpi_get(vhpiStateP, new_hdl);
        if (vhpiEnable != cbState) {
            LOG_ERROR("VHPI ERROR: Registered callback isn't enabled! Got %d\n", cbState);
            goto error;
        }

        m_obj_hdl = new_hdl;
    }
    m_state = GPI_PRIMED;

    return ret;

error:
    m_state = GPI_FREE;
    return -1;
}
Exemple #5
0
int VhpiLogicSignalObjHdl::set_signal_value(std::string &value)
{
    switch (m_value.format) {
        case vhpiEnumVal:
        case vhpiLogicVal: {
            m_value.value.enumv = chr2vhpi(value.c_str()[0]);
            break;
        }

        case vhpiEnumVecVal:
        case vhpiLogicVecVal: {
            int len = value.length();

            // Since we may not get the numElems correctly from the sim and have to infer it
            // we also need to set it here as well each time.

            m_value.numElems = len;

            if (len > m_num_elems) {
                LOG_DEBUG("VHPI: Attempt to write string longer than (%s) signal %d > %d",
                          m_name.c_str(), len, m_num_elems);
                m_value.numElems = m_num_elems;
            }

            std::string::iterator iter;

            int i = 0;
            for (iter = value.begin();
                 (iter != value.end()) && (i < m_num_elems);
                 iter++, i++) {
                m_value.value.enumvs[i] = chr2vhpi(*iter);
            }

            // Fill bits at the end of the value to 0's
            for (i = len; i < m_num_elems; i++) {
                m_value.value.enumvs[i] = vhpi0;
            }

            break;
        }

        default: {
           LOG_ERROR("VHPI: Unable to set a std_logic signal with a raw value");
           return -1;
        }
    }

    if (vhpi_put_value(GpiObjHdl::get_handle<vhpiHandleT>(), &m_value, vhpiDepositPropagate)) {
        check_vhpi_error();
        return -1;
    }

    return 0;
}
Exemple #6
0
double VhpiSignalObjHdl::get_signal_value_real(void)
{
    m_value.format = vhpiRealVal;
    m_value.numElems = 1;
    m_value.bufSize = sizeof(double);

    if (vhpi_get_value(GpiObjHdl::get_handle<vhpiHandleT>(), &m_value)) {
        check_vhpi_error();
        LOG_ERROR("failed to get real value");
    }
    return m_value.value.real;
}
Exemple #7
0
int VhpiSignalObjHdl::initialise(std::string &name) {
    // Determine the type of object, either scalar or vector
    m_value.format = vhpiObjTypeVal;
    m_value.bufSize = 0;
    m_value.value.str = NULL;

    vhpi_get_value(GpiObjHdl::get_handle<vhpiHandleT>(), &m_value);
    check_vhpi_error();

    switch (m_value.format) {
        case vhpiEnumVal:
        case vhpiLogicVal: {
            m_value.value.enumv = vhpi0;
            break;
        }

        case vhpiEnumVecVal:
        case vhpiLogicVecVal: {
            m_size = vhpi_get(vhpiSizeP, GpiObjHdl::get_handle<vhpiHandleT>());
            m_value.bufSize = m_size*sizeof(vhpiEnumT); 
            m_value.value.enumvs = (vhpiEnumT *)malloc(m_value.bufSize);
            if (!m_value.value.enumvs) {
                LOG_CRITICAL("Unable to alloc mem for write buffer: ABORTING");
            }

            break;
        }

        default: {
            LOG_ERROR("Unable to determine property for %s (%d) format object",
                         ((VhpiImpl*)GpiObjHdl::m_impl)->format_to_string(m_value.format), m_value.format);
        }
    }

    /* We also alloc a second value member for use with read string operations */
    m_binvalue.format = vhpiBinStrVal;
    m_binvalue.bufSize = 0;
    m_binvalue.value.str = NULL;

    int new_size = vhpi_get_value(GpiObjHdl::get_handle<vhpiHandleT>(), &m_binvalue);

    m_binvalue.bufSize = new_size*sizeof(vhpiCharT) + 1;
    m_binvalue.value.str = (vhpiCharT *)calloc(m_binvalue.bufSize, m_binvalue.bufSize);

    if (!m_value.value.str) {
        LOG_CRITICAL("Unable to alloc mem for read buffer: ABORTING");
    }

    GpiObjHdl::initialise(name);

    return 0;
}
Exemple #8
0
long VhpiSignalObjHdl::get_signal_value_long(void)
{
    vhpiValueT value;
    value.format = vhpiIntVal;
    value.numElems = 0;

    if (vhpi_get_value(GpiObjHdl::get_handle<vhpiHandleT>(), &value)) {
        check_vhpi_error();
        LOG_ERROR("failed to get long value");
    }

    return value.value.intg;
}
Exemple #9
0
/**
 * @name    Find the root handle
 * @brief   Find the root handle using a optional name
 *
 * Get a handle to the root simulator object.  This is usually the toplevel.
 *
 * FIXME: In VHPI we always return the first root instance
 * 
 * TODO: Investigate possibility of iterating and checking names as per VHPI
 * If no name is defined, we return the first root instance.
 *
 * If name is provided, we check the name against the available objects until
 * we find a match.  If no match is found we return NULL
 */
gpi_sim_hdl gpi_get_root_handle(const char* name)
{
    FENTER
    vhpiHandleT root;
    vhpiHandleT dut;
    gpi_sim_hdl rv;

    root = vhpi_handle(vhpiRootInst, NULL);
    check_vhpi_error();

    if (!root) {
        LOG_ERROR("VHPI: Attempting to get the root handle failed");
        FEXIT
        return NULL;
    }
Exemple #10
0
int VhpiSignalObjHdl::set_signal_value(std::string &value)
{
    switch (m_value.format) {
        case vhpiEnumVal:
        case vhpiLogicVal: {
            m_value.value.enumv = chr2vhpi(value.c_str()[0]);
            break;
        }

        case vhpiEnumVecVal:
        case vhpiLogicVecVal: {

            unsigned int len = value.length();

            if (len > m_size)  {
                LOG_ERROR("VHPI: Attempt to write string longer than signal %d > %d",
                          len, m_size);
                return -1;
            }

            std::string::iterator iter;

            unsigned int i = 0;
            for (iter = value.begin();
                 iter != value.end();
                 iter++, i++) {
                m_value.value.enumvs[i] = chr2vhpi(*iter);
            }

            // Fill bits at the end of the value to 0's
            for (i = len; i < m_size; i++) {
                m_value.value.enumvs[i] = vhpi0;
            }

            break;
        }

        default: {
           LOG_CRITICAL("VHPI type of object has changed at runtime: ABORTING");
        }
    }

    vhpi_put_value(GpiObjHdl::get_handle<vhpiHandleT>(), &m_value, vhpiForcePropagate);
    check_vhpi_error();
    return 0;
}
Exemple #11
0
// Value related functions
int VhpiSignalObjHdl::set_signal_value(long value)
{
    switch (m_value.format) {
        case vhpiEnumVecVal:
        case vhpiLogicVecVal: {
            int i;
            for (i=0; i<m_num_elems; i++)
                m_value.value.enumvs[m_num_elems-i-1] = value&(1<<i);

            // Since we may not get the numElems correctly from the sim and have to infer it
            // we also need to set it here as well each time.

            m_value.numElems = m_num_elems;
            break;
        }

        case vhpiLogicVal:
        case vhpiEnumVal: {
            m_value.value.enumv = value;
            break;
        }

        case vhpiIntVal: {
            m_value.value.intg = value;
            break;
        }

        case vhpiCharVal: {
            m_value.value.ch = value;
            break;
        }

        default: {
            LOG_ERROR("VHPI: Unable to handle this format type %s",
                      ((VhpiImpl*)GpiObjHdl::m_impl)->format_to_string(m_value.format));
            return -1;
        }
    }
    if (vhpi_put_value(GpiObjHdl::get_handle<vhpiHandleT>(), &m_value, vhpiDepositPropagate)) {
        check_vhpi_error();
        return -1;
    }

    return 0;
}
Exemple #12
0
int VhpiCbHdl::cleanup_callback(void)
{
    /* For non timer callbacks we disable rather than remove */
    int ret = 0;
    if (m_state == GPI_FREE)
        return 0;

    vhpiStateT cbState = (vhpiStateT)vhpi_get(vhpiStateP, get_handle<vhpiHandleT>());
    if (vhpiEnable == cbState) {
        ret = vhpi_disable_cb(get_handle<vhpiHandleT>());
        m_state = GPI_FREE;
    }

    if (ret)
        check_vhpi_error();

    return 0;
}
Exemple #13
0
const char* VhpiSignalObjHdl::get_signal_value_str(void)
{
    switch (m_value.format) {
        case vhpiStrVal: {
            int ret = vhpi_get_value(GpiObjHdl::get_handle<vhpiHandleT>(), &m_value);
            if (ret) {
                check_vhpi_error();
                LOG_ERROR("Size of m_value.value.str was not large enough req=%d have=%d for type %s",
                          ret,
                          m_value.bufSize,
                          ((VhpiImpl*)GpiObjHdl::m_impl)->format_to_string(m_value.format));
            }
            break;
        }
        default: {
            LOG_ERROR("Reading strings not valid for this handle");
            return "";
        }
    }
    return m_value.value.str;
}
Exemple #14
0
const char* VhpiSignalObjHdl::get_signal_value_binstr(void)
{
    switch (m_value.format) {
        case vhpiRealVal:
            LOG_INFO("get_signal_value_binstr not supported for %s",
                      ((VhpiImpl*)GpiObjHdl::m_impl)->format_to_string(m_value.format));
            return "";
        default: {
            /* Some simulators do not support BinaryValues so we fake up here for them */
            int ret = vhpi_get_value(GpiObjHdl::get_handle<vhpiHandleT>(), &m_binvalue);
            if (ret) {
                check_vhpi_error();
                LOG_ERROR("Size of m_binvalue.value.str was not large enough req=%d have=%d for type %s",
                          ret,
                          m_binvalue.bufSize,
                          ((VhpiImpl*)GpiObjHdl::m_impl)->format_to_string(m_value.format));
            }

            return m_binvalue.value.str;
        }
    }
}
Exemple #15
0
static inline int __gpi_register_cb(p_vhpi_cb_user_data user, vhpiCbDataT *cb_data)
{
    /* If the user data already has a callback handle then deregister
     * before getting the new one
     */
    vhpiHandleT new_hdl = vhpi_register_cb(cb_data, vhpiReturnCb);
    int ret = 0;

    if (!new_hdl) {
        LOG_CRITICAL("VHPI: Unable to register callback a handle for VHPI type %s(%d)",
                     vhpi_reason_to_string(cb_data->reason), cb_data->reason);
        check_vhpi_error();
        ret = -1;
    }

    if (user->cb_hdl != NULL) {
        printf("VHPI: Attempt to register a callback that's already registered...\n");
        gpi_deregister_callback(&user->gpi_hdl);
    }

    user->cb_hdl = new_hdl;

    return ret;
}
Exemple #16
0
int VhpiSignalObjHdl::set_signal_value(double value)
{
    switch (m_value.format) {
        case vhpiRealVal:
            m_value.numElems = 1;
            m_value.bufSize = sizeof(value);
            m_value.value.real = value;
            break;

        default: {
            LOG_ERROR("VHPI: Unable to set a Real handle this format type %s",
                      ((VhpiImpl*)GpiObjHdl::m_impl)->format_to_string(m_value.format));
            return -1;
        }

    }

    if (vhpi_put_value(GpiObjHdl::get_handle<vhpiHandleT>(), &m_value, vhpiDepositPropagate)) {
        check_vhpi_error();
        return -1;
    }

    return 0;
}