Skip to content

Commit ef2905e

Browse files
committed
Replace fnUART* classes and switch to IOChannel abstraction (FujiNetWIFI#1038)
New abstraction supports any streaming I/O type (serial, network, USB) with a single consistent API.
1 parent c284e95 commit ef2905e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1270
-1524
lines changed

fujinet_pc.cmake

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,7 @@ if(FUJINET_TARGET STREQUAL "ATARI")
270270
list(APPEND SOURCES
271271

272272
lib/bus/sio/sio.h lib/bus/sio/sio.cpp
273-
lib/bus/sio/siocom/sioport.h lib/bus/sio/siocom/sioport.cpp
274-
lib/bus/sio/siocom/serialsio.h lib/bus/sio/siocom/serialsio.cpp
275-
lib/bus/sio/siocom/netsio.h lib/bus/sio/siocom/netsio.cpp
276-
lib/bus/sio/siocom/fnSioCom.h lib/bus/sio/siocom/fnSioCom.cpp
273+
lib/bus/sio/NetSIO.h lib/bus/sio/NetSIO.cpp
277274
lib/media/atari/diskType.h lib/media/atari/diskType.cpp
278275
lib/media/atari/diskTypeAtr.h lib/media/atari/diskTypeAtr.cpp
279276
lib/media/atari/diskTypeAtx.h lib/media/atari/diskTypeAtx.cpp

include/debug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#ifdef DEBUG
2424
#ifdef ESP_PLATFORM
2525
// Use FujiNet debug serial output
26-
#include "../lib/hardware/UARTChannel.h"
26+
#include "../lib/hardware/ESP32UARTChannel.h"
2727
#define Serial fnDebugConsole
2828
#ifdef PINMAP_RS232_S3
2929
#define Debug_print(...) printf( __VA_ARGS__ )

lib/bus/adamnet/adamnet.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,9 @@ void systemBus::setup()
332332
gpio_isr_handler_add((gpio_num_t)PIN_ADAMNET_RESET, adamnet_reset_isr_handler, (void *)PIN_CARD_DETECT_FIX);
333333

334334
// Set up UART
335-
_port.begin(ADAMNET_BAUDRATE);
335+
_port.begin(ChannelConfig()
336+
.baud(ADAMNET_BAUDRATE)
337+
);
336338
}
337339

338340
void systemBus::shutdown()

lib/bus/adamnet/adamnet.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* AdamNet Routines
66
*/
77

8-
#include "fnUART.h"
8+
#include "UARTChannel.h"
99
#include <freertos/FreeRTOS.h>
1010
#include <freertos/queue.h>
1111

@@ -247,7 +247,7 @@ class systemBus
247247
adamFuji *_fujiDev = nullptr;
248248
adamPrinter *_printerDev = nullptr;
249249

250-
UARTManager _port = UARTManager(FN_UART_BUS);
250+
UARTChannel _port;
251251

252252
void _adamnet_process_cmd();
253253
void _adamnet_process_queue();
@@ -285,12 +285,12 @@ class systemBus
285285

286286
// Everybody thinks "oh I know how a serial port works, I'll just
287287
// access it directly and bypass the bus!" ಠ_ಠ
288-
size_t read(void *buffer, size_t length) { return _port.readBytes(buffer, length); }
288+
size_t read(void *buffer, size_t length) { return _port.read(buffer, length); }
289289
size_t read() { return _port.read(); }
290290
size_t write(const void *buffer, size_t length) { return _port.write(buffer, length); }
291291
size_t write(int n) { return _port.write(n); }
292292
size_t available() { return _port.available(); }
293-
void flush() { _port.flush(); }
293+
void flush() { _port.flushOutput(); }
294294
size_t print(int n, int base = 10) { return _port.print(n, base); }
295295
size_t print(const char *str) { return _port.print(str); }
296296
size_t print(const std::string &str) { return _port.print(str); }

lib/bus/drivewire/BeckerSocket.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ BeckerSocket::BeckerSocket() :
4343
_host(""),
4444
_ip(IPADDR_NONE),
4545
_port(BECKER_DEFAULT_PORT),
46-
_baud(DW_DEFAULT_BAUD), // not used by Becker
4746
_listening(true),
4847
_fd(-1),
4948
_listen_fd(-1),
@@ -62,7 +61,6 @@ void BeckerSocket::begin(std::string host, int baud)
6261
end();
6362

6463
_host = host;
65-
_baud = baud;
6664
read_timeout_ms = 500;
6765

6866
// listen or connect
@@ -94,7 +92,7 @@ void BeckerSocket::end()
9492
/* Clears input buffer and flushes out transmit buffer waiting at most
9593
waiting MAX_FLUSH_WAIT_TICKS until all sends are completed
9694
*/
97-
void BeckerSocket::flush()
95+
void BeckerSocket::flushOutput()
9896
{
9997
// only in connected state
10098
if (_state != BeckerConnected)
@@ -671,8 +669,10 @@ size_t BeckerSocket::dataOut(const void *buffer, size_t size)
671669
return result;
672670
}
673671

674-
//
675-
// Becker state handlers
676-
//
672+
void BeckerSocket::setHost(std::string host, int port)
673+
{
674+
_host = host;
675+
_port = port;
676+
}
677677

678678
#endif // BUILD_COCO

lib/bus/drivewire/BeckerSocket.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ class BeckerSocket : public IOChannel
2323
in_addr_t _ip;
2424
uint16_t _port;
2525

26-
uint32_t _baud; // not used by Becker
27-
2826
// is waiting for connection (listening) or connecting to?
2927
bool _listening;
3028

@@ -74,15 +72,9 @@ class BeckerSocket : public IOChannel
7472
void begin(std::string host, int baud);
7573
void end() override;
7674

77-
void setBaudrate(uint32_t baud) override { _baud = baud; }
78-
uint32_t getBaudrate() override { return _baud; }
79-
80-
bool getDTR() { return false; }
81-
void setDSR(bool state) { return; }
82-
bool getRTS() { return false; }
83-
void setCTS(bool state) { return; }
75+
void flushOutput() override;
8476

85-
void flush() override;
77+
void setHost(std::string host, int port);
8678
};
8779

8880
#endif // BECKERSOCKET_H

lib/bus/drivewire/drivewire.cpp

Lines changed: 68 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ void systemBus::op_readex()
158158
{
159159
size_t bytesrd;
160160
Debug_printf("op_readex: open successful %s\r\n", szNamedMount);
161-
161+
162162
memset(blk_buffer,0,MEDIA_BLOCK_SIZE);
163163
bytesrd = fread(blk_buffer,1,MEDIA_BLOCK_SIZE,pNamedObjFp);
164164
if (bytesrd!=MEDIA_BLOCK_SIZE || feof(pNamedObjFp))
165-
{
165+
{
166166
Debug_printf("op_readex: closed named object %s\r\n",szNamedMount);
167167
fclose(pNamedObjFp);
168168
pNamedObjFp = NULL;
@@ -173,12 +173,12 @@ void systemBus::op_readex()
173173
else
174174
{
175175
Debug_printf("op_readex: open failed %s\r\n", szNamedMount);
176-
fnDwCom.write(0xF4);
176+
_port->write(0xF4);
177177
return;
178178
}
179179
}
180180
else
181-
{
181+
{
182182
if (true==bDragon && drive_num>=5) drive_num = drive_num-5;
183183
Debug_printf("OP_READ: DRIVE %3u - SECTOR %8lu\n", drive_num, lsn);
184184

@@ -211,16 +211,16 @@ void systemBus::op_readex()
211211
blk_size = MEDIA_BLOCK_SIZE;
212212
use_media_buffer = false;
213213
}
214-
214+
215215
if (bDragon)
216216
{
217217
Debug_printf("dragon read\n");
218218
if (d->read(lsn, sector_data))
219219
{
220220
Debug_printf("Read error\n");
221-
fnDwCom.write(0xF4);
222-
fnDwCom.flush();
223-
fnDwCom.flush_input();
221+
_port->write(0xF4);
222+
_port->flushOutput();
223+
_port->discardInput();
224224
return;
225225
}
226226
}
@@ -662,44 +662,25 @@ void systemBus::service()
662662
_port->setDSR(!hasUpdate);
663663
}
664664

665-
if (fnDwCom.available())
665+
if (_port->available())
666666
_drivewire_process_cmd();
667667

668668
// dload.dload_process();
669669
}
670670

671-
// Setup DRIVEWIRE bus
672-
void systemBus::setup()
673-
{
674671
#ifdef ESP_PLATFORM
675-
// Create a queue to handle parallel event from ISR
676-
drivewire_evt_queue = xQueueCreate(10, sizeof(uint32_t));
677-
bDragon = false;
678-
679-
// Start task
680-
// xTaskCreate(drivewire_intr_task, "drivewire_intr_task", 2048, NULL, 10, NULL);
681-
// xTaskCreatePinnedToCore(drivewire_intr_task, "drivewire_intr_task", 4096, this, 10, NULL, 0);
682-
683-
#ifdef CONFIG_IDF_TARGET_ESP32S3
684-
// Configure UART to RP2040
685-
#ifdef FORCE_UART_BAUD
686-
Debug_printv("FORCE_UART_BAUD set to %u", FORCE_UART_BAUD);
687-
_drivewireBaud = FORCE_UART_BAUD;
688-
#else /* !FORCE_UART_BAUD */
689-
_drivewireBaud = 115200;
690-
#endif /* FORCE_UART_BAUD */
691-
692-
#else /* !CONFIG_IDF_TARGET_ESP32S3 */
693-
// Setup interrupt for cassette motor pin
694-
gpio_config_t io_conf = {
695-
.pin_bit_mask = (1ULL << PIN_CASS_MOTOR), // bit mask of the pins that you want to set
672+
void systemBus::configureGPIO()
673+
{
674+
// Setup interrupt for cassette motor pin
675+
gpio_config_t io_conf = {
676+
.pin_bit_mask = (1ULL << PIN_CASS_MOTOR), // bit mask of the pins that you want to set
696677
.mode = GPIO_MODE_INPUT, // set as input mode
697678
.pull_up_en = GPIO_PULLUP_DISABLE, // disable pull-up mode
698679
.pull_down_en = GPIO_PULLDOWN_ENABLE, // enable pull-down mode
699680
.intr_type = GPIO_INTR_POSEDGE // interrupt on positive edge
700-
};
681+
};
701682

702-
_cassetteDev = new drivewireCassette();
683+
_cassetteDev = new drivewireCassette();
703684

704685
// configure GPIO with the given settings
705686
gpio_config(&io_conf);
@@ -718,46 +699,78 @@ void systemBus::setup()
718699
fnSystem.set_pin_mode(PIN_EPROM_A14, gpio_mode_t::GPIO_MODE_INPUT, SystemManager::pull_updown_t::PULL_NONE);
719700
fnSystem.set_pin_mode(PIN_EPROM_A15, gpio_mode_t::GPIO_MODE_INPUT, SystemManager::pull_updown_t::PULL_NONE);
720701

721-
#ifdef FORCE_UART_BAUD
722-
Debug_printv("FORCE_UART_BAUD set to %u",FORCE_UART_BAUD);
723-
_drivewireBaud = FORCE_UART_BAUD;
724-
#else /* !FORCE_UART_BAUD */
725-
if (fnSystem.digital_read(PIN_EPROM_A14) == DIGI_LOW && fnSystem.digital_read(PIN_EPROM_A15) == DIGI_LOW)
702+
return;
703+
}
704+
705+
int systemBus::readBaudSwitch()
706+
{
707+
if (fnSystem.digital_read(PIN_EPROM_A14) == DIGI_LOW
708+
&& fnSystem.digital_read(PIN_EPROM_A15) == DIGI_LOW)
726709
{
727-
_drivewireBaud = 38400; //Coco1 ROM Image
728710
Debug_printv("A14 Low, A15 Low, 38400 baud");
711+
return 38400; //Coco1 ROM Image
729712
}
730-
else if (fnSystem.digital_read(PIN_EPROM_A14) == DIGI_HIGH && fnSystem.digital_read(PIN_EPROM_A15) == DIGI_LOW)
713+
714+
if (fnSystem.digital_read(PIN_EPROM_A14) == DIGI_HIGH
715+
&& fnSystem.digital_read(PIN_EPROM_A15) == DIGI_LOW)
731716
{
732-
_drivewireBaud = 57600; //Coco2 ROM Image
733717
Debug_printv("A14 High, A15 Low, 57600 baud");
718+
return 57600; //Coco2 ROM Image
734719
}
735-
else if (fnSystem.digital_read(PIN_EPROM_A14) == DIGI_LOW && fnSystem.digital_read(PIN_EPROM_A15) == DIGI_HIGH)
720+
721+
if (fnSystem.digital_read(PIN_EPROM_A14) == DIGI_LOW
722+
&& fnSystem.digital_read(PIN_EPROM_A15) == DIGI_HIGH)
736723
{
737-
_drivewireBaud = 115200; //Coco3 ROM Image
738724
Debug_printv("A14 Low, A15 High, 115200 baud");
725+
return 115200; //Coco3 ROM Image
739726
}
740-
else
741-
{
742-
_drivewireBaud = 57600; // Dragon
743-
bDragon = true;
744-
Debug_printv("A14 and A15 High, (DRAGON) 57600 baud");
745-
}
746727

747-
#endif /* FORCE_UART_BAUD */
728+
Debug_printv("A14 and A15 High, defaulting to 57600 baud");
729+
return 57600; //Default or no switch
730+
}
731+
#endif /* ESP_PLATFORM */
732+
733+
// Setup DRIVEWIRE bus
734+
void systemBus::setup()
735+
{
736+
#ifdef ESP_PLATFORM
737+
// Create a queue to handle parallel event from ISR
738+
drivewire_evt_queue = xQueueCreate(10, sizeof(uint32_t));
739+
bDragon = false;
740+
741+
#ifdef CONFIG_IDF_TARGET_ESP32S3
742+
// Configure UART to RP2040
743+
#ifdef FORCE_UART_BAUD
744+
Debug_printv("FORCE_UART_BAUD set to %u", FORCE_UART_BAUD);
745+
_drivewireBaud = FORCE_UART_BAUD;
746+
#else /* !FORCE_UART_BAUD */
747+
_drivewireBaud = 115200;
748+
#endif /* FORCE_UART_BAUD */
749+
750+
#else /* ! CONFIG_IDF_TARGET_ESP32S3 */
751+
configureGPIO();
752+
#ifdef FORCE_UART_BAUD
753+
Debug_printv("FORCE_UART_BAUD set to %u",FORCE_UART_BAUD);
754+
_drivewireBaud = FORCE_UART_BAUD;
755+
#else /* !FORCE_UART_BAUD */
756+
_drivewireBaud = readBaudSwitch();
757+
#endif /* FORCE_UART_BAUD */
748758
#endif /* CONFIG_IDF_TARGET_ESP32S3 */
749759
#else /* !ESP_PLATFORM */
750760
// FujiNet-PC specific
751761
_drivewireBaud = Config.get_serial_baud();
752762
#endif /* !ESP_PLATFORM */
763+
753764
if (Config.get_boip_enabled())
754765
{
755766
_becker.begin(Config.get_boip_host(), _drivewireBaud);
756767
_port = &_becker;
757768
}
758769
else
759770
{
760-
_serial.begin(ChannelConfig().baud(_drivewireBaud).deviceID(DW_UART_DEVICE)
771+
_serial.begin(ChannelConfig()
772+
.baud(_drivewireBaud)
773+
.deviceID(DW_UART_DEVICE)
761774
.readTimeout(500)
762775
#ifdef ESP_PLATFORM
763776
.inverted(DW_UART_DEVICE == UART_NUM_2)
@@ -768,10 +781,8 @@ void systemBus::setup()
768781

769782
_port->discardInput();
770783
Debug_printv("DRIVEWIRE MODE");
771-
szNamedMount[0]=(uint8_t)0;
772-
pNamedObjFp = NULL;
773784

774-
// jeff hack to see if the S3 is getting serial data
785+
// jeff hack to see if the S3 is getting serial data
775786
// Debug_println("now receiving data...");
776787
// uint8_t b[] = {' '};
777788
// while(1)
@@ -782,7 +793,7 @@ void systemBus::setup()
782793
// Debug_printf("%c\n",b[0]);
783794
// }
784795
// }
785-
// end jeff hack
796+
// end jeff hack
786797

787798
}
788799

0 commit comments

Comments
 (0)