Skip to content

Commit da676c8

Browse files
committed
[iec] fix ml http client
add define for JIFFYDOS replace timer functions in _protocol
1 parent b5f5823 commit da676c8

File tree

9 files changed

+185
-267
lines changed

9 files changed

+185
-267
lines changed

lib/bus/iec/iec.cpp

Lines changed: 48 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ void IRAM_ATTR systemBus::cbm_on_clk_isr_handler()
116116
else
117117
{
118118
newIO(val);
119+
#ifdef JIFFYDOS
119120
if (flags & JIFFYDOS_ACTIVE)
120121
{
121122
detected_protocol = PROTOCOL_JIFFYDOS;
122123
protocol = selectProtocol();
123124
}
125+
#endif
124126
}
125127
break;
126128

@@ -210,8 +212,7 @@ static void ml_iec_intr_task(void* arg)
210212
if ( IEC.enabled )
211213
IEC.service();
212214

213-
if ( IEC.state < BUS_ACTIVE )
214-
taskYIELD();
215+
taskYIELD();
215216
}
216217
}
217218
#endif
@@ -226,43 +227,6 @@ void systemBus::init_gpio(gpio_num_t _pin)
226227
return;
227228
}
228229

229-
bool IRAM_ATTR systemBus::status()
230-
{
231-
// uint64_t pin_states;
232-
// pin_states = REG_READ(GPIO_IN1_REG);
233-
// pin_states << 32 & REG_READ(GPIO_IN_REG);
234-
// pin_atn = pin_states & BIT(PIN_IEC_ATN);
235-
// pin_clk = pin_states & BIT(PIN_IEC_CLK_IN);
236-
// pin_data = pin_states & BIT(PIN_IEC_DATA_IN);
237-
// pin_srq = pin_states & BIT(PIN_IEC_SRQ);
238-
// pin_reset = pin_states & BIT(PIN_IEC_RESET);
239-
return true;
240-
};
241-
242-
// uint8_t IRAM_ATTR systemBus::status()
243-
// {
244-
// int data = 0;
245-
246-
// // gpio_config_t io_config =
247-
// // {
248-
// // .pin_bit_mask = BIT(PIN_IEC_CLK_IN) | BIT(PIN_IEC_CLK_OUT) |BIT(PIN_IEC_DATA_IN) | BIT(PIN_IEC_DATA_OUT) | BIT(PIN_IEC_SRQ) | BIT(PIN_IEC_RESET),
249-
// // .mode = GPIO_MODE_INPUT,
250-
// // .pull_up_en = GPIO_PULLUP_ENABLE,
251-
// // .intr_type = GPIO_INTR_DISABLE,
252-
// // };
253-
254-
// // ESP_ERROR_CHECK(gpio_config(&io_config));
255-
// uint64_t io_data = REG_READ(GPIO_IN_REG);
256-
257-
// //data |= (0 & (io_data & (1 << PIN_IEC_ATN)));
258-
// data |= (1 & (io_data & (1 << PIN_IEC_CLK_IN)));
259-
// data |= (2 & (io_data & (1 << PIN_IEC_DATA_IN)));
260-
// data |= (3 & (io_data & (1 << PIN_IEC_SRQ)));
261-
// data |= (4 & (io_data & (1 << PIN_IEC_RESET)));
262-
263-
// return data;
264-
// }
265-
266230
void systemBus::setup()
267231
{
268232
Debug_printf("IEC systemBus::setup()\r\n");
@@ -285,6 +249,8 @@ void systemBus::setup()
285249
#warning intr_type likely needs to be fixed!
286250
#endif
287251

252+
iec_commandQueue = xQueueCreate(10, sizeof(IECData *));
253+
288254
// Start task
289255
// xTaskCreatePinnedToCore(ml_iec_intr_task, "ml_iec_intr_task", 4096, NULL, 20, NULL, 1);
290256

@@ -301,19 +267,21 @@ void systemBus::setup()
301267

302268
// Setup interrupt config for CLK
303269
io_conf = {
304-
.pin_bit_mask = (1ULL << PIN_IEC_CLK_IN), // bit mask of the pins that you want to set
305-
.mode = GPIO_MODE_INPUT, // set as input mode
306-
.pull_up_en = GPIO_PULLUP_DISABLE, // disable pull-up mode
307-
.pull_down_en = GPIO_PULLDOWN_DISABLE, // disable pull-down mode
308-
.intr_type = GPIO_INTR_POSEDGE // interrupt of rising edge
270+
.pin_bit_mask = (1ULL << PIN_IEC_CLK_IN), // bit mask of the pins that you want to set
271+
.mode = GPIO_MODE_INPUT, // set as input mode
272+
.pull_up_en = GPIO_PULLUP_DISABLE, // disable pull-up mode
273+
.pull_down_en = GPIO_PULLDOWN_DISABLE, // disable pull-down mode
274+
#ifdef IEC_INVERTED_LINES
275+
.intr_type = GPIO_INTR_NEGEDGE // interrupt of falling edge
276+
#else
277+
.intr_type = GPIO_INTR_POSEDGE // interrupt of rising edge
278+
#endif
309279
};
310280
gpio_config(&io_conf);
311281
gpio_isr_handler_add((gpio_num_t)PIN_IEC_CLK_IN, cbm_on_clk_isr_forwarder, this);
312282

313-
iec_commandQueue = xQueueCreate(10, sizeof(IECData *));
314-
315283
// Start SRQ timer service
316-
timer_start();
284+
//timer_start_srq();
317285
}
318286

319287
void IRAM_ATTR systemBus::service()
@@ -341,7 +309,7 @@ void IRAM_ATTR systemBus::service()
341309
/**
342310
* Start the Interrupt rate limiting timer
343311
*/
344-
void systemBus::timer_start()
312+
void systemBus::timer_start_srq()
345313
{
346314
esp_timer_create_args_t tcfg;
347315
tcfg.arg = this;
@@ -355,7 +323,7 @@ void systemBus::timer_start()
355323
/**
356324
* Stop the Interrupt rate limiting timer
357325
*/
358-
void systemBus::timer_stop()
326+
void systemBus::timer_stop_srq()
359327
{
360328
// Delete existing timer
361329
if (rateTimerHandle != nullptr)
@@ -373,23 +341,28 @@ std::shared_ptr<IECProtocol> systemBus::selectProtocol()
373341

374342
switch (detected_protocol)
375343
{
376-
case PROTOCOL_JIFFYDOS: {
377-
auto p = std::make_shared<JiffyDOS>();
378-
return std::static_pointer_cast<IECProtocol>(p);
379-
}
344+
#ifdef JIFFYDOS
345+
case PROTOCOL_JIFFYDOS:
346+
{
347+
auto p = std::make_shared<JiffyDOS>();
348+
return std::static_pointer_cast<IECProtocol>(p);
349+
}
350+
#endif
380351
#ifdef PARALLEL_BUS
381-
case PROTOCOL_DOLPHINDOS: {
382-
auto p = std::make_shared<DolphinDOS>();
383-
return std::static_pointer_cast<IECProtocol>(p);
384-
}
352+
case PROTOCOL_DOLPHINDOS:
353+
{
354+
auto p = std::make_shared<DolphinDOS>();
355+
return std::static_pointer_cast<IECProtocol>(p);
356+
}
385357
#endif
386-
default: {
358+
default:
359+
{
387360
#ifdef PARALLEL_BUS
388-
PARALLEL.state = PBUS_IDLE;
361+
PARALLEL.state = PBUS_IDLE;
389362
#endif
390-
auto p = std::make_shared<CPBStandardSerial>();
391-
return std::static_pointer_cast<IECProtocol>(p);
392-
}
363+
auto p = std::make_shared<CPBStandardSerial>();
364+
return std::static_pointer_cast<IECProtocol>(p);
365+
}
393366
}
394367
}
395368

@@ -448,7 +421,7 @@ void systemBus::assert_interrupt()
448421
if (interruptSRQ)
449422
IEC_ASSERT(PIN_IEC_SRQ);
450423
else
451-
IEC_RELEASE(PIN_DEBUG);
424+
IEC_RELEASE(PIN_IEC_SRQ);
452425
}
453426

