📄 cfunc.mod
字号:
s = base_address; /** Retrieve each token, analyze, and **/ /** store the timepoint and bit information **/ for (j=0; j<(info->width + 1); j++) { token = CNVget_token(&s, &type); if ( 0 == j ) { /* obtain timepoint value... */ /* convert to a floating point number... */ cnv_get_spice_value(token,&number); timepoints[i] = number; /* provided this is not the first timepoint to be written... */ if ( 0 != i ) { /* if current timepoint value is not greater than the previous value, then return with an error message... */ if ( timepoints[i] <= timepoints[i-1] ) { return 1; } } } else { /* obtain each bit value & set bits entry */ /* preset this bit location */ bit_value = 12; if (0 == strcmp(token,"0s")) bit_value = 0; if (0 == strcmp(token,"1s")) bit_value = 1; if (0 == strcmp(token,"Us")) bit_value = 2; if (0 == strcmp(token,"0r")) bit_value = 3; if (0 == strcmp(token,"1r")) bit_value = 4; if (0 == strcmp(token,"Ur")) bit_value = 5; if (0 == strcmp(token,"0z")) bit_value = 6; if (0 == strcmp(token,"1z")) bit_value = 7; if (0 == strcmp(token,"Uz")) bit_value = 8; if (0 == strcmp(token,"0u")) bit_value = 9; if (0 == strcmp(token,"1u")) bit_value = 10; if (0 == strcmp(token,"Uu")) bit_value = 11; /* if this bit was not recognized, return with an error */ if (12 == bit_value) { return 1; } else { /* need to store this value in the bits[] array */ /* obtain offset value from word_number, word_width & bit_number */ int1 = i * info->width + (j-1); double1 = int1 / 4.0; modf(double1, &double2); bit_index = double2; bit_offset = int1 - (double2 * 4.0); /* retrieve entire base_address bits integer... */ base = bits[bit_index]; /* for each offset, mask off the bits and store values */ cm_source_mask_and_store(&base,bit_offset,bit_value); /* store modified base value */ bits[bit_index] = base; } } } i++; } s = temp; } } return 0;} /*==============================================================================FUNCTION cm_d_source()AUTHORS 13 Jun 1991 Jeffrey P. MurrayMODIFICATIONS 8 Aug 1991 Jeffrey P. Murray 30 Sep 1991 Jeffrey P. MurraySUMMARY This function implements the d_source code model.INTERFACES FILE ROUTINE CALLED CMmacros.h cm_message_send(); CMevt.c void *cm_event_alloc() void *cm_event_get_ptr() int cm_event_queue()RETURNED VALUE Returns inputs and outputs via ARGS structure.GLOBAL VARIABLES NONENON-STANDARD FEATURES NONE==============================================================================*//*=== CM_D_SOURCE ROUTINE ==============*//************************************************* The following is the model for the ** digital source for the ** ATESSE Version 2.0 system. ** ** Created 6/13/91 J.P.Murray *************************************************/void cm_d_source(ARGS) { int i, /* generic loop counter index */ err, /* integer for storage of error status */ test, /* testing integer */ dummy; /* temp holding variable */ short *bits, /* the storage array for the output bit representations... this will have size equal to (width * depth)/4, since one short will hold four 12-state bit descriptions. */ *bits_old; /* the storage array for old bit values */ double *timepoints, /* the storage array for the timepoints...this will have size equal to "depth" */ *timepoints_old, /* the storage array for the old timepoints */ test_double, /* test variable for doubles */ double_dummy; /* fake holding double */ FILE *source; /* pointer to the source.in input vector file */ Source_Table_Info_t *info, /* storage location for source index and depth info. */ *info_old; /* storage location for old info */ Digital_t out; /* storage for each output bit */ char temp[MAX_STRING_SIZE], /* holding string variable for testing input from source.in */ *s; /* main string variable */ char *loading_error = "\n***ERROR***\nD_SOURCE: source.in file was not read successfully. \n"; /**** Setup required state variables ****/ if(INIT) { /* initial pass */ /*** open file and count the number of vectors in it ***/ source = fopen( PARAM(input_file), "r"); /* increment counter if not a comment until EOF reached... */ i = 0; if (source) { s = temp; while ( fgets(s,MAX_STRING_SIZE,source) != NULL) { if ( '*' != s[0] ) { while(isspace(*s) || (*s == '*')) (s)++; if ( *s != '\0' ) i++; } s = temp; } } /*** allocate storage for *index, *bits & *timepoints ***/ info = info_old = (Source_Table_Info_t *) cm_event_alloc(0,sizeof(Source_Table_Info_t)); modf( (PORT_SIZE(out) * i / 4), &double_dummy ); dummy = double_dummy + 1; bits = bits_old = (short *) cm_event_alloc(1,(dummy * sizeof(short))); timepoints = timepoints_old = (double *) cm_event_alloc(2,i * sizeof(double)); /**** Get all pointers again (to avoid realloc problems) ****/ info = info_old = (Source_Table_Info_t *) cm_event_get_ptr(0,0); bits = bits_old = (short *) cm_event_get_ptr(1,0); timepoints = timepoints_old = (double *) cm_event_get_ptr(2,0); /* Initialize info values... */ info->index = 0; info->depth = i; /* Retrieve width of the source */ info->width = PORT_SIZE(out); /* Initialize *bits & *timepoints to zero */ for (i=0; i<dummy; i++) bits[i] = 0; for (i=0; i<info->depth; i++) timepoints[i] = 0; /* Send file pointer and the two array storage pointers */ /* to "cm_read_source()". This will return after */ /* reading the contents of source.in, and if no */ /* errors have occurred, the "*bits" and "*timepoints" */ /* vectors will be loaded and the width and depth */ /* values supplied. */ if (source) { rewind(source); err = cm_read_source(source,bits,timepoints,info); } else { err=1; } if (err) { /* problem occurred in load...send error msg. */ cm_message_send(loading_error); /* Reset *bits & *timepoints to zero */ for (i=0; i<(test = (info->width*info->depth)/4); i++) bits[i] = 0; for (i=0; i<info->depth; i++) timepoints[i] = 0; } /* close source file */ if (source) fclose(source); } else { /*** Retrieve previous values ***/ /** Retrieve info... **/ info = (Source_Table_Info_t *) cm_event_get_ptr(0,0); info_old = (Source_Table_Info_t *) cm_event_get_ptr(0,1); /* Set old values to new... */ info->index = info_old->index; info->depth = info_old->depth; info->width = info_old->width; /** Retrieve bits... **/ bits = (short *) cm_event_get_ptr(1,0); bits_old = (short *) cm_event_get_ptr(1,1); /* Set old values to new... */ modf( (info->width * info->depth / 4), &double_dummy ); dummy = double_dummy + 1; for (i=0; i<dummy; i++) bits[i] = bits_old[i]; /** Retrieve timepoints... **/ timepoints = (double *) cm_event_get_ptr(2,0); timepoints_old = (double *) cm_event_get_ptr(2,1); /* Set old values to new... */ for (i=0; i<info->depth; i++) timepoints[i] = timepoints_old[i]; } /*** For the case of TIME==0.0, set special breakpoint ***/ if ( 0.0 == TIME ) { test_double = timepoints[info->index]; if ( 0.0 == test_double && info->depth > 0 ) { /* Set DC value */ /* reset current breakpoint */ test_double = timepoints[info->index]; cm_event_queue( test_double ); /* Output new values... */ for (i=0; i<info->width; i++) { /* retrieve output value */ cm_get_source_value(info->width,i,info->index,bits,&out); OUTPUT_STATE(out[i]) = out.state; OUTPUT_STRENGTH(out[i]) = out.strength; } /* increment breakpoint */ (info->index)++; /* set next breakpoint as long as depth has not been exceeded */ if ( info->index < info->depth ) { test_double = timepoints[info->index] - 1.0e-10; cm_event_queue( test_double ); } } else { /* Set breakpoint for first time index */ /* set next breakpoint as long as depth has not been exceeded */ if ( info->index < info->depth ) { test_double = timepoints[info->index] - 1.0e-10; cm_event_queue( test_double ); } for(i=0; i<info->width; i++) { OUTPUT_STATE(out[i]) = UNKNOWN; OUTPUT_STRENGTH(out[i]) = UNDETERMINED; } } } else { /*** Retrieve last index value and branch to appropriate *** *** routine based on the last breakpoint's relationship *** *** to the current time value. ***/ test_double = timepoints[info->index] - 1.0e-10; if ( TIME < test_double ) { /* Breakpoint has not occurred */ /** Output hasn't changed...do nothing this time. **/ for (i=0; i<info->width; i++) { OUTPUT_CHANGED(out[i]) = FALSE; } if ( info->index < info->depth ) { test_double = timepoints[info->index] - 1.0e-10; cm_event_queue( test_double ); } } else /* Breakpoint has been reached or exceeded */ if ( TIME == test_double ) { /* Breakpoint reached */ /* reset current breakpoint */ test_double = timepoints[info->index] - 1.0e-10; cm_event_queue( test_double ); /* Output new values... */ for (i=0; i<info->width; i++) { /* retrieve output value */ cm_get_source_value(info->width,i,info->index,bits,&out); OUTPUT_STATE(out[i]) = out.state; OUTPUT_DELAY(out[i]) = 1.0e-10; OUTPUT_STRENGTH(out[i]) = out.strength; } /* increment breakpoint */ (info->index)++; /* set next breakpoint as long as depth has not been exceeded */ if ( info->index < info->depth ) { test_double = timepoints[info->index] - 1.0e-10; cm_event_queue( test_double ); } } else { /* Last source file breakpoint has been exceeded... do not change the value of the output */ for (i=0; i<info->width; i++) { OUTPUT_CHANGED(out[i]) = FALSE; } } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -