1 /****************************************************************************
2     Copyright (C) 1987-2015 by Jeffery P. Hansen
3 
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License along
15     with this program; if not, write to the Free Software Foundation, Inc.,
16     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 ****************************************************************************/
18 #ifndef __simulate_h
19 #define __simulate_h
20 /*
21     Simulator dependant	state.	Contains information on	the
22     positions of switches and probes.  Also used to generate
23     unique names for circuit elements.
24 */
25 
26 
27 #define UNITS_S		0
28 #define UNITS_MS	1
29 #define UNITS_US	2
30 #define UNITS_NS	3
31 #define UNITS_PS	4
32 #define UNITS_FS	5
33 #define NUM_UNITS	6
34 
35 
36 /*****************************************************************************
37  *
38  * Simulator probe
39  *
40  *****************************************************************************/
41 typedef struct {
42   char 		*name;		/* Name of probe */
43   GNet		*net;		/* Net of probe */
44   int 		x,y;		/* Position */
45   GSimModule	*ss;		/* Simmodule this belongs to */
46 } GSimProbe;
47 
48 /*****************************************************************************
49  *
50  * Simulator switch
51  *
52  *****************************************************************************/
53 typedef struct {
54   char		*name;		/* Full name of wire */
55   char		*gname;		/* Full name of gate */
56   GCElement	*gate;		/* switch gate */
57   unsigned	*state;		/* State of switch */
58 } GSimSwitch;
59 
60 /*****************************************************************************
61  *
62  * Simulator LED (device that changes with simulation state)
63  *
64  *****************************************************************************/
65 typedef struct {
66   char		*name;		/* Full name of wire */
67   char		*gname;		/* Full name of gate */
68   GCElement	*gate;		/* led gate */
69 } GSimLed;
70 
71 /*****************************************************************************
72  *
73  * Simulator Module - A simulator module is generated for each instance of a
74  * module in the circuit hierarchy.
75  *
76  *****************************************************************************/
77 struct simmodule {
78   GCElement	*inst;		/* Module instance in parent */
79   GModuleDef	*mod;		/* Module this corresponds to */
80 
81   SHash		*probes;	/* Probes in this module instance */
82   SHash		*switches;	/* Switches in this module instance */
83   SHash		*leds;		/* Leds in this module instance */
84   SHash		*children;	/* Child module instance */
85 
86   GSimModule	*parent;	/* Parent module instance */
87 };
88 
89 /*****************************************************************************
90  *
91  * Simulator interface
92  *
93  *****************************************************************************/
94 typedef struct SimInterface_str {
95   int		active;			/* Flag indicating running simulator */
96   char		simFileName[STRMAX];	/* Temp file with circuit description */
97   GSimModule	*sim_root;		/* Root simulator module */
98 
99   int		no_scope;		/* Non-zero if no scope should be created */
100 
101   int		area;			/* Area reported for circuit */
102   int		staticPower;		/* Static power reported for circuit */
103 
104   int		si_tsmult;		/* Timescale multiplier */
105   int		si_units;		/* Timescale units */
106   simtime_t	si_precision;		/* Precision is smaller than units */
107 } SimInterface;
108 
109 const char* SimInterface_unitsToStr(int);
110 int SimInterface_strToUnits(const char*);
111 
112 void SimInterface_init(SimInterface*);
113 void SimInterface_begin(SimInterface*);
114 void SimInterface_end(SimInterface*);
115 void SimInterface_drawProbes(SimInterface*);
116 void SimInterface_hit(SimInterface*,int x,int y,int isDoubleClick);
117 void SimInterface_hitRelease(SimInterface*);
118 void SimInterface_addDelProbe(SimInterface *si,GSimModule *sM,const char *name,GWire *w,GWireNode *n,int x,int y);
119 void SimInterface_delProbe(SimInterface *si,const char *name);
120 void SimInterface_addDelHDLProbe(SimInterface *si,GSimModule *sM,const char *name,GNet *net);
121 int SimInterface_probeExists(SimInterface *si,GSimModule *sM,const char *name);
122 void SimInterface_send(SimInterface*,const char*,...);
123 int SimInterface_lookupGate(SimInterface*,const char*,GSimModule **M,GCElement **g,GSimSwitch **ss);
124 int SimInterface_lookupWire(SimInterface*,const char*,GSimModule **M,GWire **w,GNet **n);
125 int SimInterface_command(SimInterface *si,const char *C);
126 void SimInterface_changeCurrentModule(GSimModule *new_sm,GSimModule *old_sm);
127 void SimInterface_gateError(SimInterface *si,const char *gname,const char *msg);
128 void SimInterface_fileError(SimInterface *si,const char *msg);
129 void SimInterface_wireError(SimInterface *si,const char *wname,const char *msg);
130 void SimInterface_navigateToModule(EditState **es,const char *path);
131 void SimInterface_updateNetlistProbes(GSimModule *SM);
132 char *SimInterface_formatTime(SimInterface *si, char *buf,simtime_t t);
133 
134 void GSimModule_getNetPathName(GSimModule *M,GNet *n,char *buf);
135 void GSimModule_getFullPath(GSimModule *M,GCElement *g,char *buf);
136 char *GSimModule_getPathPrefix(GSimModule *M,char *buf);
137 
138 GNet *sim_findNet(const char *name);
139 GCElement *sim_findGate(const char *name);
140 GModuleDef *sim_findContainingMod(const char *path);
141 
142 
143 int breakpoint_check(const char *s);
144 
145 void getSimTempFile(char*);
146 
147 void sendSimCmd(char *fmt,...);
148 
149 #endif
150 
151