454427
bool systemBus::sendByte(const char c, bool eoi) { return protocol->sendByte(c, eoi); }
@@ -530,19 +503,18 @@ void systemBus::reset_all_our_devices()
530503

531504
void systemBus::setBitTiming(std::string set, int p1, int p2, int p3, int p4)
532505
{
533-
uint8_t i = 0; // Send
534-
if (mstr::equals(set, (char *)"r"))
535-
i = 1;
536-
if (p1)
537-
protocol->bit_pair_timing[i][0] = p1;
538-
if (p2)
539-
protocol->bit_pair_timing[i][1] = p2;
540-
if (p3)
541-
protocol->bit_pair_timing[i][2] = p3;
542-
if (p4)
543-
protocol->bit_pair_timing[i][3] = p4;
544-
545-
Debug_printv("i[%d] timing[%d][%d][%d][%d]", i, protocol->bit_pair_timing[i][0], protocol->bit_pair_timing[i][1], protocol->bit_pair_timing[i][2], protocol->bit_pair_timing[i][3]);
506+
uint8_t i = 0; // Send
507+
if (mstr::equals(set, (char *) "r")) i = 1;
508+
if (p1) protocol->bit_pair_timing[i][0] = p1;
509+
if (p2) protocol->bit_pair_timing[i][1] = p2;
510+
if (p3) protocol->bit_pair_timing[i][2] = p3;
511+
if (p4) protocol->bit_pair_timing[i][3] = p4;
512+
513+
Debug_printv("i[%d] timing[%d][%d][%d][%d]", i,
514+
protocol->bit_pair_timing[i][0],
515+
protocol->bit_pair_timing[i][1],
516+
protocol->bit_pair_timing[i][2],
517+
protocol->bit_pair_timing[i][3]);
546518
}
547519

548520
void IRAM_ATTR systemBus::releaseLines(bool wait)

lib/bus/iec/iec.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,12 +457,12 @@ friend oiecstream;
457457
/**
458458
* @brief Start the Interrupt rate limiting timer
459459
*/
460-
void timer_start();
460+
void timer_start_srq();
461461

462462
/**
463463
* @brief Stop the Interrupt rate limiting timer
464464
*/
465-
void timer_stop();
465+
void timer_stop_srq();
466466

467467
public:
468468
/**

lib/bus/iec/protocol/_protocol.cpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,6 @@
99

1010
using namespace Protocol;
1111

12-
13-
/**
14-
* Callback function to set timeout
15-
*/
16-
static void onTimer(void *arg)
17-
{
18-
IECProtocol *p = (IECProtocol *)arg;
19-
p->timer_timedout = true;
20-
//IEC.release( PIN_IEC_SRQ );
21-
}
22-
23-
IECProtocol::IECProtocol() {
24-
esp_timer_create_args_t args = {
25-
.callback = onTimer,
26-
.arg = this,
27-
.dispatch_method = ESP_TIMER_TASK,
28-
.name = "onTimer",
29-
.skip_unhandled_events = 0,
30-
};
31-
esp_timer_create(&args, &timer_handle);
32-
};
33-
34-
IECProtocol::~IECProtocol() {
35-
esp_timer_stop(timer_handle);
36-
esp_timer_delete(timer_handle);
37-
};
38-
39-
/**
40-
* Start the timeout timer
41-
*/
42-
void IECProtocol::timer_start(uint64_t timeout_us)
43-
{
44-
timer_timedout = false;
45-
timer_started = esp_timer_get_time();
46-
esp_timer_start_once(timer_handle, timeout_us);
47-
//IEC.pull( PIN_IEC_SRQ );
48-
}
49-
void IECProtocol::timer_stop()
50-
{
51-
esp_timer_stop(timer_handle);
52-
timer_elapsed = esp_timer_get_time() - timer_started;
53-
//IEC.release( PIN_IEC_SRQ );
54-
}
55-
5612
int IRAM_ATTR IECProtocol::waitForSignals(int pin1, int state1,
5713
int pin2, int state2,
5814
int timeout)

lib/bus/iec/protocol/_protocol.h

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
})
3939
#endif /* !IEC_INVERTED_LINES */
4040

41+
static uint64_t timer_start_us;
42+
#define timer_start() timer_start_us = esp_timer_get_time()
43+
#define timer_elapsed() esp_timer_get_time() - timer_start_us
44+
#define timer_wait(us) while( (esp_timer_get_time()-timer_start_us) < ((int) (us+0.5)) )
45+
#define timer_timeout(us) (esp_timer_get_time() - timer_start_us > us)
46+
4147
namespace Protocol
4248
{
4349
/**
@@ -50,32 +56,12 @@ namespace Protocol
5056

5157
public:
5258

53-
// 2bit Fast Loader Pair Timing
59+
// Fast Loader Pair Timing
5460
std::vector<std::vector<uint8_t>> bit_pair_timing = {
5561
{0, 0, 0, 0}, // Receive
5662
{0, 0, 0, 0} // Send
5763
};
5864

59-
bool timer_timedout = false;
60-
uint64_t timer_started = 0;
61-
uint64_t timer_elapsed = 0;
62-
63-
64-
65-
/**
66-
* ESP timer handle for the Interrupt rate limiting timer
67-
*/
68-
esp_timer_handle_t timer_handle = nullptr;
69-
70-
/**
71-
* @brief ctor
72-
*/
73-
IECProtocol();
74-
75-
/**
76-
* @brief dtor
77-
*/
78-
~IECProtocol();
7965

8066
/**
8167
* @brief receive byte from bus
@@ -91,12 +77,6 @@ namespace Protocol
9177
*/
9278
virtual bool sendByte(uint8_t b, bool signalEOI) = 0;
9379

94-
/*
95-
* @brief Start timer
96-
*/
97-
void timer_start(uint64_t timeout);
98-
void timer_stop();
99-
10080
int waitForSignals(int pin1, int state1, int pin2, int state2, int timeout);
10181
void transferDelaySinceLast(size_t minimumDelay);
10282
};

lib/bus/iec/protocol/cpbstandardserial.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,12 @@ uint8_t CPBStandardSerial::receiveByte()
139139
// bit. When the talker figures the data has been held for a
140140
// sufficient length of time, it asserts the Clock line and releases
141141
// the Data line. Then it starts to prepare the next bit.
142+
143+
#ifndef JIFFYDOS
144+
for (idx = data = 0; !abort && idx < 8; idx++) {
145+
#else
142146
for (idx = data = 0; !abort && idx < 7; idx++) {
147+
#endif
143148
if ((abort = waitForSignals(PIN_IEC_CLK_IN, IEC_RELEASED, 0, 0, TIMEOUT_DEFAULT)))
144149
break;
145150

@@ -152,6 +157,7 @@ uint8_t CPBStandardSerial::receiveByte()
152157
}
153158
}
154159

160+
#ifdef JIFFYDOS
155161
// If there is a 218us delay before bit 7, the controller uses JiffyDOS
156162
if (waitForSignals(PIN_IEC_CLK_IN, IEC_RELEASED, 0, 0,
157163
TIMING_PROTOCOL_DETECT) == TIMED_OUT) {
@@ -163,6 +169,7 @@ uint8_t CPBStandardSerial::receiveByte()
163169

164170
abort = waitForSignals(PIN_IEC_CLK_IN, IEC_RELEASED, 0, 0, TIMEOUT_DEFAULT);
165171
}
172+
#endif
166173

167174
if (!abort) {
168175
// JiffyDOS check complete, Get last bit

0 commit comments

Comments
 (0)