PICSimLab - Programmable IC Simulator Laboratory 0.9.3
PICSimLab - API
Loading...
Searching...
No Matches
picsimlab.h
1/* ########################################################################
2
3 PICSimLab - Programmable IC Simulator Laboratory
4
5 ########################################################################
6
7 Copyright (c) : 2010-2026 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
42class CPICSimLab {
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 int GetCheckForDevelVersionUpdate(void) { return check_for_devel; };
183
187 void SetCheckForDevelVersionUpdate(int cfd) { check_for_devel = cfd; };
188
192 void SavePrefs(std::string name, std::string value);
193
194 void PrefsClear(void) { prefs.clear(); };
195 int PrefsSaveToFile(std::string fname) { return SaveToFile(prefs, fname.c_str()); };
196 int PrefsLoadFromFile(std::string fname) { return LoadFromFile(prefs, fname.c_str()); };
197 unsigned int PrefsGetLinesCount(void) { return prefs.size(); };
198 std::string PrefsGetLine(int ln) { return prefs.at(ln); };
199
200 void OpenLoadHexFileDialog(void);
201
202 void SetNeedReboot(int nr = 1);
203 int GetNeedReboot(void) { return NeedReboot; };
204
205 void RegisterError(const std::string error);
206 int GetErrorCount(void) { return Errors.size(); };
207
208 std::string GetError(int en) { return Errors.at(en); };
209
210 void DeleteError(int en) { Errors.erase(Errors.begin() + en); };
211
212 void EndSimulation(int saveold = 0, const char* newpath = NULL);
213
214 void SetWorkspaceFileName(const std::string fname) { Workspacefn = fname; };
215
216 void SetLabs(const int lb, const int lb_) {
217 lab = lb;
218 lab_ = lb_;
219 };
220
221 int GetLab(void) { return lab; };
222 int GetLab_(void) { return lab_; };
223
224 int LoadHexFile(std::string fname);
225
226 void LoadWorkspace(std::string fnpzw, const int show_readme = 1);
227 void SaveWorkspace(std::string fnpzw);
228
229 void SetSimulationRun(int run);
230 int GetSimulationRun(void);
231
232 double GetScale(void) { return scale; };
233 void SetScale(double s) { scale = s; };
234
235 int GetNeedResize(void) { return need_resize; };
236 void SetNeedResize(int nr) { need_resize = nr; };
237
238 void Configure(const char* home, int use_default_board = 0, int create = 0, const char* lfile = NULL,
239 const int disable_debug = 0);
240
241 void SetplWidth(int pw) { plWidth = pw; };
242
243 void SetplHeight(int ph) { plHeight = ph; };
244
245 double GetIdleMs(void);
246 void SetIdleMs(double im);
247
248 int GetUseDSRReset(void) { return use_dsr_reset; };
249 void SetUseDSRReset(int udsr) { use_dsr_reset = udsr; };
250
251 void SetToDestroy(int reason = RC_EXIT);
252 int GetToDestroy(void) { return settodestroy; };
253
254 void SetSync(unsigned char s) { sync = s; };
255 unsigned char GetSync(void) { return sync; };
256
257 char* GetPzwTmpdir(void) { return pzwtmpdir; };
258
259 void UpdateStatus(const PICSimlabStatus field, const std::string msg);
260
261 void* UpdateGUI(const int id, const PICSimlabGUIType type, const PICSimlabGUIAction action, const void* arg);
262
263 void ConfigMenuGUI(const PICSimlabGUIMenu type);
264
265 static int CanvasCmd(const CanvasCmd_t cmd);
266
267 static int WindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value,
268 void* ReturnBuff = NULL);
269
270 static int SystemCmd(const PICSimLabSystemCmd cmd, const char* Arg, void* ReturnBuff = NULL);
271
272 std::atomic<unsigned short int> status;
273
274 std::atomic<int> tgo;
275
276 int plWidth;
277 int plHeight;
278 int use_dsr_reset;
279
280 void (*OnUpdateStatus)(const int field, const std::string msg);
281 void (*OnConfigure)(void);
282 void (*OnClockSet)(const float clk, const int update);
283 void (*OnReadPreferences)(const char* name, const char* value, const int create);
284 void (*OnSavePrefs)(void);
285 void (*OnLoadHexFile)(const std::string fname);
286 void (*OnOpenLoadHexFileDialog)(void);
287 void (*OnEndSimulation)(void);
288 void* (*OnUpdateGUI)(const int id, const PICSimlabGUIType type, const PICSimlabGUIAction action, const void* arg);
289 void (*OnConfigMenuGUI)(const PICSimlabGUIMenu type);
290
291 int (*OnCanvasCmd)(const CanvasCmd_t cmd);
292 int (*OnWindowCmd)(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value,
293 void* ReturnBuff);
294 int (*OnSystemCmd)(const PICSimLabSystemCmd cmd, const char* Arg, void* ReturnBuff);
295
296private:
297 void StartRControl(void);
298 board* pboard;
299 int lab;
300 int lab_;
301 std::string SHARE;
302 std::string libpath;
303 long int NSTEP;
304 long int NSTEPJ;
305 int JUMPSTEPS;
306 int mcurun;
307 int mcupwr;
308 int mcurst;
309 int mcudbg;
310 PICSimlabCPUState cpustate;
311 unsigned short debug_port;
312 unsigned short remotec_port;
313 std::string HOME;
314 std::string PATH;
315 std::string FNAME;
316 std::string OldPath;
317 std::string proc_;
318 std::string pzw_ver;
319 int Instance;
320 int debug_type;
321 int debug;
322 int need_resize;
323 std::vector<std::string> prefs;
324 int NeedReboot;
325 std::vector<std::string> Errors;
326 std::string Workspacefn;
327 double scale;
328 double idle_ms;
329 int settodestroy;
330 unsigned char sync;
331 char pzwtmpdir[1024];
332 int check_for_devel;
333};
334
335extern CPICSimLab PICSimLab;
336
337#ifdef _WIN_
338#define msleep(x) Sleep(x)
339// extern void usleep(unsigned int usec);
340#include <unistd.h>
341#else
342#define msleep(x) usleep(x * 1000)
343#endif
344
345#define ST_T1 0x01
346#define ST_T2 0x02
347#define ST_TH 0x04
348#define ST_DI 0x80 // DISABLE
349
350#ifdef _WIN_
351#define NULLFILE "\\\\.\\NUL"
352#else
353#define NULLFILE "/dev/null"
354#endif
355
356#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 GetCheckForDevelVersionUpdate(void)
Return the selected debugger type.
Definition picsimlab.h:182
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:218
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:206
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:202
int GetDebugStatus(void)
Get debug status (On/Off).
Definition picsimlab.cc:214
int GetMcuPwr(void)
Return actual power status of microcontroller ON/OFF.
Definition picsimlab.h:97
void SetCheckForDevelVersionUpdate(int cfd)
Set debug type (MDB or GDB).
Definition picsimlab.h:187
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:254
Board class.
Definition board.h:114