diff --git a/src/xspice/icm/digital/d_const/cfunc.mod b/src/xspice/icm/digital/d_const/cfunc.mod new file mode 100644 index 000000000..c889cad6a --- /dev/null +++ b/src/xspice/icm/digital/d_const/cfunc.mod @@ -0,0 +1,86 @@ +/*.......1.........2.........3.........4.........5.........6.........7.........8 +================================================================================ + +AUTHORS + + 18 Nov 2019 Florian Ballenegger, Anamosic Ballenegger Design + + +SUMMARY + + This file contains the functional description of the d_const + code model. + "word" string format: optional prefix 'h'=hex or 'd'=decimal + Output vector is LSB first (little endian) + +===============================================================================*/ + +#include +#include + +void cm_d_const(ARGS) + +{ + unsigned int i,n,x; + char *str; + Digital_Strength_t strength; + Digital_State_t* vec; + + n = (unsigned int) PORT_SIZE(out); + strength = UNDETERMINED; + + if(INIT) { + str = PARAM(strength); + if(strcmp(str,"s")==0) + strength = STRONG; + else if(strcmp(str,"r")==0) + strength = RESISTIVE; + else if(strcmp(str,"h")==0) + strength = HI_IMPEDANCE; + else if(strcmp(str,"u")==0) + strength = UNDETERMINED; + else { + cm_message_send("Unknown strength string"); + cm_message_send(PARAM(strength)); + } + STATIC_VAR(locstrength) = (int) strength; + + str = PARAM(word); + if(str[0]!='h' && str[0]!='d') + if(strlen(str)!=n) + cm_message_send("Mismatch between word string value length and output vector bus width"); + + vec = (Digital_State_t*) calloc(n, sizeof(Digital_State_t)); + STATIC_VAR(locvec) = vec; + + if(str[0]=='d') { + x = (unsigned int) atoi(&str[1]); + for(i=0;i + + +/*============================================================================*/ + +void cm_da_switch(ARGS) + +{ + double + r, rinv, ron, roff; /* ON and OFF resistances of the switch */ + + Mif_Complex_t ac_gain; + + + int i, /* generic loop counter index */ + size; /* number of input & output ports */ + + + Digital_State_t *in, /* base address of array holding all input + values */ + *in_old; /* array holding previous input values */ + + + + + + /* determine "width" of the node bridge... */ + + size = PORT_SIZE(in); + if(PORT_SIZE(out) != size) { + cm_message_send("Error: output port size different than input port size\n"); + } + + /** Read in remaining parameters **/ + + ron = PARAM(r_on); + roff = PARAM(r_off); + + if (INIT) { /*** Test for INIT == TRUE. If so, allocate storage, etc. ***/ + /* printf("Call cm_da_switch with size=%d, ron=%g, roff=%g\n", size, ron, roff); */ + + /* Allocate storage for inputs */ + cm_event_alloc(0, size * (int) sizeof(Digital_State_t)); + + /* assign discrete addresses */ + in = in_old = (Digital_State_t *) cm_event_get_ptr(0,0); + + + /* read current input values */ + for (i=0; i