Commit e7965fd5 authored by lcgamboa's avatar lcgamboa

new: Add support to use analog values in gpboard (gpsim backend)

parent bb6ef5ff
......@@ -2,5 +2,5 @@ PACKAGE=picsimlab
MAINVER=0
MINORVER=9
VERSION=0.9.1
DATE=231224
DATE=240106
VERSION_STABLE=0.9.1
......@@ -15,7 +15,7 @@
void simulation_cleanup(void);
static pic_processor* gpic;
static pic_processor* gpic = NULL;
int bridge_gpsim_init(const char* processor, const char* fileName, float freq) {
// initialize_gpsim_core ();
......@@ -24,11 +24,17 @@ int bridge_gpsim_init(const char* processor, const char* fileName, float freq) {
CSimulationContext::GetContext()->LoadProgram(fileName, processor, &tempProc, NULL);
gpic = dynamic_cast<pic_processor*>(tempProc);
gpic->set_frequency(freq);
bridge_gpsim_set_frequency(freq);
return (gpic != NULL) - 1;
}
void bridge_gpsim_set_frequency(double freq) {
if (gpic) {
gpic->set_frequency(freq);
}
}
void bridge_gpsim_reset(void) {
if (gpic->is_sleeping())
gpic->exit_sleep();
......@@ -89,8 +95,19 @@ void bridge_gpsim_set_pin_value(int pin, unsigned char value) {
}
}
void bridge_gpsim_set_apin_value(int pin, float value) {
IOPIN* iopin = gpic->get_pin(pin);
iopin->set_is_analog(true);
iopin->set_Cth(5e-12);
iopin->set_nodeVoltage(value);
}
void bridge_gpsim_step(void) {
gpic->step_cycle();
if (gpic->mCurrentPhase == ((ClockPhase*)gpic->mExecute2ndHalf)) {
gpic->step_cycle();
}
}
void bridge_gpsim_end(void) {
......
......@@ -25,6 +25,8 @@ const char* bridge_gpsim_get_pin_name(int pin);
unsigned char bridge_gpsim_get_pin_value(int pin);
unsigned char bridge_gpsim_get_pin_dir(int pin);
void bridge_gpsim_set_pin_value(int pin, unsigned char value);
void bridge_gpsim_set_apin_value(int pin, float value);
void bridge_gpsim_set_frequency(double freq);
void bridge_gpsim_step(void);
void bridge_gpsim_end(void);
int bridge_gpsim_dump_memory(const char* fname);
......
......@@ -28,7 +28,7 @@
#include "../lib/picsimlab.h"
#include "bsim_gpsim.h"
static const unsigned char GPSIM_PORTS[5] = {0, 1, 2, 3, 0xFF};
static const unsigned char GPSIM_PORTS[7] = {0, 1, 2, 3, 4, 5, 0xFF};
bsim_gpsim::bsim_gpsim(void) {
char list[2000];
......@@ -61,13 +61,14 @@ void bsim_gpsim::MSetSerial(const char* port) {
}
}
ret = bridge_gpsim_init(processor, fname, freq);
pins_reset();
}
return ret;
}
void bsim_gpsim::MEnd(void) {
bridge_gpsim_end();
// bridge_gpsim_end(); //Not needed when SetNeedReboot is used
}
int bsim_gpsim::MGetArchitecture(void) {
......@@ -80,6 +81,7 @@ void bsim_gpsim::MSetSerial(const char* port) {
void bsim_gpsim::MSetFreq(float freq_) {
freq = freq_;
bridge_gpsim_set_frequency(freq);
TimerUpdateFrequency(freq);
}
......@@ -115,6 +117,9 @@ void bsim_gpsim::MSetSerial(const char* port) {
pinname = "R" + pinname.substr(4, 2);
pinname = uppercase(pinname);
}
if (pinname.length() == 0) {
pinname = "nd";
}
}
return pinname;
}
......@@ -125,7 +130,7 @@ void bsim_gpsim::MSetSerial(const char* port) {
int bsim_gpsim::DebugInit(int dtyppe) // argument not used in picm only mplabx
{
return 0; //! mplabxd_init (this, Window1.Get_debug_port ()) - 1;
return 0; //! mplabxd_init (this, Window1.Get_debug_port ()) - 1;
}
int bsim_gpsim::MGetPinCount(void) {
......@@ -135,27 +140,35 @@ void bsim_gpsim::MSetSerial(const char* port) {
void bsim_gpsim::pins_reset(void) {
for (int p = 0; p < MGetPinCount(); p++) {
lxString pname = MGetPinName(p + 1);
if (pname[0] == 'p') {
pins[p].port = (unsigned char*)&GPSIM_PORTS[pname[4] - 'a'];
pins[p].pord = pname[5] - '0';
if (pname[0] == 'R') {
pins[p].port = (unsigned char*)&GPSIM_PORTS[pname[1] - 'A'];
pins[p].pord = pname[2] - '0';
pins[p].ptype = PT_DIGITAL;
pins[p].dir = PD_IN;
pins[p].value = 0;
} else if (pname[0] == 'M') { // MCLR
pins[p].port = (unsigned char*)&GPSIM_PORTS[6];
pins[p].pord = -1;
pins[p].ptype = PT_DIGITAL;
pins[p].dir = PD_IN;
pins[p].value = 1;
} else {
pins[p].port = (unsigned char*)&GPSIM_PORTS[4];
pins[p].port = (unsigned char*)&GPSIM_PORTS[6];
pins[p].pord = -1;
pins[p].ptype = PT_POWER;
pins[p].dir = PD_OUT;
pins[p].value = 0;
}
pins[p].avalue = 0;
pins[p].lvalue = 0;
pins[p].value = 0;
pins[p].ptype = PT_DIGITAL;
pins[p].dir = PD_IN;
pins[p].ovalue = 0;
pins[p].oavalue = 55;
}
/*TODO add VCC and GND pins
pins[7 - 1].value = 0;
pins[7 - 1].dir = PD_OUT;
pins[9 - 1].value = 1;
pins[9 - 1].dir = PD_OUT;
*/
// TODO add VCC and GND pins
// pins[7 - 1].value = 0;
// pins[7 - 1].dir = PD_OUT;
// pins[9 - 1].value = 1;
// pins[9 - 1].dir = PD_OUT;
}
void bsim_gpsim::MSetPin(int pin, unsigned char value) {
......@@ -167,7 +180,11 @@ void bsim_gpsim::MSetSerial(const char* port) {
}
void bsim_gpsim::MSetAPin(int pin, float value) {
// set_apin (pin, value);
if (pins[pin - 1].dir == PD_IN) {
pins[pin - 1].ptype = PT_ANALOG;
pins[pin - 1].avalue = value;
bridge_gpsim_set_apin_value(pin, value);
}
}
unsigned char bsim_gpsim::MGetPin(int pin) {
......
......@@ -154,7 +154,7 @@ static int test_IN_OUT_ESP32(void* arg) {
register_test("IN/OUT ESP32", test_IN_OUT_ESP32, NULL);
static int test_IN_OUT_ESP32C3(void* arg) {
return in_out_test("SPI ESP32C3", "in_out/in_out_esp32c3.pzw", 1, 2000000L);
return in_out_test("SPI ESP32C3", "in_out/in_out_esp32c3.pzw", 1, 3500000L);
}
register_test("IN/OUT ESP32C3", test_IN_OUT_ESP32C3, NULL);
......@@ -169,6 +169,11 @@ static int test_IN_OUT_STM32(void* arg) {
register_test("IN/OUT STM32", test_IN_OUT_STM32, NULL);
static int test_IN_OUT_PIC18F(void* arg) {
return in_out_test("SPI PIC18F", "in_out/in_out_pic18.pzw");
return in_out_test("SPI PIC18F", "in_out/in_out_pic18.pzw", 2);
}
register_test("IN/OUT PIC18F", test_IN_OUT_PIC18F, NULL);
static int test_IN_OUT_PIC18FGP(void* arg) {
return in_out_test("SPI PIC18FGP", "in_out/in_out_pic18gp.pzw", 2);
}
register_test("IN/OUT PIC18F GP", test_IN_OUT_PIC18FGP, NULL);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment