PICSimLab - Programmable IC Simulator Laboratory 0.9.2
PICSimLab - API
Loading...
Searching...
No Matches
picsimlab.h
1/* ########################################################################
2
3 PICSimLab - Programmable IC Simulator Laboratory
4
5 ########################################################################
6
7 Copyright (c) : 2010-2024 Luis Claudio GambĂ´a Lopes <lcgamboa@yahoo.com>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
23 For e-mail suggestions : lcgamboa@yahoo.com
24 ######################################################################## */
25
26#ifndef PICSIMLAB
27#define PICSIMLAB
28
29#define BASETIMER 100 // timer period in ms
30#define NSTEPKF (4000.0 / BASETIMER) // Freq constant 4.0*timer_freq
31#define NSTEPKT (1e6 / NSTEPKF) // TIMER constant 1MHz/(4.0*timer_freq)
32#define DEFAULTJS 100 // IO refresh rate
33
34extern char SERIALDEVICE[100];
35
36#include "board.h"
37#include "draw.h"
38#include "types.h"
39#include "util.h"
40
42public:
43 CPICSimLab();
44
45 void Init(void);
46
50 std::string GetSharePath(void) { return SHARE; };
51 void SetSharePath(std::string spath) { SHARE = spath; };
52
53 std::string GetLibPath(void) { return libpath; };
54 void SetLibPath(std::string lpath) { libpath = lpath; };
55
56 std::string GetHomePath(void) { return HOME; };
57 void SetHomePath(std::string home) { HOME = home; };
58
59 std::string GetPath(void) { return PATH; };
60 void SetPath(std::string path) { PATH = path; };
61
62 std::string GetFNAME(void) { return FNAME; };
63 void SetFNAME(std::string fname) { FNAME = fname; };
64
65 std::string GetOldPath(void) { return OldPath; };
66 void SetOldPath(std::string op) { OldPath = op; };
67
68 std::string GetProcessorName(void) { return proc_; };
69 void SetProcessorName(std::string pn) { proc_ = pn; };
70
71 long int GetNSTEP(void) { return NSTEP; };
72 void SetNSTEP(long int ns) { NSTEP = ns; };
73
77 long int GetNSTEPJ(void) { return NSTEPJ; };
78 void SetNSTEPJ(long int nsj) { NSTEPJ = nsj; };
79
83 int GetJUMPSTEPS(void) { return JUMPSTEPS; };
84 void SetJUMPSTEPS(int js);
85
89 board* GetBoard(void) { return pboard; };
90 void SetBoard(board* b) { pboard = b; };
91 void DeleteBoard(void);
92
96 int GetMcuPwr(void) { return mcupwr; };
97
101 int GetMcuRst(void) { return mcurst; };
102
103 int GetMcuDbg(void) { return mcudbg; };
104
108 void SetMcuPwr(int pp) {
109 mcupwr = pp;
110 if (mcupwr)
111 SetCpuState(CPU_RUNNING);
112 else
113 SetCpuState(CPU_POWER_OFF);
114 };
115
116 void SetCpuState(const PICSimlabCPUState cs);
117
121 void SetMcuRst(int pr) { mcurst = pr; };
122
123 char GetCpuState(void) { return cpustate; };
124
125 void Set_mcudbg(int pd);
126
127 void SetMcuRun(int mr) { mcurun = mr; };
128 int GetMcuRun(void) { return mcurst; };
129
133 unsigned short GetDebugPort(void) { return debug_port + Instance; };
134
138 void SetDebugPort(unsigned short dp);
139
143 unsigned short GetRemotecPort(void) { return remotec_port + Instance; };
144
148 void SetRemotecPort(unsigned short rcp);
149
153 int GetInstanceNumber(void) { return Instance; };
154
158 int GetDebugType(void) { return debug_type; };
159
163 void SetDebugType(int dt) { debug_type = dt; };
164
168 int GetDebugStatus(void);
169
173 void SetDebugStatus(int dbs);
174
175 void SetClock(const float clk, const int update = 1);
176 float GetClock(void);
177
181 void SavePrefs(std::string name, std::string value);
182
183 void PrefsClear(void) { prefs.clear(); };
184 int PrefsSaveToFile(std::string fname) { return SaveToFile(prefs, fname.c_str()); };
185 int PrefsLoadFromFile(std::string fname) { return LoadFromFile(prefs, fname.c_str()); };
186 unsigned int PrefsGetLinesCount(void) { return prefs.size(); };
187 std::string PrefsGetLine(int ln) { return prefs.at(ln); };
188
189 void OpenLoadHexFileDialog(void);
190
191 void SetNeedReboot(int nr = 1);
192 int GetNeedReboot(void) { return NeedReboot; };
193
194 void RegisterError(const std::string error);
195 int GetErrorCount(void) { return Errors.size(); };
196
197 std::string GetError(int en) { return Errors.at(en); };
198
199 void DeleteError(int en) { Errors.erase(Errors.begin() + en); };
200
201 void EndSimulation(int saveold = 0, const char* newpath = NULL);
202
203 void SetWorkspaceFileName(const std::string fname) { Workspacefn = fname; };
204
205 void SetLabs(const int lb, const int lb_) {
206 lab = lb;
207 lab_ = lb_;
208 };
209
210 int GetLab(void) { return lab; };
211 int GetLab_(void) { return lab_; };
212
213 int LoadHexFile(std::string fname);
214
215 void LoadWorkspace(std::string fnpzw, const int show_readme = 1);
216 void SaveWorkspace(std::string fnpzw);
217
218 void SetSimulationRun(int run);
219 int GetSimulationRun(void);
220
221 double GetScale(void) { return scale; };
222 void SetScale(double s) { scale = s; };
223
224 int GetNeedResize(void) { return need_resize; };
225 void SetNeedResize(int nr) { need_resize = nr; };
226
227 void Configure(const char* home, int use_default_board = 0, int create = 0, const char* lfile = NULL,
228 const int disable_debug = 0);
229
230 void SetplWidth(int pw) { plWidth = pw; };
231
232 void SetplHeight(int ph) { plHeight = ph; };
233
234 double GetIdleMs(void);
235 void SetIdleMs(double im);
236
237 int GetUseDSRReset(void) { return use_dsr_reset; };
238 void SetUseDSRReset(int udsr) { use_dsr_reset = udsr; };
239
240 void SetToDestroy(void);
241 int GetToDestroy(void) { return settodestroy; };
242
243 void SetSync(unsigned char s) { sync = s; };
244 unsigned char GetSync(void) { return sync; };
245
246 char* GetPzwTmpdir(void) { return pzwtmpdir; };
247
248 void UpdateStatus(const PICSimlabStatus field, const std::string msg);
249
250 void* UpdateGUI(const int id, const PICSimlabGUIType type, const PICSimlabGUIAction action, const void* arg);
251
252 void ConfigMenuGUI(const PICSimlabGUIMenu type);
253
254 static int CanvasCmd(const CanvasCmd_t cmd);
255
256 static int WindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value,
257 void* ReturnBuff = NULL);
258
259 static int SystemCmd(const PICSimLabSystemCmd cmd, const char* Arg, void* ReturnBuff = NULL);
260
261 union {
262 char st[2];
263 unsigned short int status;
264 } status;
265
266 int tgo;
267
268 int plWidth;
269 int plHeight;
270 int use_dsr_reset;
271
272 void (*OnUpdateStatus)(const int field, const std::string msg);
273 void (*OnConfigure)(void);
274 void (*OnClockSet)(const float clk, const int update);
275 void (*OnReadPreferences)(const char* name, const char* value, const int create);
276 void (*OnSavePrefs)(void);
277 void (*OnLoadHexFile)(const std::string fname);
278 void (*OnOpenLoadHexFileDialog)(void);
279 void (*OnEndSimulation)(void);
280 void* (*OnUpdateGUI)(const int id, const PICSimlabGUIType type, const PICSimlabGUIAction action, const void* arg);
281 void (*OnConfigMenuGUI)(const PICSimlabGUIMenu type);
282
283 int (*OnCanvasCmd)(const CanvasCmd_t cmd);
284 int (*OnWindowCmd)(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value,
285 void* ReturnBuff);
286 int (*OnSystemCmd)(const PICSimLabSystemCmd cmd, const char* Arg, void* ReturnBuff);
287
288private:
289 void StartRControl(void);
290 board* pboard;
291 int lab;
292 int lab_;
293 std::string SHARE;
294 std::string libpath;
295 long int NSTEP;
296 long int NSTEPJ;
297 int JUMPSTEPS;
298 int mcurun;
299 int mcupwr;
300 int mcurst;
301 int mcudbg;
302 PICSimlabCPUState cpustate;
303 unsigned short debug_port;
304 unsigned short remotec_port;
305 std::string HOME;
306 std::string PATH;
307 std::string FNAME;
308 std::string OldPath;
309 std::string proc_;
310 std::string pzw_ver;
311 int Instance;
312 int debug_type;
313 int debug;
314 int need_resize;
315 std::vector<std::string> prefs;
316 int NeedReboot;
317 std::vector<std::string> Errors;
318 std::string Workspacefn;
319 double scale;
320 double idle_ms;
321 int settodestroy;
322 unsigned char sync;
323 char pzwtmpdir[1024];
324};
325
326extern CPICSimLab PICSimLab;
327
328#ifdef _WIN_
329#define msleep(x) Sleep(x)
330// extern void usleep(unsigned int usec);
331#include <unistd.h>
332#else
333#define msleep(x) usleep(x * 1000)
334#endif
335
336#define ST_T1 0x01
337#define ST_T2 0x02
338#define ST_TH 0x04
339#define ST_DI 0x80 // DISABLE
340
341#ifdef _WIN_
342#define NULLFILE "\\\\.\\NUL"
343#else
344#define NULLFILE "/dev/null"
345#endif
346
347#endif // PICSIMLAB
Definition picsimlab.h:41
void SetMcuRst(int pr)
Set mcu rst flag (inform simulator about mcu reset state)
Definition picsimlab.h:121
int GetMcuRst(void)
Retunr if microcontroller reset pin is enabled.
Definition picsimlab.h:101
void SetDebugStatus(int dbs)
Set debug status flag.
Definition picsimlab.cc:215
long int GetNSTEPJ(void)
Get the number of steps in 100ms of simulation.
Definition picsimlab.h:77
void SetRemotecPort(unsigned short rcp)
Set remote control TCP port.
Definition picsimlab.cc:203
std::string GetSharePath(void)
Get the file path of resources.
Definition picsimlab.h:50
void SetMcuPwr(int pp)
Set the power status of microcontroller ON/OFF.
Definition picsimlab.h:108
void SetDebugPort(unsigned short dp)
Set debug TCP port.
Definition picsimlab.cc:199
int GetDebugStatus(void)
Get debug status (On/Off)
Definition picsimlab.cc:211
int GetMcuPwr(void)
Return actual power status of microcontroller ON/OFF.
Definition picsimlab.h:96
unsigned short GetRemotecPort(void)
Return the selected remote control port.
Definition picsimlab.h:143
int GetInstanceNumber(void)
Return the program instance number.
Definition picsimlab.h:153
int GetDebugType(void)
Return the selected debugger type.
Definition picsimlab.h:158
int GetJUMPSTEPS(void)
Get the number of steps to be skipped in board update.
Definition picsimlab.h:83
board * GetBoard(void)
Return a pointer to board object.
Definition picsimlab.h:89
unsigned short GetDebugPort(void)
Return the selected debugger port.
Definition picsimlab.h:133
void SetDebugType(int dt)
Set debug type (MDB or GDB)
Definition picsimlab.h:163
void SavePrefs(std::string name, std::string value)
Save the preferences.
Definition picsimlab.cc:251
Board class.
Definition board.h:111
Definition draw.h:77