leomseq_tbl.c 7.8 KB
/*
 *  F i l e N a m e  : l e o m s e q _ t b l . c
 *
 ****************************************************************************
 *                   (C) Copyright ALPS Electric Co., Ltd. 1995-1996
 ****************************************************************************
 *  Version:
 *
 *  ver     date
 *  ----  --------
 *  1.05  '96-12-24   Delete SYSTEMWRITE and add #ifdef _LONGCMD for long command. Modefy leoSet_mseq().
 *  1.04a '96-10-07   Enable bad-ecc write on tk6 if SYSTEMWRITE is defined.
 *  1.04  '96-10-01   Delete OSPiHandle errStatus check .
 *  1.03  '96-07-05   Add LEOPiDmaParam initialize for phase1  .
 *  1.02  '96-02-27   Rename file name mseq_tbl.c to leomseq_tbl.c .
 *  1.01  '95-12-20   Initial Revision.
 ****************************************************************************
 */
#include "os.h"

#include <ultra64.h>
#include "leodefine.h"
#include "leodrive.h"
#include "leomacro.h"
#ifdef _LONGCMD
#include "leoappli.h"
#include "leospappli.h"
#endif

/*************************************/
/* PROTOTYPE                         */
/*************************************/
void leoSet_mseq(u16 rwmode);

/*************************************/
/* EXTERNAL RAMS                     */
/*************************************/
extern u32 LEOasic_seq_ctl_shadow;
extern u8  LEORDGAP_TBL1[ZONES_PER_DRV];
extern u8  LEORDGAP_TBL2[ZONES_PER_DRV];
extern u8  LEOWRGAP_TBL1[ZONES_PER_DRV];
extern u8  LEOWRGAP_TBL2[ZONES_PER_DRV];
extern struct tgt_param_form LEOtgt_param;
extern OSMesgQueue LEOdma_que;

extern OSPiHandle *LEOPiInfo;
extern OSIoMesg   LEOPiDmaParam;

extern volatile u16 LEOrw_flags;

#ifdef _LONGCMD
extern OSMesg      LEOcur_command;
#define    read_long_command    ((LEOCmdReadLong *)LEOcur_command)
#endif

/***************************************/
/*  Micro Sequencer Address            */
/***************************************/
#define MSEQ_RD_GAP1_ADR           1
#define MSEQ_RD_DATA_ADR           4
#define MSEQ_RD_GAP2_ADR           7

#define MSEQ_WR_GAP1_ADR           1
#define MSEQ_WR_DATA_ADR           4
#define MSEQ_WR_GAP2_ADR           8

#define MSEQ_LEN                  16

/*************************************/
/* RAM DEFINITIONS                   */
/*************************************/
static u32  mseq_tbl[MSEQ_LEN];    /* must be top of this file */

/********************************************/
/* SEQUENCER MAP                            */
/********************************************/
/* read */
static const   u32 rd_mseq_code[MSEQ_LEN] = {
    0x00010000,            /* 00H WAIT    */
    0x00020200,            /* 01H GAP     */
    0x80030100,            /* 02H GAP     */
    0x82040000,            /* 03H AM      */
    0xa8050000,            /* 04H DATA    */
    0xa0060600,            /* 05H C1      */
    0x31760000,            /* 06H SSP     */
    0x00020300,            /* 07H GAP     */
    0x00000000,            /* 08H NOT USE */
    0x00000000,            /* 09H NOT USE */
    0x00000000,            /* 0AH NOT USE */
    0x00000000,            /* 0BH NOT USE */
    0x00000000,            /* 0CH NOT USE */
    0x00000000,            /* 0DH NOT USE */
    0x00000000,            /* 0EH NOT USE */
    0x04060000 };          /* 0FH NEXT    */

/* write */
static const   u32 wt_mseq_code[MSEQ_LEN] = {
    0x40020000,            /* 00H WAIT    */
    0x00020000,            /* 01H GAP     */
    0x40130b00,            /* 02H SYNC    */
    0x42140100,            /* 03H AM      */
    0x68050000,            /* 04H DATA    */
    0x50060600,            /* 05H C1      */
    0x401702ff,            /* 06H PAD     */
    0x01870000,            /* 07H SSP     */
    0x40020000,            /* 08H GAP     */
    0x00000000,            /* 09H NOT USE */
    0x00000000,            /* 0AH NOT USE */
    0x00000000,            /* 0BH NOT USE */
    0x00000000,            /* 0CH NOT USE */
    0x00000000,            /* 0DH NOT USE */
    0x00000000,            /* 0EH NOT USE */
    0x040f0000 };          /* 0FH DONE    */

