📄 ms_drv.c
字号:
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*****************************************************************************
*
* Filename:
* ---------
* ms_drv.c
*
* Project:
* --------
* Maui_Software
*
* Description:
* ------------
* Adaption driver of file system for Memory Stick
*
* Author:
* -------
* -------
*
*============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*============================================================================
****************************************************************************/
#include "kal_release.h"
#include "app_buff_alloc.h"
#include "fat_fs.h"
#include "msdc_def.h"
#include "sd_def.h"
#include "ms_def.h"
#if defined(__MSDC_MS__)
#define MAX_CLUSTERS (0x0FFF6 - 2)
#define SECTOR_SIZE 512
#define MSDC_MEDIA_DESCRIPTOR 0xF8
#define MAX_TRY 3
static int ReadSectors(void * DriveData, DWORD Sector, UINT Sectors, void * Buffer);
static int WriteSectors(void * DriveData, DWORD Sector, UINT Sectors, void * Buffer);
kal_uint8 MS_MBR[MS_SUPPORT_TYPES][MS_MBR_SIZE] = {
{ 0x80, 0x01, 0x0C, 0x00, 0x01, 0x01, 0x10, 0xF5, 0x1B, 0x00, 0x00, 0x00, 0xA5, 0x1E, 0x00, 0x00},
{ 0x80, 0x01, 0x0A, 0x00, 0x01, 0x01, 0x50, 0xED, 0x19, 0x00, 0x00, 0x00, 0xA7, 0x3D, 0x00, 0x00},
{ 0x80, 0x01, 0x0A, 0x00, 0x01, 0x03, 0x50, 0xED, 0x19, 0x00, 0x00, 0x00, 0x67, 0x7B, 0x00, 0x00},
{ 0x80, 0x01, 0x04, 0x00, 0x01, 0x03, 0xD0, 0xDD, 0x13, 0x00, 0x00, 0x00, 0x6D, 0xF7, 0x00, 0x00},
{ 0x80, 0x02, 0x08, 0x00, 0x01, 0x07, 0xD0, 0xDD, 0x27, 0x00, 0x00, 0x00, 0xD9, 0xEE, 0x01, 0x00},
{ 0x80, 0x02, 0x02, 0x00, 0x06, 0x0F, 0xD0, 0xDD, 0x21, 0x00, 0x00, 0x00, 0xDF, 0xDD, 0x03, 0x00}
};
__align(4) kal_uint8 MS_buffer[16*1024];
/*-----------------------------------*/
kal_uint16 MS_GetLPIndex(kal_uint32 ladrs)
{
kal_uint8 seg;
kal_uint16 min;
seg = (ladrs < 494)?0:((ladrs-494)/496 + 1);
min = (seg == 0)?0:(seg*496-2);
return ladrs - min;
}
#if defined(MS_FORMAT)
static int MS_MountDevice(int DeviceType)
{
kal_uint8 *sector = (kal_uint8*)MSDC_Sector;
FS_MasterBootRecord *MBR;
FS_BootRecord *PBR;
int status;
kal_bool IsMBRExist;
kal_uint8 type = 0;
kal_uint8 c = gMS.Capacity;
// get index for MS_MBR => (type) is the index
while((c >>= 1) != 2)
type++;
IsMBRExist = KAL_FALSE;
// read MBR at sector 0
status = ReadSectors(NULL,0,1,(void*)sector);
MBR = (FS_MasterBootRecord*)sector;
PBR = (FS_BootRecord*)sector;
if( MBR->Signature == 0xAA55 &&
MBR->PTable[0].BootIndicator == 0x80)
{
IsMBRExist = KAL_TRUE;
}
if(!IsMBRExist)
{
// create MBR
kal_mem_set((void*)MBR,0,sizeof(MBR));
kal_mem_cpy((void*)&(MBR->PTable[0]),MS_MBR[type],MS_MBR_SIZE);
MBR->Signature = 0xAA55;
status = WriteSectors(NULL,0,1,(void*)sector);
if(status < NO_ERROR)
return FS_MSDC_MOUNT_ERROR;
// create PBR
FS_CreateBootSector((void*)sector, (FS_PartitionRecord*)MS_MBR[type], (BYTE)MSDC_MEDIA_DESCRIPTOR,
(UINT)gMS.PagesPerBlk, (gMS.Capacity < 128)?FS_FMT_FAT_12:FS_FMT_FAT_16);
PBR->NearJump[0] = 0xE9;
PBR->NearJump[1] = 0x00;
PBR->NearJump[2] = 0x00;
kal_mem_set((void*)PBR->BP.OEMName,0x20,8);
PBR->BP.SectorsPerCluster = gMS.PagesPerBlk;
PBR->BP.DirEntries = 0x200;
PBR->BP.E._16.BPB.PhysicalDiskNumber = 0;
PBR->BP.E._16.BPB.CurrentHead = 0;
PBR->BP.E._16.BPB.SerialNumber = 0;
kal_mem_set((void*)PBR->BP.E._16.BPB.Label,0x20,11);
status = WriteSectors(NULL, PBR->BP.NumberOfHiddenSectors,1,(void*)sector);
if(status < NO_ERROR)
return FS_MSDC_MOUNT_ERROR;
}
return FS_NO_ERROR;
}
#endif
static int DiscardSectors(void * DriveData, DWORD Sector, UINT Sectors)
{
#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
return FS_NO_ERROR;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -