PICSimLab - Programmable IC Simulator Laboratory 0.9.2
PICSimLab - API
Loading...
Searching...
No Matches
board.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 BOARD_H
27#define BOARD_H
28
29#include <picsim/picsim.h>
30#include <stdint.h>
31
32#include <stdlib.h>
33#include <string.h>
34#include <string>
35
36#define INCOMPLETE \
37 printf("Incomplete: %s -> %s :%i\n", __func__, __FILE__, __LINE__); \
38 exit(-1);
39
40enum { ARCH_P16, ARCH_P16E, ARCH_P18, ARCH_AVR8, ARCH_STM32, ARCH_STM8, ARCH_C51, ARCH_Z80, ARCH_UNKNOWN };
41
46typedef struct {
47 float x1;
48 float x2;
49 float y1;
50 float y2;
51 float cx;
52 float cy;
53 char name[10];
54 unsigned short id;
55 void* status;
56 unsigned char* update;
57 union {
58 unsigned char value;
59 short value_s;
60 float value_f;
61 };
62} input_t;
63
68typedef struct {
69 float x1;
70 float x2;
71 float y1;
72 float y2;
73 float cx;
74 float cy;
75 float r;
76 char name[10];
77 unsigned short id;
78 void* status;
79 unsigned char update;
80 union {
81 unsigned char value;
82 short value_s;
83 float value_f;
84 };
85} output_t;
86
87#define MAX_TIMERS 256
88
89#define MAX_IDS 128
90
91#define INVALID_ID (MAX_IDS - 1)
92
97typedef struct {
98 uint32_t Timer;
99 uint32_t Reload;
100 void* Arg;
101 void (*Callback)(void* arg);
102 int Enabled;
103 double Tout; // in us
104} Timers_t;
105
111class board {
112public:
116 virtual void Draw(void) = 0;
117
121 virtual void Run_CPU(void) = 0;
122
126 virtual std::string GetSupportedDevices(void) = 0;
127
131 virtual std::string GetPictureFileName(void);
132
136 virtual std::string GetMapFile(void);
137
141 virtual void Reset(void) = 0;
142
146 virtual void EvMouseButtonPress(unsigned int button, unsigned int x, unsigned int y, unsigned int state) = 0;
147
151 virtual void EvMouseButtonRelease(unsigned int button, unsigned int x, unsigned int y, unsigned int state) = 0;
152
156 virtual void EvMouseMove(unsigned int button, unsigned int x, unsigned int y, unsigned int state) {};
157
161 virtual void EvKeyPress(unsigned int key, unsigned int mask) = 0;
162
166 virtual void EvKeyRelease(unsigned int key, unsigned int mask) = 0;
167
171 virtual void EvOnShow(void);
172
176 virtual void EvThreadRun(void) {};
177
181 virtual void RefreshStatus(void);
182
186 virtual void WritePreferences(void) {};
187
191 virtual void ReadPreferences(char* name, char* value) {};
192
196 virtual unsigned short GetInputId(char* name) = 0;
197
201 virtual unsigned short GetOutputId(char* name) = 0;
202
206 virtual void board_Event(const char* controlname) {};
207
211 virtual void board_ButtonEvent(const char* controlname, unsigned int button, unsigned int x, unsigned int y,
212 unsigned int state) {};
213
217 board(void);
218
222 virtual ~board(void);
223
227 void SetUseOscilloscope(int uo);
228
232 void SetUseSpareParts(int sp);
233
237 int GetUseOscilloscope(void);
238
242 int GetUseSpareParts(void);
243
247 virtual std::string GetName(void) = 0;
248
252 void SetProcessorName(std::string proc);
253
257 std::string GetProcessorName(void);
258
262 int GetInputCount(void);
263
267 input_t* GetInput(int n);
268
272 int GetOutputCount(void);
273
277 output_t* GetOutput(int n);
278
282 virtual int DebugInit(int dtyppe) = 0;
283
287 virtual std::string GetDebugName(void) = 0;
288
292 virtual std::string GetAboutInfo(void) = 0;
293
297 virtual void DebugLoop(void) = 0;
298
302 virtual int CpuInitialized(void) = 0;
303
307 virtual void MSetSerial(const char* port) = 0;
308
312 virtual int MInit(const char* processor, const char* fname, float freq) = 0;
313
317 virtual void MEnd(void) = 0;
318
322 virtual int MGetArchitecture(void) = 0;
323
327 virtual void EndServers(void) {};
328
332 virtual int MDumpMemory(const char* fname) = 0;
333
337 virtual void MEraseFlash(void) = 0;
338
342 virtual void MSetFreq(float freq) = 0;
343
347 virtual float MGetFreq(void) = 0;
348
352 virtual void MSetVCC(float vcc) = 0;
353
357 virtual float MGetVCC(void) = 0;
358
362 virtual float MGetInstClockFreq(void) = 0;
363
368
372 virtual int MGetPinCount(void) = 0;
373
377 virtual std::string MGetPinName(int pin) = 0;
378
382 virtual void MSetPin(int pin, unsigned char value) = 0;
383
387 virtual void MSetPinDOV(int pin, unsigned char ovalue) = 0;
388
392 virtual void MSetAPin(int pin, float value) = 0;
393
397 virtual unsigned char MGetPin(int pin) = 0;
398
402 virtual const picpin* MGetPinsValues(void) = 0;
403
407 virtual void MStep(void) = 0;
408
412 virtual void MStepResume(void) = 0;
413
417 virtual void MReset(int flags) = 0;
418
422 virtual unsigned short* DBGGetProcID_p(void) {
423 INCOMPLETE;
424 return NULL;
425 };
426
430 virtual unsigned int DBGGetPC(void) {
431 INCOMPLETE;
432 return 0;
433 };
434
438 virtual void DBGSetPC(unsigned int pc) { INCOMPLETE; };
439
443 virtual unsigned char* DBGGetRAM_p(void) {
444 INCOMPLETE;
445 return NULL;
446 };
447
451 virtual unsigned char* DBGGetROM_p(void) {
452 INCOMPLETE;
453 return NULL;
454 };
455
459 virtual unsigned char* DBGGetCONFIG_p(void) {
460 INCOMPLETE;
461 return NULL;
462 };
463
467 virtual unsigned char* DBGGetID_p(void) {
468 INCOMPLETE;
469 return NULL;
470 };
471
475 virtual unsigned char* DBGGetEEPROM_p(void) {
476 INCOMPLETE;
477 return NULL;
478 };
479
483 virtual unsigned int DBGGetRAMSize(void) {
484 INCOMPLETE;
485 return 0;
486 };
487
491 virtual unsigned int DBGGetROMSize(void) {
492 INCOMPLETE;
493 return 0;
494 };
495
499 virtual unsigned int DBGGetCONFIGSize(void) {
500 INCOMPLETE;
501 return 0;
502 };
503
507 virtual unsigned int DBGGetIDSize(void) {
508 INCOMPLETE;
509 return 0;
510 };
511
515 virtual unsigned int DBGGetEEPROM_Size(void) {
516 INCOMPLETE;
517 return 0;
518 };
519
523 virtual unsigned int DBGGetRAMLAWR(void) {
524 INCOMPLETE;
525 return 0;
526 };
527
531 virtual unsigned int DBGGetRAMLARD(void) {
532 INCOMPLETE;
533 return 0;
534 };
535
539 unsigned char CalcAngle(int i, int x, int y);
540
544 virtual void SetScale(double scale);
545
549 double GetScale(void);
550
555 virtual int GetDefaultClock(void) { return 2; };
556
561 std::string GetDefaultProcessor(void) { return DProc; };
562
567 void SetDefaultProcessor(std::string dproc) { DProc = dproc; };
568
572 uint32_t GetInstCounter(void) { return InstCounter; };
573
577 uint32_t GetInstCounter_us(const uint32_t start);
578
582 uint32_t GetInstCounter_ms(const uint32_t start);
583
587 int TimerRegister_us(const double micros, void (*Callback)(void* arg), void* arg);
588
592 int TimerRegister_ms(const double miles, void (*Callback)(void* arg), void* arg);
593
597 int TimerUnregister(const int timer);
598
602 int TimerChange_us(const int timer, const double micros);
603
607 int TimerChange_ms(const int timer, const double miles);
608
612 int TimerSetState(const int timer, const int enabled);
613
617 uint64_t TimerGet_ns(const int timer);
618
622 void TimerUpdateFrequency(float freq);
623
627 virtual void IoLockAccess(void) {};
628
632 virtual void IoUnlockAccess(void) {};
633
637 virtual int GetUARTRX(const int uart_num) { return 0; };
638
642 virtual int GetUARTTX(const int uart_num) { return 0; };
643
647 virtual std::string GetClkLabel(void) { return "Clk (Mhz)"; };
648
649protected:
653 virtual void RegisterRemoteControl(void) {};
654
658 void InstCounterInc(void);
659
660 std::string Proc;
661 std::string DProc;
662 input_t input[MAX_IDS];
663 input_t* input_ids[MAX_IDS];
664 output_t output[MAX_IDS];
666 int inputc;
670 unsigned char p_RST;
671 float Scale;
672
676 void ReadMaps(void);
677
681 void StartThread(void);
682
686 void StopThread(void);
687
688private:
689 uint32_t InstCounter;
690 int TimersCount;
691 Timers_t Timers[MAX_TIMERS];
692 Timers_t* TimersList[MAX_TIMERS];
693
697 void ReadInputMap(std::string fname);
698
702 void ReadOutputMap(std::string fname);
703};
704
705extern int ioupdated;
706
707#endif /* BOARD_H */
708
709#ifndef BOARDS_DEFS_H
710#define BOARDS_DEFS_H
711
712#define board_init(name, function) \
713 static board* function##_create(void) { \
714 board* b = new function(); \
715 b->SetDefaultProcessor(b->GetProcessorName()); \
716 return b; \
717 }; \
718 static void __attribute__((constructor)) function##_init(void); \
719 static void function##_init(void) { \
720 board_register(name, function##_create); \
721 }
722
723typedef board* (*board_create_func)(void);
724
725void board_register(const char* name, board_create_func bcreate);
726
727// boards object creation
728board* create_board(int* lab, int* lab_);
729
730#define BOARDS_MAX 25
731
732extern int BOARDS_LAST;
733
734typedef struct {
735 char name[30]; // name
736 char name_[30]; // name without spaces
737 board_create_func bcreate;
738} board_desc;
739
740extern board_desc boards_list[BOARDS_MAX];
741
742// Arduino Uno is the dafault board
743#define DEFAULT_BOARD 2
744
745#endif /* BOARDS_DEFS_H */
Board class.
Definition board.h:111
virtual unsigned int DBGGetRAMLARD(void)
board microcontroller get last ram read address
Definition board.h:531
virtual unsigned int DBGGetROMSize(void)
board microcontroller get ROM (FLASH) memory size
Definition board.h:491
virtual unsigned short GetOutputId(char *name)=0
return the output ids numbers of names used in output map
virtual unsigned short GetInputId(char *name)=0
return the input ids numbers of names used in input map
int TimerChange_ms(const int timer, const double miles)
Modify timer value with us.
Definition board.cc:489
input_t * GetInput(int n)
Get board input.
Definition board.cc:315
virtual std::string GetName(void)=0
Get board name registered in PICSimLab.
virtual void EvMouseButtonPress(unsigned int button, unsigned int x, unsigned int y, unsigned int state)=0
Event on the board.
output_t output[MAX_IDS]
output map elements
Definition board.h:664
void StartThread(void)
Start parallel thread.
Definition board.cc:382
virtual int DebugInit(int dtyppe)=0
Start debug support.
virtual unsigned char * DBGGetCONFIG_p(void)
board microcontroller get CONFIG memory pointer
Definition board.h:459
virtual void board_ButtonEvent(const char *controlname, unsigned int button, unsigned int x, unsigned int y, unsigned int state)
Called when window side controls are activated.
Definition board.h:211
input_t * input_ids[MAX_IDS]
input map elements by id order
Definition board.h:663
virtual void EvKeyRelease(unsigned int key, unsigned int mask)=0
Event on the board.
virtual unsigned int DBGGetRAMLAWR(void)
board microcontroller get last ram write address
Definition board.h:523
virtual std::string GetAboutInfo(void)=0
Return the about information of part.
virtual void Reset(void)=0
Reset board status.
virtual std::string GetClkLabel(void)
Return the description of clk label.
Definition board.h:647
virtual unsigned int DBGGetCONFIGSize(void)
board microcontroller get CONFIG memory size
Definition board.h:499
int use_oscope
use oscilloscope window
Definition board.h:668
virtual void MSetPin(int pin, unsigned char value)=0
board microcontroller set digital pin
virtual int GetUARTRX(const int uart_num)
Return the UART N RX pin number.
Definition board.h:637
virtual unsigned short * DBGGetProcID_p(void)
board microcontroller get pointer to processor ID
Definition board.h:422
void ReadOutputMap(std::string fname)
Read the Output Map.
Definition board.cc:206
virtual void RegisterRemoteControl(void)
Register remote control variables.
Definition board.h:653
virtual void EvThreadRun(void)
Event on the board.
Definition board.h:176
virtual void ReadPreferences(char *name, char *value)
Called whe configuration file load preferences.
Definition board.h:191
virtual float MGetInstClockFreq(void)=0
board microcontroller get cpu internal clock (in PIC frequency/4)
virtual void IoLockAccess(void)
Lock IO to others threads access.
Definition board.h:627
virtual unsigned int DBGGetIDSize(void)
board microcontroller get internal IDS memory size
Definition board.h:507
virtual void Draw(void)=0
Called ever 100ms to draw board.
virtual unsigned char * DBGGetID_p(void)
board microcontroller get internal IDS memory pointer
Definition board.h:467
std::string DProc
Name of default board processor.
Definition board.h:661
void SetDefaultProcessor(std::string dproc)
Set board default processor.
Definition board.h:567
int TimerRegister_us(const double micros, void(*Callback)(void *arg), void *arg)
Register a new timer with time in us (default enabled)
Definition board.cc:415
output_t * GetOutput(int n)
Get board input.
Definition board.cc:326
virtual unsigned char * DBGGetRAM_p(void)
board microcontroller get RAM memory pointer
Definition board.h:443
virtual unsigned char MGetPin(int pin)=0
board microcontroller get digital pin value
double GetScale(void)
Get board draw scale.
Definition board.cc:364
int GetOutputCount(void)
Get board output count.
Definition board.cc:322
int GetInputCount(void)
Get board input count.
Definition board.cc:311
int TimerSetState(const int timer, const int enabled)
Enable or disable timer.
Definition board.cc:502
virtual void EndServers(void)
board servers shutdown
Definition board.h:327
void InstCounterInc(void)
Increment the Intructions Counter.
Definition board.cc:402
int outputc
output map elements counter
Definition board.h:667
virtual void DBGSetPC(unsigned int pc)
board microcontroller set PC
Definition board.h:438
void SetUseOscilloscope(int uo)
Enable/disable oscilloscope measurement.
Definition board.cc:287
virtual void MSetFreq(float freq)=0
board microcontroller set frequency
virtual void EvMouseButtonRelease(unsigned int button, unsigned int x, unsigned int y, unsigned int state)=0
Event on the board.
virtual int MInit(const char *processor, const char *fname, float freq)=0
board microcontroller init
virtual unsigned char * DBGGetROM_p(void)
board microcontroller get ROM (FLASH) memory pointer
Definition board.h:451
virtual std::string GetPictureFileName(void)
Return the filename of board picture.
Definition board.cc:374
void SetProcessorName(std::string proc)
Set board processor.
Definition board.cc:303
virtual int MGetPinCount(void)=0
board microcontroller pin count
virtual int MGetArchitecture(void)=0
Return board microcontroller architecture.
virtual int CpuInitialized(void)=0
return true if microcontroller is initialized
virtual int MDumpMemory(const char *fname)=0
board microcontroller save non volatile memory to hex file
output_t * output_ids[MAX_IDS]
output map elements by id order
Definition board.h:665
virtual void WritePreferences(void)
Called to save board preferences in configuration file.
Definition board.h:186
virtual const picpin * MGetPinsValues(void)=0
board microcontroller get all pins list struct
int TimerChange_us(const int timer, const double micros)
Modify timer value with us.
Definition board.cc:476
unsigned char p_RST
board /RESET pin state
Definition board.h:670
int MGetClocksPerInstructions(void)
board microcontroller get Clock pulses per instruction (in PIC equal to 4)
Definition board.cc:333
virtual void MEraseFlash(void)=0
board microcontroller erase flash memory (program)
input_t input[MAX_IDS]
input map elements
Definition board.h:662
virtual void MSetPinDOV(int pin, unsigned char ovalue)=0
board microcontroller set Default Open Value (external pull)
virtual std::string MGetPinName(int pin)=0
board microcontroller pin name
virtual void MReset(int flags)=0
board microcontroller reset
virtual std::string GetDebugName(void)=0
Get debug interface name.
uint32_t GetInstCounter_ms(const uint32_t start)
Get elapsed time from instruction counter in us.
Definition board.cc:524
virtual float MGetVCC(void)=0
board microcontroller get vcc
board(void)
Called once on board creation.
Definition board.cc:34
virtual void board_Event(const char *controlname)
Called when window side controls are activated.
Definition board.h:206
uint64_t TimerGet_ns(const int timer)
Get elapsed time from instruction counter in ns.
Definition board.cc:513
std::string GetProcessorName(void)
Get board processor in use.
Definition board.cc:307
virtual void Run_CPU(void)=0
Paralle thread called ever 100ms to run cpu code.
virtual unsigned char * DBGGetEEPROM_p(void)
board microcontroller get data EEPROM memory pointer
Definition board.h:475
virtual void RefreshStatus(void)
Called ever 1s to refresh status.
Definition board.cc:283
void StopThread(void)
Stop parallel thread.
Definition board.cc:392
virtual void SetScale(double scale)
Set board draw scale.
Definition board.cc:360
virtual void MEnd(void)=0
board microcontroller end
std::string GetDefaultProcessor(void)
Get board default processor.
Definition board.h:561
virtual void MSetAPin(int pin, float value)=0
board microcontroller set analog pin
int use_spare
use spare parts window
Definition board.h:669
int TimerUnregister(const int timer)
Unregister timer.
Definition board.cc:455
virtual void MStepResume(void)=0
board microcontroller run one or two steps to resume instruction
virtual int GetUARTTX(const int uart_num)
Return the UART N TX pin number.
Definition board.h:642
virtual std::string GetSupportedDevices(void)=0
Return a list of supported microcontrollers.
int GetUseSpareParts(void)
Get if spare parts is in use.
Definition board.cc:299
virtual void IoUnlockAccess(void)
Unlock IO to others threads access.
Definition board.h:632
unsigned char CalcAngle(int i, int x, int y)
Calc rotary potentiometer angle.
Definition board.cc:337
virtual void MSetSerial(const char *port)=0
Set serial port name to use.
virtual void MStep(void)=0
board microcontroller run one step
virtual std::string GetMapFile(void)
Return the filename of board picture map.
Definition board.cc:378
int TimerRegister_ms(const double miles, void(*Callback)(void *arg), void *arg)
Register a new timer with time in ms (default enabled)
Definition board.cc:435
int inputc
input map elements counter
Definition board.h:666
virtual float MGetFreq(void)=0
board microcontroller get frequency
int GetUseOscilloscope(void)
Get if oscilloscope is in use.
Definition board.cc:295
virtual ~board(void)
Called once on board destruction.
Definition board.cc:59
virtual int GetDefaultClock(void)
Get board default clock in MHz.
Definition board.h:555
virtual unsigned int DBGGetEEPROM_Size(void)
board microcontroller get data EEPROM memory size
Definition board.h:515
virtual void EvMouseMove(unsigned int button, unsigned int x, unsigned int y, unsigned int state)
Event on the board.
Definition board.h:156
uint32_t GetInstCounter(void)
Get instruction counter.
Definition board.h:572
virtual unsigned int DBGGetRAMSize(void)
board microcontroller get RAM memory size
Definition board.h:483
void ReadMaps(void)
Read maps.
Definition board.cc:61
virtual void DebugLoop(void)=0
debug step (pooling)
void SetUseSpareParts(int sp)
Enable/disable spare parts.
Definition board.cc:291
virtual void MSetVCC(float vcc)=0
board microcontroller set vcc
virtual void EvOnShow(void)
Event on the board.
Definition board.cc:368
virtual unsigned int DBGGetPC(void)
board microcontroller get PC
Definition board.h:430
virtual void EvKeyPress(unsigned int key, unsigned int mask)=0
Event on the board.
uint32_t GetInstCounter_us(const uint32_t start)
Get elapsed time from instruction counter in us.
Definition board.cc:520
void ReadInputMap(std::string fname)
Read the Input Map.
Definition board.cc:76
std::string Proc
Name of processor in use.
Definition board.h:660
void TimerUpdateFrequency(float freq)
Update Timer counters on frequency change.
Definition board.cc:528
internal timer struct
Definition board.h:97
Definition board.h:734
input map struct
Definition board.h:46
float x2
x2 position
Definition board.h:48
float value_f
updated value float
Definition board.h:60
short value_s
updated value short
Definition board.h:59
float cx
center x position
Definition board.h:51
unsigned char * update
output need draw update
Definition board.h:56
float y2
y2 position
Definition board.h:50
float x1
x1 position
Definition board.h:47
void * status
rcontrol status
Definition board.h:55
unsigned char value
updated value
Definition board.h:58
unsigned short id
region ID
Definition board.h:54
float y1
y1 position
Definition board.h:49
float cy
center y position
Definition board.h:52
output map struct
Definition board.h:68
float r
radius
Definition board.h:75
float x2
x2 position
Definition board.h:70
short value_s
updated value short
Definition board.h:82
unsigned char value
updated value
Definition board.h:81
float y2
y2 position
Definition board.h:72
float y1
y1 position
Definition board.h:71
void * status
rcontrol status
Definition board.h:78
unsigned short id
region ID
Definition board.h:77
float x1
x1 position
Definition board.h:69
float value_f
updated value float
Definition board.h:83
unsigned char update
need draw update
Definition board.h:79
float cx
center x position
Definition board.h:73
float cy
center y position
Definition board.h:74