📄 l1_storage.c
字号:
/*++
Copyright (c) 2001 Sunplus Technology Co., Ltd.
Module Name:
L1_Storage.c
Abstract:
Storage related function
Environment:
Keil C51 Compiler
Revision History:
11/30/2001 WZH created
--*/
//=============================================================================
//Header file
//=============================================================================
#include "general.h"
#include "main.h"
#include "asicreg.h"
#include "uiflow.h"
//=============================================================================
//Symbol
//=============================================================================
//-----------------------------------------------------------------------------
//Constant
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//Variable
//-----------------------------------------------------------------------------
extern xdata ULONG G_Card_TotalCardSize;
#if (SD)
extern xdata USHORT SD_BlockSize;
xdata UCHAR SD_OCR[4];
xdata UCHAR SD_RCA[2];
xdata UCHAR SD_CID[16];
xdata UCHAR SD_CSD[16];
#endif
//=============================================================================
//Program
//=============================================================================
#if (CFAIDE)
/*++
Copyright (c) 2001 Sunplus Technology Co., Ltd.
Module Name:
L1_CF.c
Abstract:
Module related to L1 CF card functions
Environment:
Keil C51 Compiler
Revision History:
11/12/2001 WZH created
--*/
//=============================================================================
//Program
//=============================================================================
#if 1
//-----------------------------------------------------------------------------
//L1_DMARdCFIDE
//-----------------------------------------------------------------------------
/*
routine description:
DMA read data from CF card in IDE mode
arguments:
Dst: the destination of DMA
0: DRAM
1: CPU 4K SRAM (0x1000 ~ 0x1FFF)
2: forbidden (flash itself)
3: Audio
4: USB
5: DMA data port (0x2300)
CylHigh: CF card register: cylinder high
CylLow: CF card register: cylinder low
SecNum: CF card register: sector number
SecSize: the number of byte in a sector
SecCnt: the number of sector
return value:
TRUE - success
FALSE - error
*/
//ada@0312
UCHAR L1_DMARdCFIDE(UCHAR Dst, UCHAR HS, UCHAR CylHigh, UCHAR CylLow, UCHAR SecNum, ULONG SecCnt, USHORT SecSize) USING_0
{
UCHAR Ready;
USHORT WordData;
UCHAR Haddr;
UCHAR Scnt;
USHORT tmp;
ULONG dramaddr = 0; // WMP3
ULONG i;
/* Chamber PA8591
if (Dst == 0)
{
L2_ReadDRAMDMAAdr(&dramaddr);
}
*/
// check interface ready
Ready = 0x00;
while ((Ready & 0x01) != 0x00)
{
L2_CFCheckRdy(&Ready);
}
Haddr = 0xE0 | (HS & 0x0F);
for (i = SecCnt; i > 256 ; i = (i - 256))
{
//check CF status register not busy and ready
WordData = 0x0000;
while ((WordData & 0x00c0) != 0x0040)
{
L2_CFSetWordCsARd(0x17,&WordData);
}
// Write command
L2_CFSetWordCsAWr(0x12,0x0000); // Sec Cnt
L2_CFSetWordCsAWr(0x13,(USHORT)SecNum); // Sec Nu.
L2_CFSetWordCsAWr(0x14,(USHORT)CylLow); // CylLow
L2_CFSetWordCsAWr(0x15,(USHORT)CylHigh); // CylHigh
L2_CFSetWordCsAWr(0x16,(USHORT)Haddr); //ada@0312
// Write Sector command
L2_CFSetWordCsAWr(0x17,0x0021);
// DMA
for (tmp = 0; tmp < 256 ; tmp++)
{
// check if busy
WordData = 0x0000;
while (WordData != 0x0058)
{
L2_CFSetWordCsARd(0x17,&WordData);
}
/* Chamber PA8591
if (Dst == 0)
{
L2_SetDRAMDMA(dramaddr);
}
*/
L2_CFSetCsA(0x10);
//richie@mi 0409 begin
//sss mark
//L2_DoDMA(2,Dst,SecSize,0,0);
//sss begin
if (Dst != K_DMA_USB)
{
// sync mode
L2_DoDMA(2,Dst,SecSize,0,0);
}
else
{
UCHAR bi;
// async mode
L2_DoDMA(2,Dst,SecSize,1,0);
for (bi=0;bi<8;bi++)
{
while (XBYTE[K_USB_CLASS_IN_BUF_SIZE] < 64) ; //wait for 64 in bulk buffer
XBYTE[0x25a1] = K_USB_CLASS_IN_OPEN;//0x01;//open bulk in
while ((XBYTE[0x25c2] & K_USB_CLASS_IN_ACK_MASK) == 0) ; //wait pc ack
XBYTE[0x25c2] = XBYTE[0x25c2] & K_USB_CLASS_IN_ACK_RESET;//reset 0x25c2
}
}
//sss end
//richie@mi 0409 end
//ada@0312
WordData = 0x0000;
while ((WordData & 0x00c0) != 0x0040) //check CF status register not busy and ready
{
L2_CFSetWordCsARd(0x17,&WordData);
}
if (Dst == 0)
{
dramaddr += (ULONG)(SecSize >> 1);
}
}
if ((CylLow == 255) && (CylHigh == 255))
{
Haddr++;
CylHigh = 0x00;
CylLow = 0x00;
}
else
{
if (CylLow == 255)
{
CylHigh++;
CylLow = 0x00;
}
else
{
CylLow++;
}
}
}
if (i != 0)
{
// check if busy
WordData = 0x0000;
while ((WordData & 0xC0) != 0x40)
{
L2_CFSetWordCsARd(0x17,&WordData);
}
if (i == 256)
{
Scnt = 0;
}
else
{
Scnt = (UCHAR)i;
}
// Write command
L2_CFSetWordCsAWr(0x12,(USHORT)Scnt); // Sec Cnt
L2_CFSetWordCsAWr(0x13,(USHORT)SecNum); // Sec Nu.
L2_CFSetWordCsAWr(0x14,(USHORT)CylLow); // CylLow
L2_CFSetWordCsAWr(0x15,(USHORT)CylHigh); // CylHigh
L2_CFSetWordCsAWr(0x16,(USHORT)Haddr);
// Write Sector command
L2_CFSetWordCsAWr(0x17,0x0021);
// DMA
for (tmp = 0; tmp < i; tmp++)
{
// check if busy
WordData = 0x0000;
while (WordData != 0x0058)
{
L2_CFSetWordCsARd(0x17,&WordData);
}
/* Chamber PA8591
if (Dst == 0)
{
L2_SetDRAMDMA(dramaddr);
}
*/
L2_CFSetCsA(0x10);
//richie@mi 0409 begin
//sss mark
//L2_DoDMA(2,Dst,SecSize,0,0);
//sss begin
if (Dst != K_DMA_USB)
{
// sync mode
L2_DoDMA(2,Dst,SecSize,0,0);
}
else
{
UCHAR bi;
// async mode
L2_DoDMA(2,Dst,SecSize,1,0);
for (bi=0;bi<8;bi++)
{
while (XBYTE[K_USB_CLASS_IN_BUF_SIZE] < 64) ; //wait for 64 in bulk buffer
XBYTE[0x25a1] = K_USB_CLASS_IN_OPEN;//0x01;//open bulk in
while ((XBYTE[0x25c2] & K_USB_CLASS_IN_ACK_MASK) == 0) ; //wait pc ack
XBYTE[0x25c2] = XBYTE[0x25c2] & K_USB_CLASS_IN_ACK_RESET;//reset 0x25c2
}
}
//sss end
//richie@mi 0409 end
//check CF status register not busy and ready
WordData = 0x0000;
while ((WordData & 0x00c0) != 0x0040)
{
L2_CFSetWordCsARd(0x17,&WordData);
}
if (Dst == 0)
{
dramaddr += (ULONG)(SecSize >> 1);
}
}
}
return TRUE;
}
#endif
#endif
#if (CFAMEM)
//-----------------------------------------------------------------------------
//L1_DMAWrCFMEM
//-----------------------------------------------------------------------------
/*
routine description:
DMA write data from CF card in memory mode
arguments:
Src: the source of DMA
0: DRAM
1: CPU 4K SRAM (0x1000 ~ 0x1FFF)
2: forbidden (flash itself)
3: Audio
4: USB
5: DMA data port (0x2300)
CylHigh: CF card register: cylinder high
CylLow: CF card register: cylinder low
SecNum: CF card register: sector number
SecSize: the number of byte in a sector
SecCnt: the number of sector
return value:
TRUE - success
FALSE - error
*/
//ada@0312
UCHAR L1_DMAWrCFMEM(UCHAR Src, UCHAR HS, UCHAR CylHigh, UCHAR CylLow, UCHAR SecNum, ULONG SecCnt, USHORT SecSize) USING_0
{
UCHAR Ready;
UCHAR Haddr;
UCHAR Scnt;
USHORT tmp;
ULONG dramaddr;
ULONG i;
/* Chamber PA8591
if (Src == 0)
{
L2_ReadDRAMDMAAdr(&dramaddr);
}
*/
// check interface ready
Ready = 0x00;
while ((Ready & 0x01) != 0x00)
{
L2_CFCheckRdy(&Ready);
}
Haddr = 0xE0 | (HS & 0x0F);
for (i = SecCnt; i > 256 ; i = (i - 256))
{
//check CF status register not busy and ready
Ready = 0x00;
while ((Ready & 0xc0) != 0x40)
{
L2_CFComMemRd(0x00,0x07,&Ready);
}
// Write command
L2_CFComMemWr(0x00,0x02,0); // SecCnt
L2_CFComMemWr(0x00,0x03,SecNum); // SecNu
L2_CFComMemWr(0x00,0x04,CylLow); // CylLow
L2_CFComMemWr(0x00,0x05,CylHigh); // CylHigh
L2_CFComMemWr(0x00,0x06,Haddr); // Logical addrss
// Write Sector command
L2_CFComMemWr(0x00,0x07,0x31);
// DMA
for (tmp = 0; tmp < 256; tmp++)
{
Ready = 0x00;
while (Ready != 0x58)
{
L2_CFComMemRd(0x00,0x07,&Ready);
}
/* Chamber PA8591
if (Src == 0)
{
L2_SetDRAMDMA(dramaddr);
}
*/
L2_CFSetMemA(0x00,0x00);
//richie@mi 0411 mark
//L2_DoDMA(Src,2,SecSize,0,0);
//richie@mi 0411 begin
if (Src != K_DMA_USB)
{ // sync mode
L2_DoDMA(Src,2,SecSize,0,0);
}
else
{
UCHAR bi;
// async mode
L2_DoDMA(Src,2,SecSize,1,0);
for (bi=0;bi<8;bi++)
{
while (XBYTE[K_USB_CLASS_OUT_BUF_SIZE] > 0) ; //wait for 0 in bulk buffer
XBYTE[0x25a1] = K_USB_CLASS_OUT_OPEN;//0x02;//open bulk out
while ((XBYTE[0x25c2] & K_USB_CLASS_OUT_ACK_MASK) == 0) ; //wait pc ack
XBYTE[0x25c2] = XBYTE[0x25c2] & K_USB_CLASS_OUT_ACK_RESET;//reset 0x25c2
}
while (XBYTE[K_USB_CLASS_OUT_BUF_SIZE] > 0) ; //wait for 0 in bulk buffer
}
//richie@mi 0411 end
//check CF status register not busy and ready
Ready = 0x00;
while ((Ready & 0xc0) != 0x40)
{
L2_CFComMemRd(0x00,0x07,&Ready);
}
if (Src == 0)
{
dramaddr += (ULONG)(SecSize >> 1);
}
}
if ((CylLow == 255) && (CylHigh == 255))
{
Haddr++;
CylHigh = 0x00;
CylLow = 0x00;
}
else
{
if (CylLow == 255)
{
CylHigh++;
CylLow = 0x00;
}
else
{
CylLow++;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -