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

📄 tmfat32usb.c

📁 PNX1500上Fat32文件系统源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 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. * *----------------------------------------------------------*//*! * * *      This file implements the USB tmFat32 device driver API. * *//*----------------------------------------------------------- * *      %version:       9 % *      instance:       DS_4 *      %date_created:  Sun Nov 12 15:09:39 2006 % * */ //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------// Standard include files://-----------------------------------------------------------------------------//#include <tmStdLib.h>#include <tmNxTypes.h>#include <tmDbg.h>#include <tmosal.h>//-----------------------------------------------------------------------------// Project include files://-----------------------------------------------------------------------------//#include <tmFat32.h>#include <tmFat32Debug.h>#include <tmFat32Device.h>#include <tmFat32Usb.h>#include <tmUsbIspHost.h>#include <tmml.h>//-----------------------------------------------------------------------------// Types and defines://-----------------------------------------------------------------------------#define TMFAT32_USB_CACHE_ALIGN   64#define TMFAT32_USB_SECTOR_SIZE  512#define SCRATCH_SECTORS          128/*The maximum number of USB devices we support is the maximum number ofports times maximum number of logical units for each port. A port mayhave a multicard reader/writer and each card on is logical unit.*/#define USB_MAX_UNITS (TM_USBISPHOST_MAX_PORTS * TM_USBISPHOST_MAX_LUNS)//-----------------------------------------------------------------------------// Global Variables//-----------------------------------------------------------------------------static tmFat32_Usb_t usb_device[USB_MAX_UNITS];static UInt8         myBuffer[SCRATCH_SECTORS*TMFAT32_USB_SECTOR_SIZE +                              TMFAT32_USB_CACHE_ALIGN];static UInt8         *pScratchPad; // Cache-aligned scratch buffer//-----------------------------------------------------------------------------// Internal Prototypes://-----------------------------------------------------------------------------////-----------------------------------------------------------------------------// External Prototypes://-----------------------------------------------------------------------------////-----------------------------------------------------------------------------// FUNCTION:    tmFat32_Usb_Term//// DESCRIPTION://// RETURN:      tmErrorCode_t: Status of operation (TM_OK = PASS)//// NOTES://-----------------------------------------------------------------------------//static tmErrorCode_ttmFat32_Usb_Term (    ptmFat32_Dev_t  d     // IO: Pointer to tmFat32_Dev_t structure    ){    tmErrorCode_t   status = TM_OK;    tmFat32_Usb_t  *p;    TMFAT_ASSERT (d != Null);    p = &usb_device[d->unit];    p->init_count--;    if (p->init_count == 0)    {        //FIXTHIS: Do something to terminate the USB device?    }    return status;}//-----------------------------------------------------------------------------// FUNCTION:    tmFat32_Usb_Init//// DESCRIPTION://// RETURN:      tmErrorCode_t: Status of operation (TM_OK = PASS)//// NOTES://-----------------------------------------------------------------------------//static tmErrorCode_ttmFat32_Usb_Init (    ptmFat32_Dev_t  d     // IO: Pointer to tmFat32_Dev_t structure    ){    ptmFat32_Usb_t  p;    TMFAT_DEBUG1("tmFat32_Usb_Init(d=0x%X)\n", d);    TMFAT_ASSERT (d != Null);    p = &usb_device[d->unit];    p->init_count++;	return TM_OK;}//-----------------------------------------------------------------------------// FUNCTION:    tmFat32_Usb_Read_Sectors//// DESCRIPTION://// RETURN:      tmErrorCode_t: Status of operation (TM_OK = PASS)//// NOTES://-----------------------------------------------------------------------------//static tmErrorCode_ttmFat32_Usb_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    ){	ptmFat32_Usb_t         r;	UInt32                 nsec;	UInt8                  *pBuf;    tmUsbIspHost_Command_t cmd;    tmErrorCode_t          status;    TMFAT_ASSERT (d != Null);	r = &usb_device[d->unit];    // The driver is installed but the device is disconnected.    if (r->installed && !r->connected)	{	    TMFAT_DEBUG0("tmFat32_Usb_Read_Sectors trying to read from a disconnected device.\n");	    return TM_FAT32_ERR_READ;	}    if (sector + count > d->lbaMax + 1)        return TM_FAT32_ERR_READ;    if (d->eventNotify && (d->eventMask & TM_FAT32_EVENT_READ))        d->eventNotify(d->vol, TM_FAT32_EVENT_READ);    cmd.op = tmUsbIspHost_CmdMsReadSectors;    cmd.control[0] = r->uAppHandle;    cmd.control[1] = r->LogUnitNo;    cmd.control[4] = d->bytesPerSector;    // We may not be cache-line aligned.    if (r->manageCache && ((UInt32) buffer % TMFAT32_USB_CACHE_ALIGN))    {        pBuf = pScratchPad;//        TMFAT_DEBUG2("tmFat32_Usb_Read_Sectors: sector=%llu,count=%d buffer is not aligned on a cache-line\n",//                      sector, count);        while (count > 0)        {            nsec = count;            if (nsec > SCRATCH_SECTORS)                nsec = SCRATCH_SECTORS;        	tmmlCacheFlush((void *)(pBuf), nsec * (d->bytesPerSector));        	tmmlCacheInvalidate((void *)(pBuf), nsec * (d->bytesPerSector));            cmd.control[2] = (UInt32) sector;            cmd.control[3] = nsec;            cmd.control[5] = (UInt32) pBuf;            status = tmUsbIspHost_Command(&cmd);        	if (status != 0)        	{        	    TMFAT_DEBUG1("tmFat32_Usb_Read_Sectors failed: 0x%X\n", status);        	    return TM_FAT32_ERR_READ;        	}            memcpy(buffer, pBuf, nsec * d->bytesPerSector);            sector += nsec;            buffer += nsec * d->bytesPerSector;            count -= nsec;        }    }    else    {        if (r->manageCache)        {        	tmmlCacheFlush((void *)(buffer), count * (d->bytesPerSector));        	tmmlCacheInvalidate((void *)(buffer), count * (d->bytesPerSector));    	}        cmd.control[2] = (UInt32) sector;        cmd.control[3] = count;        cmd.control[5] = (UInt32) buffer;        status = tmUsbIspHost_Command(&cmd);    	if (status != 0)    	{    	    TMFAT_DEBUG1("tmFat32_Usb_Read_Sectors failed: 0x%X\n", status);    	    return TM_FAT32_ERR_READ;    	}    }	return TM_OK;}//-----------------------------------------------------------------------------// FUNCTION:    tmFat32_Usb_Write_Sectors//// DESCRIPTION://// RETURN:      tmErrorCode_t: Status of operation (TM_OK = PASS)//// NOTES://-----------------------------------------------------------------------------//static tmErrorCode_ttmFat32_Usb_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    ){    tmUsbIspHost_Command_t cmd;    tmErrorCode_t          status;	ptmFat32_Usb_t         r;	UInt32                 nsec;	UInt8                 *pBuf;

⌨️ 快捷键说明

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