48 changed files with 412 additions and 393 deletions
-
5.cvsignore
-
49ChangeLog
-
4src/include/cmproto.h
-
4src/include/dllitf.h
-
8src/xspice/cm/cm.c
-
11src/xspice/cm/cmevt.c
-
182src/xspice/examples/nco/cfunc.mod
-
93src/xspice/examples/real_delay/cfunc.mod
-
152src/xspice/examples/real_to_v/cfunc.mod
-
6src/xspice/icm/analog/d_dt/cfunc.mod
-
4src/xspice/icm/analog/hyst/cfunc.mod
-
7src/xspice/icm/analog/int/cfunc.mod
-
18src/xspice/icm/analog/oneshot/cfunc.mod
-
71src/xspice/icm/analog/s_xfer/cfunc.mod
-
2src/xspice/icm/analog/sine/cfunc.mod
-
8src/xspice/icm/analog/slew/cfunc.mod
-
10src/xspice/icm/analog/square/cfunc.mod
-
8src/xspice/icm/analog/triangle/cfunc.mod
-
6src/xspice/icm/digital/adc_bridge/cfunc.mod
-
2src/xspice/icm/digital/d_and/cfunc.mod
-
2src/xspice/icm/digital/d_buffer/cfunc.mod
-
11src/xspice/icm/digital/d_dff/cfunc.mod
-
10src/xspice/icm/digital/d_dlatch/cfunc.mod
-
6src/xspice/icm/digital/d_fdiv/cfunc.mod
-
2src/xspice/icm/digital/d_inverter/cfunc.mod
-
8src/xspice/icm/digital/d_jkff/cfunc.mod
-
2src/xspice/icm/digital/d_nand/cfunc.mod
-
2src/xspice/icm/digital/d_nor/cfunc.mod
-
1src/xspice/icm/digital/d_open_c/cfunc.mod
-
1src/xspice/icm/digital/d_open_e/cfunc.mod
-
2src/xspice/icm/digital/d_or/cfunc.mod
-
8src/xspice/icm/digital/d_osc/cfunc.mod
-
8src/xspice/icm/digital/d_ram/cfunc.mod
-
4src/xspice/icm/digital/d_source/cfunc.mod
-
8src/xspice/icm/digital/d_srff/cfunc.mod
-
12src/xspice/icm/digital/d_srlatch/cfunc.mod
-
8src/xspice/icm/digital/d_state/cfunc.mod
-
8src/xspice/icm/digital/d_tff/cfunc.mod
-
2src/xspice/icm/digital/d_xnor/cfunc.mod
-
2src/xspice/icm/digital/d_xor/cfunc.mod
-
6src/xspice/icm/digital/dac_bridge/cfunc.mod
-
8src/xspice/icm/dlmain.c
-
3src/xspice/icm/xtradev/capacitor/cfunc.mod
-
4src/xspice/icm/xtradev/core/cfunc.mod
-
3src/xspice/icm/xtradev/inductor/cfunc.mod
-
18src/xspice/icm/xtradev/lcouple/cfunc.mod
-
2src/xspice/icm/xtraevt/real_delay/cfunc.mod
-
4src/xspice/icm/xtraevt/real_to_v/cfunc.mod
@ -1,90 +1,92 @@ |
|||||
/* $Id$ */ |
|
||||
|
|
||||
void *malloc(unsigned); |
|
||||
|
|
||||
#define OUT_STATE 0 |
|
||||
#define NXT_TIME 1 |
|
||||
#define NUM_NOTES 128 |
|
||||
|
|
||||
|
|
||||
/* A numerically controlled oscillator. Output frequencies */ |
|
||||
/* are determined according to the MIDI note number at input */ |
|
||||
|
|
||||
void ucm_nco (ARGS) |
|
||||
{ |
|
||||
|
|
||||
double *freq; |
|
||||
|
|
||||
int *output_state; |
|
||||
double *next_time; |
|
||||
|
|
||||
int i; |
|
||||
int index; |
|
||||
int scale_factor; |
|
||||
|
|
||||
double half_period; |
|
||||
|
|
||||
|
|
||||
if(INIT) { |
|
||||
|
|
||||
/* Setup storage for the toggled output state */ |
|
||||
output_state = (int *) cm_event_alloc(OUT_STATE, sizeof(int)); |
|
||||
next_time = (double *) cm_event_alloc(NXT_TIME, sizeof(double)); |
|
||||
|
|
||||
/* Allocate storage for frequencies */ |
|
||||
STATIC_VAR(freq) = malloc(NUM_NOTES * sizeof(double)); |
|
||||
freq = STATIC_VAR(freq); |
|
||||
|
|
||||
/* Initialize the frequency array */ |
|
||||
for(i = 0; i < NUM_NOTES; i++) { |
|
||||
if(i == 0) |
|
||||
freq[0] = 8.17578 * PARAM(mult_factor); |
|
||||
else |
|
||||
freq[i] = freq[i-1] * 1.059463094; |
|
||||
} |
|
||||
} |
|
||||
else { |
|
||||
|
|
||||
/* Get old output state */ |
|
||||
output_state = (int *) cm_event_get_ptr(OUT_STATE, 0); |
|
||||
next_time = (double *) cm_event_get_ptr(NXT_TIME, 0); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/* Convert the input bits to an integer */ |
|
||||
index = 0; |
|
||||
scale_factor = 64; |
|
||||
for(i = 0; i < 7; i++) { |
|
||||
if(INPUT_STATE(in[i]) == ONE) |
|
||||
index += scale_factor; |
|
||||
scale_factor /= 2; |
|
||||
} |
|
||||
|
|
||||
/* Look up the frequency and compute half its period */ |
|
||||
freq = STATIC_VAR(freq); |
|
||||
half_period = 1.0 / freq[index]; |
|
||||
|
|
||||
|
|
||||
/* Queue up events and output the new state */ |
|
||||
if(TIME == 0.0) { |
|
||||
*next_time = half_period; |
|
||||
cm_event_queue(*next_time); |
|
||||
OUTPUT_STATE(out) = *output_state; |
|
||||
} |
|
||||
else { |
|
||||
if(TIME == *next_time) { |
|
||||
*next_time = TIME + half_period; |
|
||||
cm_event_queue(*next_time); |
|
||||
*output_state = 1 - *output_state; |
|
||||
OUTPUT_STATE(out) = *output_state; |
|
||||
OUTPUT_DELAY(out) = PARAM(delay); |
|
||||
} |
|
||||
else |
|
||||
OUTPUT_CHANGED(out) = FALSE; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
/* $Id$ */ |
||||
|
|
||||
|
void *malloc(unsigned); |
||||
|
|
||||
|
#define OUT_STATE 0 |
||||
|
#define NXT_TIME 1 |
||||
|
#define NUM_NOTES 128 |
||||
|
|
||||
|
|
||||
|
/* A numerically controlled oscillator. Output frequencies */ |
||||
|
/* are determined according to the MIDI note number at input */ |
||||
|
|
||||
|
void ucm_nco (ARGS) |
||||
|
{ |
||||
|
|
||||
|
double *freq; |
||||
|
|
||||
|
int *output_state; |
||||
|
double *next_time; |
||||
|
|
||||
|
int i; |
||||
|
int index; |
||||
|
int scale_factor; |
||||
|
|
||||
|
double half_period; |
||||
|
|
||||
|
|
||||
|
if(INIT) { |
||||
|
|
||||
|
/* Setup storage for the toggled output state */ |
||||
|
cm_event_alloc(OUT_STATE, sizeof(int)); |
||||
|
cm_event_alloc(NXT_TIME, sizeof(double)); |
||||
|
output_state = (int *) cm_event_get_ptr(OUT_STATE, 0); |
||||
|
next_time = (double *) cm_event_get_ptr(NXT_TIME, 0); |
||||
|
|
||||
|
/* Allocate storage for frequencies */ |
||||
|
STATIC_VAR(freq) = malloc(NUM_NOTES * sizeof(double)); |
||||
|
freq = STATIC_VAR(freq); |
||||
|
|
||||
|
/* Initialize the frequency array */ |
||||
|
for(i = 0; i < NUM_NOTES; i++) { |
||||
|
if(i == 0) |
||||
|
freq[0] = 8.17578 * PARAM(mult_factor); |
||||
|
else |
||||
|
freq[i] = freq[i-1] * 1.059463094; |
||||
|
} |
||||
|
} |
||||
|
else { |
||||
|
|
||||
|
/* Get old output state */ |
||||
|
output_state = (int *) cm_event_get_ptr(OUT_STATE, 0); |
||||
|
next_time = (double *) cm_event_get_ptr(NXT_TIME, 0); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/* Convert the input bits to an integer */ |
||||
|
index = 0; |
||||
|
scale_factor = 64; |
||||
|
for(i = 0; i < 7; i++) { |
||||
|
if(INPUT_STATE(in[i]) == ONE) |
||||
|
index += scale_factor; |
||||
|
scale_factor /= 2; |
||||
|
} |
||||
|
|
||||
|
/* Look up the frequency and compute half its period */ |
||||
|
freq = STATIC_VAR(freq); |
||||
|
half_period = 1.0 / freq[index]; |
||||
|
|
||||
|
|
||||
|
/* Queue up events and output the new state */ |
||||
|
if(TIME == 0.0) { |
||||
|
*next_time = half_period; |
||||
|
cm_event_queue(*next_time); |
||||
|
OUTPUT_STATE(out) = *output_state; |
||||
|
} |
||||
|
else { |
||||
|
if(TIME == *next_time) { |
||||
|
*next_time = TIME + half_period; |
||||
|
cm_event_queue(*next_time); |
||||
|
*output_state = 1 - *output_state; |
||||
|
OUTPUT_STATE(out) = *output_state; |
||||
|
OUTPUT_DELAY(out) = PARAM(delay); |
||||
|
} |
||||
|
else |
||||
|
OUTPUT_CHANGED(out) = FALSE; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
@ -1,46 +1,47 @@ |
|||||
/* $Id$ */ |
|
||||
|
|
||||
|
|
||||
#define CLK_STATE 0 |
|
||||
|
|
||||
|
|
||||
void ucm_real_delay (ARGS) |
|
||||
{ |
|
||||
|
|
||||
double *in; |
|
||||
double *out; |
|
||||
|
|
||||
Digital_State_t *state; |
|
||||
Digital_State_t *old_state; |
|
||||
|
|
||||
|
|
||||
if(INIT) { |
|
||||
state = (void *) cm_event_alloc(CLK_STATE, sizeof(Digital_State_t)); |
|
||||
old_state = state; |
|
||||
*state = INPUT_STATE(clk); |
|
||||
} |
|
||||
else { |
|
||||
state = (void *) cm_event_get_ptr(CLK_STATE, 0); |
|
||||
old_state = (void *) cm_event_get_ptr(CLK_STATE, 1); |
|
||||
} |
|
||||
|
|
||||
if(ANALYSIS != TRANSIENT) |
|
||||
OUTPUT_CHANGED(out) = FALSE; |
|
||||
else { |
|
||||
*state = INPUT_STATE(clk); |
|
||||
if(*state == *old_state) |
|
||||
OUTPUT_CHANGED(out) = FALSE; |
|
||||
else if(*state != ONE) |
|
||||
OUTPUT_CHANGED(out) = FALSE; |
|
||||
else { |
|
||||
in = INPUT(in); |
|
||||
out = OUTPUT(out); |
|
||||
*out = *in; |
|
||||
OUTPUT_DELAY(out) = PARAM(delay); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
/* $Id$ */ |
||||
|
|
||||
|
|
||||
|
#define CLK_STATE 0 |
||||
|
|
||||
|
|
||||
|
void ucm_real_delay (ARGS) |
||||
|
{ |
||||
|
|
||||
|
double *in; |
||||
|
double *out; |
||||
|
|
||||
|
Digital_State_t *state; |
||||
|
Digital_State_t *old_state; |
||||
|
|
||||
|
|
||||
|
if(INIT) { |
||||
|
cm_event_alloc(CLK_STATE, sizeof(Digital_State_t)); |
||||
|
state = (void *) cm_event_get_ptr(CLK_STATE, 0); |
||||
|
old_state = state; |
||||
|
*state = INPUT_STATE(clk); |
||||
|
} |
||||
|
else { |
||||
|
state = (void *) cm_event_get_ptr(CLK_STATE, 0); |
||||
|
old_state = (void *) cm_event_get_ptr(CLK_STATE, 1); |
||||
|
} |
||||
|
|
||||
|
if(ANALYSIS != TRANSIENT) |
||||
|
OUTPUT_CHANGED(out) = FALSE; |
||||
|
else { |
||||
|
*state = INPUT_STATE(clk); |
||||
|
if(*state == *old_state) |
||||
|
OUTPUT_CHANGED(out) = FALSE; |
||||
|
else if(*state != ONE) |
||||
|
OUTPUT_CHANGED(out) = FALSE; |
||||
|
else { |
||||
|
in = INPUT(in); |
||||
|
out = OUTPUT(out); |
||||
|
*out = *in; |
||||
|
OUTPUT_DELAY(out) = PARAM(delay); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
@ -1,75 +1,77 @@ |
|||||
/* $Id$ */ |
|
||||
|
|
||||
|
|
||||
#define TS 0 |
|
||||
#define VS 1 |
|
||||
|
|
||||
|
|
||||
void ucm_real_to_v (ARGS) |
|
||||
{ |
|
||||
|
|
||||
double *t, *v; |
|
||||
double *in; |
|
||||
|
|
||||
double out; |
|
||||
|
|
||||
|
|
||||
in = INPUT(in); |
|
||||
|
|
||||
if(INIT) { |
|
||||
t = (void *) cm_event_alloc(TS, 2 * sizeof(double)); |
|
||||
v = (void *) cm_event_alloc(VS, 2 * sizeof(double)); |
|
||||
t[0] = -2.0; |
|
||||
t[1] = -1.0; |
|
||||
v[0] = *in; |
|
||||
v[1] = *in; |
|
||||
} |
|
||||
else { |
|
||||
t = (void *) cm_event_get_ptr(TS, 0); |
|
||||
v = (void *) cm_event_get_ptr(VS, 0); |
|
||||
} |
|
||||
|
|
||||
switch(CALL_TYPE) { |
|
||||
|
|
||||
case ANALOG: |
|
||||
if(TIME == 0.0) { |
|
||||
OUTPUT(out) = *in; |
|
||||
v[0] = *in; |
|
||||
v[1] = *in; |
|
||||
} |
|
||||
else { |
|
||||
if(TIME <= t[0]) |
|
||||
OUTPUT(out) = v[0]; |
|
||||
else if(TIME >= t[1]) |
|
||||
OUTPUT(out) = v[1]; |
|
||||
else { |
|
||||
OUTPUT(out) = v[0] + (v[1] - v[0]) * |
|
||||
(TIME - t[0]) / (t[1] - t[0]); |
|
||||
} |
|
||||
} |
|
||||
break; |
|
||||
|
|
||||
case EVENT: |
|
||||
if(TIME == 0.0) |
|
||||
return; |
|
||||
if(TIME >= t[1]) { |
|
||||
v[0] = v[1]; |
|
||||
v[1] = *in; |
|
||||
t[0] = TIME; |
|
||||
t[1] = TIME + PARAM(transition_time); |
|
||||
} |
|
||||
else { |
|
||||
v[0] = v[0] + (v[1] - v[0]) * |
|
||||
(TIME - t[0]) / (t[1] - t[0]); |
|
||||
v[1] = *in; |
|
||||
t[0] = TIME; |
|
||||
t[1] = TIME + PARAM(transition_time); |
|
||||
} |
|
||||
break; |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
/* $Id$ */ |
||||
|
|
||||
|
|
||||
|
#define TS 0 |
||||
|
#define VS 1 |
||||
|
|
||||
|
|
||||
|
void ucm_real_to_v (ARGS) |
||||
|
{ |
||||
|
|
||||
|
double *t, *v; |
||||
|
double *in; |
||||
|
|
||||
|
double out; |
||||
|
|
||||
|
|
||||
|
in = INPUT(in); |
||||
|
|
||||
|
if(INIT) { |
||||
|
cm_event_alloc(TS, 2 * sizeof(double)); |
||||
|
cm_event_alloc(VS, 2 * sizeof(double)); |
||||
|
t = (void *) cm_event_get_ptr(TS, 0); |
||||
|
v = (void *) cm_event_get_ptr(VS, 0); |
||||
|
t[0] = -2.0; |
||||
|
t[1] = -1.0; |
||||
|
v[0] = *in; |
||||
|
v[1] = *in; |
||||
|
} |
||||
|
else { |
||||
|
t = (void *) cm_event_get_ptr(TS, 0); |
||||
|
v = (void *) cm_event_get_ptr(VS, 0); |
||||
|
} |
||||
|
|
||||
|
switch(CALL_TYPE) { |
||||
|
|
||||
|
case ANALOG: |
||||
|
if(TIME == 0.0) { |
||||
|
OUTPUT(out) = *in; |
||||
|
v[0] = *in; |
||||
|
v[1] = *in; |
||||
|
} |
||||
|
else { |
||||
|
if(TIME <= t[0]) |
||||
|
OUTPUT(out) = v[0]; |
||||
|
else if(TIME >= t[1]) |
||||
|
OUTPUT(out) = v[1]; |
||||
|
else { |
||||
|
OUTPUT(out) = v[0] + (v[1] - v[0]) * |
||||
|
(TIME - t[0]) / (t[1] - t[0]); |
||||
|
} |
||||
|
} |
||||
|
break; |
||||
|
|
||||
|
case EVENT: |
||||
|
if(TIME == 0.0) |
||||
|
return; |
||||
|
if(TIME >= t[1]) { |
||||
|
v[0] = v[1]; |
||||
|
v[1] = *in; |
||||
|
t[0] = TIME; |
||||
|
t[1] = TIME + PARAM(transition_time); |
||||
|
} |
||||
|
else { |
||||
|
v[0] = v[0] + (v[1] - v[0]) * |
||||
|
(TIME - t[0]) / (t[1] - t[0]); |
||||
|
v[1] = *in; |
||||
|
t[0] = TIME; |
||||
|
t[1] = TIME + PARAM(transition_time); |
||||
|
} |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue