📄 aplif.c
字号:
/*
*********************************************************************************************************
* File: aplif.C
* Contents:
*
* $Date: 04/06/06 Kimi v0.1
* 01/05/07 kevin v0.2
* 01/08/07 kevin v0.3
*
* Copyright (c) 2007 Fameg, Inc. All rights reserved
*********************************************************************************************************
*/
#include "fs7805.h"
#include "fs7805regs.h"
#include "Include.h"
#include "aplif.h"
#include "string.h"
/*
*********************************************************************************************************
* ReadPIO8
*
* Description: Read ATA device register value
*
* Arguments : register address
*
* Returns : register value
*********************************************************************************************************
*/
BYTE ReadPIO8 (BYTE addr)
{
BYTE retval;
while (!AplifIdle()); //wait for aplif idle
OUTATAPI = addr | (~ATAPI_ADDR_MASK & ATAPI_IDLE_VALUE); //set register address
retval = APLIFS_DATX_L; //start single read
while (!AplifIdle()); //wait for read flow done
retval = APLIFS_DAT_L; //read the regiser value
return (retval);
}
/*
*********************************************************************************************************
* ReadUDMA
*
* Description: Read data from ATA device with ultra dma mode
*
* Arguments : data number need to be read
*
* Returns : none
*********************************************************************************************************
*/
void ReadUDMA (WORD count)
{
INT8U temp,i=0;
SectorCount = 0x01;
while (!AplifIdle()); //wait for aplif idle
OUTATAPI=CS(3) | DA(0) | (~ATAPI_ADDR_MASK & ATAPI_IDLE_VALUE); //set chip select and Device address value for the udma mode
APLIFTCH = (count >> 1) >> 8; //set transaction count value
APLIFTCL = (count >> 1) & 0xFF;
if (SectorCount == 0x80)
{
APLIFTCL = 0x00;
APLIFTCH = 0x80;
}
FLOWSTATE = 0x82; //enter into flowstate
temp = EPCAPLIFTRIG; //start udma read flow
while (1)
{
if ( SFI_EPINT & 0x04 ) //wait for slave fifo interrupt
{
PassIn(); //reverse SW_IN_FIFO_Toggle
SFI_EPINT = SFI_EPINT & ~0x04; //clear slave fifo interrupt
EPCCS = EPCCS | bmEP_RXTXEN; // Enable RXTX send data to usb bus
i++;
if (i == SectorCount) break;
}
}
while (!(AplifIdle())); //after all the usb data been sent and aplif enter in idle state then stop this IN transaction
FLOWSTATE = 0x00 ; //leave flowstate
}
/*
*********************************************************************************************************
* WritePIO8
*
* Description: write ATA device register
*
* Arguments : register address and value need to be write
*
* Returns : none
*********************************************************************************************************
*/
void WritePIO8 (BYTE addr, BYTE indata)
{
while (!AplifIdle()); //wait for aplif idle
OUTATAPI = addr | (~ATAPI_ADDR_MASK & ATAPI_IDLE_VALUE); //set register address
APLIFS_DATX_L = indata; //start single write
while (!AplifIdle()); //wait for write flow done
OUTATAPI = ATAPI_IDLE_VALUE;
}
/*
*********************************************************************************************************
* WriteUDMA
*
* Description: Write data to ATA device with UDMA mode
*
* Arguments : data number need to be write
*
* Returns : none
*********************************************************************************************************
*/
void WriteUDMA (WORD count) //manual
{
unsigned char i = 0;
PassOut(); //pass the first frame data to slave fifo
SectorCount = 0x01;
while (!AplifIdle()); //wait for aplif idle
OUTATAPI=CS(3) | DA(0) | (~ATAPI_ADDR_MASK & ATAPI_IDLE_VALUE); //set chip select and Device address value for the udma mode
APLIFTCL = (count >> 1) & 0xFF; //set transaction count value
APLIFTCH = (count >> 1) >> 8;
if (SectorCount == 0x80)
{
APLIFTCL = 0x00;
APLIFTCH = 0x80;
}
FLOWSTATE = 0x83; //enter into flowstate
EPAAPLIFTRIG = 0xAA; //start udma write flow
while (1)
{
if ( SFI_EPINT & 0x01 ) //wait for slave fifo interrupt
{
i++;
SFI_EPINT = SFI_EPINT & ~0x01; //clear slave fifo interrupt
EP1CS = EP1CS | bmEP_RXTXEN; //enable usb receive next frame data
if (i < SectorCount)
{
while ((!(EPAFIFOCS & bmFIFO0_FULL)) && (!(EPAFIFOCS & bmFIFO1_FULL))); //wait for next frame data received in fifo then start operation
PassOut(); //pass usb data to slave fifo
}
else
{
break;
}
}
}
while (!AplifIdle()); //after all the usb data been sent and aplif enter in idle state then stop this IN transaction
FLOWSTATE = 0x00;
}
/*
*********************************************************************************************************
* ReadATAPI_STATUS_REG
*
* Description: Read ATA device status register value
*
* Arguments : none
*
* Returns : Status register value
*********************************************************************************************************
*/
BYTE ReadATAPI_STATUS_REG (void)
{
return (ReadPIO8(ATA_ALT_STATUS_REG));
}
/*
*********************************************************************************************************
* AbortAplif
*
* Description: Abort aplif transaction
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
void AbortAplif (void)
{
APLIFABORT = 0xAA;
}
/*
*********************************************************************************************************
* setFeatures
*
* Description: Set UDMA mode
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
void setFeatures(BYTE command,BYTE subcommand)
{
WritePIO8(ATA_DRIVESEL_REG, 0xE0);
WaitForBusyBit();
WritePIO8(ATA_SECTOR_COUNT_REG,subcommand);
WritePIO8(ATAPI_FEATURE_REG,command); // opcode 0x03 used for transfer mode
WritePIO8(ATAPI_COMMAND_REG,0xef); // execute the command
WaitForBusyBit();
}
/*
*********************************************************************************************************
* init_udma_read
*
* Description: initialize UDMA register for data read
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
void init_udma_read()
{
FSLOGIC = 0x36;//0xf1
FSEQ0CTL = 0x00;
FSEQ1CTL = 0x02;
FSTB = 0x90;
FSHOLDON = 0x19;
}
/*
*********************************************************************************************************
* init_udma_write
*
* Description: initialize UDMA register for data write
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
void init_udma_write()
{
FSLOGIC = 0x70;
FSEQ0CTL = 0x00;
FSEQ1CTL = 0x08;
FSTB = 0x11;
}
/*
*********************************************************************************************************
* WaitForBusyBit
*
* Description: wait for IDE device idle
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
void WaitForBusyBit(void)
{
while((ReadATAPI_STATUS_REG()&ATAPI_STATUS_BUSY_BIT));
ReadATAPI_STATUS_REG();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -