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

📄 evtsetup.c

📁 ngspice又一个电子CAD仿真软件代码.功能更全
💻 C
📖 第 1 页 / 共 2 页
字号:
/*============================================================================FILE    EVTsetup.cMEMBER OF process XSPICECopyright 1991Georgia Tech Research CorporationAtlanta, Georgia 30332All Rights ReservedPROJECT A-8503AUTHORS    9/12/91  Bill KuhnMODIFICATIONS    <date> <person name> <nature of modifications>SUMMARY    This file contains function EVTsetup which clears/allocates the    event-driven queues and data structures immediately prior to a new    analysis.  In addition, it places entries in the job list so that    results data from multiple analysis can be retrieved similar to    SPICE3C1 saving multiple 'plots'.INTERFACES    int EVTsetup(CKTcircuit *ckt)REFERENCED FILES    None.NON-STANDARD FEATURES    None.============================================================================*/#include <stdio.h>#include <string.h>#include "ngspice.h"//#include "misc.h"#include "cktdefs.h"#include "sperror.h"//#include "util.h"#include "mif.h"#include "evt.h"#include "evtudn.h"#include "mifproto.h"#include "evtproto.h"static int EVTsetup_queues(CKTcircuit *ckt);static int EVTsetup_data(CKTcircuit *ckt);static int EVTsetup_jobs(CKTcircuit *ckt);static int EVTsetup_load_ptrs(CKTcircuit *ckt);/* Allocation macros with built-in check for out-of-memory *//* Adapted from SPICE 3C1 code in CKTsetup.c */#define CKALLOC(var,size,type) \    if(size) { \        if(!(var = (void *) MALLOC((size) * sizeof(type)))) \            return(E_NOMEM); \    }#define CKREALLOC(var,size,type) \    if((size) == 1) { \        if(!(var = (void *) MALLOC((size) * sizeof(type)))) \            return(E_NOMEM); \    } else if((size) > 1) { \        if(!(var = (void *) REALLOC((void *) (var), (size) * sizeof(type)))) \            return(E_NOMEM); \    }/*EVTsetupThis function clears/allocates the event-driven queues and data structuresimmediately prior to a new analysis.  In addition, it places entriesin the job list so that results data from multiple analysis can beretrieved similar to SPICE3C1 saving multiple 'plots'.*/int EVTsetup(    CKTcircuit *ckt)   /* The circuit structure */{    int err;    /* Exit immediately if no event-driven instances in circuit */    if(ckt->evt->counts.num_insts == 0)        return(OK);    /* Clear the inst, node, and output queues, and initialize the to_call */    /* elements in the instance queue to call all event-driven instances */    err = EVTsetup_queues(ckt);    if(err)        return(err);    /* Allocate and initialize the node, state, message, and statistics data */    err = EVTsetup_data(ckt);    if(err)        return(err);    /* Set the job pointers to the allocated results, states, messages, */    /* and statistics so that data will be accessable after run */    err = EVTsetup_jobs(ckt);    if(err)        return(err);    /* Setup the pointers in the MIFinstance structure for inputs, outputs, */    /* and total loads */    err = EVTsetup_load_ptrs(ckt);    if(err)        return(err);    /* Initialize additional event data */    g_mif_info.circuit.evt_step = 0.0;    /* Return OK */    return(OK);}/*EVTsetup_queuesThis function clears the event-driven queues in preparation fora new simulation.*/static int EVTsetup_queues(    CKTcircuit *ckt)         /* The circuit structure */{    int i;    int num_insts;    int num_nodes;    int num_outputs;    Evt_Inst_Queue_t    *inst_queue;    Evt_Node_Queue_t    *node_queue;    Evt_Output_Queue_t  *output_queue;    Evt_Inst_Event_t    *inst_event;    Evt_Output_Event_t  *output_event;    void                *ptr;    /* ************************ */    /* Clear the instance queue */    /* ************************ */    num_insts = ckt->evt->counts.num_insts;    inst_queue = &(ckt->evt->queue.inst);    for(i = 0; i < num_insts; i++) {        inst_event = inst_queue->head[i];        while(inst_event) {            ptr = inst_event;            inst_event = inst_event->next;            FREE(ptr);        }        inst_event = inst_queue->free[i];        while(inst_event) {            ptr = inst_event;            inst_event = inst_event->next;            FREE(ptr);        }        inst_queue->head[i] = NULL;        inst_queue->current[i] = &(inst_queue->head[i]);        inst_queue->last_step[i] = &(inst_queue->head[i]);        inst_queue->free[i] = NULL;    }    inst_queue->next_time = 0.0;    inst_queue->last_time = 0.0;    inst_queue->num_modified = 0;    inst_queue->num_pending = 0;    inst_queue->num_to_call = 0;    for(i = 0; i < num_insts; i++) {        inst_queue->modified[i] = MIF_FALSE;        inst_queue->pending[i] = MIF_FALSE;        inst_queue->to_call[i] = MIF_FALSE;    }    /* ******************** */    /* Clear the node queue */    /* ******************** */    num_nodes = ckt->evt->counts.num_nodes;    node_queue = &(ckt->evt->queue.node);    node_queue->num_changed = 0;    node_queue->num_to_eval = 0;    for(i = 0; i < num_nodes; i++) {        node_queue->changed[i] = MIF_FALSE;        node_queue->to_eval[i] = MIF_FALSE;    }    /* ********************** */    /* Clear the output queue */    /* ********************** */    num_outputs = ckt->evt->counts.num_outputs;    output_queue = &(ckt->evt->queue.output);    for(i = 0; i < num_outputs; i++) {        output_event = output_queue->head[i];        while(output_event) {            ptr = output_event;            output_event = output_event->next;            FREE(ptr);        }        output_event = output_queue->free[i];        while(output_event) {            ptr = output_event;            output_event = output_event->next;            FREE(ptr);        }        output_queue->head[i] = NULL;        output_queue->current[i] = &(output_queue->head[i]);        output_queue->last_step[i] = &(output_queue->head[i]);        output_queue->free[i] = NULL;    }    output_queue->next_time = 0.0;    output_queue->last_time = 0.0;    output_queue->num_modified = 0;    output_queue->num_pending = 0;    output_queue->num_changed = 0;    for(i = 0; i < num_outputs; i++) {        output_queue->modified[i] = MIF_FALSE;        output_queue->pending[i] = MIF_FALSE;        output_queue->changed[i] = MIF_FALSE;    }    return(OK);}/*EVTsetup_dataThis function sets up the event-driven node, state, andmessage data runtime structures in preparation fora new simulation.*/static int EVTsetup_data(    CKTcircuit *ckt)       /* The circuit structure */{    Evt_Data_t  *data;    int         i;    int         j;    int         num_insts;    int         num_ports;    int         num_nodes;    int         udn_index;

⌨️ 快捷键说明

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