1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
|
/****************************************************************************
Copyright (C) 1987-2015 by Jeffery P. Hansen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
****************************************************************************/
#ifndef __evqueue_h
#define __evqueue_h
/*****************************************************************************
*
* Event Queue Data Structures
*
* The event queue is the center of the simulation. Everything to be executed
* by the simulator passes through the event queue.
*
*****************************************************************************/
/*****************************************************************************
* evtype_t - Event type code
*****************************************************************************/
typedef enum {
EV_UNKNOWN = 0, /* An unknown event type */
EV_THREAD = 1, /* A thread becomes ready for execution */
EV_NET = 2, /* A net value change */
EV_CONTROL = 3, /* A control event occured */
EV_DRIVER = 4, /* A wire driver change event occured */
EV_STROBE = 5, /* A strobe display */
EV_PROBE = 6, /* A probe display */
EV_MEM = 7, /* A memory assignment */
} evtype_t;
/*****************************************************************************
* evstatus_t - Event status
*****************************************************************************/
typedef enum {
ES_MACTIVE = 1, /* Active event allocated by malloc() */
ES_FACTIVE = 2, /* Active event allocated from freelist */
ES_FREELIST = 3, /* Event is on free list */
} evstatus_t;
/*****************************************************************************
* Event queue flags
*****************************************************************************/
typedef enum {
EVF_NONE = 0x0,
EVF_RUN = 0x1, /* Event queue is free running */
EVF_POSCLOCK = 0x2, /* Wait for a clock posedge transition */
EVF_NEGCLOCK = 0x4, /* Wait for a clock negedge transition */
EVF_HASCLOCK = 0x8, /* The circuit contains at least one clock */
EVF_LIMIT = 0x10, /* Limit simulation time until pause */
EVF_NOCMD = 0x20, /* Do not process commands */
EVF_CLKWATCH = 0x40, /* Check for clock signals */
} eqflag_t;
typedef enum {
WC_NONE = 0, /* No clock checking */
WC_ANYPOS = 1, /* Any clock posedge */
WC_ANYNEG = 2, /* Any clock negedge */
WC_ACTIVEPOS = 3, /* Active clock posedge */
WC_ACTIVENEG = 4, /* Active clock negedge */
} ckwatchcmd_t;
/*****************************************************************************
*
* Function type for event processing functions.
*
*****************************************************************************/
typedef void EventProcess_f(Event*,EvQueue*);
/*****************************************************************************
*
* Function type for event uninitialization functions.
*
*****************************************************************************/
typedef void EventUninit_f(Event*);
/*****************************************************************************
*
* EventVTable - virtual function table for events
*
*****************************************************************************/
typedef struct {
evtype_t evv_class; /* Type of event */
EventProcess_f *evv_process; /* Process an event */
EventUninit_f *evv_uninit; /* Uninitialization of an event */
} EventVTable;
/*****************************************************************************
*
* EvBase - Basic event members shared by all event types.
*
*****************************************************************************/
typedef struct {
EventVTable *eb_vtable; /* Virtual table for event */
simtime_t eb_time; /* Time of event */
Event *eb_next; /* Next event in bucket */
evstatus_t eb_status; /* Event status */
} EvBase;
/*****************************************************************************
*
* EvStrobe - System task call delayed until strobe phase.
*
*****************************************************************************/
typedef struct {
EvBase es_base; /* Base event members */
systask_f *es_task; /* Task to execute */
TaskContext *es_taskContext;/* Task context */
} EvStrobe;
/*****************************************************************************
*
* EvProbe - Probe a net for changes. These events are normally "persistant"
* in that they remain in the finalQ until explicitly removed
*
*****************************************************************************/
typedef struct {
EvBase ep_base; /* Base event members */
char *ep_who; /* Who do we report to */
Net *ep_net; /* Net to test. */
char *ep_name; /* Net name to report with probe (which alias of ep_net) */
Value *ep_lastValue; /* Last value of net */
} EvProbe;
/*****************************************************************************
*
* EvNet - Event causing a net value to change
*
*****************************************************************************/
typedef struct {
EvBase en_base; /* Base event members */
Net *en_net; /* Net which changed */
int en_lsb; /* LSB in net to write to (MSB implied from en_state width) */
Value *en_state; /* New value for net */
} EvNet;
/*****************************************************************************
*
* EvDriver - Event causing a wire driver value to change
*
*****************************************************************************/
typedef struct {
EvBase ed_base; /* Base event members */
Net *ed_net; /* Net which changed */
int ed_id; /* ID of driver that changed */
Value *ed_state; /* New value for net */
} EvDriver;
/*****************************************************************************
*
* EvControl - A control event
*
*****************************************************************************/
typedef struct {
EvBase ec_base; /* Base event members */
unsigned ec_type; /* Control code */
void *ec_data; /* Control data */
} EvControl;
/*****************************************************************************
*
* EvThread - A thread activation event
*
*****************************************************************************/
typedef struct {
EvBase et_base; /* Base event members */
VGThread *et_thread; /* Thread affected by event */
} EvThread;
/*****************************************************************************
*
* EvMem - Event causing a memory value to change
*
*****************************************************************************/
typedef struct {
EvBase em_base; /* Base event members */
Net *em_mem; /* Net for memory that is changing */
unsigned em_addr; /* Address in memory to change */
int em_lsb; /* LSB in net to write to (MSB implied from en_state width) */
Value *em_state; /* New value for memory */
} EvMem;
/*****************************************************************************
*
* Event - Simulator event
*
*****************************************************************************/
union Event_union {
EventVTable *ev_vtable;
EvBase ev_base;
EvNet ev_net;
EvStrobe ev_strobe;
EvDriver ev_driver;
EvThread ev_thread;
EvControl ev_control;
EvProbe ev_probe;
EvMem ev_mem;
};
/*****************************************************************************
*
* SQueue - Simple event queue.
*
*****************************************************************************/
typedef struct {
Event *sq_head;
Event *sq_tail;
} SQueue;
/*****************************************************************************
*
* WClock - Clock watch description
*
*****************************************************************************/
typedef struct {
ckwatchcmd_t wc_cmd; /* Clock watch command */
Net *wc_net; /* Net of clock */
int wc_numEdge; /* Number of edges to watch */
deltatime_t wc_overstep; /* Overstep amount */
} WClock;
/*****************************************************************************
*
* EvQueue - The event queue.
*
*****************************************************************************/
struct EvQueue_str {
Circuit *eq_circuit; /* Pointer to top level cicuit */
eqflag_t eq_flags; /* Event queue flags */
simtime_t eq_finalTime; /* Time of last final processing */
simtime_t eq_curTime; /* Current time step */
simtime_t eq_limitTime; /* Time to stop simulator if limit enabled */
unsigned eq_numPending; /* Number of pending events */
Event *eq_wheelHead[THYMEWHEEL_SIZE]; /* Event queues for each step (for dequeue) */
Event *eq_wheelTail[THYMEWHEEL_SIZE]; /* Event queues for each step (for enqueue) */
int eq_monitorOn; /* Non-zero if monitor is enabled */
SQueue eq_assignQ; /* Queue for current time non-blocking assignment */
SQueue eq_strobeQ; /* Queue for current strobe events */
SQueue eq_inactiveQ; /* Inactive events queue (used for #0 statements) */
SHash eq_finalQ; /* Persistent events occuring at end of each step */
Event *eq_monitor; /* Event for monitor execution */
Event *eq_overflowQ; /* Overflow events ouside regular time window */
Event *eq_realQ; /* Events with real-time time stamps */
WClock eq_watchClock; /* Clock watch description */
int eq_monitoredChange; /* Monitored variables have changed in this epoch */
};
/*****************************************************************************
* EvQueue member functions
*****************************************************************************/
EvQueue *new_EvQueue(Circuit *C);
void EvQueue_init(EvQueue *Q,Circuit *C);
void EvQueue_print(EvQueue *Q);
void EvQueue_enqueue(EvQueue *Q,Event *E);
void EvQueue_enqueueAt(EvQueue *Q,Event *E,simtime_t t);
void EvQueue_enqueueAfter(EvQueue *Q,Event *E,deltatime_t t);
void EvQueue_enqueueInactive(EvQueue *Q, Event*);
void EvQueue_enqueueStrobe(EvQueue *Q, Event*);
void EvQueue_enqueueMonitor(EvQueue *Q, Event*);
void EvQueue_timedEnqueue(EvQueue *Q, Event *E, simtime_t t);
void EvQueue_enqueueAtHead(EvQueue *Q, Event *E);
void EvQueue_enqueueFinal(EvQueue *Q, const char *key, Event*);
#define EvQueue_findFinal(Q,key) ((Event*) SHash_find(&(Q)->eq_finalQ, key))
void EvQueue_removeFinal(EvQueue *Q, const char *key);
Event *EvQueue_dequeue(EvQueue*);
void EvQueue_remove(EvQueue *Q,Event *E);
void EvQueue_update(EvQueue *Q);
void EvQueue_mainEventLoop(EvQueue *Q);
void EvQueue_interactiveMainEventLoop(EvQueue *Q);
int EvQueue_check(EvQueue *Q);
void EvQueue_stopAfter(EvQueue*,deltatime_t dt);
void EvQueue_clockStop(EvQueue *Q,Net *n,int numEdge,transtype_t tt,deltatime_t dt);
void EvQueue_clockNotify(EvQueue *Q,Net *n, transtype_t tt);
#define EvQueue_pending(Q) (Q)->eq_numPending
#define EvQueue_getCurTime(Q) (Q)->eq_curTime
#define EvQueue_isRunning(Q) ((Q)->eq_flags & EVF_RUN)
#define EvQueue_stop(Q) ((Q)->eq_flags = (eqflag_t)((Q)->eq_flags & ~(EVF_RUN|EVF_LIMIT)))
#define EvQueue_monitoredChangeNotify(Q) ((Q)->eq_monitoredChange = 1)
void EvQueue_go(EvQueue *Q);
/*****************************************************************************
* Event member functions
*****************************************************************************/
Event *new_Event();
void delete_Event(Event*);
Event *new_EvThread(VGThread *t);
Event *new_EvNet(Net*,int nlsb,Value*,int smsb,int slsb);
Event *new_EvStrobe(systask_f *task,TaskContext *tContext);
Event *new_EvProbe(Net *n,const char *who,const char *name);
Event *new_EvDriver(Net *n,int id,int nlsb,Value *s,int smsb,int slsb);
Event *new_EvMem(Net*,Value *addr,int nlsb,Value*,int smsb,int slsb);
Event *Event_priorityInsert(Event *PQ,Event *E);
#define Event_process(e,q) (*(e)->ev_vtable->evv_process)(e,q)
#define Event_getType(e) (e)->ev_vtable->evv_class
#define Event_isThreadUser(e,t) (Event_getType(e) == EV_THREAD && ((EvThread*)(e))->et_thread == (t))
void Event_print(Event*e);
Event *new_EvThread(VGThread *thread);
void SQueue_init(SQueue *Q);
void SQueue_enqueue(SQueue *Q, Event *E);
void SQueue_remove(SQueue *Q, Event *E);
Event *SQueue_dequeue(SQueue *Q);
#endif
|