Skip to content

Commit 9739551

Browse files
committed
Fix problems with transferDelaySinceLast()
1 parent 0913c87 commit 9739551

File tree

4 files changed

+32
-26
lines changed

4 files changed

+32
-26
lines changed

lib/bus/iec/iec.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,14 @@ void IRAM_ATTR systemBus::cbm_on_clk_isr_handler()
9191
case IEC_LISTEN:
9292
case IEC_TALK:
9393
if (dev == IEC_ALLDEV || !isDeviceEnabled(dev)) {
94-
if (cmd == IEC_TALK) {
94+
if (dev == IEC_ALLDEV) {
9595
// Handle releaseLines() when ATN is released outside of this
9696
// interrupt to prevent watchdog timeout
9797
IEC_SET_STATE(BUS_RELEASE);
9898
}
9999
else {
100100
IEC_SET_STATE(BUS_IDLE);
101+
protocol->transferDelaySinceLast(TIMING_Tbb);
101102
releaseLines();
102103
}
103104
sendInput();

lib/bus/iec/protocol/_protocol.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,22 @@ int IRAM_ATTR IECProtocol::waitForSignals(int pin1, int state1,
8181

8282
void IECProtocol::transferDelaySinceLast(size_t minimumDelay)
8383
{
84-
uint64_t now, remaining;
85-
uint64_t ended = 0;
84+
uint64_t now, elapsed;
85+
int64_t remaining;
8686

8787

8888
now = esp_timer_get_time();
89+
elapsed = now - _transferEnded;
8990
if (minimumDelay > 0) {
90-
remaining = now - (ended + minimumDelay);
91+
remaining = minimumDelay;
92+
remaining -= elapsed;
9193
if (remaining > 0) {
9294
usleep(remaining);
9395
now = esp_timer_get_time();
9496
}
9597
}
9698

97-
ended = now;
99+
_transferEnded = now;
98100
return;
99101
}
100102

lib/bus/iec/protocol/_protocol.h

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,32 @@
99

1010
#include "../../include/cbm_defines.h"
1111

12-
#define IEC_RELEASE(pin) ({ \
13-
uint32_t _pin = pin; \
14-
uint32_t _mask = 1 << (_pin % 32); \
15-
if (_pin >= 32) \
16-
GPIO.enable1_w1tc.val = _mask; \
17-
else \
18-
GPIO.enable_w1tc = _mask; \
12+
#define IEC_RELEASE(pin) ({ \
13+
uint32_t _pin = pin; \
14+
uint32_t _mask = 1 << (_pin % 32); \
15+
if (_pin >= 32) \
16+
GPIO.enable1_w1tc.val = _mask; \
17+
else \
18+
GPIO.enable_w1tc = _mask; \
1919
})
20-
#define IEC_ASSERT(pin) ({ \
21-
uint32_t _pin = pin; \
22-
uint32_t _mask = 1 << (_pin % 32); \
23-
if (_pin >= 32) \
24-
GPIO.enable1_w1ts.val = _mask; \
25-
else \
26-
GPIO.enable_w1ts = _mask; \
20+
#define IEC_ASSERT(pin) ({ \
21+
uint32_t _pin = pin; \
22+
uint32_t _mask = 1 << (_pin % 32); \
23+
if (_pin >= 32) \
24+
GPIO.enable1_w1ts.val = _mask; \
25+
else \
26+
GPIO.enable_w1ts = _mask; \
2727
})
2828

2929
#ifndef IEC_INVERTED_LINES
30-
#define IEC_IS_ASSERTED(pin) ({ \
31-
uint32_t _pin = pin; \
32-
!((_pin >= 32 ? GPIO.in1.val : GPIO.in) & (1 << (_pin % 32))); \
30+
#define IEC_IS_ASSERTED(pin) ({ \
31+
uint32_t _pin = pin; \
32+
!((_pin >= 32 ? GPIO.in1.val : GPIO.in) & (1 << (_pin % 32))); \
3333
})
3434
#else
35-
#define IEC_IS_ASSERTED(pin) ({ \
36-
uint32_t _pin = pin; \
37-
!!(_pin >= 32 ? GPIO.in1.val : GPIO.in) & (1 << (_pin % 32)); \
35+
#define IEC_IS_ASSERTED(pin) ({ \
36+
uint32_t _pin = pin; \
37+
!!(_pin >= 32 ? GPIO.in1.val : GPIO.in) & (1 << (_pin % 32)); \
3838
})
3939
#endif /* !IEC_INVERTED_LINES */
4040

@@ -45,6 +45,9 @@ namespace Protocol
4545
*/
4646
class IECProtocol
4747
{
48+
private:
49+
uint64_t _transferEnded = 0;
50+
4851
public:
4952

5053
// 2bit Fast Loader Pair Timing

lib/bus/iec/protocol/cpbstandardserial.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#ifdef BUILD_IEC
1919

20-
#define DYMANIC_DELAY
20+
#define DYNAMIC_DELAY
2121

2222
#include "cpbstandardserial.h"
2323

0 commit comments

Comments
 (0)