Skip to content

Commit

Permalink
Merge pull request erichelgeson#142 from mynameistroy/troy/phase_fix
Browse files Browse the repository at this point in the history
SCSI Phase handling improved for SCSI-2
  • Loading branch information
erichelgeson authored and androda committed Jul 28, 2022
1 parent bd7b73b commit 19619f2
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions F4_BlueSCSI/F4_BlueSCSI.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1534,39 +1534,44 @@ void loop()
m_lun = 0xff;
SCSI_DEVICE *dev = (SCSI_DEVICE *)0; // HDD image for current SCSI-ID, LUN

// Wait until RST = H, BSY = H, SEL = L
do {} while( !SCSI_IN(vBSY) || SCSI_IN(vRST));
// We're in ARBITRATION
//LOG(" A:"); LOGHEX(readIO()); LOG(" ");

do {} while( SCSI_IN(vBSY) || !SCSI_IN(vSEL) || SCSI_IN(vRST));

// BSY+ SEL-
// If the ID to respond is not driven, wait for the next
//LOG(" S:"); LOGHEX(readIO()); LOG(" ");
// We're in SELECTION

byte scsiid = readIO() & scsi_id_mask;
if((scsiid) == 0) {
if(SCSI_IN(vIO) || (scsiid) == 0) {
delayMicroseconds(1);
return;
}
LOGN("Selection");
m_isBusReset = false;
if (setjmp(m_resetJmpBuf) == 1) {
LOGN("Reset, going to BusFree");
goto BusFree;
}
enableResetJmp();

// We've been selected

#if XCVR == 1
TRANSCEIVER_IO_SET(vTR_TARGET,TR_OUTPUT);
#endif
SCSI_TARGET_ACTIVE() // (BSY), REQ, MSG, CD, IO output turned on

// Set BSY to-when selected
SCSI_BSY_ACTIVE(); // Turn only BSY output ON, ACTIVE

// Wait until SEL becomes inactive
while(isHigh(gpio_read(SEL))) {}

// Ask for a TARGET-ID to respond
m_id = 31 - __builtin_clz(scsiid);

// Wait until SEL becomes inactive
while(isHigh(digitalRead(SEL)) && isLow(digitalRead(BSY))) {
m_isBusReset = false;
if (setjmp(m_resetJmpBuf) == 1) {
LOGN("Reset, going to BusFree");
goto BusFree;
}
enableResetJmp();

//
if(isHigh(digitalRead(ATN))) {
// In SCSI-2 this is mandatory, but in SCSI-1 it's optional
if(isHigh(gpio_read(ATN))) {
SCSI_PHASE_CHANGE(SCSI_PHASE_MESSAGEOUT);
// Bus settle delay 400ns. Following code was measured at 350ns before REQ asserted. Added another 50ns. STM32F103.
SCSI_PHASE_CHANGE(SCSI_PHASE_MESSAGEOUT);// 28ns delay STM32F103
Expand Down

0 comments on commit 19619f2

Please sign in to comment.