13 #define PAVO_CONE_INDEX 0xf0270705
21 long ModificationDate
;
26 typedef struct pavo_cone_simulator_info
30 } pavo_ConeSimulatorInfo
;
32 pavo_ConeSimulatorInfo CSI
;
34 int pavo_get_cone_index(cone_list
*cl
)
37 if ((pt
=getptype(cl
->USER
, PAVO_CONE_INDEX
))!=NULL
) return (int)(long)pt
->DATA
;
41 int pavo_get_input_cone(char *name
)
44 if ((l
=gethtitem(CSI
.ExternalCones
, namealloc(name
)))==EMPTYHT
) {exit(10); return -1;} // msg
48 int pavo_UpdateFunction(Scheduler
*S
, int index
, void *data
)
50 float newval
=*(float *)data
;
53 ci
=(ConeInformations
*)Scheduler_GetRegisterObject(S
, index
);
55 if (DEBUG
) avt_fprintf(stdout
,"date ¤+%ld¤. : update '%s' %g -> %g\n", S
->Date
, ci
->CONE
->NAME
, ci
->CurrentVoltage
, newval
);
57 if (fabs(ci
->CurrentVoltage
-newval
)>1e-3)
59 ci
->CurrentVoltage
=newval
;
60 ci
->ModificationDate
=S
->Date
;
61 return 1; // event detected
63 // value is the same, no event detected
67 void pavo_GetConeDelay_and_Voltage(Scheduler
*S
, cone_list
*cl
, long *delay
, float *value
)
72 // positionning voltage on the cone inputs
73 for (el
=cl
->INCONE
; el
!=NULL
; el
=el
->NEXT
)
75 if ((el
->TYPE
& CNS_EXT
)!=CNS_EXT
)
77 ci
=(ConeInformations
*)Scheduler_GetRegisterObject(S
, pavo_get_cone_index(el
->UEDGE
.CONE
));
78 pavo_SetSignalVoltage(pavo_GetLosigByCone(CSI
.cf
, el
->UEDGE
.CONE
), ci
->CurrentVoltage
);
82 // calling appropriate function
83 *value
=pavo_CalcInternalNodeVoltage(cl
);
84 *delay
=1+(rand() % 10);
87 // --- fake value and timing-- a remplacer par la fonction adequate
89 // evaluation de la sortie
93 if (ra
==0 || ra
==4) *value
=0;
94 else if (ra
==1 || ra
==5) *value
=1.6;
95 else if (ra
==2) *value
=PAVO_HZ_VOLTAGE
;
96 else *value
=PAVO_UNKNOWN_VOLTAGE
;
99 // recuperation du temps de propagation
101 // ---------------------------
104 for (el
=cl
->INCONE
; el
!=NULL
; el
=el
->NEXT
)
106 if ((el
->TYPE
& CNS_EXT
)!=CNS_EXT
)
108 ci
=(ConeInformations
*)Scheduler_GetRegisterObject(S
, pavo_get_cone_index(el
->UEDGE
.CONE
));
109 pavo_RemoveSignalVoltage(pavo_GetLosigByCone(CSI
.cf
, el
->UEDGE
.CONE
));
115 void pavo_ExecuteFunction(Scheduler
*S
, int index
)
120 ConeInformations
*ci
;
123 ci
=(ConeInformations
*)Scheduler_GetRegisterObject(S
, index
);
125 for (el
=ci
->CONE
->OUTCONE
; el
!=NULL
; el
=el
->NEXT
)
127 if ((el
->TYPE
& CNS_EXT
)!=CNS_EXT
)
129 output
=pavo_get_cone_index(el
->UEDGE
.CONE
);
131 pavo_GetConeDelay_and_Voltage(S
, el
->UEDGE
.CONE
, &timing
, &newval
);
133 if (DEBUG
) printf("exec '%s'=f('%s') after %ld => %g\n",el
->UEDGE
.CONE
->NAME
, ci
->CONE
->NAME
, timing
, newval
);
134 if (newval
!=PAVO_HZ_VOLTAGE
) Scheduler_AddTransaction(S
, output
, timing
, &newval
);
139 long nextpatterndate
=0;
142 void pavo_RandomPatterns(Scheduler
*S
, long lastdate
, long nextdate
)
144 if (endofpattern
==0 && nextpatterndate
>=lastdate
&& nextpatterndate
<=nextdate
)
146 long delta
=nextpatterndate
-lastdate
;
151 if (DEBUG
) avt_fprintf(stdout
, "¤2reading patterns at %ld¤.\n",nextpatterndate
);
152 else avt_fprintf(stdout
, "\r¤2reading patterns at %ld¤.",nextpatterndate
);
153 switch (nextpatterndate
)
156 newval
=1.6; Scheduler_AddTransaction(S
, pavo_get_input_cone("a"), delta
, &newval
);
157 nextpatterndate
=1000;
160 newval
=0; Scheduler_AddTransaction(S
, pavo_get_input_cone("b"), delta
, &newval
);
161 nextpatterndate
=1500;
164 newval
=1.6; Scheduler_AddTransaction(S
, pavo_get_input_cone("d"), delta
, &newval
);
165 nextpatterndate
=3000;
168 newval
=0; Scheduler_AddTransaction(S
, pavo_get_input_cone("c"), delta
, &newval
);
169 nextpatterndate
=3200;
172 newval
=1.6; Scheduler_AddTransaction(S
, pavo_get_input_cone("a"), delta
, &newval
);
173 newval
=1.6; Scheduler_AddTransaction(S
, pavo_get_input_cone("b"), delta
, &newval
);
174 newval
=1.6; Scheduler_AddTransaction(S
, pavo_get_input_cone("c"), delta
, &newval
);
175 newval
=0; Scheduler_AddTransaction(S
, pavo_get_input_cone("d"), delta
, &newval
);
176 nextpatterndate
=5000;
179 newval
=0; Scheduler_AddTransaction(S
, pavo_get_input_cone("a"), delta
, &newval
);
180 newval
=0; Scheduler_AddTransaction(S
, pavo_get_input_cone("b"), delta
, &newval
);
181 newval
=1.6; Scheduler_AddTransaction(S
, pavo_get_input_cone("c"), delta
, &newval
);
182 newval
=1.6; Scheduler_AddTransaction(S
, pavo_get_input_cone("d"), delta
, &newval
);
183 nextpatterndate
=6000;
188 sprintf(name
,"%c",'a'+var
);
189 if (rand() % 3==0) inewval
=rand() % 4;
190 else inewval
=rand() % 2;
191 if (inewval
==1) newval
=1.6;
192 else if (inewval
==2) newval
=PAVO_UNKNOWN_VOLTAGE
;
194 Scheduler_AddTransaction(S
, pavo_get_input_cone(name
), delta
, &newval
);
195 nextpatterndate
+=1+(rand() % 10);
203 void pavo_register_cones(cnsfig_list
*cf
, Scheduler
*S
, pavo_ConeSimulatorInfo
*CSI
)
207 ConeInformations
*ci
;
209 CSI
->ExternalCones
=addht(100);
211 for (cl
=cf
->CONE
; cl
!=NULL
; cl
=cl
->NEXT
)
213 cl
->USER
=addptype(cl
->USER
, PAVO_CONE_INDEX
, (void *)(long)number
);
214 ci
=(ConeInformations
*)mbkalloc(sizeof(ConeInformations
));
216 Scheduler_RegisterObject(S
, number
, ci
);
217 if (cl
->TYPE
& CNS_EXT
)
219 addhtitem(CSI
->ExternalCones
, cl
->NAME
, number
);
225 void pavo_initialize_cone(cnsfig_list
*cf
, Scheduler
*S
)
229 ConeInformations
*ci
;
231 for (cl
=cf
->CONE
; cl
!=NULL
; cl
=cl
->NEXT
)
233 index
=pavo_get_cone_index(cl
);
234 ci
=(ConeInformations
*)Scheduler_GetRegisterObject(S
, index
);
235 ci
->CurrentVoltage
=PAVO_UNKNOWN_VOLTAGE
;
236 ci
->ModificationDate
=0;
240 void pavo_uninitialize_cone(cnsfig_list
*cf
, Scheduler
*S
)
244 ConeInformations
*ci
;
246 for (cl
=cf
->CONE
; cl
!=NULL
; cl
=cl
->NEXT
)
248 index
=pavo_get_cone_index(cl
);
249 ci
=(ConeInformations
*)Scheduler_GetRegisterObject(S
, index
);
254 void pavo_SimulateNetlist(cnsfig_list
*cf
, long UntilDate
)
258 S
=Scheduler_CreateSimulator(sizeof(float), pavo_UpdateFunction
, pavo_ExecuteFunction
, pavo_RandomPatterns
);
262 pavo_register_cones(cf
, S
, &CSI
);
263 pavo_initialize_cone(cf
, S
);
265 Scheduler_RunSimulator(S
, UntilDate
);
267 printf("%d transactions remaining\n",S
->DS
.TransactionCount
);
268 printf("next date = %ld\n",Scheduler_GetNextDate(S
));
270 pavo_uninitialize_cone(cf
, S
);
271 delht(CSI
.ExternalCones
);
273 Scheduler_DeleteSimulator(S
);
276 void pavo_SimulateNetlist_test(char *name
, long UntilDate
)
279 if ((cf
=getloadedcnsfig(name
))!=NULL
)
281 pavo_SimulateNetlist(cf
, UntilDate
);
285 printf("could not find cone netlist '%s', no simulation done.\n", name
);
290 int ymain(int ac
, char *av
[])
298 // desassembler netlist
301 pavo_SimulateNetlist(cf
, 4000);