malt-wr
vpassfail.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "constype.h"
Include dependency graph for vpassfail.c:

Go to the source code of this file.

Data Structures

struct  passfail_condition
 

Macros

#define STEP_PARTS   10
 

Typedefs

typedef struct passfail_condition PF_CONDITION
 

Functions

static void print_condition (FILE *fp, char *name, TIME chtime, int index, int lvalue, int printstep, int stepnr)
 
static int latch_signal_value (TIME check_time, EDGE **prev_edge, int init_value)
 
static int generate_sync_latch_passfail (FILE *fp, SIGNALS *sp, int runall)
 
static int collect_passfail_condition (PF_CONDITION **bpf, int sig_num, TIME check_time, int curr_index, int curr_value)
 
static void print_passfail_conditions (FILE *fp, SIGNALS *sp, PF_CONDITION *bpf, int runall)
 
static int generate_async_latch_passfail (FILE *fp, SIGNALS *sp, int runall)
 
int generate_latch_passfail_file (SIGNALS *sp, char *filename, int runall)
 

Macro Definition Documentation

#define STEP_PARTS   10

Definition at line 117 of file vpassfail.c.

Typedef Documentation

Definition at line 127 of file vpassfail.c.

Function Documentation

static int collect_passfail_condition ( PF_CONDITION **  bpf,
int  sig_num,
TIME  check_time,
int  curr_index,
int  curr_value 
)
static

Definition at line 129 of file vpassfail.c.

131 {
132  PF_CONDITION *npf, *cpf, *opf;
133 
134  npf=(PF_CONDITION *) calloc(1, sizeof(PF_CONDITION));
135  if(npf==0)
136  return 0;
137  npf->signum = sig_num;
138  npf->index = curr_index;
139  npf->time = check_time;
140  npf->value = curr_value;
141 
142 /* empty list */
143  if((*bpf) == NULL) {
144  (*bpf) = npf;
145  npf->next = NULL;
146  return 1;
147  }
148 
149  opf=cpf=(*bpf);
150 
151 /* new component introduced at the beginning of the list */
152  if(curr_index < cpf->index) {
153  (*bpf) = npf;
154  npf->next = cpf;
155  return 1;
156  }
157 
158 /* looking for an appropriate position on the list */
159  while(cpf!=NULL) {
160  if(curr_index < cpf->index)
161  break;
162  opf=cpf;
163  cpf=cpf->next;
164  }
165  opf->next = npf;
166  npf->next = cpf;
167  return 1;
168 }
struct passfail_condition * next
Definition: vpassfail.c:124
static int generate_async_latch_passfail ( FILE *  fp,
SIGNALS sp,
int  runall 
)
static

Definition at line 208 of file vpassfail.c.

