From 1e1efaf4470a20c9ba05da3daece9cb5e8e45a3e Mon Sep 17 00:00:00 2001 From: Leo C Date: Sat, 21 May 2016 10:14:03 +0200 Subject: [PATCH] timeout in disk initialisation --- cbios/cfio.180 | 96 +++++++++++++++++++++++++++++++++++++++++++++++--- cbios/time.180 | 42 +++++++++++++++++++++- 2 files changed, 132 insertions(+), 6 deletions(-) diff --git a/cbios/cfio.180 b/cbios/cfio.180 index a76c9bd..604070a 100644 --- a/cbios/cfio.180 +++ b/cbios/cfio.180 @@ -32,7 +32,7 @@ extrn bnk2phy ; extrn add_hla - + extrn gstimer ; get timer short (16 bit) ; Port Address Equates @@ -114,7 +114,7 @@ wait: in a,(IdeCmd) jr c,wait endm - ; Macro: wait while device is busy + ; Macro: wait until device is ready WAITREADY macro local wait @@ -319,17 +319,39 @@ ptab_read: ret cf_init: - WAITREADY + ld hl,25600 ;32000/1.25 ms + call wait_nbsy_to + jr c,cfi_error ; return error on timeout + in a,(IDESCnt) + dec a + jr nz,cfi_error + in a,(IDESNum) + dec a + jr nz,cfi_error + in a,(IDECLo) + or a + jr nz,cfi_error + in a,(IDECHi) + or a + jr nz,cfi_error + in a,(IDESDH) + or a + jr nz,cfi_error + ld hl,25600 ;32000/1.25 ms + call wait_rdy_to + jr c,cfi_error ; return error on timeout + ld a,0E0h ; assume unit 0, lba mode out (IdeSDH),a ; ld a,1 ; Enable 8-bit data transfer. out (IDEFeat),a - ld a,CmdSF - out (IdeCmd),a ; command: read sector data + ld a,CmdSF ; Set feature command + out (IdeCmd),a ; WAITNOTBUSY in a,(IdeCmd) ; check final drive status and 10001001b ; Busy, DRQ, or Error? ret z ; no: everything is ok +cfi_error: ld a,1 ; return with A=1 on error ret @@ -352,6 +374,70 @@ pr_char: pop hl ret +;------------------------------------------------------------------------------- + +reftime:dw 2 +to: dw 2 + +chk_to: + or a + jr z,chk_1 + ld (to),hl + ld hl,0 + call gstimer + ld (reftime),hl + ret +chk_1: + push hl + push de + ld hl,(reftime) + call gstimer + ex de,hl + ld hl,(to) + or a + sbc hl,de + pop de + pop hl + ret + + +; Wait while device is busy with time out +; hl: timer tics (1.25ms) to wait +; return carry flag set, if time out + +wait_nbsy_to: + ld a,1 + call chk_to +wnb_l: + in a,(IdeCmd) + rla + jr nc,wnb_e + xor a + call chk_to + jr nc,wnb_l +wnb_e: + ret + +; Wait for ready signal with time out +; hl: timer tics (1.25ms) to wait +; return carry flag set, if time out + +wait_rdy_to: + ld a,1 + call chk_to +wrdy_l: + in a,(IdeCmd) + xor 01000000b + and 11000000b ; clears carry + jr z,wrdy_e + xor a + call chk_to + jr nc,wrdy_l +wrdy_e: + ret + +;------------------------------------------------------------------------------- + ; Print an id string ; Remove leading and trailing spaces diff --git a/cbios/time.180 b/cbios/time.180 index cd01749..1c63144 100644 --- a/cbios/time.180 +++ b/cbios/time.180 @@ -2,7 +2,7 @@ public ?time, gs_rtc public prt0ini - + public gtimer,gstimer extrn @date,@hour,@min,@sec extrn f_cpu @@ -86,6 +86,46 @@ gs_rtc: pop hl ret +;---------------------------------------------------------------------- + +;uint32_t get_timer(uint32_t base) +;{ +; uint32_t ret; +; ATOMIC_BLOCK(ATOMIC_FORCEON) +; { +; ret = timestamp; +; } +; return ret - base; +;} + + dseg ; called from banked only +gstimer: + push de + ex de,hl + ld hl,(uptime) + or a + sbc hl,de + pop de + ret + +;---------------------------------------------------------------------- + +gtimer: + push bc + ld b,h + ld c,l + or a + di + ld hl,(uptime) + sbc hl,bc + push hl + ei + ld hl,(uptime+2) + sbc hl,de + ex de,hl + pop hl + pop bc + ret ;---------------------------------------------------------------------- ; intit timer interrupt -- 2.39.2