#ifdef _LONGCMD
/* read long */
static const   u32 rlong_mseq_code[MSEQ_LEN] = {
    0x00010000,            /* 00H */
    0x00020200,            /* 01H */
    0x80030100,            /* 02H */
    0x82040000,            /* 03H */
    0x88060000,            /* 04H */
    0x80060600,            /* 05H */
    0x01764055,            /* 06H */
    0x00020300,            /* 07H */
    0x00000000,            /* 08H */
    0x00000000,            /* 09H */
    0x00000000,            /* 0AH */
    0x00000000,            /* 0BH */
    0x00000000,            /* 0CH */
    0x00000000,            /* 0DH */
    0x00000000,            /* 0EH */
    0x04060000 };          /* 0FH */

/* write long */
static const   u32 wlong_mseq_code[MSEQ_LEN] = {
    0x40020000,            /* 00H */
    0x00020000,            /* 01H */
    0x40130b00,            /* 02H */
    0x42140100,            /* 03H */
    0x48060000,            /* 04H */
    0x50060600,            /* 05H */
    0x401702ff,            /* 06H */
    0x01874054,            /* 07H */
    0x40020000,            /* 08H */
    0x00000000,            /* 09H */
    0x00000000,            /* 0AH */
    0x00000000,            /* 0BH */
    0x00000000,            /* 0CH */
    0x00000000,            /* 0DH */
    0x00000000,            /* 0EH */
    0x040f0000 };          /* 0FH */
#endif

/* ==========================================================================
* Function : leoSet_mseq
* --------------------------------------------------------------------------
* Description : WRITE SEQUENCER MAP TO DRIVE
* --------------------------------------------------------------------------
* IN   : LEOtgt_param.zone
* OUT  : non
* ARG  : u16 rw_mode  .. read/write
* RET  : non
* ==========================================================================
*/
void leoSet_mseq(u16 rwmode)
{
    u32 *tbl;
    u32 sct_byte_x,sct_byte_u;
    u8  i;

    leoMicro_pc_disable();   /* SLEEP BM */

    /* copy map */
#ifdef _LONGCMD
    if (LEOrw_flags & LONG_RW)
    {
        if (rwmode == W_MODE)
            tbl = (u32*)wlong_mseq_code;
        else
            tbl = (u32*)rlong_mseq_code;
    }
    else
#endif
    {
        if (rwmode == W_MODE)
            tbl = (u32*)wt_mseq_code;
        else
            tbl = (u32*)rd_mseq_code;
    }
    for (i=0; i<MSEQ_LEN; i++)
    {
        mseq_tbl[i] = *tbl;
        ++tbl;
    }

    /* setup map */
#ifdef _LONGCMD
    if (LEOrw_flags & FIXSIZE)
    {
        sct_byte_x = sct_byte_u = read_long_command->size - 1;
        if (rwmode == W_MODE)
        {
            mseq_tbl[6] &= ~0x0000ff00;
            mseq_tbl[6] |= ((u32)LEOtgt_param.sec_bytes - sct_byte_u + 1)<<8;
        }
    }
    else
#endif
    {
        sct_byte_x = sct_byte_u = (u32)LEOtgt_param.sec_bytes - 1;
    }
    sct_byte_u += C1_LENGTH;

#ifdef _LONGCMD
    if (LEOrw_flags & LONG_RW)
    {
        sct_byte_x = sct_byte_u;
        if (LEOtgt_param.start_block)
        {
            if (rwmode == W_MODE)
                mseq_tbl[7] += 90;
            else
                mseq_tbl[6] += 90;
        }
    }
#endif
    sct_byte_x <<= 8;
    mseq_tbl[4] |= sct_byte_x;

    osWritebackDCache((void *)mseq_tbl, (s32)(MSEQ_LEN * sizeof(u32)));

    /* write map to drive */
    LEOPiDmaParam.dramAddr  = (void*)mseq_tbl;
    LEOPiDmaParam.devAddr  = MSEQ_RAM_ADDR;
    LEOPiDmaParam.size   = (u32)(MSEQ_LEN * sizeof(u32));
    LEOPiInfo->transferInfo.cmdType = OS_OTHERS;  /* not disk_read, not disk-write, simple DMA */
    leoAd16StartDma(OS_WRITE);      /* start dma */

    /* WAIT DMA DONE */
    (void)osRecvMesg(DMA_QUE, NULL, OS_MESG_BLOCK);

    /* SET SECTOR AND BYTE NUM */
    leoAd16WriteIo(ASIC_SEC_BYTE, (u32)(HALF_SECS_U16 | sct_byte_u) << 16 );

    /* SET BYTE NUM */
    if (LEOrw_flags & LONG_RW)
        sct_byte_x += 0x100;
    leoAd16WriteIo(ASIC_HOST_SECBYTE, (sct_byte_x << 8));

    leoMicro_pc_enable();  /* WAKEUP BM(NOT START) */
}