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

📄 evtload.c

📁 ngspice又一个电子CAD仿真软件代码.功能更全
💻 C
📖 第 1 页 / 共 2 页
字号:
    return(OK);}/*EVTcreate_stateThis function creates a new state storage area for a particular instanceduring an event-driven simulation.  New states must be created sothat old states are saved and can be accessed by code models in thefuture.  The new state is initialized to the previous state value.*/static void EVTcreate_state(    CKTcircuit  *ckt,         /* The circuit structure */    int         inst_index)   /* The instance to create state for */{    int                 i;    int                 total_size;    Evt_State_Data_t    *state_data;    Evt_State_t         *new_state;    Evt_State_t         *prev_state;    char                *from;    char                *to;    /* Get variables for fast access */    state_data = ckt->evt->data.state;    /* Exit immediately if no states on this instance */    if(state_data->desc[inst_index] == NULL)        return;    /* Get size of state block to be allocated */    total_size = state_data->total_size[inst_index];    /* Allocate a new state for the instance */    if(state_data->free[inst_index]) 	{        new_state = state_data->free[inst_index];        state_data->free[inst_index] = new_state->next;    }    else 	{		        new_state = (void *) MALLOC(sizeof(Evt_State_t));        new_state->block = (void *) MALLOC(total_size);    }    /* Splice the new state into the state data linked list */    /* and update the tail pointer */    prev_state = *(state_data->tail[inst_index]);    prev_state->next = new_state;    new_state->prev = prev_state;    state_data->tail[inst_index] = &(prev_state->next);    /* Copy the old state to the new state and set the step */    from = prev_state->block;    to = new_state->block;    for(i = 0; i < total_size; i++)        to[i] = from[i];    new_state->step = g_mif_info.circuit.evt_step;    /* Mark that the state data on the instance has been modified */    if(! state_data->modified[inst_index]) {        state_data->modified[inst_index] = MIF_TRUE;        state_data->modified_index[(state_data->num_modified)++] = inst_index;    }}/*EVTcreate_output_eventThis function creates a new output event.*/static void EVTcreate_output_event(    CKTcircuit  *ckt,           /* The circuit structure */    int         node_index,     /* The node type port is on */    int         output_index,   /* The output index for this port */    void        **value_ptr)    /* The event created */{    int                 udn_index;    Evt_Node_Info_t     **node_table;    Evt_Output_Queue_t  *output_queue;    Evt_Output_Event_t  *event;    /* Check the output queue free list and use the structure */    /* at the head of the list if non-null.  Otherwise, create a new one. */    output_queue = &(ckt->evt->queue.output);    if(output_queue->free[output_index]) {        *value_ptr = output_queue->free[output_index]->value;    }    else {        /* Create a new event */        event = (void *) MALLOC(sizeof(Evt_Output_Event_t));        event->next = NULL;        /* Initialize the value */        node_table = ckt->evt->info.node_table;        udn_index = node_table[node_index]->udn_index;        (*(g_evt_udn_info[udn_index]->create)) (&(event->value));        /* Put the event onto the free list and return the value pointer */        output_queue->free[output_index] = event;        *value_ptr = event->value;    }}/*EVTadd_msgThis function records a message output by a code model into themessage results data structure.*/static void EVTadd_msg(    CKTcircuit  *ckt,          /* The circuit structure */    int         port_index,    /* The port to add message to */    char        *msg_text)     /* The message text */{    Evt_Msg_Data_t      *msg_data;    Evt_Msg_t           **msg_ptr;    Evt_Msg_t           *msg;    /* Get pointers for fast access */    msg_data = ckt->evt->data.msg;    msg_ptr = msg_data->tail[port_index];    /* Set pointer to location at which to add, and update tail */    if(*msg_ptr != NULL) {        msg_ptr = &((*msg_ptr)->next);        msg_data->tail[port_index] = msg_ptr;    }    /* Add a new entry in the list of messages for this port */    if(msg_data->free[port_index]) {        *msg_ptr = msg_data->free[port_index];        msg_data->free[port_index] = msg_data->free[port_index]->next;    }    else {        *msg_ptr = (void *) MALLOC(sizeof(Evt_Msg_t));    }    /* Fill in the values */    msg = *msg_ptr;    msg->next = NULL;    if((ckt->CKTmode & MODEDCOP) == MODEDCOP)        msg->op = MIF_TRUE;    else        msg->step = g_mif_info.circuit.evt_step;    msg->text = MIFcopy(msg_text);    /* Update the modified indexes */    if(g_mif_info.circuit.anal_type == MIF_TRAN) {        if(! msg_data->modified[port_index]) {            msg_data->modified[port_index] = MIF_TRUE;            msg_data->modified_index[(msg_data->num_modified)++] = port_index;        }    }}/*EVTprocess_outputThis function processes an event-driven output produced by a codemodel.  If transient analysis mode, the event is placed into theoutput queue according to its (non-zero) delay.  If DC analysis,the event is processed immediately.*/static void EVTprocess_output(    CKTcircuit     *ckt,          /* The circuit structure */    Mif_Boolean_t  changed,       /* Has output changed? */    int            output_index,  /* The output of interest */    Mif_Boolean_t  invert,        /* Does output need to be inverted? */    double         delay)         /* The output delay in transient analysis */{    int                 num_outputs;    int                 node_index;    int                 udn_index;    int                 output_subindex;    Evt_Output_Info_t   **output_table;    Evt_Node_Info_t     **node_table;    Evt_Node_t          *rhs;    Evt_Node_t          *rhsold;    Evt_Output_Queue_t  *output_queue;    Evt_Output_Event_t  *output_event;    Mif_Boolean_t       equal;    output_queue = &(ckt->evt->queue.output);    output_table = ckt->evt->info.output_table;    node_table = ckt->evt->info.node_table;    node_index = output_table[output_index]->node_index;    udn_index = node_table[node_index]->udn_index;    /* if transient analysis, just put the output event on the queue */    /* to be processed at a later time */    if(g_mif_info.circuit.anal_type == MIF_TRAN) {        /* If model signaled that output was not posted, */        /* leave the event struct on the free list and return */        if((! changed) || (delay <= 0.0)) {            if(changed && (delay <= 0.0))                printf("\nERROR - Output delay <= 0 not allowed - output ignored!\n");            return;        }        /* Remove the (now used) struct from the head of the free list */        output_event = output_queue->free[output_index];        output_queue->free[output_index] = output_event->next;        /* Invert the output value if necessary */        if(invert)            (*(g_evt_udn_info[udn_index]->invert))                (output_event->value);        /* Add it to the queue */        EVTqueue_output(ckt, output_index, udn_index, output_event,                        g_mif_info.circuit.evt_step,                        g_mif_info.circuit.evt_step + delay);        return;    }    /* If not transient analysis, process immediately. */    /* Determine if output has changed from rhsold value */    /* and put entry in output queue changed list if so */    else {        /* If model signaled that output was not posted, */        /* just return */        if(! changed)            return;/*        if(delay > 0.0)            printf("\nWARNING - Non-zero output delay not allowed in DCOP - delay ignored!\n");*/        rhs = ckt->evt->data.node->rhs;        rhsold = ckt->evt->data.node->rhsold;        /* Determine if changed */        num_outputs = node_table[node_index]->num_outputs;        if(num_outputs > 1) {            output_subindex = output_table[output_index]->output_subindex;            if(invert)                (*(g_evt_udn_info[udn_index]->invert))                    (rhs[node_index].output_value[output_subindex]);            (*(g_evt_udn_info[udn_index]->compare))                    (rhs[node_index].output_value[output_subindex],                    rhsold[node_index].output_value[output_subindex],                    &equal);            if(! equal) {                (*(g_evt_udn_info[udn_index]->copy))                    (rhs[node_index].output_value[output_subindex],                    rhsold[node_index].output_value[output_subindex]);            }        }        else {            if(invert)                (*(g_evt_udn_info[udn_index]->invert))                    (rhs[node_index].node_value);            (*(g_evt_udn_info[udn_index]->compare))                    (rhs[node_index].node_value,                    rhsold[node_index].node_value,                    &equal);            if(! equal) {                (*(g_evt_udn_info[udn_index]->copy))                    (rhs[node_index].node_value,                    rhsold[node_index].node_value);            }        }        /* If changed, put in changed list of output queue */        if(! equal) {            if(! output_queue->changed[output_index]) {                output_queue->changed[output_index] = MIF_TRUE;                output_queue->changed_index[(output_queue->num_changed)++] =                        output_index;            }        }        return;    } /* end else process immediately */}

⌨️ 快捷键说明

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