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
367 virtual int MGetPinCount(void) = 0;
368
372 virtual std::string MGetPinName(int pin) = 0;
373
377 virtual void MSetPin(int pin, unsigned char value) = 0;
378
382 virtual void MSetPinDOV(int pin, unsigned char ovalue) = 0;
383
387 virtual void MSetAPin(int pin, float value) = 0;
388
392 virtual unsigned char MGetPin(int pin) = 0;
393
397 virtual const picpin* MGetPinsValues(void) = 0;
398
402 virtual void MStep(void) = 0;
403
407 virtual void MStepResume(void) = 0;
408
412 virtual void MReset(int flags) = 0;
413
417 virtual unsigned short* DBGGetProcID_p(void) {
418 INCOMPLETE;
419 return NULL;
420 };
421
425 virtual unsigned int DBGGetPC(void) {
426 INCOMPLETE;
427 return 0;
428 };
429
433 virtual void DBGSetPC(unsigned int pc) { INCOMPLETE; };
434
438 virtual unsigned char* DBGGetRAM_p(void) {
439 INCOMPLETE;
440 return NULL;
441 };
442
446 virtual unsigned char* DBGGetROM_p(void) {
447 INCOMPLETE;
448 return NULL;
449 };
450
454 virtual unsigned char* DBGGetCONFIG_p(void) {
455 INCOMPLETE;
456 return NULL;
457 };
458
462 virtual unsigned char* DBGGetID_p(void) {
463 INCOMPLETE;
464 return NULL;
465 };
466
470 virtual unsigned char* DBGGetEEPROM_p(void) {
471 INCOMPLETE;
472 return NULL;
473 };
474
478 virtual unsigned int DBGGetRAMSize(void) {
479 INCOMPLETE;
480 return 0;
481 };
482
486 virtual unsigned int DBGGetROMSize(void) {
487 INCOMPLETE;
488 return 0;
489 };
490
494 virtual unsigned int DBGGetCONFIGSize(void) {
495 INCOMPLETE;
496 return 0;
497 };
498
502 virtual unsigned int DBGGetIDSize(void) {
503 INCOMPLETE;
504 return 0;
505 };
506
510 virtual unsigned int DBGGetEEPROM_Size(void) {
511 INCOMPLETE;
512 return 0;
513 };
514
518 virtual unsigned int DBGGetRAMLAWR(void) {
519 INCOMPLETE;
520 return 0;
521 };
522
526 virtual unsigned int DBGGetRAMLARD(void) {
527 INCOMPLETE;
528 return 0;
529 };
530
534 unsigned char CalcAngle(int i, int x, int y);
535
539 virtual void SetScale(double scale);
540
544 double GetScale(void);
545
550 virtual int GetDefaultClock(void) { return 2; };
551
556 std::string GetDefaultProcessor(void) { return DProc; };
557
562 void SetDefaultProcessor(std::string dproc) { DProc = dproc; };
563
567 uint32_t GetInstCounter(void) { return InstCounter; };
568
572 uint32_t GetInstCounter_us(const uint32_t start);
573
577 uint32_t GetInstCounter_ms(const uint32_t start);
578
582 int TimerRegister_us(const double micros, void (*Callback)(void* arg), void* arg);
583
587 int TimerRegister_ms(const double miles, void (*Callback)(void* arg), void* arg);
588
592 int TimerUnregister(const int timer);
593
597 int TimerChange_us(const int timer, const double micros);
598
602 int TimerChange_ms(const int timer, const double miles);
603
607 int TimerSetState(const int timer, const int enabled);
608
612 uint64_t TimerGet_ns(const int timer);
613
617 void TimerUpdateFrequency(float freq);
618
622 virtual void IoLockAccess(void){};
623
627 virtual void IoUnlockAccess(void){};
628
632 virtual int GetUARTRX(const int uart_num) { return 0; };
633
637 virtual int GetUARTTX(const int uart_num) { return 0; };
638
642 virtual std::string GetClkLabel(void) { return "Clk (Mhz)"; };
643
644protected:
648 virtual void RegisterRemoteControl(void){};
649
653 void InstCounterInc(void);
654
655 std::string Proc;
656 std::string DProc;
657 input_t input[MAX_IDS];
658 input_t* input_ids[MAX_IDS];
659 output_t output[MAX_IDS];
661 int inputc;
665 unsigned char p_RST;
666 float Scale;
667
671 void ReadMaps(void);
672
676 void StartThread(void);
677
681 void StopThread(void);
682
683private:
684 uint32_t InstCounter;
685 int TimersCount;
686 Timers_t Timers[MAX_TIMERS];
687 Timers_t* TimersList[MAX_TIMERS];
688
692 void ReadInputMap(std::string fname);
693
697 void ReadOutputMap(std::string fname);
698};
699
700extern int ioupdated;
701
702#endif /* BOARD_H */
703
704#ifndef BOARDS_DEFS_H
705#define BOARDS_DEFS_H
706
707#define board_init(name, function) \
708 static board* function##_create(void) { \
709 board* b = new function(); \
710 b->SetDefaultProcessor(b->GetProcessorName()); \
711 return b; \
712 }; \
713 static void __attribute__((constructor)) function##_init(void); \
714 static void function##_init(void) { \
715 board_register(name, function##_create); \
716 }
717
718typedef board* (*board_create_func)(void);
719
720void board_register(const char* name, board_create_func bcreate);
721
722// boards object creation
723board* create_board(int* lab, int* lab_);
724
725#define BOARDS_MAX 25
726
727extern int BOARDS_LAST;
728
729typedef struct {
730 char name[30]; // name
731 char name_[30]; // name without spaces
732 board_create_func bcreate;
733} board_desc;
734
735extern board_desc boards_list[BOARDS_MAX];
736
737// Arduino Uno is the dafault board
738#define DEFAULT_BOARD 2
739
740#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:526
virtual unsigned int DBGGetROMSize(void)
board microcontroller get ROM (FLASH) memory size
Definition board.h:486
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:485
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:659
void StartThread(void)
Start parallel thread.
Definition board.cc:378
virtual int DebugInit(int dtyppe)=0
Start debug support.
virtual unsigned char * DBGGetCONFIG_p(void)
board microcontroller get CONFIG memory pointer
Definition board.h:454
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:658
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:518
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:642
virtual unsigned int DBGGetCONFIGSize(void)
board microcontroller get CONFIG memory size
Definition board.h:494
int use_oscope
use oscilloscope window
Definition board.h:663
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:632
virtual unsigned short * DBGGetProcID_p(void)
board microcontroller get pointer to processor ID
Definition board.h:417
void ReadOutputMap(std::string fname)
Read the Output Map.
Definition board.cc:206
virtual void RegisterRemoteControl(void)
Register remote control variables.
Definition board.h:648
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:622
virtual unsigned int DBGGetIDSize(void)
board microcontroller get internal IDS memory size
Definition board.h:502
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:462
std::string DProc
Name of default board processor.
Definition board.h:656
void SetDefaultProcessor(std::string dproc)
Set board default processor.
Definition board.h:562
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:411
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:438
virtual unsigned char MGetPin(int pin)=0
board microcontroller get digital pin value
double GetScale(void)
Get board draw scale.
Definition board.cc:360
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:498
virtual void EndServers(void)
board servers shutdown
Definition board.h:327
void InstCounterInc(void)
Increment the Intructions Counter.
Definition board.cc:398
int outputc
output map elements counter
Definition board.h:662
virtual void DBGSetPC(unsigned int pc)
board microcontroller set PC
Definition board.h:433
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:446
virtual std::string GetPictureFileName(void)
Return the filename of board picture.
Definition board.cc:370
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:660
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:472
unsigned char p_RST
board /RESET pin state
Definition board.h:665
virtual void MEraseFlash(void)=0
board microcontroller erase flash memory (program)
input_t input[MAX_IDS]
input map elements
Definition board.h:657
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:520
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:509
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:470
virtual void RefreshStatus(void)
Called ever 1s to refresh status.
Definition board.cc:283
void StopThread(void)
Stop parallel thread.
Definition board.cc:388
virtual void SetScale(double scale)
Set board draw scale.
Definition board.cc:356
virtual void MEnd(void)=0
board microcontroller end
std::string GetDefaultProcessor(void)
Get board default processor.
Definition board.h:556
virtual void MSetAPin(int pin, float value)=0
board microcontroller set analog pin
int use_spare
use spare parts window
Definition board.h:664
int TimerUnregister(const int timer)
Unregister timer.
Definition board.cc:451
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:637
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:627
unsigned char CalcAngle(int i, int x, int y)
Calc rotary potentiometer angle.
Definition board.cc:333
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:374
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:431
int inputc
input map elements counter
Definition board.h:661
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:550
virtual unsigned int DBGGetEEPROM_Size(void)
board microcontroller get data EEPROM memory size
Definition board.h:510
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:567
virtual unsigned int DBGGetRAMSize(void)
board microcontroller get RAM memory size
Definition board.h:478
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:364
virtual unsigned int DBGGetPC(void)
board microcontroller get PC
Definition board.h:425
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:516
void ReadInputMap(std::string fname)
Read the Input Map.
Definition board.cc:76
std::string Proc
Name of processor in use.
Definition board.h:655
void TimerUpdateFrequency(float freq)
Update Timer counters on frequency change.
Definition board.cc:524
internal timer struct
Definition board.h:97
Definition board.h:729
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