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 <atomic>
37#include "board.h"
38#include "draw.h"
39#include "types.h"
40#include "util.h"
41
43public:
44 CPICSimLab();
45
46 void Init(void);
47
51 std::string GetSharePath(void) { return SHARE; };
52 void SetSharePath(std::string spath) { SHARE = spath; };
53
54 std::string GetLibPath(void) { return libpath; };
55 void SetLibPath(std::string lpath) { libpath = lpath; };
56
57 std::string GetHomePath(void) { return HOME; };
58 void SetHomePath(std::string home) { HOME = home; };
59
60 std::string GetPath(void) { return PATH; };
61 void SetPath(std::string path) { PATH = path; };
62
63 std::string GetFNAME(void) { return FNAME; };
64 void SetFNAME(std::string fname) { FNAME = fname; };
65
66 std::string GetOldPath(void) { return OldPath; };
67 void SetOldPath(std::string op) { OldPath = op; };
68
69 std::string GetProcessorName(void) { return proc_; };
70 void SetProcessorName(std::string pn) { proc_ = pn; };
71
72 long int GetNSTEP(void) { return NSTEP; };
73 void SetNSTEP(long int ns) { NSTEP = ns; };
74
78 long int GetNSTEPJ(void) { return NSTEPJ; };
79 void SetNSTEPJ(long int nsj) { NSTEPJ = nsj; };
80
84 int GetJUMPSTEPS(void) { return JUMPSTEPS; };
85 void SetJUMPSTEPS(int js);
86
90 board* GetBoard(void) { return pboard; };
91 void SetBoard(board* b) { pboard = b; };
92 void DeleteBoard(void);
93
97 int GetMcuPwr(void) { return mcupwr; };
98
102 int GetMcuRst(void) { return mcurst; };
103
104 int GetMcuDbg(void) { return mcudbg; };
105
109 void SetMcuPwr(int pp) {
110 mcupwr = pp;
111 if (mcupwr)
112 SetCpuState(CPU_RUNNING);
113 else
114 SetCpuState(CPU_POWER_OFF);
115 };
116
117 void SetCpuState(const PICSimlabCPUState cs);
118
122 void SetMcuRst(int pr) { mcurst = pr; };
123
124 char GetCpuState(void) { return cpustate; };
125
126 void Set_mcudbg(int pd);
127
128 void SetMcuRun(int mr) { mcurun = mr; };
129 int GetMcuRun(void) { return mcurun; };
130
134 unsigned short GetDebugPort(void) { return debug_port + Instance; };
135
139 void SetDebugPort(unsigned short dp);
140
144 unsigned short GetRemotecPort(void) { return remotec_port + Instance; };
145
149 void SetRemotecPort(unsigned short rcp);
150
154 int GetInstanceNumber(void) { return Instance; };
155
159 int GetDebugType(void) { return debug_type; };
160
164 void SetDebugType(int dt) { debug_type = dt; };
165
169 int GetDebugStatus(void);
170
174 void SetDebugStatus(int dbs);
175
176 void SetClock(const float clk, const int update = 1);
177 float GetClock(void);
178
182 void SavePrefs(std::string name, std::string value);
183
184 void PrefsClear(void) { prefs.clear(); };
185 int PrefsSaveToFile(std::string fname) { return SaveToFile(prefs, fname.c_str()); };
186 int PrefsLoadFromFile(std::string fname) { return LoadFromFile(prefs, fname.c_str()); };
187 unsigned int PrefsGetLinesCount(void) { return prefs.size(); };
188 std::string PrefsGetLine(int ln) { return prefs.at(ln); };
189
190 void OpenLoadHexFileDialog(void);
191
192 void SetNeedReboot(int nr = 1);
193 int GetNeedReboot(void) { return NeedReboot; };
194
195 void RegisterError(const std::string error);
196 int GetErrorCount(void) { return Errors.size(); };
197
198 std::string GetError(int en) { return Errors.at(en); };
199
200 void DeleteError(int en) { Errors.erase(Errors.begin() + en); };
201
202 void EndSimulation(int saveold = 0, const char* newpath = NULL);
203
204 void SetWorkspaceFileName(const std::string fname) { Workspacefn = fname; };
205
206 void SetLabs(const int lb, const int lb_) {
207 lab = lb;
208 lab_ = lb_;
209 };
210
211 int GetLab(void) { return lab; };
212 int GetLab_(void) { return lab_; };
213
214 int LoadHexFile(std::string fname);
215
216 void LoadWorkspace(std::string fnpzw, const int show_readme = 1);
217 void SaveWorkspace(std::string fnpzw);
218
219 void SetSimulationRun(int run);
220 int GetSimulationRun(void);
221
222 double GetScale(void) { return scale; };
223 void SetScale(double s) { scale = s; };
224
225 int GetNeedResize(void) { return need_resize; };
226 void SetNeedResize(int nr) { need_resize = nr; };
227
228 void Configure(const char* home, int use_default_board = 0, int create = 0, const char* lfile = NULL,
229 const int disable_debug = 0);
230
231 void SetplWidth(int pw) { plWidth = pw; };
232
233 void SetplHeight(int ph) { plHeight = ph; };
234
235 double GetIdleMs(void);
236 void SetIdleMs(double im);
237
238 int GetUseDSRReset(void) { return use_dsr_reset; };
239 void SetUseDSRReset(int udsr) { use_dsr_reset = udsr; };
240
241 void SetToDestroy(int reason = RC_EXIT);
242 int GetToDestroy(void) { return settodestroy; };
243
244 void SetSync(unsigned char s) { sync = s; };
245 unsigned char GetSync(void) { return sync; };
246
247 char* GetPzwTmpdir(void) { return pzwtmpdir; };
248
249 void UpdateStatus(const PICSimlabStatus field, const std::string msg);
250
251 void* UpdateGUI(const int id, const PICSimlabGUIType type, const PICSimlabGUIAction action, const void* arg);
252
253 void ConfigMenuGUI(const PICSimlabGUIMenu type);
254
255 static int CanvasCmd(const CanvasCmd_t cmd);
256
257 static int WindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value,
258 void* ReturnBuff = NULL);
259
260 static int SystemCmd(const PICSimLabSystemCmd cmd, const char* Arg, void* ReturnBuff = NULL);
261
262 std::atomic<unsigned short int> status;
263
264 std::atomic<int> tgo;
265
266 int plWidth;
267 int plHeight;
268 int use_dsr_reset;
269
270 void (*OnUpdateStatus)(const int field, const std::string msg);
271 void (*OnConfigure)(void);
272 void (*OnClockSet)(const float clk, const int update);
273 void (*OnReadPreferences)(const char* name, const char* value, const int create);
274 void (*OnSavePrefs)(void);
275 void (*OnLoadHexFile)(const std::string fname);
276 void (*OnOpenLoadHexFileDialog)(void);
277 void (*OnEndSimulation)(void);
278 void* (*OnUpdateGUI)(const int id, const PICSimlabGUIType type, const PICSimlabGUIAction action, const void* arg);
279 void (*OnConfigMenuGUI)(const PICSimlabGUIMenu type);
280
281 int (*OnCanvasCmd)(const CanvasCmd_t cmd);
282 int (*OnWindowCmd)(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value,
283 void* ReturnBuff);
284 int (*OnSystemCmd)(const PICSimLabSystemCmd cmd, const char* Arg, void* ReturnBuff);
285
286private:
287 void StartRControl(void);
288 board* pboard;
289 int lab;
290 int lab_;
291 std::string SHARE;
292 std::string libpath;
293 long int NSTEP;
294 long int NSTEPJ;
295 int JUMPSTEPS;
296 int mcurun;
297 int mcupwr;
298 int mcurst;
299 int mcudbg;
300 PICSimlabCPUState cpustate;
301 unsigned short debug_port;
302 unsigned short remotec_port;
303 std::string HOME;
304 std::string PATH;
305 std::string FNAME;
306 std::string OldPath;
307 std::string proc_;
308 std::string pzw_ver;
309 int Instance;
310 int debug_type;
311 int debug;
312 int need_resize;
313 std::vector<std::string> prefs;
314 int NeedReboot;
315 std::vector<std::string> Errors;
316 std::string Workspacefn;
317 double scale;
318 double idle_ms;
319 int settodestroy;
320 unsigned char sync;
321 char pzwtmpdir[1024];
322};
323
324extern CPICSimLab PICSimLab;
325
326#ifdef _WIN_
327#define msleep(x) Sleep(x)
328// extern void usleep(unsigned int usec);
329#include <unistd.h>
330#else
331#define msleep(x) usleep(x * 1000)
332#endif
333
334#define ST_T1 0x01
335#define ST_T2 0x02
336#define ST_TH 0x04
337#define ST_DI 0x80 // DISABLE
338
339#ifdef _WIN_
340#define NULLFILE "\\\\.\\NUL"
341#else
342#define NULLFILE "/dev/null"
343#endif
344
345#endif // PICSIMLAB
Definition picsimlab.h:42
void SetMcuRst(int pr)
Set mcu rst flag (inform simulator about mcu reset state)
Definition picsimlab.h:122
int GetMcuRst(void)
Retunr if microcontroller reset pin is enabled.
Definition picsimlab.h:102
void SetDebugStatus(int dbs)
Set debug status flag.
Definition picsimlab.cc:217
long int GetNSTEPJ(void)
Get the number of steps in 100ms of simulation.
Definition picsimlab.h:78
void SetRemotecPort(unsigned short rcp)
Set remote control TCP port.
Definition picsimlab.cc:205
std::string GetSharePath(void)
Get the file path of resources.
Definition picsimlab.h:51
void SetMcuPwr(int pp)
Set the power status of microcontroller ON/OFF.
Definition picsimlab.h:109
void SetDebugPort(unsigned short dp)
Set debug TCP port.
Definition picsimlab.cc:201
int GetDebugStatus(void)
Get debug status (On/Off)
Definition picsimlab.cc:213
int GetMcuPwr(void)
Return actual power status of microcontroller ON/OFF.
Definition picsimlab.h:97
unsigned short GetRemotecPort(void)
Return the selected remote control port.
Definition picsimlab.h:144
int GetInstanceNumber(void)
Return the program instance number.
Definition picsimlab.h:154
int GetDebugType(void)
Return the selected debugger type.
Definition picsimlab.h:159
int GetJUMPSTEPS(void)
Get the number of steps to be skipped in board update.
Definition picsimlab.h:84
board * GetBoard(void)
Return a pointer to board object.
Definition picsimlab.h:90
unsigned short GetDebugPort(void)
Return the selected debugger port.
Definition picsimlab.h:134
void SetDebugType(int dt)
Set debug type (MDB or GDB)
Definition picsimlab.h:164
void SavePrefs(std::string name, std::string value)
Save the preferences.
Definition picsimlab.cc:253
Board class.
Definition board.h:111
Definition draw.h:80