Skip to content

Commit 1da6d39

Browse files
committed
Remove fnUartBUS global so all bus IO goes through the systemBus
1 parent 01a7597 commit 1da6d39

File tree

21 files changed

+2934
-2989
lines changed

21 files changed

+2934
-2989
lines changed

include/debug.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
#ifdef ESP_PLATFORM
2525
// Use FujiNet debug serial output
2626
#include "../lib/hardware/fnUART.h"
27-
#define Serial fnUartDebug
27+
#define Serial fnDebugConsole
2828
#if defined(PINMAP_RS232_S3) /*|| defined(PINMAP_ESP32S3_XDRIVE)*/
2929
#define Debug_print(...) printf( __VA_ARGS__ )
3030
#define Debug_printf(...) printf( __VA_ARGS__ )
3131
#define Debug_println(...) do { printf(__VA_ARGS__); printf("\n"); } while (0)
3232
#define Debug_printv(format, ...) {printf( ANSI_YELLOW "[%s:%u] %s(): " ANSI_GREEN_BOLD format ANSI_RESET "\r\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);}
3333
#else
34-
#define Debug_print(...) fnUartDebug.print( __VA_ARGS__ )
35-
#define Debug_printf(...) fnUartDebug.printf( __VA_ARGS__ )
36-
#define Debug_println(...) fnUartDebug.println( __VA_ARGS__ )
37-
#define Debug_printv(format, ...) {fnUartDebug.printf( ANSI_YELLOW "[%s:%u] %s(): " ANSI_GREEN_BOLD format ANSI_RESET "\r\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);}
34+
#define Debug_print(...) fnDebugConsole.print( __VA_ARGS__ )
35+
#define Debug_printf(...) fnDebugConsole.printf( __VA_ARGS__ )
36+
#define Debug_println(...) fnDebugConsole.println( __VA_ARGS__ )
37+
#define Debug_printv(format, ...) {fnDebugConsole.printf( ANSI_YELLOW "[%s:%u] %s(): " ANSI_GREEN_BOLD format ANSI_RESET "\r\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);}
3838
#endif // PINMAP_RS232_S3
3939

4040
#define HEAP_CHECK(x) Debug_printf("HEAP CHECK %s " x "\r\n", heap_caps_check_integrity_all(true) ? "PASSED":"FAILED")
@@ -55,7 +55,7 @@
5555
#ifdef ESP_PLATFORM
5656
// Use FujiNet debug serial output
5757
#include "../lib/hardware/fnUART.h"
58-
#define Serial fnUartDebug
58+
#define Serial fnDebugConsole
5959
#endif
6060

6161
#define Debug_print(...)

lib/bus/rs232/rs232.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ void virtualDevice::bus_to_computer(uint8_t *buf, uint16_t len, bool err)
6868
rs232_complete();
6969

7070
// Write data frame
71-
fnUartBUS.write(buf, len);
71+
SYSTEM_BUS.write(buf, len);
7272
// Write checksum
73-
fnUartBUS.write(rs232_checksum(buf, len));
73+
SYSTEM_BUS.write(rs232_checksum(buf, len));
7474

75-
fnUartBUS.flush();
75+
SYSTEM_BUS.flush();
7676
}
7777

7878
/*
@@ -87,13 +87,13 @@ uint8_t virtualDevice::bus_to_peripheral(uint8_t *buf, unsigned short len)
8787
Debug_printf("<-RS232 read %hu bytes\n", len);
8888

8989
__BEGIN_IGNORE_UNUSEDVARS
90-
size_t l = fnUartBUS.readBytes(buf, len);
90+
size_t l = SYSTEM_BUS.read(buf, len);
9191
__END_IGNORE_UNUSEDVARS
9292

9393
// Wait for checksum
94-
while (fnUartBUS.available() <= 0)
94+
while (SYSTEM_BUS.available() <= 0)
9595
fnSystem.yield();
96-
uint8_t ck_rcv = fnUartBUS.read();
96+
uint8_t ck_rcv = SYSTEM_BUS.read();
9797

9898
uint8_t ck_tst = rs232_checksum(buf, len);
9999

@@ -120,33 +120,33 @@ uint8_t virtualDevice::bus_to_peripheral(uint8_t *buf, unsigned short len)
120120
// RS232 NAK
121121
void virtualDevice::rs232_nak()
122122
{
123-
fnUartBUS.write('N');
124-
fnUartBUS.flush();
123+
SYSTEM_BUS.write('N');
124+
SYSTEM_BUS.flush();
125125
Debug_println("NAK!");
126126
}
127127

128128
// RS232 ACK
129129
void virtualDevice::rs232_ack()
130130
{
131-
fnUartBUS.write('A');
131+
SYSTEM_BUS.write('A');
132132
fnSystem.delay_microseconds(DELAY_T5); //?
133-
fnUartBUS.flush();
133+
SYSTEM_BUS.flush();
134134
Debug_println("ACK!");
135135
}
136136

137137
// RS232 COMPLETE
138138
void virtualDevice::rs232_complete()
139139
{
140140
fnSystem.delay_microseconds(DELAY_T5);
141-
fnUartBUS.write('C');
141+
SYSTEM_BUS.write('C');
142142
Debug_println("COMPLETE!");
143143
}
144144

145145
// RS232 ERROR
146146
void virtualDevice::rs232_error()
147147
{
148148
fnSystem.delay_microseconds(DELAY_T5);
149-
fnUartBUS.write('E');
149+
SYSTEM_BUS.write('E');
150150
Debug_println("ERROR!");
151151
}
152152

@@ -166,14 +166,14 @@ void systemBus::_rs232_process_cmd()
166166
{
167167
_modemDev->modemActive = false;
168168
Debug_println("Modem was active - resetting RS232 baud");
169-
fnUartBUS.set_baudrate(_rs232Baud);
169+
_port.set_baudrate(_rs232Baud);
170170
}
171171

172172
// Read CMD frame
173173
cmdFrame_t tempFrame;
174174
memset(&tempFrame, 0, sizeof(tempFrame));
175175

176-
if (fnUartBUS.readBytes((uint8_t *)&tempFrame, sizeof(tempFrame)) != sizeof(tempFrame))
176+
if (_port.readBytes((uint8_t *)&tempFrame, sizeof(tempFrame)) != sizeof(tempFrame))
177177
{
178178
Debug_println("Timeout waiting for data after CMD pin asserted");
179179
return;
@@ -281,7 +281,7 @@ void systemBus::service()
281281
// Neither CMD nor active modem, so throw out any stray input data
282282
{
283283
//Debug_println("RS232 Srvc Flush");
284-
fnUartBUS.flush_input();
284+
_port.flush_input();
285285
}
286286

287287
// Handle interrupts from network protocols
@@ -298,7 +298,7 @@ void systemBus::setup()
298298
Debug_printf("RS232 SETUP: Baud rate: %u\n",Config.get_rs232_baud());
299299

300300
// Set up UART
301-
fnUartBUS.begin(Config.get_rs232_baud());
301+
_port.begin(Config.get_rs232_baud());
302302

303303
// // INT PIN
304304
// fnSystem.set_pin_mode(PIN_RS232_RI, gpio_mode_t::GPIO_MODE_OUTPUT_OD, SystemManager::pull_updown_t::PULL_UP);
@@ -326,7 +326,7 @@ void systemBus::setup()
326326
qRs232Messages = xQueueCreate(4, sizeof(rs232_message_t));
327327

328328
Debug_println("RS232 Setup Flush");
329-
fnUartBUS.flush_input();
329+
_port.flush_input();
330330
}
331331

332332
// Add device to RS232 bus
@@ -421,7 +421,7 @@ void systemBus::toggleBaudrate()
421421

422422
// Debug_printf("Toggling baudrate from %d to %d\n", _rs232Baud, baudrate);
423423
_rs232Baud = baudrate;
424-
fnUartBUS.set_baudrate(_rs232Baud);
424+
_port.set_baudrate(_rs232Baud);
425425
}
426426

427427
int systemBus::getBaudrate()
@@ -439,7 +439,7 @@ void systemBus::setBaudrate(int baud)
439439

440440
Debug_printf("Changing baudrate from %d to %d\n", _rs232Baud, baud);
441441
_rs232Baud = baud;
442-
fnUartBUS.set_baudrate(baud);
442+
_port.set_baudrate(baud);
443443
}
444444

445445
// Set HRS232 index. Sets high speed RS232 baud and also returns that value.

lib/bus/rs232/rs232.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef RS232_H
22
#define RS232_H
33

4+
#include "fnUART.h"
45
#include <freertos/FreeRTOS.h>
56
#include <freertos/queue.h>
67

@@ -216,6 +217,8 @@ class systemBus
216217

217218
bool useUltraHigh = false; // Use fujinet derived clock.
218219

220+
UARTManager _port = UARTManager(FN_UART_BUS);
221+
219222
void _rs232_process_cmd();
220223
/* void _rs232_process_queue(); */
221224

@@ -250,6 +253,18 @@ class systemBus
250253

251254
bool shuttingDown = false; // TRUE if we are in shutdown process
252255
bool getShuttingDown() { return shuttingDown; };
256+
257+
// Everybody thinks "oh I know how a serial port works, I'll just
258+
// access it directly and bypass the bus!" ಠ_ಠ
259+
size_t read(void *buffer, size_t length) { return _port.readBytes(buffer, length); }
260+
size_t read() { return _port.read(); }
261+
size_t write(const void *buffer, size_t length) { return _port.write(buffer, length); }
262+
size_t write(int n) { return _port.write(n); }
263+
size_t available() { return _port.available(); }
264+
void flush() { _port.flush(); }
265+
size_t print(int n, int base = 10) { return _port.print(n, base); }
266+
size_t print(const char *str) { return _port.print(str); }
267+
size_t print(const std::string &str) { return _port.print(str); }
253268
};
254269

255270
extern systemBus SYSTEM_BUS;

0 commit comments

Comments
 (0)