209 {
210  TIME total_time, last_edge, next_edge, curr_time, check_time;
211  int curr_index;
212  int curr_value;
213  int sig_num;
214  EDGE *pp;
215  int done;
216  int last_edge_dir;
217  TIME min_interval_to_edge;
218  PF_CONDITION *bpf;
219 
220  total_time = sp->start_time+sp->indices_nr*sp->min_time_delta;
221 
222  for(sig_num=sp->signal_num-sp->outs_num; sig_num<sp->signal_num; sig_num++)
223  {
224  curr_value = 0;
225  last_edge = sp->start_time;
226  pp = sp->sig_edge_bgn[sig_num];
227  done = 0;
228 
229  do {
230  if(pp != NULL) {
231  last_edge_dir = 1-pp->direction;
232  next_edge = pp->exact_time;
233  }
234  else {
235  if(sp->sig_edge_bgn[sig_num]==NULL)
236  last_edge_dir = 1 - sp->sig_initial[sig_num];
237  else
238  last_edge_dir = 1 - last_edge_dir;
239  next_edge = total_time;
240  done = 1;
241  }
242 
243  if(last_edge_dir==RISING_EDGE)
244  curr_time = last_edge + param.min_interval_to_riseedge;
245  else
246  if(last_edge_dir==FALLING_EDGE)
247  curr_time = last_edge + param.min_interval_to_falledge;
248 
250  curr_time = (next_edge + last_edge)/2;
251 
252  if(last_edge_dir==RISING_EDGE)
253  min_interval_to_edge = param.min_interval_to_falledge;
254  else
255  if(last_edge_dir==FALLING_EDGE)
256  min_interval_to_edge = param.min_interval_to_riseedge;
257 
258  while(curr_time < next_edge - min_interval_to_edge) {
259  curr_index = (curr_time-sp->start_time)/sp->min_time_delta;
260  check_time = sp->start_time + curr_index*sp->min_time_delta;
261 
262  collect_passfail_condition(&bpf, sig_num, check_time, curr_index, curr_value);
263 
264  curr_time += param.min_checks_interval;
265  }
266  curr_value = 1 - curr_value;
267  last_edge = next_edge;
268  if(pp!=NULL)
269  pp=pp->next;
270 
271  } while (!done);
272 
273  }
274 
275  print_passfail_conditions(fp, sp, bpf, runall);
276 }
int direction
Definition: constype.h:313
TIME exact_time
Definition: constype.h:316
TIME min_time_delta
Definition: constype.h:393
static int collect_passfail_condition(PF_CONDITION **bpf, int sig_num, TIME check_time, int curr_index, int curr_value)
Definition: vpassfail.c:129
EDGE ** sig_edge_bgn
Definition: constype.h:412
int signal_num
Definition: constype.h:366
PARAMETERS param
Definition: init.c:10
TIME min_checks_interval
Definition: constype.h:221
int outs_num
Definition: constype.h:378
TIME min_interval_to_falledge
Definition: constype.h:229
TIME min_interval_to_riseedge
Definition: constype.h:225
int indices_nr
Definition: constype.h:399
static void print_passfail_conditions(FILE *fp, SIGNALS *sp, PF_CONDITION *bpf, int runall)
Definition: vpassfail.c:171
TIME start_time
Definition: constype.h:396
float TIME
Definition: constype.h:54
#define RISING_EDGE
Definition: constype.h:50
#define FALLING_EDGE
Definition: constype.h:51
int * sig_initial
Definition: constype.h:420
struct EDGE_DESC * next
Definition: constype.h:319
int generate_latch_passfail_file ( SIGNALS sp,
char *  filename,
int  runall 
)

Definition at line 279 of file vpassfail.c.

285 {
286  FILE *fp;
287 
288  fp=fopen(filename, "w");
289  if(fp==NULL)
290  return 0;
291 
292  fprintf(fp, "%s\n", filename);
293  fprintf(fp, ".control\n\n");
294 
295  fprintf(fp, "vthreshold0 = %f\n", param.max_zero_volt);
296  fprintf(fp, "vthreshold1 = %f\n\n", param.min_one_volt);
297 
298  if(runall)
299  fprintf(fp, "run\n\n");
300 
301  if(sp->clk_num>0)
302  generate_sync_latch_passfail(fp, sp, runall);
303  else
304  generate_async_latch_passfail(fp, sp, runall);
305 
306  fprintf(fp, "if chFAIL = 1\n");
307  fprintf(fp, "\tfree all yes\n");
308  fprintf(fp, "\tchFAIL = 1\n");
309  fprintf(fp, "end\n\n");
310 
311  fprintf(fp, "if chFAIL = 0\n");
312  fprintf(fp, "\tfree all yes\n");
313  fprintf(fp, "\tchFAIL = 0\n");
314  fprintf(fp, "end\n\n");
315 
316  return 1;
317 }
double max_zero_volt
Definition: constype.h:211
static int generate_async_latch_passfail(FILE *fp, SIGNALS *sp, int runall)
Definition: vpassfail.c:208
PARAMETERS param
Definition: init.c:10
double min_one_volt
Definition: constype.h:214
int clk_num
Definition: constype.h:369
static int generate_sync_latch_passfail(FILE *fp, SIGNALS *sp, int runall)
Definition: vpassfail.c:48
static char filename[LINE_LENGTH]
Definition: optimize.c:35
static int generate_sync_latch_passfail ( FILE *  fp,
SIGNALS sp,
int  runall 
)
static

Definition at line 48 of file vpassfail.c.

49 {
50  EDGE **prev_edge, *clk_edge;
51  TIME check_time, check_norm_time, clk_pulse_bgn, clk_pulse_end, total_time;
52  int check_index;
53  int signal_value;
54  int sig_num;
55  int step_nr;
56  int last_index=-STEP_FORWARD;
57  int printstep;
58 
59  total_time = sp->start_time+sp->indices_nr*sp->min_time_delta;
60 
61 /* preparing an array of output signal edges prior to the clock checkpoint */
62  prev_edge = (EDGE **) calloc(sizeof(EDGE *), sp->outs_num);
63  if(prev_edge == NULL) {
64  exit(255); /* WARNING!!! */
65  }
66  for(sig_num=0; sig_num<sp->outs_num; sig_num++) {
67  prev_edge[sig_num] = sp->sig_edge_bgn[sig_num+sp->signal_num-sp->outs_num];
68  }
69 
70 /* starting from the first edge of the clock signal */
71  clk_edge = sp->sig_edge_bgn[0];
72 
73  do {
74  if(clk_edge==NULL)
75  break;
76 
77  if(clk_edge->direction == RISING_EDGE) {
78  clk_pulse_bgn = clk_edge->exact_time;
79  clk_edge=clk_edge->next;
80  if(clk_edge!=NULL)
81  clk_pulse_end = clk_edge->exact_time;
82  else
83  clk_pulse_end = total_time;
84  }
85  else
86 /* if the first edge is a falling edge, place the checkpoint between the
87  start of the simulation and the first edge */
88  if(clk_edge->direction == FALLING_EDGE) {
89  clk_pulse_bgn = sp->start_time;
90  clk_pulse_end = clk_edge->exact_time;
91  }
92 
93  check_time = clk_pulse_bgn +
94  (clk_pulse_end - clk_pulse_bgn)*param.clk_chktime_ratio;
95  check_index = (check_time-sp->start_time)/sp->min_time_delta;
96  check_norm_time = sp->start_time + check_index*sp->min_time_delta;
97 
98  printstep = !runall;
99  for(sig_num=sp->signal_num-sp->outs_num; sig_num<sp->signal_num; sig_num++) {
100  signal_value =
101  latch_signal_value(check_time,
102  &prev_edge[sig_num-sp->signal_num+sp->outs_num],
103  sp->sig_initial[sig_num]);
104  print_condition(fp, sp->jspice_voltage_names[sig_num], check_norm_time, check_index, signal_value, printstep, check_index-last_index);
105  printstep = 0;
106  /* steps executed only before the first output signal is checked */
107  }
108 
109  last_index = check_index;
110 
111  if(clk_edge!=NULL)
112  clk_edge=clk_edge->next;
113  } while (1);
114 }
int direction
Definition: constype.h:313
static void print_condition(FILE *fp, char *name, TIME chtime, int index, int lvalue, int printstep, int stepnr)
Definition: vpassfail.c:7
TIME exact_time
Definition: constype.h:316
TIME min_time_delta
Definition: constype.h:393
EDGE ** sig_edge_bgn
Definition: constype.h:412
int signal_num
Definition: constype.h:366
PARAMETERS param
Definition: init.c:10
int outs_num
Definition: constype.h:378
static int latch_signal_value(TIME check_time, EDGE **prev_edge, int init_value)
Definition: vpassfail.c:22
int indices_nr
Definition: constype.h:399
#define STEP_FORWARD
Definition: constype.h:48
TIME start_time
Definition: constype.h:396
float TIME
Definition: constype.h:54
#define RISING_EDGE
Definition: constype.h:50
double clk_chktime_ratio
Definition: constype.h:234
char(* jspice_voltage_names)[NAME_LENGTH]
Definition: constype.h:384
#define FALLING_EDGE
Definition: constype.h:51
int * sig_initial
Definition: constype.h:420
struct EDGE_DESC * next
Definition: constype.h:319
static int latch_signal_value ( TIME  check_time,
EDGE **  prev_edge,
int  init_value 
)
static

Definition at line 22 of file vpassfail.c.

23 {
24  EDGE *ne, *pe;
25 
26  pe=(*prev_edge);
27  if(pe == NULL)
28  return init_value;
29 
30  if(pe->exact_time > check_time)
31  return init_value;
32 
33  ne=pe->next;
34  while(ne!=NULL) {
35  if(check_time < ne->exact_time)
36  break;
37 /* if the difference is too small - WARNING !!! */
38 
39  pe=ne;
40  ne=ne->next;
41  }
42 
43  (*prev_edge)=pe;
44  return 1 - pe->direction;
45 }
int direction
Definition: constype.h:313
TIME exact_time
Definition: constype.h:316
struct EDGE_DESC * next
Definition: constype.h:319
static void print_condition ( FILE *  fp,
char *  name,
TIME  chtime,
int  index,
int  lvalue,
int  printstep,
int  stepnr 
)
static

Definition at line 7 of file vpassfail.c.

8 {
9  char sign = lvalue?'<':'>';
10 
11  fprintf(fp, "if chFAIL = 0\n");
12  if(printstep)
13  fprintf(fp, "\tstep %d\n", stepnr);
14  fprintf(fp, "\tif (%s[%d]) %c vthreshold%d\n", name, index, sign, lvalue);
15  fprintf(fp, "\t\tchFAIL = 1\n");
16  fprintf(fp, "\t\techo FAILED FOR TIME = %.1f ps\n", chtime*1.0e12);
17  fprintf(fp, "\tend\n");
18  fprintf(fp, "end\n\n");
19 }
static void print_passfail_conditions ( FILE *  fp,
SIGNALS sp,
PF_CONDITION bpf,
int  runall 
)
static

Definition at line 171 of file vpassfail.c.

173 {
174  PF_CONDITION *cpf=bpf;
175  int i;
176  int stepnum, indexlimit, edgenum;
177 
178  if(cpf == NULL)
179  return;
180 
181  stepnum = 0;
182  indexlimit = 0;
183  for(i=0; i<STEP_PARTS; i++) {
184 
185  edgenum = 0;
186  indexlimit += sp->indices_nr/STEP_PARTS;
187  stepnum += sp->indices_nr/STEP_PARTS;
188 
189  while(cpf->index < indexlimit) {
190  if(edgenum==0)
191  print_condition(fp, sp->jspice_voltage_names[cpf->signum], cpf->time,
192  cpf->index, cpf->value, !runall, stepnum);
193  else
194  print_condition(fp, sp->jspice_voltage_names[cpf->signum], cpf->time,
195  cpf->index, cpf->value, 0, stepnum);
196  edgenum ++;
197  cpf=cpf->next;
198  if(cpf==NULL)
199  return;
200  }
201 
202  if(edgenum>0)
203  stepnum=0;
204  }
205 }
static void print_condition(FILE *fp, char *name, TIME chtime, int index, int lvalue, int printstep, int stepnr)
Definition: vpassfail.c:7
struct passfail_condition * next
Definition: vpassfail.c:124
int indices_nr
Definition: constype.h:399
#define STEP_PARTS
Definition: vpassfail.c:117
char(* jspice_voltage_names)[NAME_LENGTH]
Definition: constype.h:384