PICSimLab - Programmable IC Simulator Laboratory 0.9.3
PICSimLab - API
Loading...
Searching...
No Matches
bsim_remote.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 BOARD_REMOTETCP_H
27#define BOARD_REMOTETCP_H
28
29#include <stdint.h>
30#include "../devices/bitbang_i2c.h"
31#include "../devices/bitbang_spi.h"
32#include "../devices/bitbang_uart.h"
33#include "../lib/board.h"
34
35//===================== Ripes protocol =========================================
36typedef struct {
37 uint32_t msg_type;
38 uint32_t payload_size;
39 uint64_t time;
41
42enum { VB_PINFO = 1, VB_PWRITE, VB_PREAD, VB_PSTATUS, VB_QUIT, VB_SYNC, VB_LAST };
43//==============================================================================
44
45#define TTIMEOUT (BASETIMER * 1000000L)
46
47class bsim_remote : virtual public board {
48public:
49 bsim_remote(void);
50 ~bsim_remote(void);
51 int DebugInit(int dtyppe) override;
52 std::string GetDebugName(void) override { return "NONE"; };
53 void DebugLoop(void) override;
54 int CpuInitialized(void) override;
55 void MSetSerial(const char* port) override;
56 int MInit(const char* processor, const char* fname, float freq) override;
57 void MEnd(void) override;
58 int MGetArchitecture(void) override;
59 std ::string GetSimBackends(void) override { return "Remote TCP/IP,"; };
60 std ::string GetDebuggers(void) override { return "N/A,"; };
61 int MDumpMemory(const char* fname) override;
62 void MEraseFlash(void) override;
63 void MSetFreq(float freq) override;
64 float MGetFreq(void) override;
65 void MSetVCC(float vcc) override;
66 float MGetVCC(void) override;
67 float MGetInstClockFreq(void) override;
68 int MGetPinCount(void) override;
69 std::string MGetPinName(int pin) override;
70 void MSetPin(int pin, unsigned char value) override;
71 void MSetPinDOV(int pin, unsigned char ovalue) override;
72 void MSetPinOAV(int pin, float value) override;
73 void MSetAPin(int pin, float value) override;
74 unsigned char MGetPin(int pin) override;
75 const picpin* MGetPinsValues(void) override;
76 float* MGetPinOAVPtr(int pin) override;
77 void MStep(void) override;
78 void MStepResume(void) override {};
79 int MReset(int flags) override;
80 int MGetResetPin(void) override;
81 int MGetIOUpdated(void) override;
82 void MClearIOUpdated(void) override;
83 virtual void Run_CPU_ns(uint64_t time) = 0;
84 int GetInc_ns(void) { return inc_ns; };
85 int GetUARTRX(const int uart_num) override;
86 int GetUARTTX(const int uart_num) override;
87 virtual std::string GetClkLabel(void) override { return "IO (Mhz)"; };
88 // Called ever 1s to refresh status
89 void RefreshStatus(void) override;
90
91protected:
92 const int TestConnection(void);
93 const int DataAvaliable(void);
94 void ConnectionError(const char* s_error);
95 void Disconnect(void);
96 void pins_reset(void);
97 //===================== Ripes protocol =========================================
98 int32_t recv_cmd(cmd_header_t* cmd_header);
99 int32_t recv_payload(char* buff, const uint32_t payload_size);
100 int32_t send_cmd(const uint32_t cmd, const char* payload = NULL, const uint32_t payload_size = 0);
101//==============================================================================
102#ifdef _WIN_
103 HANDLE serialfd[4];
104#else
105 int serialfd[4];
106#endif
107 int procid;
108 picpin pins[MAX_PIN_COUNT];
109 unsigned int serialbaud;
110 float serialexbaud;
111 float freq;
112 int sockfd;
113 int connected;
114 char fname_[300];
115 char fname_bak[300];
116 unsigned short ADCvalues[16];
117
118 unsigned short Dirs[2] = {0xFF, 0xFF};
119 unsigned short Ports[2] = {0x00, 0x00};
120 unsigned short t0CNT = 0;
121 unsigned short t0STA = 0;
122 unsigned short t0CON = 0x7FFF;
123 unsigned short t0PR = 0xFFFF;
124 unsigned short t0iclk = 0;
125
126 int64_t timerlast = 0;
127 unsigned int inc_ns = 0;
128 unsigned int ns_count = 0;
129
130 bitbang_i2c_t master_i2c[2];
131 bitbang_spi_t master_spi[2];
132 bitbang_uart_t master_uart[2];
133};
134
135#endif /* BOARD_REMOTETCP_H */
board(void)
Called once on board creation.
Definition board.cc:34
int GetUARTRX(const int uart_num) override
Return the UART N RX pin number.
Definition bsim_remote.cc:796
int GetUARTTX(const int uart_num) override
Return the UART N TX pin number.
Definition bsim_remote.cc:803
int CpuInitialized(void) override
return true if microcontroller is initialized
Definition bsim_remote.cc:293
int MGetResetPin(void) override
Get the Reset pin of microcontroller.
Definition bsim_remote.cc:717
void MClearIOUpdated(void) override
clear microcontroler status IO updated
Definition bsim_remote.cc:725
const picpin * MGetPinsValues(void) override
board microcontroller get all pins list struct
Definition bsim_remote.cc:729
void MEnd(void) override
board microcontroller end
Definition bsim_remote.cc:245
void MSetVCC(float vcc) override
board microcontroller set vcc
Definition bsim_remote.cc:281
std::string MGetPinName(int pin) override
board microcontroller pin name
Definition bsim_remote.cc:299
std::string GetSimBackends(void) override
Return board backends name.
Definition bsim_remote.h:59
int DebugInit(int dtyppe) override
Start debug support.
Definition bsim_remote.cc:523
void MStep(void) override
board microcontroller run one step
Definition bsim_remote.cc:737
void MSetFreq(float freq) override
board microcontroller set frequency
Definition bsim_remote.cc:271
float MGetInstClockFreq(void) override
board microcontroller get cpu internal clock (in PIC frequency/4)
Definition bsim_remote.cc:289
int MReset(int flags) override
board microcontroller reset
Definition bsim_remote.cc:696
float MGetFreq(void) override
board microcontroller get frequency
Definition bsim_remote.cc:277
void MSetSerial(const char *port) override
Set serial port name to use.
Definition bsim_remote.cc:97
virtual std::string GetClkLabel(void) override
Return the description of clk label.
Definition bsim_remote.h:87
std::string GetDebuggers(void) override
Return board supported debug interfaces name.
Definition bsim_remote.h:60
float * MGetPinOAVPtr(int pin) override
board microcontroller get pointer to digital pin average value
Definition bsim_remote.cc:733
void MSetAPin(int pin, float value) override
board microcontroller set analog pin
Definition bsim_remote.cc:605
int MInit(const char *processor, const char *fname, float freq) override
board microcontroller init
Definition bsim_remote.cc:104
void RefreshStatus(void) override
Called ever 1s to refresh status.
Definition bsim_remote.cc:901
void DebugLoop(void) override
debug step (pooling)
Definition bsim_remote.cc:297
int MDumpMemory(const char *fname) override
board microcontroller save non volatile memory to hex file
Definition bsim_remote.cc:511
void MSetPinDOV(int pin, unsigned char ovalue) override
board microcontroller set Default Open Value (external pull)
Definition bsim_remote.cc:597
unsigned char MGetPin(int pin) override
board microcontroller get digital pin value
Definition bsim_remote.cc:689
int MGetPinCount(void) override
board microcontroller pin count
Definition bsim_remote.cc:528
void MStepResume(void) override
board microcontroller run one or two steps to resume instruction
Definition bsim_remote.h:78
void MSetPinOAV(int pin, float value) override
board microcontroller set digital pin output average value
Definition bsim_remote.cc:601
std::string GetDebugName(void) override
Get debug interface name.
Definition bsim_remote.h:52
float MGetVCC(void) override
board microcontroller get vcc
Definition bsim_remote.cc:285
int MGetArchitecture(void) override
Return board microcontroller architecture.
Definition bsim_remote.cc:263
void MSetPin(int pin, unsigned char value) override
board microcontroller set digital pin
Definition bsim_remote.cc:580
int MGetIOUpdated(void) override
get microcontroler status IO updated
Definition bsim_remote.cc:721
void MEraseFlash(void) override
board microcontroller erase flash memory (program)
Definition bsim_remote.cc:267
Definition bsim_remote.h:36