?? mmconecard.c
字號:
/******************************************************************************
C H E A D E R F I L E
(c) Copyright Motorola Semiconductors Hong Kong Limited 1999 - 2002
ALL RIGHTS RESERVED
*******************************************************************************
Project Name : Portable Personal System Manager - GT version 2.0
Project No. : PDAPSM05
Last Modified: Jan 31, 2002
File Name: MMC.c
Description: The funcitions stored in this file were interface with Device Mange
*******************************************************************************/
#include "rtoshdrs.h"
#include "dev_ptyp.h"
#include "dev_pdef.h"
#include "DEV_pptt.h"
#include "mmclocal.h"
#include "os_typ.h"
#include "mmc_ptt.h"
#include "DMA_def.h"
#include "DMA_pptt.h"
#include "HAL_pptt.h"
#include "DMA_typ.h"
#include "FLS_dd.h"
#include "Mem_pptt.h"
struct driver_FS _gMMCDriverFs={MMCInit,MMCRawRead,MMCRawWrite,MMCFormat, MMCRead,
MMCWrite,MMCTimeStamp,MMCDiskChange,MMCIoctl};
/******************************************************************************
Function Name : STATUS MmcSetupDriver()
Input Parameters : VOID
Output Parameters: VOID
Value returned : SYS_OK : Sucessful operation
Description : Driver Setup Function, Function Name is fixed
Cautions :
Prev Condition : VOID
Post Condition : VOID
******************************************************************************/
STATUS _MmcSetupDriver()
{
DEVICE mmcDevice={
1, /* Common fields. device type 1=pcfm,it is used for devices with USFiles support. 255 = devices without File System support */
0, /* Common fields, number of open paths to this device */
(DRIVER*)&_gMMCDriverFs, /* Common fields, pointer to device driver routines */
"MMC", /* Common fields, device name */
0, /*Common fields, Indicates the device' attributes. Its definition is as following:
bit 0 ~ 5 --- Power mode attributes
bit 6 ~ 29 --- reserved for future use
bit 30 --- reserved for DMA use, here set to 0
bit 31 --- Indicate if the device has DMA capability, 1 */
0x7, /* Only used for devices with File System support.bits: 0 = read, 1 = write , 2 = text mode*/
0, /* Only used for devices with File System support.for pcfm this will flag when the drive has been recalibrated.*/
MMC_UNIT_NO, /* Only used for devices with File System support.device unit no.For multiunit devices. */
0, /* Only used for devices with File System support.partition if hard disk (units 128-255).*/
0, /* Only used for devices with File System support.Reserved for USFiles */
0, /* Only used for devices with File System support.Reserved for USFiels */
NULL,
/* Only used for devices with File System support.device base address */
PPSMFILEMANAGER, /* Only used for devices with File System support.pointer to file manager routine*/
PPSMPCPARM, /*Only used for devices with File System support.device parameter table pointer,for pcfm the
table of info derived from the disk BPB. */
NULL, /* Only used for devices with File System support.Pointer to the file*/
};
_HalAttachIsr(HAL_INT_MMC,_MMCIrptHandle);
_HalMaskIrptSource(HAL_INT_MMC);
return _DevInstall(&mmcDevice);
}
/******************************************************************************
Function Name : MMCInit( DEVICE *devp )
Input Parameters : DEVICE *devp DEVICE Table
Output Parameters: VOID
Value returned : int 0: Sucessful operation, others: meet Error
Description : Interface functions between USFiles and MMC driver. Initialize
A card
Cautions :
Prev Condition : VOID
Post Condition : VOID
******************************************************************************/
int MMCInit( DEVICE *devp )
{
MMC_STATUS ret;/* ERROR DURING INITIALIZATION */
TRACE("***************************************************************\n");
ret = 0;
_gMMCDMAChannel=0xFF;
_HalUnMaskIrptSource(HAL_INT_MMC);
TRACE("MMC init function\n");
/* INITIALIZE A CARD (FOR MMC MODE, CMD0 TO CMD3.) */
if ( ret = _MMCInitOneCard(&_gCardInfo ) )
{
TRACE("MMC init function---Fail! ERR_MEDIA_NOREADY\n");
return( ERR_MEDIA_NOREADY );
}
return( 0 );
}
/******************************************************************************
Function Name : MMCRead( MMC_STATUS log_sect, PCFM_BUFFER *bufp )
Input Parameters : MMC_STATUS log_sect : Logical Sector Number
PCFM_BUFFER *buf : Buffer pointer
Output Parameters: VOID
Value returned : int 0: Sucessful operation, others: meet Error
Description : Interface functions between USFiles and MMC driver.
Read 1 block(SECTOR);
Cautions :
Prev Condition : VOID
Post Condition : VOID
******************************************************************************/
int MMCRead( U32 log_sect, PCFM_BUFFER *bufp )
{
U8 card_no;
MMC_STATUS ret;
DMA_CONFIG DmaConfig;
ret = 0;
TRACE("***************************************************************\n");
TRACE("MMC Read Function\n");
_gMMCDMAChannel=0xFF;
_gMMCDMAChannel=_DmaRequestChannel(DMA_TYPE_IO,DMA_MMC,&_gMMCDMAReq);
if(_gMMCDMAChannel!=0xFF)
{
DmaConfig.Mask=DMA_BURSTLENGTH;
if(_gCardInfo.type==MMC_TYPE_MMC)
DmaConfig.BurstLength=16; //depond on MMC FIFO Size
else
DmaConfig.BurstLength=0; //depond on MMC FIFO Size
_DmaConfigChannel(_gMMCDMAChannel,&DmaConfig);
}
/*----------------------------------------------------------------------*/
/* ACQUIRE THE CARD NUMBER */
/*----------------------------------------------------------------------*/
card_no = (bufp->devp->unit_no & ~MMC_UNIT_NO);
/*----------------------------------------------------------------------*/
/* READ */
/*----------------------------------------------------------------------*/
if ( bufp->userbuf == 0 )
{
if ( ret = _MMCReadSectOneCard(log_sect, (uint16)1,
bufp->buf) )
{
if(_gMMCDMAChannel!=0xFF)
_DmaReleaseChannel(_gMMCDMAChannel);
return _MMCErrorConvert(ret) ;
}
}
else
{
if ( ret = _MMCReadSectOneCard(log_sect, bufp->nsects,
bufp->userbuf ) )
{
if(_gMMCDMAChannel!=0xFF)
_DmaReleaseChannel(_gMMCDMAChannel);
return _MMCErrorConvert(ret) ;
}
}
if(_gMMCDMAChannel!=0xFF)
_DmaReleaseChannel(_gMMCDMAChannel);
TRACE("MMC Read Function: Succcess\n");
return( 0 );
}
/******************************************************************************
Function Name : MMCWrite( U32 log_sect, PCFM_BUFFER *bufp )
Input Parameters : U32 log_sect : Logical Sector Number
PCFM_BUFFER *buf : Buffer pointer
Output Parameters: VOID
Value returned : int 0: Sucessful operation, others: meet Error
Description : Interface functions between USFiles and MMC driver.
Write 1 block(SECTOR);
Cautions :
Prev Condition : VOID
Post Condition : VOID
******************************************************************************/
int MMCWrite( U32 log_sect, PCFM_BUFFER *bufp )
{
U8 card_no;
MMC_STATUS ret;
DMA_CONFIG DmaConfig;
TRACE("***************************************************************\n");
TRACE("MMC Write Function\n");
//_gMMCDMAChannel=0xFF;
_gMMCDMAChannel=_DmaRequestChannel(DMA_TYPE_IO,DMA_MMC,&_gMMCDMAReq);
if(_gMMCDMAChannel!=0xFF)
{
DmaConfig.Mask=DMA_BURSTLENGTH;
if(_gCardInfo.type==MMC_TYPE_MMC)
DmaConfig.BurstLength=16; //depond on MMC FIFO Size
else
DmaConfig.BurstLength=0; //depond on MMC FIFO Size
_DmaConfigChannel(_gMMCDMAChannel,&DmaConfig);
}
ret = 0;
/*----------------------------------------------------------------------*/
/* ACQUIRE THE CARD NUMBER */
/*----------------------------------------------------------------------*/
card_no = (bufp->devp->unit_no & ~MMC_UNIT_NO);
/*----------------------------------------------------------------------*/
/* WRITE */
/*----------------------------------------------------------------------*/
if ( bufp->userbuf == 0 )
{
if ( ret = _MMCWriteSectOneCard( log_sect, (uint16)1,
bufp->buf) )
{
if(_gMMCDMAChannel!=0xFF)
_DmaReleaseChannel(_gMMCDMAChannel);
//_HalDetachIrpt() TEMP
return _MMCErrorConvert(ret);
}
}
else
{
if ( ret = _MMCWriteSectOneCard(log_sect, bufp->nsects,
bufp->userbuf) )
{
if(_gMMCDMAChannel!=0xFF)
_DmaReleaseChannel(_gMMCDMAChannel);
//_HalDetachIrpt() TEMP
return _MMCErrorConvert(ret);
}
}
if(_gMMCDMAChannel!=0xFF)
_DmaReleaseChannel(_gMMCDMAChannel);
//_HalDetachIrpt() TEMP
TRACE("MMC Write Function: Success\n");
return( 0 );
}
/******************************************************************************
Function Name : MMCRead( DEVICE *devp, int cylinder, int head,
int nsects, void *bufp )
Input Parameters : *devp --> Device Table
cylinder --> Cylinder
head --> Header
nsects --> Sector
*bufp --> Buffer Point
Output Parameters: VOID
Value returned : int 0: Sucessful operation, others: meet Error
Description : Interface functions between USFiles and MMC driver.
Format
Cautions :
Prev Condition : VOID
Post Condition : VOID
******************************************************************************/
int MMCFormat( DEVICE *devp, int cylinder, int head,
int nsects, void *bufp )
{
return( 0 );
}
/******************************************************************************
Function Name : MMCRawRead( DEVICE *devp, int cylinder, int head, int sector,
int nsects, void *bufp )
Input Parameters : *devp --> Device Table
cylinder --> The number of cylinder
head --> The head number of header
sector --> The number of sector per cylinder
nsects --> The number of sectors
*bufp --> Buffer Pointer
Output Parameters: VOID
Value returned : int 0: Sucessful operation, others: meet Error
Description : Interface functions between USFiles and MMC driver.
Raw Read
Cautions :
Prev Condition : VOID
Post Condition : VOID
******************************************************************************/
int MMCRawRead( DEVICE *devp, int cylinder, int head, int sector,
int nsects, void *bufp )
{
return( SYS_ERR );/* raw_read SHALL NOT BE CALLED BECAUSE THIS IS HDD FORMAT */
}
/******************************************************************************
Function Name : MMCRawWrite( DEVICE *devp, int cylinder, int head, int sector,
int nsects, void *bufp )
Input Parameters : *devp --> Device Table
cylinder --> The number of cylinder
head --> The head number of header
sector --> The number of sector per cylinder
nsects --> The number of sectors
*bufp --> Buffer Pointer
Output Parameters: VOID
Value returned : int 0: Sucessful operation, others: meet Error
Description : Interface functions between USFiles and MMC driver.
Raw Write
Cautions : Public function.
Prev Condition : VOID
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -