⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tmfat32sd.c

📁 PNX1500上Fat32文件系统源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2003-2006 Koninklijke Philips Electronics N.V., * All Rights Reserved. * * This source code and any compilation or derivative thereof is the * proprietary information of Koninklijke Philips Electronics N.V. * and is confidential in nature. * Under no circumstances is this software to be exposed to or placed * under an Open Source License of any type without the expressed * written permission of Koninklijke Philips Electronics N.V. * *----------------------------------------------------------*//*! *      \file           tmFat32Sd.c * *      This file implements the tmFat32 device driver for a *      Sd Card. * *//*----------------------------------------------------------- * *      %version:       10 % *      instance:       DS_4 *      %date_created:  Sun Nov 12 15:08:40 2006 % * */ //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------// Standard include files://-----------------------------------------------------------------------------//#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#if USE_GENERIC_C#include <tmFat32Generic.h>#else#include <sys/syslimits.h>#include <tmStdLib.h>#include <tmNxTypes.h>#include <tmDbg.h>#endif//-----------------------------------------------------------------------------// Project include files://-----------------------------------------------------------------------------//#include <tmFat32.h>#include <tmFat32Debug.h>#include <tmFat32Device.h>#include <tmFat32Ram.h>#include <tmFat32Sd.h>#include <tmdlSd.h>//-----------------------------------------------------------------------------// Types and defines://-----------------------------------------------------------------------------#define NUM_SD_CARD     2       // To demonstrate that we can support more than                                // one device of a given tmFat32_DeviceType_t//-----------------------------------------------------------------------------// Global data://-----------------------------------------------------------------------------//static tmFat32_Sd_t             sd_device[NUM_SD_CARD];//-----------------------------------------------------------------------------// Internal Prototypes://-----------------------------------------------------------------------------//static tmErrorCode_t tmFat32_Sd_Init (ptmFat32_Dev_t  p);static tmErrorCode_t tmFat32_Sd_Term (ptmFat32_Dev_t  p);static tmErrorCode_t tmFat32_Sd_Read_Sectors (                ptmFat32_Dev_t  p,      // I: Pointer to tmFat32_Dev_t structure                UInt64          sector, // I: Starting sector number                UInt32          count,  // I: Number of sectors                UInt8 *         buffer  // 0: Pointer to buffer to receive data                );static tmErrorCode_t tmFat32_Sd_Write_Sectors (                ptmFat32_Dev_t  p,      // I: Pointer to tmFat32_Dev_t structure                UInt64          sector, // I: Starting sector number                UInt32          count,  // I: Number of sectors                UInt8 *         buffer  // I: Pointer to buffer containing data                );//-----------------------------------------------------------------------------// Internal Functions//-----------------------------------------------------------------------------////-----------------------------------------------------------------------------// FUNCTION:    tmFat32_Sd_Init//// DESCRIPTION://// RETURN:      tmErrorCode_t: Status of operation (TM_OK = PASS)//// NOTES://-----------------------------------------------------------------------------//static tmErrorCode_ttmFat32_Sd_Init (    ptmFat32_Dev_t  d     // IO: Pointer to tmFat32_Dev_t structure    ){    ptmFat32_Sd_t       p;    ptmdlSdInstanceSetup_t  ptmsdsetup;    tmErrorCode_t       err = TM_OK;    UInt64              maxLba;    UInt32              bytesPerSector;    TMFAT_DEBUG1("+tmFat32_Sd_Init(d=0x%x)\n", d);    TMFAT_ASSERT (d != Null);    p = &sd_device[d->unit];    if (p->init_count > 0)    {        d->type = p->common.type;        d->lbaMax = p->common.lbaMax;        d->bytesPerSector = p->common.bytesPerSector;        d->devInstance = p->common.devInstance;        p->init_count++;        p->connected = True;        TMFAT_DEBUG1("-tmFat32_Sd_Init() returning 0x%x\n", TM_OK);        return TM_OK;    }    // Application opens the removable device (unit 0) but we open the     // internal device        if (0 == d->unit)    {        if( (err = tmdlSdOpenM(&p->sdInstance, d->unit )) != TM_OK )            goto error;        p->common.devInstance = (UInt32) &p->sdInstance;        if( (err = tmdlSdGetInstanceSetup(p->sdInstance, &ptmsdsetup )) != TM_OK )            goto error;        if( (err = tmdlSdInstanceSetup(p->sdInstance, ptmsdsetup )) != TM_OK )            goto error;        if( (err = tmdlSdStart(p->sdInstance)) != TM_OK )            goto error;        if( (err = tmdlSdGetSectorInfo(p->sdInstance, &maxLba, &bytesPerSector)) != TM_OK )            goto error;           p->common.lbaMax = maxLba - 1;        p->common.bytesPerSector = bytesPerSector;        p->connected = True;    }        d->type = p->common.type;    d->lbaMax = p->common.lbaMax;    d->bytesPerSector = p->common.bytesPerSector;    d->devInstance = p->common.devInstance;    p->init_count = 1;error:    TMFAT_DEBUG1("-tmFat32_Sd_Init() returning 0x%x\n", err);    return err;}//-----------------------------------------------------------------------------// FUNCTION:    tmFat32_Sd_Read_Sectors//// DESCRIPTION://// RETURN:      tmErrorCode_t: Status of operation (TM_OK = PASS)//// NOTES://-----------------------------------------------------------------------------//static tmErrorCode_ttmFat32_Sd_Read_Sectors (    ptmFat32_Dev_t  d,    // I: Pointer to tmFat32_Dev_t structure    UInt64            sector,     // I: Starting sector number    UInt32            count,      // I: Number of sectors    UInt8 *           buffer      // 0: Pointer to buffer to receive data    ){    UInt8              *data_ptr = buffer;    UInt32              sec_size;    tmErrorCode_t       errorCode = TM_OK;    tmFat32_Sd_t       *p;    TMFAT_DEBUG2("+tmFat32_Sd_Read_Sectors(sector=%llu,count=%u)\n", sector, count);    TMFAT_ASSERT (d != Null);    p = &sd_device[d->unit];    // The driver is installed but the device is disconnected.    if (p->installed && !p->connected)	{	    TMFAT_DEBUG0("tmFat32_Sd_Read_Sectors trying to read from a disconnected device.\n");	    return TM_FAT32_ERR_READ;	}    // DOS BPB_BytsPerSec may be 512, 1024, 2048, or 4096    if (sector + count > d->lbaMax + 1)        return TM_FAT32_ERR_READ;    sec_size = d->bytesPerSector;    if (d->eventNotify && (d->eventMask & TM_FAT32_EVENT_READ))        d->eventNotify(d->vol, TM_FAT32_EVENT_READ);    errorCode = tmdlSdRead(p->sdInstance, (sector)*sec_size, sec_size * count,                            (UInt8*)(data_ptr));    TMFAT_DEBUG1("-tmFat32_Sd_Read_Sectors() returning 0x%x\n", errorCode);    return errorCode;}//-----------------------------------------------------------------------------// FUNCTION:    tmFat32_Sd_Write_Sectors//// DESCRIPTION://// RETURN:      tmErrorCode_t: Status of operation (TM_OK = PASS)//// NOTES://-----------------------------------------------------------------------------//static tmErrorCode_ttmFat32_Sd_Write_Sectors (    ptmFat32_Dev_t  d,    // I: Pointer to tmFat32_Dev_t structure    UInt64            sector,     // I: Starting sector number    UInt32            count,      // I: Number of sectors    UInt8 *           buffer      // I: Pointer to buffer containing data    ){    tmErrorCode_t       errorCode = TM_OK;    UInt8              *data_ptr = NULL;    UInt32              sec_size;    tmFat32_Sd_t       *p;    TMFAT_DEBUG2("+tmFat32_Sd_Write_Sectors(sector=%llu,count=%u)\n", sector, count);    TMFAT_ASSERT (d != Null);    TMFAT_ASSERT (buffer != Null);    // DOS BPB_BytsPerSec may be 512, 1024, 2048, or 4096    if (sector + count > d->lbaMax + 1)        return TM_FAT32_ERR_WRITE;	p = &sd_device[d->unit];    // If the driver is installed but the device is disconnected we may    // be dismounting the file system. This could potentially issue write    // operations which must be ignored.    if (p->installed && !p->connected)    {        TMFAT_DEBUG2("tmFat32_Sd_Write_Sectors(sector=%llu,count=%d) while not connected.\n",                      sector, count);        return TM_OK;    }    if (d->eventNotify && (d->eventMask & TM_FAT32_EVENT_WRITE))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -