1 /****************************************************************************/
3 /* Chaine de CAO & VLSI AVERTEC */
5 /* Produit : STM Version 1.00 */
6 /* Fichier : stm_modfct_eval.c */
8 /* (c) copyright 2000 AVERTEC */
9 /* Tous droits reserves */
11 /* Auteur(s) : Gilles Augustins */
13 /****************************************************************************/
15 /****************************************************************************/
17 /****************************************************************************/
22 /****************************************************************************/
24 /****************************************************************************/
26 ExecutionContext
*STM_EC
= NULL
;
28 ExecutionContext
*Get_stm_C_context ()
31 char path
[200], lib
[200], *str
;
36 STM_EC
= APINewExecutionContext ();
38 str
= V_STR_TAB
[__GENIUS_LIB_PATH
].VALUE
;
40 strcpy (lib
, "cells");
44 sprintf (path
, "%s/%s/", WORK_LIB
, lib
);
46 str
= V_STR_TAB
[__GENIUS_LIB_NAME
].VALUE
;
48 sprintf (lib
, "%sLIBRARY", path
);
50 sprintf (lib
, "%s%s", path
, str
);
52 le
= APIReadLibrary (lib
, path
, NULL
);
53 if (ReadAllCorVHDL (STM_EC
, le
, NULL
)) {
54 printf ("stmfct could not read rule files\n");
57 // call user init function
63 if (APIExecAPICallFunc(STM_EC
, &cf
, &ret
, 1)==0)
72 ht *ALL_FCT_FILES=NULL;
74 ExecutionContext *Get_stm_C_context(char *file)
82 if (ALL_FCT_FILES==NULL) ALL_FCT_FILES=addht(10);
84 name=sensitive_namealloc(file);
85 if ((l=gethtitem(ALL_FCT_FILES, name))!=EMPTYHT) return (ExecutionContext *)l;
87 if (!(f = mbkfopen (name, NULL, READ_TEXT))) {
88 fprintf (stderr, "Cannot open file '%s'\n", name);
93 ec = APINewExecutionContext ();
94 tr = APIParseFile (f, name, ec);
95 APIVerify_C_Functions (ec);
96 if (APICheckCFunctions (ec)) { fclose(f); return NULL;}
97 addhtitem(ALL_FCT_FILES, name, (long)ec);
102 void Free_stm_C_context()
106 cl=GetAllHTElems(ALL_FCT_FILES);
108 for (ch=cl; ch!=NULL; ch=ch->NEXT)
109 APIFreeExecutionContext ((ExecutionContext *)ch->DATA);
113 delht(ALL_FCT_FILES);
118 static double __STM_DELAY__
, __STM_INPUT_SLOPE__
, __STM_COMMAND_SLOPE__
;
119 static double __STM_SLOPE__
, __STM_OUTPUT_LOAD__
;
120 static timing_function
*__STM_ARC__
=NULL
;
123 timing_function
*stm_get_current_arc()
128 void stm_set_current_arc(timing_function
*arc
)
133 void stm_set_computed_delay (double value
)
135 __STM_DELAY__
= value
;
138 void stm_set_computed_slope (double value
)
140 __STM_SLOPE__
= value
;
143 double stm_get_computed_delay ()
145 return __STM_DELAY__
;
148 double stm_get_computed_slope ()
150 return __STM_SLOPE__
;
153 double stm_get_output_load ()
155 return __STM_OUTPUT_LOAD__
;
158 double stm_get_input_slope ()
160 return __STM_INPUT_SLOPE__
;
163 double stm_get_command_slope ()
165 return __STM_COMMAND_SLOPE__
;
168 void stm_set_output_load (double val
)
170 __STM_OUTPUT_LOAD__
= val
;
173 void stm_set_input_slope (double val
)
175 __STM_INPUT_SLOPE__
= val
;
178 void stm_set_command_slope (double val
)
180 __STM_COMMAND_SLOPE__
= val
;
183 void stm_call_simulation()
189 if ((tf
=stm_get_current_arc())==NULL
)
191 avt_errmsg (STM_ERRMSG
, "042", AVT_ERROR
);
194 hli
=gethierlofiginfo(CUR_HIER_LOFIG
);
195 ai
=getarcinfo(hli
, tf
->LOCALNAME
);
198 avt_errmsg (STM_ERRMSG
, "043", AVT_ERROR
, CUR_HIER_LOFIG
, tf
->LOCALNAME
);
201 if (APIExecAPICallFunc (Get_stm_C_context (), ai
->SIM
, &ta
, 0)) EXIT (1);
205 void stm_call_simulation_env()
211 if ((tf
=stm_get_current_arc())==NULL
)
213 avt_errmsg (STM_ERRMSG
, "044", AVT_ERROR
);
216 hli
=gethierlofiginfo(CUR_HIER_LOFIG
);
217 ai
=getarcinfo(hli
, tf
->LOCALNAME
);
220 avt_errmsg (STM_ERRMSG
, "045", AVT_ERROR
, CUR_HIER_LOFIG
, tf
->LOCALNAME
);
223 if (APIExecAPICallFunc (Get_stm_C_context (), ai
->ENV
, &ta
, 0)) EXIT (1);
227 void stm_call_ctk_env()
233 if ((tf
=stm_get_current_arc())==NULL
)
235 avt_errmsg (STM_ERRMSG
, "046", AVT_ERROR
);
238 hli
=gethierlofiginfo(CUR_HIER_LOFIG
);
239 ai
=getarcinfo(hli
, tf
->LOCALNAME
);
240 if (ai
->CTK_ENV
==NULL
)
242 avt_errmsg (STM_ERRMSG
, "047", AVT_ERROR
, tf
->LOCALNAME
);
245 if (APIExecAPICallFunc (Get_stm_C_context (), ai
->CTK_ENV
, &ta
, 0)) EXIT (1);
249 /****************************************************************************/
250 /* function stm_modfct_slew() */
251 /****************************************************************************/
253 float stm_modfct_slew (timing_function
* fct
, float slew
, float load
)
257 if (!fct
|| !fct
->FCT
)
260 //printf ("stmfct SLEW recompute request instance = '%s' slope = %g load = %g\n", fct->INS, slew, load);
261 if (LATEST_GNS_RUN
==NULL
)
263 avt_errmsg (STM_ERRMSG
, "048", AVT_ERROR
);
266 sins
= gen_get_hier_instance (LATEST_GNS_RUN
, fct
->INS
);
268 avt_errmsg (STM_ERRMSG
, "049", AVT_ERROR
, fct
->INS
);
272 in_genius_context_of (LATEST_GNS_RUN
, sins
);
273 APICallApiInitFunctions();
274 stm_set_input_slope (slew
* 1e-12);
275 stm_set_output_load (load
* 1e-15);
276 stm_set_current_arc(fct
);
277 stm_call_func (Get_stm_C_context (), fct
);
278 stm_set_current_arc(NULL
);
279 APICallApiTerminateFunctions();
280 out_genius_context_of ();
282 if ( stm_get_computed_slope ()>10000e-12)
284 printf("big slope returned : %g\n",stm_get_computed_slope());
288 return stm_get_computed_slope () * 1e12
;
291 /****************************************************************************/
292 /* function stm_call_func () */
293 /****************************************************************************/
295 void stm_call_func (ExecutionContext
* ec
, timing_function
* fct
)
298 if (APIExecAPICallFunc (ec
, fct
->FCT
, &ta
, 0))
303 /****************************************************************************/
304 /* function stm_modfct_delay () */
305 /****************************************************************************/
307 float stm_modfct_delay (timing_function
* fct
, float slew
, float load
)
311 if (!fct
|| !fct
->FCT
)
314 //printf ("stmfct DELAY recompute request instance = '%s' slope = %g load = %g\n", fct->INS, slew, load);
315 if (LATEST_GNS_RUN
==NULL
)
317 avt_errmsg (STM_ERRMSG
, "048", AVT_ERROR
);
320 sins
= gen_get_hier_instance (LATEST_GNS_RUN
, fct
->INS
);
322 avt_errmsg (STM_ERRMSG
, "049", AVT_ERROR
, fct
->INS
);
326 in_genius_context_of (LATEST_GNS_RUN
, sins
);
327 APICallApiInitFunctions();
328 stm_set_input_slope (slew
* 1e-12);
329 stm_set_output_load (load
* 1e-15);
330 stm_set_current_arc(fct
);
331 stm_call_func (Get_stm_C_context (), fct
);
332 stm_set_current_arc(NULL
); // pour etre sur de voir une erreur hors context
333 APICallApiTerminateFunctions();
334 out_genius_context_of ();
336 if ( stm_get_computed_delay ()>10000e-12)
338 printf("big delay returned : %g\n",stm_get_computed_delay());
342 return stm_get_computed_delay () * 1e12
;
345 /****************************************************************************/
346 /* function stm_modfct_constraint() */
347 /****************************************************************************/
349 float stm_modfct_constraint (timing_function
* fct
, float inslew
, float ckslew
)
353 if (!fct
|| !fct
->FCT
)
356 // printf ("stmfct CONSTRAINT recompute request instance = '%s' inslope = %g comslope = %g\n", fct->INS, inslew, ckslew);
357 if (LATEST_GNS_RUN
==NULL
)
359 avt_error("stm", 1, AVT_ERR
, "Gns informations not loaded, can't compute constraint\n");
362 sins
= gen_get_hier_instance (LATEST_GNS_RUN
, fct
->INS
);
364 avt_errmsg (STM_ERRMSG
, "049", AVT_ERROR
, fct
->INS
);
368 in_genius_context_of (LATEST_GNS_RUN
, sins
);
369 APICallApiInitFunctions();
370 stm_set_input_slope (inslew
* 1e-12);
371 stm_set_command_slope (ckslew
* 1e-15);
372 stm_set_current_arc(fct
);
373 stm_call_func (Get_stm_C_context (), fct
);
374 stm_set_current_arc(NULL
); // pour etre sur de voir une erreur hors context
375 APICallApiTerminateFunctions();
376 out_genius_context_of ();
378 return stm_get_computed_delay () * 1e12
;