📄 cf_driver.c
字号:
while (CF_CR_L & (1<<BSY)); // loop while busy
CF_CR_L = ((1<<HIS) | (1<<INVOKE) | (1<<RWB));
while (CF_CR_L & (1<<BSY)); // loop while busy
while ((CF_IFR & (1<<OOIF)) == 0);
dummy = CF_CR;
CF_CR_L = 0;
// while ((QC34DSR & 0x03) != 0x02);
(void) CF_WaitCardBusy();
while (CF_CR_L & (1<<BSY)); // loop while busy
IQUECR = (1<<CH34DBE)+(1<<IQUEEN); // Enable double buffer
mSetBit(QnEN,QC1CR); // enable QC1
mClearBit(QnEN,QC3CR);
QC3REQ = kQCREQNone;
mSet2Bit(DRHE,DTHE,QC34DTR); // enable force handshake
return(0);
}
CFErrorCode CF_IQWriteMem(void)
{
muint16 dummy;
CF_CCR_L = (1<<REGB); // card in 16 bit memory mode
CF_BBAR = CF_M_DATA; // set reg address
while (CF_CR_L & (1<<BSY)); // loop while busy
CF_CR_L = ((1<<HIS) | (1<<INVOKE)); // IQUE Write
while (CF_CR_L & (1<<BSY)); // loop while busy
while ((CF_IFR & (1<<OOIF)) == 0);
dummy = CF_CR;
CF_CR_L = 0;
return (0);
}
CFErrorCode CF_IQRead8Mem(muint16 Mem)
{
muint16 dummy;
CF_CCR_L = (1<<CE2B) | (1<<REGB); // card in 8 bit memory mode
CF_BBAR = Mem; // set reg address
while (CF_CR_L & (1<<BSY)); // loop while busy
CF_CR_L = ((1<<HIS) | (1<<INVOKE) | (1<<RWB));
while (CF_CR_L & (1<<BSY)); // loop while busy
while ((CF_IFR & (1<<OOIF)) == 0);
dummy = CF_CR;
CF_CR_L = 0;
return(0);
}
CFErrorCode CF_IQWrite8Mem(muint16 Mem)
{
muint16 dummy;
CF_CCR_L = (1<<CE2B) | (1<<REGB); // card in 16 bit memory mode
CF_BBAR = Mem; // set reg address
while (CF_CR_L & (1<<BSY)); // loop while busy
while (CF_CR_L & (1<<BSY)); // loop while busy
CF_CR_L = (1<<HIS) | (1<<INVOKE); // IQUE Write
while (CF_CR_L & (1<<BSY)); // loop while busy
while ((CF_IFR & (1<<OOIF)) == 0);
dummy = CF_CR;
CF_CR_L = 0;
return (0);
}
// ==================================================================
// CF_WriteMem() -
//
// To write CF in 16 bit memory mode
//
// Input - = Memory location, data
//
// Output - = nil
//
// Function return:
//
// ==================================================================
CFErrorCode CF_WriteMem(muint16 Mem, muint16 Data)
{
CF_CR_L = 0x00;
CF_CCR_L = (1<<REGB); // card in 16 bit memory mode
CF_BBAR = Mem; // set reg address
while ((CF_IFR_L & (1<<CFTEIF)) ==0);
CF_DR = Data;
while (CF_CR_L & (1<<BSY)); // loop while busy
CF_CR_L = (1<<INVOKE); // write CF
while ((CF_IFR & (1<<OOIF)) == 0);
return (CF_WaitCardBusy());
}
void CF_Write8Mem(muint16 Mem, muint8 Data)
{
CF_CR_L = 0x00;
CF_CCR_L = (1<<CE2B) | (1<<REGB); // card in 8 bit memory mode
CF_BBAR = Mem; // set reg address
while ((CF_IFR_L & (1<<CFTEIF)) ==0);
// if (Mem & 0x0001)
CF_DR_H = Data;
// else
// CF_DR_L = Data;
while (CF_CR_L & (1<<BSY)); // loop while busy
CF_CR_L = 1<<INVOKE; // write CF
while ((CF_IFR & (1<<OOIF)) == 0);
CF_Wait8CardBusy();
}
void CF_WriteIO(muint16 Mem, muint16 Data)
{
CF_CR_L = 0x00;
CF_CCR_L = (1<<COM); // card in 16 bit I/O mode
CF_BBAR = Mem; // set reg address
while ((CF_IFR_L & (1<<CFTEIF)) ==0);
CF_DR = Data;
while (CF_CR_L & (1<<BSY)); // loop while busy
CF_CR_L = (1<<INVOKE); // write CF
while ((CF_IFR & (1<<OOIF)) == 0);
(void) CF_WaitCardBusyIO();
}
// ==================================================================
// CF_Command() -
//
// To set command to CF device
//
// Input - = 7 command parameters
//
// Output - =
//
// Function returns error code
//
// ==================================================================
CFErrorCode CF_Command(muint16 *command)
{
CFErrorCode error;
error = CF_WriteMem(CF_M_DATA_FEATURE,command[0]);
if (error)
return (error);
error = CF_WriteMem(CF_M_COUNT_SECTOR,command[1]);
if (error)
return (error);
error = CF_WriteMem(CF_M_CYL_L_H,command[2]);
if (error)
return (error);
return (CF_WriteMem(CF_M_HEAD_COMMAND,command[3]));
}
CFErrorCode CF_Command8(muint8 *command)
{
mint16 error = 0;
CF_Write8Mem(CF_M_FEATURE,command[0]);
CF_Write8Mem(CF_M_COUNT,command[1]);
CF_Write8Mem(CF_M_SECTOR,command[2]);
CF_Write8Mem(CF_M_CYL_L,command[3]);
CF_Write8Mem(CF_M_CYL_H,command[4]);
CF_Write8Mem(CF_M_HEAD,command[5]);
CF_Write8Mem(CF_M_COMMAND,command[6]);
return (0);
}
CFErrorCode CF_CommandIO(muint16 *command)
{
mint16 error = 0;
CF_WriteIO(CF_M_DATA_FEATURE,command[0]);
CF_WriteIO(CF_M_COUNT_SECTOR,command[1]);
CF_WriteIO(CF_M_CYL_L_H,command[2]);
CF_WriteIO(CF_M_HEAD_COMMAND,command[3]);
return (0);
}
// ==================================================================
// CF_LBACFCommand() -
//
// To set command to CF device
//
// Input - = 7 command parameters
//
// Output - =
//
// Function returns error code
//
// ==================================================================
CFErrorCode CF_LBACFCommand(muint8 Block, muint8 CFCmd)
{
CFErrorCode error;
error = CF_WaitCardBusy();
if (error)
return (error);
// error = CF_WriteMem(CF_M_DATA_FEATURE,0x0000);
// if (error)
// return (error);
error = CF_WriteMem(CF_M_COUNT_SECTOR, ((muint16) Block << 8) | (muint8) *(gpbCBWPacket+kSCSI10LBAByte0));
if (error)
return (error);
error = CF_WriteMem(CF_M_CYL_L_H, ((muint16) *(gpbCBWPacket+kSCSI10LBAByte1) << 8) | (muint8) *(gpbCBWPacket+kSCSI10LBAByte2));
if (error)
return (error);
return(CF_WriteMem(CF_M_HEAD_COMMAND,0xE000 | ( (muint16) *(gpbCBWPacket+kSCSI10LBAByte3) << 8) | CFCmd));
}
// ==================================================================
// CF_LBACFCommand() -
//
// To set command to CF device
//
// Input - = 7 command parameters
//
// Output - =
//
// Function returns error code
//
// ==================================================================
CFErrorCode CF_LBACFCommand1(muint8 Block, muint8 *pLBA, muint8 CFCmd)
{
CFErrorCode error;
error = CF_WaitCardBusy();
if (error)
return (error);
// error = CF_WriteMem(CF_M_DATA_FEATURE,0x0000);
// if (error)
// return (error);
error = CF_WriteMem(CF_M_COUNT_SECTOR, ((muint16) Block << 8) | (muint8) *(pLBA+3));
if (error)
return (error);
error = CF_WriteMem(CF_M_CYL_L_H, ((muint16) *(pLBA+2) << 8) | (muint8) *(pLBA+1));
if (error)
return (error);
return(CF_WriteMem(CF_M_HEAD_COMMAND,0xE000 | ( (muint16) *(pLBA) << 8) | CFCmd));
}
// ==================================================================
// CF_GetDeviceInfo() -
//
// Get device information and do the initization
//
// Input - = NIL
//
// Output - = Data wrote to CF device
//
// Function returns CF error code
//
// ==================================================================
CFErrorCode CF_GetSetDeviceInfo(void)
{
muint16 *pBuffer;
volatile CFErrorCode error;
pBuffer = (muint16 *) (kIQUERAMBegin+0x400);
INITEE = 0x21;
error = CF_IdentifyDevice(pBuffer, 0x100);
if (error)
return (error);
gCFMaxCapacity = (muint32) (pBuffer[kCFDevInfoMaxCap+1]) << kThreeByte \
| (pBuffer[kCFDevInfoMaxCap+1]) >>kOneByte ;
gCFMaxCapacity = (gCFMaxCapacity << kTwoByte) \
| (pBuffer[kCFDevInfoMaxCap]) << kOneByte \
| (pBuffer[kCFDevInfoMaxCap]) >> kOneByte;
gCFMaxCapacity--;
return (0);
}
void CF_IQTest(void)
{
// muint16 wdata[256];
// muint16 i;
muint16 command[4];
IQUECR = (1<<CH34DBE) | (1<<IQUEEN) | (1<<IQUERST); // enable IQUE 1
IQUECR = (1<<IQUEEN);
QC3CR |= (1<<QnTHRU);
mSetBit(DBRST,QC34DCR); // reset QC34
QC34DTR |= (1<<DRHE)+(1<<DTHE);
QC4CR = 0x15; // (QnEN | Qn16EN); // initialize ch 1
QC4SZB = 0x10; // 30;
QC4REQ = 0x04; // CF rx que
command[0] = 0x0000;
command[1] = 0x020D;
command[2] = 0x0200;
command[3] = (0x4000 | kCFCmdRead);
CF_BSR = 0x0000;
(void) CF_Command(command);
CF_BSR = 0x1FF;
(void) CF_IQReadMem();
command[1] = 0x020D;
QC4CR |= (1<<QnPRST);
// CF_Command(command);
CF_BSR = 0x1FF;
(void) CF_IQReadMem();
CF_BSR = 0x0000;
/*
CF_CCR_L = (1<<REGB); // card in 16 bit memory mode
CF_BBAR = CF_M_DATA; // set reg address
CF_BSR = 0x1FF;
while (CF_CR_L & (1<<BSY)); // loop while busy
CF_CR_L = ((1<<HIS) | (1<<INVOKE) | (1<<RWB));
while(CF_BSR);
mSetBit(DBRST,QC34DCR); // reset QC34
CF_BSR = 0x1FF;
CF_CR_L = ((1<<HIS) | (1<<INVOKE) | (1<<RWB));
while (CF_CR_L & (1<<BSY)); // loop while busy
while ((CF_IFR & (1<<OOIF)) == 0);
CF_BSR = 0x1FF;
while (CF_CR_L & (1<<BSY)); // loop while busy
CF_CR_L = ((1<<HIS) | (1<<INVOKE) | (1<<RWB));
while (CF_CR_L & (1<<BSY)); // loop while busy
while ((CF_IFR & (1<<OOIF)) == 0);
CF_CR_L = 0x00;
gpUSBMBLBA = 0x020D;
QC4CR |= (1<<QnPRST);
CF_BSR = 0x0000;
CF_LBACFCommand(1,(muint8 *)&gpUSBMBLBA,kCFCmdRead);
CF_BSR = 0x1FF;
CF_IQReadMem(CF_M_DATA);
CF_BSR = 0x0000;
QC4CR |= (1<<QnPRST);
command[1] = 0x0121;
CF_Command(command);
CF_BSR = 0x1FF;
CF_IQReadMem(CF_M_DATA);
CF_BSR = 0x0000;
*/
}
CFErrorCode CF_IQWriteMemOneBlock(muint8 pIQUEBuffer)
{
muint16 dummy;
mSetBit(DBRST,QC12DCR); // reset QC34 double buffer
mSetBit(RXDA,QC12DTR);
QC1SZB = 0x10 | pIQUEBuffer;
CF_BSR = 0x1FE;
CF_CCR_L = (1<<REGB); // card in 16 bit memory mode
CF_BBAR = CF_M_DATA; // set reg address
while (CF_CR_L & (1<<BSY)); // loop while busy
CF_CR_L = ((1<<HIS) | (1<<INVOKE)); // IQUE Write
while (CF_CR_L & (1<<BSY)); // loop while busy
while ((CF_IFR & (1<<OOIF)) == 0);
dummy = CF_CR;
CF_CR_L = 0;
return (0);
}
//
// The end of file CF_Driver.c
// *********************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -