Skip to content

Commit

Permalink
[iec] fix release ATN wait on bus process
Browse files Browse the repository at this point in the history
  • Loading branch information
idolpx committed Oct 15, 2024
1 parent a9fef60 commit be34316
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
15 changes: 8 additions & 7 deletions lib/bus/iec/iec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,27 +483,28 @@ void systemBus::read_command()
}
}

//if ( state == BUS_ACTIVE ) // Normal behaviour is to ignore everything if it's not for us
if ( state == BUS_PROCESS ) // Use this to sniff the secondary commands
if ( state == BUS_ACTIVE ) // Normal behaviour is to ignore everything if it's not for us
//if ( state == BUS_PROCESS ) // Use this to sniff the secondary commands
{
if ( !isDeviceEnabled( data.device ) )
{
// Is this command for us?
state = BUS_RELEASE; // NOPE!
}
}
else if ( state == BUS_PROCESS )

if ( state == BUS_PROCESS )
{
// *** IMPORTANT! This helps keep us in sync!
// Sometimes ATN isn't released immediately. Wait for ATN to be
// released before trying to process the command.
// Long ATN delay (>1.5ms) seems to occur more frequently with VIC-20.
//pull ( PIN_IEC_SRQ );
pull ( PIN_IEC_SRQ );
protocol->timeoutWait ( PIN_IEC_ATN, RELEASED, TIMEOUT_DEFAULT, false );

// Delay after ATN is RELEASED
//protocol->wait( TIMING_Ttk, false );
//release ( PIN_IEC_SRQ );
release ( PIN_IEC_SRQ );
}


Expand Down Expand Up @@ -870,7 +871,7 @@ bool IRAM_ATTR systemBus::turnAround()
*/

// Wait for CLK to be released
//pull ( PIN_IEC_SRQ );
pull ( PIN_IEC_SRQ );
if (protocol->timeoutWait(PIN_IEC_CLK_IN, RELEASED, TIMEOUT_Ttlta) == TIMEOUT_Ttlta)
{
Debug_printv("Wait until the computer releases the CLK line\r\n");
Expand All @@ -880,7 +881,7 @@ bool IRAM_ATTR systemBus::turnAround()
}
release ( PIN_IEC_DATA_OUT );
pull ( PIN_IEC_CLK_OUT );
//release ( PIN_IEC_SRQ );
release ( PIN_IEC_SRQ );

// 80us minimum delay after TURNAROUND
// *** IMPORTANT!
Expand Down
11 changes: 7 additions & 4 deletions lib/bus/iec/protocol/cpbstandardserial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ uint8_t CPBStandardSerial::receiveByte()
// without the Clock line going to true, it has a special task to perform: note EOI.

//IEC.pull ( PIN_IEC_SRQ );
//if ( timeoutWait ( PIN_IEC_CLK_IN, PULLED, TIMING_Tye, false ) == TIMING_Tye )
timer_start( TIMING_Tye );
while ( IEC.status ( PIN_IEC_CLK_IN ) != PULLED )
if ( timeoutWait ( PIN_IEC_CLK_IN, PULLED, TIMING_Tye, false ) == TIMING_Tye )
// timer_start( TIMING_Tye );
// while ( IEC.status ( PIN_IEC_CLK_IN ) != PULLED )
{
// INTERMISSION: EOI
// If the Ready for Data signal isn't acknowledged by the talker within 200 microseconds, the
Expand All @@ -152,7 +152,7 @@ uint8_t CPBStandardSerial::receiveByte()

//IEC.pull ( PIN_IEC_SRQ );

if ( timer_timedout )
//if ( timer_timedout )
{
timer_timedout = false;
IEC.flags |= EOI_RECVD;
Expand All @@ -162,6 +162,9 @@ uint8_t CPBStandardSerial::receiveByte()
IEC.pull ( PIN_IEC_DATA_OUT );
wait ( TIMING_Tei );
IEC.release ( PIN_IEC_DATA_OUT );

// Wait for clock line to be pulled
timeoutWait ( PIN_IEC_CLK_IN, PULLED, TIMING_Tye, false );
}

//usleep( 2 );
Expand Down

0 comments on commit be34316

Please sign in to comment.