leoseek.c 3.27 KB
/*
 *  F i l e N a m e : l e o s e e k . c
 *
 ****************************************************************************
 *                   (C) Copyright ALPS Electric Co., Ltd. 1995-1996
 ****************************************************************************
 *   Version:
 *
 *  ver     date
 *  ----  --------
 *  1.05  '97-01-10  Move retry definition to leodrive.h .
 *  1.04  '96-10-30  Change seek operation call leoSeek_w() .
 *  1.03  '96-10-25  Change seek command retry count (16 -> 20) .
 *  1.02  '96-07-25  Delete leoClear_mecha_int() macro.
 *  1.01  '96-02-27  Rename file name seek.c to leoseek.c .
 *  1.00  '95-12-20  Initial Revision.
 ****************************************************************************
*/
#include <ultra64.h>
#include "leodefine.h"
#include "leodrive.h"
#include "leomacro.h"
#include "leoappli.h"

/*************************************/
/*  PROTOTYPE                        */
/*************************************/
void leoSeek(void);

/*************************************/
/* EXTERNAL FUNCTIONS                */
/*************************************/
extern u16 leoLba_to_phys(u32 lba);

/*************************************/
/* EXTERNAL RAMS                     */
/*************************************/
extern OSMesgQueue LEOevent_que;
extern OSMesg      LEOcur_command;
extern u32 LEOasic_bm_ctl_shadow;

/*************************************/
/* MACROS                            */
/*************************************/
#define seek_cmd    ((LEOCmdSeek *)LEOcur_command)

/*==========================================================================
* Function : leoSeek
*--------------------------------------------------------------------------
* Description : EXECUTE SEEK COMMAND
*--------------------------------------------------------------------------
* IN    : LEOcur_command
* OUT   : *LEOcur_command, tgt_param.cylinder , tgt_param.head
* ARG   : non
* RET   : non
*==========================================================================
*/
void leoSeek(void)
{
    u32 tgt_tk;
    u8  sense_code;
    u8  retry_cntr;

    retry_cntr = MAX_SEEK_RETRY;

    if (seek_cmd->lba > (u32)MAX_L_LBA)
    {
        /* LBA out of range */
        seek_cmd->header.sense  = LEO_SENSE_LBA_OUT_OF_RANGE;
        seek_cmd->header.status = LEO_STATUS_CHECK_CONDITION;
        return;
    }

    leoLba_to_phys(seek_cmd->lba + SYSTEM_LBAS);
    do
    {
        if (!(sense_code = leoSeek_w() ))
        {
#ifdef _ERRCHK
            sense_code = seek_cmd->header.reserve1;
            if (((MAX_SEEK_RETRY - retry_cntr) >= seek_cmd->header.reserve3 ) &&
                (sense_code == LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION) )
            {
                seek_cmd->header.reserve7 = (MAX_SEEK_RETRY - retry_cntr);
                seek_cmd->header.sense    = sense_code;
                seek_cmd->header.status   = LEO_STATUS_GOOD;
                return;
            }
#else
            seek_cmd->header.status = LEO_STATUS_GOOD;
            return;
#endif
        }
        if (leoChk_err_retry(sense_code))
            break;
    } while (retry_cntr--);

    /* ERROR */
#ifdef _ERRCHK
    seek_cmd->header.reserve7 = (MAX_SEEK_RETRY - retry_cntr);
#endif
    seek_cmd->header.sense  = sense_code;
    seek_cmd->header.status = LEO_STATUS_CHECK_CONDITION;
    return;
}