Improve timeout management logic.
This commit is contained in:
@@ -473,16 +473,20 @@ func_02_read_sector:
|
||||
mov ax, wait_msg
|
||||
call print_string
|
||||
%endif
|
||||
mov dx, XTMAX_IO_BASE+0 ; data port
|
||||
mov cx, 50000 ; timeout (50ms)
|
||||
jmp .receive_token_no_delay
|
||||
mov dx, XTMAX_IO_BASE+15; timeout port
|
||||
mov al, 10 ; 100 ms
|
||||
out dx, al
|
||||
.receive_token:
|
||||
call delay_us
|
||||
.receive_token_no_delay:
|
||||
mov dx, XTMAX_IO_BASE+0 ; data port
|
||||
in al, dx
|
||||
cmp al, 0xfe
|
||||
loopne .receive_token
|
||||
jne .error
|
||||
je .got_token
|
||||
mov dx, XTMAX_IO_BASE+15; timeout port
|
||||
in al, dx
|
||||
test al, al
|
||||
jnz .error
|
||||
jmp .receive_token
|
||||
.got_token:
|
||||
%ifdef DEBUG_IO
|
||||
mov ax, sd_token_msg
|
||||
call print_string
|
||||
@@ -625,14 +629,20 @@ cpu 8086
|
||||
mov ax, wait_msg
|
||||
call print_string
|
||||
%endif
|
||||
mov cx, 50000 ; timeout (50ms)
|
||||
jmp .receive_status_no_delay
|
||||
mov dx, XTMAX_IO_BASE+15; timeout port
|
||||
mov al, 25 ; 250 ms
|
||||
out dx, al
|
||||
.receive_status:
|
||||
call delay_us
|
||||
.receive_status_no_delay:
|
||||
mov dx, XTMAX_IO_BASE+0 ; data port
|
||||
in al, dx
|
||||
cmp al, 0xff
|
||||
loope .receive_status
|
||||
jne .got_status
|
||||
mov dx, XTMAX_IO_BASE+15; timeout port
|
||||
in al, dx
|
||||
test al, al
|
||||
jnz .error
|
||||
jmp .receive_status
|
||||
.got_status:
|
||||
%ifdef DEBUG_IO
|
||||
push ax
|
||||
mov ax, sd_status_msg
|
||||
@@ -652,15 +662,20 @@ cpu 8086
|
||||
mov ax, wait_msg
|
||||
call print_string
|
||||
%endif
|
||||
mov cx, 50000 ; timeout (50ms)
|
||||
jmp .receive_finish_no_delay
|
||||
mov dx, XTMAX_IO_BASE+15; timeout port
|
||||
mov al, 25 ; 250 ms
|
||||
out dx, al
|
||||
.receive_finish:
|
||||
call delay_us
|
||||
.receive_finish_no_delay:
|
||||
mov dx, XTMAX_IO_BASE+0 ; data port
|
||||
in al, dx
|
||||
test al, al
|
||||
loope .receive_finish
|
||||
jz .error
|
||||
jnz .got_finish
|
||||
mov dx, XTMAX_IO_BASE+15; timeout port
|
||||
in al, dx
|
||||
test al, al
|
||||
jnz .error
|
||||
jmp .receive_finish
|
||||
.got_finish:
|
||||
%ifdef DEBUG_IO
|
||||
mov ax, sd_idle_msg
|
||||
call print_string
|
||||
@@ -1118,21 +1133,6 @@ send_sd_read_write_cmd:
|
||||
; General utilities
|
||||
;
|
||||
|
||||
;
|
||||
; Wait 1 microseconds.
|
||||
; out: AX = <TRASH>
|
||||
; FL = <TRASH>
|
||||
delay_us:
|
||||
push cx
|
||||
push dx
|
||||
xor cx, cx
|
||||
mov dx, 1 ; microseconds
|
||||
mov ah, 0x86 ; wait
|
||||
int 0x15
|
||||
pop dx
|
||||
pop cx
|
||||
ret
|
||||
|
||||
%include "utils.inc"
|
||||
|
||||
%ifdef DEBUG
|
||||
|
||||
@@ -129,7 +129,7 @@ _header DD -1 ; link to the next device
|
||||
DW DGROUP:STRATEGY ; address of the strategy routine
|
||||
DW DGROUP:INTERRUPT; " " " interrupt "
|
||||
DB 1 ; number of drives
|
||||
DB 'SDCDv12' ; DOS doesn't really use these bytes
|
||||
DB 'SDCDv13' ; DOS doesn't really use these bytes
|
||||
|
||||
; The geometry (sectors/track, tracks/cylinder) defined in the BPB is rather
|
||||
; arbitrary in the case of the TU58, but there are things to watch out for.
|
||||
|
||||
@@ -254,14 +254,13 @@ int wait_ready (void) /* 1:OK, 0:Timeout */
|
||||
BYTE d;
|
||||
UINT tmr;
|
||||
|
||||
|
||||
for (tmr = 5000; tmr; tmr--) { /* Wait for ready in timeout of 500ms */
|
||||
outp(DATAPORT+15, 50);
|
||||
do { /* Wait for ready in timeout of 500ms */
|
||||
d = inp(DATAPORT);
|
||||
if (d == 0xFF) break;
|
||||
dly_us(100);
|
||||
}
|
||||
} while(!inp(DATAPORT+15));
|
||||
|
||||
return tmr ? 1 : 0;
|
||||
return d == 0xFF;
|
||||
}
|
||||
|
||||
|
||||
@@ -310,11 +309,11 @@ int rcvr_datablock ( /* 1:OK, 0:Failed */
|
||||
UINT tmr;
|
||||
|
||||
|
||||
for (tmr = 1000; tmr; tmr--) { /* Wait for data packet in timeout of 100ms */
|
||||
outp(DATAPORT+15, 10);
|
||||
do { /* Wait for data packet in timeout of 100ms */
|
||||
d = inp(DATAPORT);
|
||||
if (d != 0xFF) break;
|
||||
dly_us(100);
|
||||
}
|
||||
} while(!inp(DATAPORT+15));
|
||||
if (d != 0xFE) {
|
||||
return 0; /* If not valid data token, return with error */
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user