PICSimLab - Programmable IC Simulator Laboratory 0.9.2
PICSimLab - API
Loading...
Searching...
No Matches
bsim_qemu.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_QEMU_H
27#define BOARD_QEMU_H
28
29#include <atomic>
30#include "../devices/bitbang_i2c.h"
31#include "../devices/bitbang_out.h"
32#include "../devices/bitbang_pwm.h"
33#include "../devices/bitbang_spi.h"
34#include "../devices/bitbang_uart.h"
35#include "../lib/board.h"
36#include "qemu.h"
37
38typedef enum { QEMU_SIM_NONE = 0, QEMU_SIM_STM32, QEMU_SIM_ESP32, QEMU_SIM_ESP32_C3 } QEMUSimType;
39
40#define TTIMEOUT (BASETIMER * 1000000L)
41
42class bsim_qemu : virtual public board {
43public:
44 bsim_qemu(void);
45 ~bsim_qemu(void);
46 int DebugInit(int dtyppe) override;
47 std::string GetDebugName(void) override { return "GDB"; };
48 void DebugLoop(void) override;
49 int CpuInitialized(void) override;
50 void MSetSerial(const char* port) override;
51 int MInit(const char* processor, const char* fname, float freq) override;
52 void MEnd(void) override;
53 int MGetArchitecture(void) override;
54 int MDumpMemory(const char* fname) override;
55 void MEraseFlash(void) override;
56 void MSetFreq(float freq) override;
57 float MGetFreq(void) override;
58 void MSetVCC(float vcc) override;
59 float MGetVCC(void) override;
60 float MGetInstClockFreq(void) override;
61 void MSetPin(int pin, unsigned char value) override;
62 void MSetPinDOV(int pin, unsigned char ovalue) override;
63 unsigned char MGetPin(int pin) override;
64 const picpin* MGetPinsValues(void) override;
65 void MStep(void) override;
66 void MStepResume(void) override {};
67 void MReset(int flags) override;
68 void EvThreadRun(void) override;
69 int GetDefaultClock(void) override { return 1; };
70 int GetInc_ns(void) { return inc_ns; };
71 virtual void PinsExtraConfig(int cfg) {};
72 user_timer_t timer;
73 virtual void Run_CPU_ns(uint64_t time) = 0;
74 bitbang_i2c_t master_i2c[2];
75 bitbang_spi_t master_spi[2];
76 bitbang_uart_t master_uart[3];
77 bitbang_pwm_t pwm_out;
78 bitbang_out_t rmt_out;
79 void IoLockAccess(void) override;
80 void IoUnlockAccess(void) override;
81 int GetUARTRX(const int uart_num) override;
82 int GetUARTTX(const int uart_num) override;
83 virtual std::string GetClkLabel(void) override { return "IO (Mhz)"; };
84
85protected:
86 int MipsStrToIcount(const char* mipstr);
87 const char* IcountToMipsStr(int icount);
88 const char* IcountToMipsItens(char* buffer);
89 unsigned int ns_count;
90 void pins_reset(void);
91 virtual void BoardOptions(int* argc, char** argv) {};
92 virtual const short int* GetPinMap(void) = 0;
93 int icount;
94#ifdef _WIN_
95 HANDLE serialfd[4];
96#else
97 int serialfd[4];
98#endif
99 int procid;
100 picpin pins[256];
101 unsigned int serialbaud;
102 float serialexbaud;
103 float freq;
104 unsigned int inc_ns;
105 char fname[2048];
106 char fname_[2048];
107 char fname_bak[2048];
108 unsigned short ADCvalues[16];
109 int mtx_qinitId;
110 std::atomic_int qemu_started;
111 QEMUSimType SimType;
112 std::string cmdline;
113 int use_cmdline_extra;
114 std::string cmdline_extra;
115 int serial_open;
116 unsigned int application_offset;
117 int ConfEnableSerial;
118 int ConfigWaitGdb;
119
120private:
121 int load_qemu_lib(const char* path);
122};
123
124#endif /* BOARD_QEMU_H */
Board class.
Definition board.h:111
Definition bsim_qemu.h:42
void MSetPinDOV(int pin, unsigned char ovalue) override
board microcontroller set Default Open Value (external pull)
Definition bsim_qemu.cc:1154
float MGetFreq(void) override
board microcontroller get frequency
Definition bsim_qemu.cc:1002
int MInit(const char *processor, const char *fname, float freq) override
board microcontroller init
Definition bsim_qemu.cc:361
void MSetFreq(float freq) override
board microcontroller set frequency
Definition bsim_qemu.cc:996
void IoLockAccess(void) override
Lock IO to others threads access.
Definition bsim_qemu.cc:1299
void MEraseFlash(void) override
board microcontroller erase flash memory (program)
Definition bsim_qemu.cc:992
float MGetVCC(void) override
board microcontroller get vcc
Definition bsim_qemu.cc:1010
int GetDefaultClock(void) override
Get board default clock in MHz.
Definition bsim_qemu.h:69
float MGetInstClockFreq(void) override
board microcontroller get cpu internal clock (in PIC frequency/4)
Definition bsim_qemu.cc:1014
unsigned char MGetPin(int pin) override
board microcontroller get digital pin value
Definition bsim_qemu.cc:1158
virtual std::string GetClkLabel(void) override
Return the description of clk label.
Definition bsim_qemu.h:83
void MEnd(void) override
board microcontroller end
Definition bsim_qemu.cc:961
std::string GetDebugName(void) override
Get debug interface name.
Definition bsim_qemu.h:47
void MStep(void) override
board microcontroller run one step
Definition bsim_qemu.cc:1196
void MStepResume(void) override
board microcontroller run one or two steps to resume instruction
Definition bsim_qemu.h:66
void EvThreadRun(void) override
Event on the board.
Definition bsim_qemu.cc:417
int DebugInit(int dtyppe) override
Start debug support.
Definition bsim_qemu.cc:1113
int MGetArchitecture(void) override
Return board microcontroller architecture.
Definition bsim_qemu.cc:984
void MReset(int flags) override
board microcontroller reset
Definition bsim_qemu.cc:1165
int GetUARTTX(const int uart_num) override
Return the UART N TX pin number.
Definition bsim_qemu.cc:1314
void MSetSerial(const char *port) override
Set serial port name to use.
Definition bsim_qemu.cc:359
int GetUARTRX(const int uart_num) override
Return the UART N RX pin number.
Definition bsim_qemu.cc:1307
int MDumpMemory(const char *fname) override
board microcontroller save non volatile memory to hex file
Definition bsim_qemu.cc:1024
const picpin * MGetPinsValues(void) override
board microcontroller get all pins list struct
Definition bsim_qemu.cc:1192
int CpuInitialized(void) override
return true if microcontroller is initialized
Definition bsim_qemu.cc:1018
void DebugLoop(void) override
debug step (pooling)
Definition bsim_qemu.cc:1022
void MSetPin(int pin, unsigned char value) override
board microcontroller set digital pin
Definition bsim_qemu.cc:1143
void MSetVCC(float vcc) override
board microcontroller set vcc
Definition bsim_qemu.cc:1006
void IoUnlockAccess(void) override
Unlock IO to others threads access.
Definition bsim_qemu.cc:1303
Definition bitbang_i2c.h:39
Definition bitbang_out.h:33
Definition bitbang_pwm.h:43
Definition bitbang_spi.h:35
Definition bitbang_uart.h:35
Definition qemu.h:56