📄 at91cfdev.c
字号:
/********************************************************************************* cfcBlkWrt - write one or more blocks to a cfc disk** This routine writes one or more blocks to the specified device,* starting with the specified block number.** If any block offset was specified during cfcDevCreate(), it is added* to <startBlk> before the transfer takes place.** RETURNS: OK, ERROR if the write command didn't succeed.*/LOCAL STATUS cfcBlkWrt ( AT91PS_CF_Card_Device pcfcDev, int startBlk, int nBlks, char *pBuf ) { return (cfcBlkRW (pcfcDev, startBlk, nBlks, pBuf, O_WRONLY)); }/********************************************************************************* cfcReset - reset a cfc disk controller** This routine resets a cfc disk controller.** RETURNS: OK, always.*/LOCAL STATUS cfcReset ( AT91PS_CF_Card_Device pcfcDev ) { semTake (&cfcMuteSem, WAIT_FOREVER); /* cfcInit ();*/ semGive (&cfcMuteSem); return (OK); }/********************************************************************************* cfcIoctl - do device specific control function** This routine is called when the file system cannot handle an ioctl()* function.** RETURNS: OK or ERROR.*/LOCAL STATUS cfcIoctl ( AT91PS_CF_Card_Device pcfcDev, int function, int arg ) { FAST int status = ERROR; semTake (&cfcMuteSem, WAIT_FOREVER); switch (function) { case FIODISKFORMAT: status = OK; break; default: (void) errnoSet (S_ioLib_UNKNOWN_REQUEST); }doneIoctl: semGive (&cfcMuteSem); return (status); }/********************************************************************************* cfcBlkRW - read or write sectors to a cfc disk.** Read or write sectors to a cfc disk.** RETURNS: OK, ERROR if the command didn't succeed.*/LOCAL STATUS cfcBlkRW ( AT91PS_CF_Card_Device pCFC, int startBlk, int nBlks, char *pBuf, int direction ) { BLK_DEV *pBlkDev = &pCFC->blkDev; int src,ix,i ; int status = ERROR; int semStatus = 0; char databuf[1200]; int Max_Read_DataBlock_Length = pCFC->pagesize; startBlk+=pCFC->blkOffset; src = startBlk; /* Max_Read_DataBlock_Length;*/ semTake (&cfcMuteSem, WAIT_FOREVER); memset(databuf,0,1200);if(direction==O_RDONLY){ for (ix = 0; ix < nBlks; ix ++) { /*AT91F_CF_READ16_SECTOR(pCFC,src,databuf,Max_Read_DataBlock_Length);*/ AT91F_CF_READ16_SECTOR((short*)databuf,(src&0xff000000)>>24,(src&0xff0000)>>16,(src&0xff00)>>8,src&0xff); semStatus = cfcWaitReady(AT91C_CFC_TIMEOUT); if ((cfcStatus & STAT_ERR) || (semStatus == ERROR)) goto errorRW; AT91F_CF_RDY(); memcpy(pBuf,databuf, pBlkDev->bd_bytesPerBlk); #ifdef __TEST__ if(memcmp(pBuf,gpCache+src, pBlkDev->bd_bytesPerBlk)!=0) { fprintf(stderr,"not the same \n"); }#endif src ++;/*= Max_Read_DataBlock_Length ;*/ pBuf += pBlkDev->bd_bytesPerBlk;/*Max_Read_DataBlock_Length;*/ }}else{ for (ix = 0; ix < nBlks; ix ++) {#ifdef __TEST__ memcpy(gpCache+src,pBuf,pBlkDev->bd_bytesPerBlk); #endif memcpy(databuf,pBuf,pBlkDev->bd_bytesPerBlk); AT91F_CF_WRITE16_SECTOR((unsigned short*)databuf,(src&0xff000000)>>24,(src&0xff0000)>>16,(src)>>8,src&0xff); AT91F_CF_RDY(); semStatus = cfcWaitReady(AT91C_CFC_TIMEOUT); if ((cfcStatus & STAT_ERR) || (semStatus == ERROR)) goto errorRW; /* AT91F_DataFlashWrite(pCFC , (unsigned int*) databuf ,src,Max_Read_DataBlock_Length); semStatus =OK;*/ #ifdef __TEST__ AT91F_CF_RDY(); AT91F_CF_READ16_SECTOR((short*)databuf,(src&0xff000000)>>24,(src&0xff0000)>>16,(src&0xff00)>>8,src&0xff); semStatus = cfcWaitReady(AT91C_CFC_TIMEOUT); if ((cfcStatus & STAT_ERR) || (semStatus == ERROR)) goto errorRW; AT91F_CF_RDY(); /*AT91F_DataFlashRead(pCFC,src,Max_Read_DataBlock_Length,databuf);*/ if(0!=memcmp(databuf,pBuf,pBlkDev->bd_bytesPerBlk)) { fprintf(stderr,"write cfc error \n"); } #endif src ++; /*= Max_Read_DataBlock_Length ;*/ pBuf += pBlkDev->bd_bytesPerBlk; /*Max_Read_DataBlock_Length;*/ }} status = OK;errorRW: if (status == ERROR) (void)errnoSet (S_ioLib_DEVICE_ERROR); semGive (&cfcMuteSem); return (status); }/********************************************************************************* cfcIntr - cfc controller interrupt handler.** RETURNS: N/A*/LOCAL void cfcIntr ( int ctrl ) {/*cfcStatus = ( AT91C_BASE_SPI->SPI_SR & AT91C_BASE_SPI->SPI_IMR );*//*AT91F_DataFlashHandler(pDataFlash_Device->pDataFlashDesc,cfcStatus);*/semGive (&cfcSyncSem); }/********************************************************************************* cfcIntr - cfc controller watchdog handler.** RETURNS: N/A*/LOCAL void cfcWdog ( int ctrl ) { cfcWaitForever = FALSE; }/********************************************************************************* cfcWait - wait the drive ready** Wait the drive ready** RETURNS: OK, ERROR if the drive didn't become ready in certain period of time.*/LOCAL void cfcWait ( int request ) { cfcWaitReady(AT91C_CFC_TIMEOUT); if (cfcDebug) printErr ("cfcWait end: \n"); }/********************************************************************************* cfcInit - init a cfc disk controller** This routine initializes a cfc disk controller.** RETURNS: OK, ERROR if the command didn't succeed.*/LOCAL void cfcInit (void) { /* AT91F_CfgSPIForDataFlash();*/ if (cfcDebug) printErr ("cfcInit end: \n"); }/********************************************************************************* cfcDiagnose - diagnose the drive** Diagnose the drive** RETURNS: OK, ERROR if the command didn't succeed.*/LOCAL STATUS cfcDiagnose (void) { return (OK); }/********************************************************************************* cfcPread - Read drive parameters** Read drive parameters.** RETURNS: OK, ERROR if the command didn't succeed.*/LOCAL STATUS cfcPread ( int drive, void *buffer ) { return (OK); }/********************************************************************************* cfcRecalib - recalibrate the drive** Recalibrate the drive** RETURNS: OK, ERROR if the command didn't succeed.*/LOCAL STATUS cfcRecalib ( int drive ) { return (OK); }/********************************************************************************* cfcSeek - seek the drive heads to the specified cylinder** Seek the drive heads to the specified cylinder** RETURNS: OK, ERROR if the command didn't succeed.*/LOCAL STATUS cfcSeek(int drive, int cylinder, int head){ return (OK); }/********************************************************************************* cfcRW - read/write a number of sectors on the current track** Read/write a number of sectors on the current track** RETURNS: OK, ERROR if the command didn't succeed.*//********************************************************************************* cfcFormat - format the current track** format the current track; not supported.** RETURNS: ERROR always.*/LOCAL STATUS cfcFormat ( int drive, int cylinder, int head, int interleave ) { return (ERROR); }/********************************************************************************* fdStatusChk - check a status of a floppy disk** This routine checks for a disk change on devices.** RETURNS: OK.*/LOCAL STATUS cfcStatusChk ( AT91PS_CF_Card_Device pcfcDev ) {/* pcfcDev->blkDev.bd_readyChanged = TRUE;*/ pcfcDev->blkDev.bd_mode = O_RDWR; #if 0 FD_TYPE *pType = &fdTypes[pFdDev->fdType]; wdCancel (fdWid); semTake (&fdMuteSem, WAIT_FOREVER); sysOutByte (FD_REG_OUTPUT, fdDORvalues[pFdDev->drive]); sysDelay (); /* * Bit 7 is set when a diskette is changed. * To clear the bit, we need to perform a seek. */ if (sysInByte (FD_REG_INPUT) & 0x80) { pFdDev->blkDev.bd_readyChanged = TRUE; /* do seek to clear DCHG bit in FD_REG_INPUT */ if (++fdCylinder >= pType->cylinders) fdCylinder = 1; fdDriveSelect (pFdDev->fdType, pFdDev->drive); (void) fdSeek(pFdDev->drive, fdCylinder, 0); /* set the bd_mode per the WP tab */ pFdDev->blkDev.bd_mode = (fdDriveIsWP(pFdDev->drive))? O_RDONLY : O_RDWR; } semGive (&fdMuteSem); wdStart (fdWid, (sysClkRateGet() * fdWdSec), (FUNCPTR)fdDriveRelease, 0);#endif return (OK); }void cfPrompt( DOS_VOL_CONFIG *pConfig ){ pConfig->fatType = 12 ; /* M- Fat format Type */ pConfig-> volSerial =0x12345678; /* M- disk serial number */ pConfig->sysId = "VXDOS12"; strcpy(pConfig->volLabel,"CF Card"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -