leomotor.c 3.53 KB
/*
 *  F i l e N a m e : l e o m o t o r .c
 *
 ****************************************************************************
 *                   (C) Copyright ALPS Electric Co., Ltd. 1995-1996
 ****************************************************************************
 *  Version:
 *
 *  ver       date
 *  ----    ---------
 *  1.04    '97-11-18  Add MOTOR BRAKE setting to control byte.
 *  1.03    '97-01-10  Move retry definition to leodrive.h .
 *  1.02    '96-10-25  Change start/stop command retry count (16 -> 8) .
 *  1.01    '96-02-27  Rename file name motor.c to leomotor.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 leoStart_stop(void);

/*************************************/
/* EXTERNAL FUNCTION                 */
/*************************************/
extern u8 leoSend_asic_cmd_w_nochkDiskChange(u32 asic_cmd, u32 asic_data);

/*************************************/
/* EXTERNAL RAM                      */
/*************************************/
extern OSMesg      LEOcur_command;

#define motor_cmd   ((LEOCmdStartStop *)LEOcur_command)

/* ==========================================================================
* Function : leoStart_stop
* --------------------------------------------------------------------------
* Description : Issue start/sleep/stby command
* --------------------------------------------------------------------------
* IN   : LEOcur_command
* OUT  : *LEOcur_command
* ARG  : non
* RET  : non
* ==========================================================================
*/
void leoStart_stop(void)
{
    u32 send_cmd;
    u8  sense_code;
    u8  retry_cntr;
    u32 send_data;

    retry_cntr = MAX_MOTOR_RETRY;

    do
    {
        send_data = 0;

        /* START ? */
        if (motor_cmd->header.control & LEO_CONTROL_START)
        {
            send_cmd = ASIC_START;
        }
        else
        {
            /* STAND-BY ? */
            if (motor_cmd->header.control & LEO_CONTROL_STBY)
            {
                send_cmd = ASIC_STANDBY;
            }
            else
            {
                /* MOTOR BRAKE ? */
                if (motor_cmd->header.control & LEO_CONTROL_BRAKE)
                {
                    send_data = 0x00010000; /* MOTOR BRAKE ON */
                }
                send_cmd = ASIC_SLEEP;
            }
        }
        if (!(sense_code = leoSend_asic_cmd_w_nochkDiskChange(send_cmd, send_data)))
        {
#ifdef _ERRCHK
            sense_code = motor_cmd->header.reserve1;
            if (((MAX_MOTOR_RETRY - retry_cntr) >= motor_cmd->header.reserve3 ) &&
                (sense_code == LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION) )
            {
                motor_cmd->header.reserve7 = (MAX_MOTOR_RETRY - retry_cntr);
                motor_cmd->header.sense    = sense_code;
                motor_cmd->header.status   = LEO_STATUS_GOOD;
                return;
            }
#else
            motor_cmd->header.status = LEO_STATUS_GOOD;
            return;
#endif
        }

        if (leoChk_err_retry(sense_code)) 
            break;

    } while (retry_cntr--);

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

}