Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move modem into lib/ and refactor to use it with new uart member #528

Merged
merged 1 commit into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ sdkconfig.fujinet-lynx-prototype
sdkconfig.fujinet-lynx-devkitc
sdkconfig.fujinet-adam-v1
sdkconfig.fujinet-cbm
sdkconfig.esp32s3

include/ssid.h
/*.log
Expand Down
6 changes: 3 additions & 3 deletions include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#define FN_VERSION_MAJOR 0
#define FN_VERSION_MINOR 5

#define FN_VERSION_BUILD "41f6bdd7"
#define FN_VERSION_BUILD "111eb575"

#define FN_VERSION_DATE "2022-11-18 04:09:59"
#define FN_VERSION_DATE "2022-11-19 11:08:58"

#define FN_VERSION_FULL "0.5.41f6bdd7"
#define FN_VERSION_FULL "0.5.111eb575"
51 changes: 29 additions & 22 deletions lib/bus/sio/sio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ void virtualDevice::bus_to_computer(uint8_t *buf, uint16_t len, bool err)
sio_complete();

// Write data frame
fnUartSIO.write(buf, len);
UARTManager *uart = sio_get_bus().get_modem()->get_uart();
uart->write(buf, len);
// Write checksum
fnUartSIO.write(sio_checksum(buf, len));
uart->write(sio_checksum(buf, len));

fnUartSIO.flush();
uart->flush();
}

/*
Expand All @@ -76,14 +77,16 @@ uint8_t virtualDevice::bus_to_peripheral(uint8_t *buf, unsigned short len)
// Retrieve data frame from computer
Debug_printf("<-SIO read %hu bytes\n", len);

UARTManager *uart = sio_get_bus().get_modem()->get_uart();

__BEGIN_IGNORE_UNUSEDVARS
size_t l = fnUartSIO.readBytes(buf, len);
size_t l = uart->readBytes(buf, len);
__END_IGNORE_UNUSEDVARS

// Wait for checksum
while (fnUartSIO.available() <= 0)
while (uart->available() <= 0)
fnSystem.yield();
uint8_t ck_rcv = fnUartSIO.read();
uint8_t ck_rcv = uart->read();

uint8_t ck_tst = sio_checksum(buf, len);

Expand All @@ -110,33 +113,35 @@ uint8_t virtualDevice::bus_to_peripheral(uint8_t *buf, unsigned short len)
// SIO NAK
void virtualDevice::sio_nak()
{
fnUartSIO.write('N');
fnUartSIO.flush();
UARTManager *uart = sio_get_bus().get_modem()->get_uart();
uart->write('N');
uart->flush();
Debug_println("NAK!");
}

// SIO ACK
void virtualDevice::sio_ack()
{
fnUartSIO.write('A');
UARTManager *uart = sio_get_bus().get_modem()->get_uart();
uart->write('A');
fnSystem.delay_microseconds(DELAY_T5); //?
fnUartSIO.flush();
uart->flush();
Debug_println("ACK!");
}

// SIO COMPLETE
void virtualDevice::sio_complete()
{
fnSystem.delay_microseconds(DELAY_T5);
fnUartSIO.write('C');
sio_get_bus().get_modem()->get_uart()->write('C');
Debug_println("COMPLETE!");
}

// SIO ERROR
void virtualDevice::sio_error()
{
fnSystem.delay_microseconds(DELAY_T5);
fnUartSIO.write('E');
sio_get_bus().get_modem()->get_uart()->write('E');
Debug_println("ERROR!");
}

Expand All @@ -148,22 +153,24 @@ void virtualDevice::sio_high_speed()
bus_to_computer((uint8_t *)&hsd, 1, false);
}

systemBus virtualDevice::sio_get_bus() { return SIO; }

// Read and process a command frame from SIO
void systemBus::_sio_process_cmd()
{
if (_modemDev != nullptr && _modemDev->modemActive && Config.get_modem_enabled())
{
_modemDev->modemActive = false;
Debug_println("Modem was active - resetting SIO baud");
fnUartSIO.set_baudrate(_sioBaud);
_modemDev->get_uart()->set_baudrate(_sioBaud);
}

// Read CMD frame
cmdFrame_t tempFrame;
tempFrame.commanddata = 0;
tempFrame.checksum = 0;

if (fnUartSIO.readBytes((uint8_t *)&tempFrame, sizeof(tempFrame)) != sizeof(tempFrame))
if (_modemDev->get_uart()->readBytes((uint8_t *)&tempFrame, sizeof(tempFrame)) != sizeof(tempFrame))
{
// Debug_println("Timeout waiting for data after CMD pin asserted");
return;
Expand Down Expand Up @@ -341,7 +348,7 @@ void systemBus::service()
else
// Neither CMD nor active modem, so throw out any stray input data
{
fnUartSIO.flush_input();
_modemDev->get_uart()->flush_input();
}

// Handle interrupts from network protocols
Expand All @@ -358,7 +365,7 @@ void systemBus::setup()
Debug_println("SIO SETUP");

// Set up UART
fnUartSIO.begin(_sioBaud);
_modemDev->get_uart()->begin(_sioBaud);

// INT PIN
fnSystem.set_pin_mode(PIN_INT, gpio_mode_t::GPIO_MODE_OUTPUT_OD, SystemManager::pull_updown_t::PULL_UP);
Expand Down Expand Up @@ -390,7 +397,7 @@ void systemBus::setup()
else
setHighSpeedIndex(_sioHighSpeedIndex);

fnUartSIO.flush_input();
_modemDev->get_uart()->flush_input();
}

// Add device to SIO bus
Expand All @@ -402,7 +409,7 @@ void systemBus::addDevice(virtualDevice *pDevice, int device_id)
}
else if (device_id == SIO_DEVICEID_RS232)
{
_modemDev = (sioModem *)pDevice;
_modemDev = (modem *)pDevice;
}
else if (device_id >= SIO_DEVICEID_FN_NETWORK && device_id <= SIO_DEVICEID_FN_NETWORK_LAST)
{
Expand Down Expand Up @@ -487,7 +494,7 @@ void systemBus::toggleBaudrate()

Debug_printf("Toggling baudrate from %d to %d\n", _sioBaud, baudrate);
_sioBaud = baudrate;
fnUartSIO.set_baudrate(_sioBaud);
_modemDev->get_uart()->set_baudrate(_sioBaud);
}

int systemBus::getBaudrate()
Expand All @@ -505,7 +512,7 @@ void systemBus::setBaudrate(int baud)

Debug_printf("Changing baudrate from %d to %d\n", _sioBaud, baud);
_sioBaud = baud;
fnUartSIO.set_baudrate(baud);
_modemDev->get_uart()->set_baudrate(baud);
}

// Set HSIO index. Sets high speed SIO baud and also returns that value.
Expand Down Expand Up @@ -605,15 +612,15 @@ void systemBus::setUltraHigh(bool _enable, int _ultraHighBaud)
// Enable PWM on CLOCK IN
ledc_channel_config(&ledc_channel_sio_ckin);
ledc_timer_config(&ledc_timer);
fnUartSIO.set_baudrate(_sioBaudUltraHigh);
_modemDev->get_uart()->set_baudrate(_sioBaudUltraHigh);
}
else
{
Debug_printf("Disabling SIO clock.\n");
ledc_stop(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_1, 0);

_sioBaudUltraHigh = 0;
fnUartSIO.set_baudrate(SIO_STANDARD_BAUDRATE);
_modemDev->get_uart()->set_baudrate(SIO_STANDARD_BAUDRATE);
}
}

Expand Down
19 changes: 11 additions & 8 deletions lib/bus/sio/sio.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ union cmdFrame_t
uint8_t sio_checksum(uint8_t *buf, unsigned short len);

// class def'ns
class sioModem; // declare here so can reference it, but define in modem.h
class sioFuji; // declare here so can reference it, but define in fuji.h
class modem; // declare here so can reference it, but define in modem.h
class sioFuji; // declare here so can reference it, but define in fuji.h
class systemBus; // declare early so can be friend
class sioNetwork; // declare here so can reference it, but define in network.h
class sioUDPStream; // declare here so can reference it, but define in udpstream.h
class sioCassette; // Cassette forward-declaration.
class sioCPM; // CPM device.
class sioPrinter; // Printer device
class sioNetwork; // declare here so can reference it, but define in network.h
class sioUDPStream; // declare here so can reference it, but define in udpstream.h
class sioCassette; // Cassette forward-declaration.
class sioCPM; // CPM device.
class sioPrinter; // Printer device

class virtualDevice
{
Expand Down Expand Up @@ -248,7 +248,7 @@ class systemBus
int _command_frame_counter = 0;

virtualDevice *_activeDev = nullptr;
sioModem *_modemDev = nullptr;
modem *_modemDev = nullptr;
sioFuji *_fujiDev = nullptr;
sioNetwork *_netDev[8] = {nullptr};
sioUDPStream *_udpDev = nullptr;
Expand Down Expand Up @@ -294,6 +294,9 @@ class systemBus
sioPrinter *getPrinter() { return _printerdev; }
sioCPM *getCPM() { return _cpmDev; }

// I wish this codebase would make up its mind to use camel or snake casing.
modem *get_modem() { return _modemDev; }

QueueHandle_t qSioMessages = nullptr;
};

Expand Down
2 changes: 1 addition & 1 deletion lib/config/fnConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "../../include/debug.h"

#include "modem.h"
#include "../device/modem.h"
#include "modem-sniffer.h"

#include "fnSystem.h"
Expand Down
4 changes: 2 additions & 2 deletions lib/device/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# include "sio/cassette.h"
# include "sio/disk.h"
# include "sio/udpstream.h"
# include "sio/modem.h"
# include "../lib/modem/modem.h"
# include "sio/network.h"
# include "sio/printer.h"
# include "sio/printerlist.h"
Expand All @@ -18,7 +18,7 @@
sioVoice sioV;
sioUDPStream udpDev;
// sioCassette sioC; // now part of sioFuji theFuji object
sioModem *sioR;
modem *sioR;
sioCPM sioZ;
#endif

Expand Down
4 changes: 2 additions & 2 deletions lib/device/modem.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define DEVICE_MODEM_H

#ifdef BUILD_ATARI
# include "sio/modem.h"
extern sioModem *sioR;
# include "../modem/modem.h"
extern modem *sioR;
#endif

#ifdef BUILD_RS232
Expand Down
2 changes: 1 addition & 1 deletion lib/http/httpService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "fnConfig.h"
#include "fnWiFi.h"
#include "fnFsSPIFFS.h"
#include "modem.h"
#include "../device/modem.h"
#include "printer.h"
#include "httpServiceConfigurator.h"
#include "httpServiceParser.h"
Expand Down
Loading