Skip to content

Commit 8f6db5d

Browse files
committed
Remove fnUartBUS global so all bus IO goes through the systemBus (FujiNetWIFI#1033)
1 parent fd74542 commit 8f6db5d

File tree

20 files changed

+2891
-2939
lines changed

20 files changed

+2891
-2939
lines changed

lib/bus/adamnet/adamnet.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,24 @@ uint8_t adamnet_checksum(uint8_t *buf, unsigned short len)
7878
void virtualDevice::adamnet_send(uint8_t b)
7979
{
8080
// Write the byte
81-
fnUartBUS.write(b);
82-
fnUartBUS.flush();
81+
SYSTEM_BUS.write(b);
82+
SYSTEM_BUS.flush();
8383
}
8484

8585
void virtualDevice::adamnet_send_buffer(uint8_t *buf, unsigned short len)
8686
{
87-
fnUartBUS.write(buf, len);
88-
fnUartBUS.flush();
87+
SYSTEM_BUS.write(buf, len);
88+
SYSTEM_BUS.flush();
8989
}
9090

9191
uint8_t virtualDevice::adamnet_recv()
9292
{
9393
uint8_t b;
9494

95-
while (fnUartBUS.available() <= 0)
95+
while (SYSTEM_BUS.available() <= 0)
9696
fnSystem.yield();
9797

98-
b = fnUartBUS.read();
98+
b = SYSTEM_BUS.read();
9999

100100
return b;
101101
}
@@ -108,17 +108,17 @@ bool virtualDevice::adamnet_recv_timeout(uint8_t *b, uint64_t dur)
108108
start = current = esp_timer_get_time();
109109
elapsed = 0;
110110

111-
while (fnUartBUS.available() <= 0)
111+
while (SYSTEM_BUS.available() <= 0)
112112
{
113113
current = esp_timer_get_time();
114114
elapsed = current - start;
115115
if (elapsed > dur)
116116
break;
117117
}
118118

119-
if (fnUartBUS.available() > 0)
119+
if (SYSTEM_BUS.available() > 0)
120120
{
121-
*b = (uint8_t)fnUartBUS.read();
121+
*b = (uint8_t)SYSTEM_BUS.read();
122122
timeout = false;
123123
} // else
124124
// Debug_printf("duration: %llu\n", elapsed);
@@ -143,7 +143,7 @@ void virtualDevice::adamnet_send_length(uint16_t l)
143143

144144
unsigned short virtualDevice::adamnet_recv_buffer(uint8_t *buf, unsigned short len)
145145
{
146-
return fnUartBUS.readBytes(buf, len);
146+
return SYSTEM_BUS.read(buf, len);
147147
}
148148

149149
uint32_t virtualDevice::adamnet_recv_blockno()
@@ -168,7 +168,7 @@ void virtualDevice::adamnet_response_ack(bool doNotWaitForIdle)
168168
{
169169
SYSTEM_BUS.wait_for_idle();
170170
}
171-
171+
172172
if (t < 300)
173173
{
174174
adamnet_send(0x90 | _devnum);
@@ -183,7 +183,7 @@ void virtualDevice::adamnet_response_nack(bool doNotWaitForIdle)
183183
{
184184
SYSTEM_BUS.wait_for_idle();
185185
}
186-
186+
187187
if (t < 300)
188188
{
189189
adamnet_send(0xC0 | _devnum);
@@ -203,12 +203,12 @@ void systemBus::wait_for_idle()
203203
do
204204
{
205205
// Wait for serial line to quiet down.
206-
while (fnUartBUS.available() > 0)
207-
fnUartBUS.read();
206+
while (_port.available() > 0)
207+
_port.read();
208208

209209
start = current = esp_timer_get_time();
210210

211-
while ((fnUartBUS.available() <= 0) && (isIdle == false))
211+
while ((_port.available() <= 0) && (isIdle == false))
212212
{
213213
current = esp_timer_get_time();
214214
dur = current - start;
@@ -221,7 +221,7 @@ void systemBus::wait_for_idle()
221221

222222
void virtualDevice::adamnet_process(uint8_t b)
223223
{
224-
fnUartDebug.printf("adamnet_process() not implemented yet for this device. Cmd received: %02x\n", b);
224+
fnDebugConsole.printf("adamnet_process() not implemented yet for this device. Cmd received: %02x\n", b);
225225
}
226226

227227
void virtualDevice::adamnet_control_status()
@@ -262,14 +262,14 @@ void virtualDevice::adamnet_idle()
262262

263263
//void virtualDevice::adamnet_status()
264264
//{
265-
// fnUartDebug.printf("adamnet_status() not implemented yet for this device.\n");
265+
// fnDebugConsole.printf("adamnet_status() not implemented yet for this device.\n");
266266
//}
267267

268268
void systemBus::_adamnet_process_cmd()
269269
{
270270
uint8_t b;
271271

272-
b = fnUartBUS.read();
272+
b = _port.read();
273273
start_time = esp_timer_get_time();
274274

275275
uint8_t d = b & 0x0F;
@@ -311,7 +311,7 @@ void systemBus::service()
311311
_adamnet_process_queue();
312312

313313
// Process anything waiting.
314-
if (fnUartBUS.available() > 0)
314+
if (_port.available() > 0)
315315
_adamnet_process_cmd();
316316
}
317317

@@ -332,7 +332,7 @@ 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-
fnUartBUS.begin(ADAMNET_BAUDRATE);
335+
_port.begin(ADAMNET_BAUDRATE);
336336
}
337337

338338
void systemBus::shutdown()

lib/bus/adamnet/adamnet.h

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

8+
#include "fnUART.h"
89
#include <freertos/FreeRTOS.h>
910
#include <freertos/queue.h>
1011

@@ -178,7 +179,7 @@ class virtualDevice
178179
* @brief Do any tasks that can only be done when the bus is quiet
179180
*/
180181
virtual void adamnet_idle();
181-
182+
182183
/**
183184
* @brief send current status of device
184185
*/
@@ -193,7 +194,7 @@ class virtualDevice
193194
* @brief send status response
194195
*/
195196
virtual void adamnet_response_status();
196-
197+
197198
/**
198199
* @brief command frame, used by network protocol, ultimately
199200
*/
@@ -232,7 +233,7 @@ class virtualDevice
232233
*/
233234
uint8_t id() { return _devnum; }
234235

235-
236+
236237
};
237238

238239
/**
@@ -246,6 +247,8 @@ class systemBus
246247
adamFuji *_fujiDev = nullptr;
247248
adamPrinter *_printerDev = nullptr;
248249

250+
UARTManager _port = UARTManager(FN_UART_BUS);
251+
249252
void _adamnet_process_cmd();
250253
void _adamnet_process_queue();
251254

@@ -279,6 +282,18 @@ class systemBus
279282

280283
bool shuttingDown = false; // TRUE if we are in shutdown process
281284
bool getShuttingDown() { return shuttingDown; };
285+
286+
// Everybody thinks "oh I know how a serial port works, I'll just
287+
// access it directly and bypass the bus!" ಠ_ಠ
288+
size_t read(void *buffer, size_t length) { return _port.readBytes(buffer, length); }
289+
size_t read() { return _port.read(); }
290+
size_t write(const void *buffer, size_t length) { return _port.write(buffer, length); }
291+
size_t write(int n) { return _port.write(n); }
292+
size_t available() { return _port.available(); }
293+
void flush() { _port.flush(); }
294+
size_t print(int n, int base = 10) { return _port.print(n, base); }
295+
size_t print(const char *str) { return _port.print(str); }
296+
size_t print(const std::string &str) { return _port.print(str); }
282297
};
283298

284299
extern systemBus SYSTEM_BUS;

lib/bus/rs232/rs232.h

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

4-
#include "ACMChannel.h"
54
#include "UARTChannel.h"
6-
#include "TTYChannel.h"
75

86
#ifdef ESP_PLATFORM
97
#include <freertos/FreeRTOS.h>
@@ -224,13 +222,7 @@ class systemBus
224222

225223
bool useUltraHigh = false; // Use fujinet derived clock.
226224

227-
#if FUJINET_OVER_USB
228-
ACMChannel _port;
229-
#elif defined(ITS_A_UNIX_SYSTEM_I_KNOW_THIS)
230-
TTYChannel _port;
231-
#else /* !FUJINET_OVER_USB */
232225
UARTChannel _port;
233-
#endif /* FUJINET_OVER_USB */
234226

235227
void _rs232_process_cmd();
236228
/* void _rs232_process_queue(); */

0 commit comments

Comments
 (0)