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

📄 rbc.c

📁 该软件为在sunplus的61单片机上实现的mp3播放器.里面有完整的源代码.
💻 C
📖 第 1 页 / 共 2 页
字号:
/*C**************************************************************************
* 文件名:       filename.c
*----------------------------------------------------------------------------
* 版权:        (c) 2004 TGE.
*----------------------------------------------------------------------------
* 释放:         Spce061A      
* 版本:         1.0     
*----------------------------------------------------------------------------
* 目的:
* This is the demonstration software for SPCE061A
*****************************************************************************/

/*_____    包括     ________________________________________________________*/
#include "rbccmd.h"
#include "TpBulk.h"
#include "rbc.h"
#include "..\\NandFlash\\NFapp.h"
#include "..\\NandFlash\\NFdrv.h"
/*_____    宏       ________________________________________________________*/

/*_____    定义     ________________________________________________________*/
const unsigned long int NF_SECTOR_TOTAL_NUM= 0xffff;
/*_____    声明     ________________________________________________________*/
extern CBW 		TPBulk_CBW;					//define CBW Struct
#define		CBW_wXferLen			TPBulk_CBW.dCBW_DataXferLen[0] + TPBulk_CBW.dCBW_DataXferLen[1]*0x100 + TPBulk_CBW.dCBW_DataXferLen[2]*0x10000 + TPBulk_CBW.dCBW_DataXferLen[3]*0x1000000
#define	    RBC_CDB					TPBulk_CBW.cdbRBC
#define     RBC_LUN					TPBulk_CBW.bCBW_LUN

extern CSW  	TPBulk_CSW;					//define CSW struct
#define     CSW_wResidue			TPBulk_CSW.dCSW_DataResidue[0] + TPBulk_CSW.dCSW_DataResidue[1]*0x100 + TPBulk_CSW.dCSW_DataResidue[2]*0x10000 +TPBulk_CSW.dCSW_DataResidue[3]*0x1000000

extern unsigned long int  LBA_Write;
extern unsigned long int g_RWaddress;   //global read/write address
extern unsigned int  g_RWBuf[512];
extern unsigned int *BOTXfer_pData;		//global variable 
extern unsigned int  BOTXfer_wResidue;
extern unsigned long int  LBA_Write;
// New Add Global Value
extern unsigned long int  Start_LBA;
extern unsigned long int  End_LBA;
extern unsigned long int  Current_LBA;
extern unsigned int 	  SectorCount;

extern BIT_STATUS bFlags;
extern unsigned int  BOTFSMstate;
/*
#define     BOTFSM_CBWProc 			Mstate.bits.CBWProc
#define     BOTFSM_DataIn			Mstate.bits.DataIn
#define     BOTFSM_DataOut			Mstate.bits.DataOut
#define     BOTFSM_CSWProc			Mstate.bits.CSWProc
#define     BOTFSM_CSW				Mstate.bits.CSW
#define     BOTFSM_IDLE				Mstate.bits.IDLE	
#define     BOTFSM_Stall			Mstate.bits.Stall
#define     BOTXfer_atROMorRAM		Mstate.bits.atROMorRAM
#define     BOTXfer_atNF			Mstate.bits.atNF
*/
/*
//*************************************************************************
//  Private Data
//*************************************************************************
*/
const REQUEST_SENSE_DATA   Req_SenseData=
{
     0x70, 	// unsigned int ResponseCode : 7;
	 0,     // unsigned int Valid : 1;

	 0,		// unsigned int SegmentNum;

	 0x5,	// unsigned int SenseKey : 4; 5= illegal request
	 0,  	// unsigned int Reserved0 : 1;
	 0,		// unsigned int WrongLenIndicator : 1;
	 0,		// unsigned int EndofMedium : 1;
	 0,		// unsigned int FileMark : 1;

	 0,		// unsigned int Info_0;
	 0,		// unsigned int Info_1;
	 0,		// unsigned int Info_2;
	 0,		// unsigned int Info_3;

	0xA,	// unsigned int AdditionalSenseLen;

	0,		// unsigned int CommandSpecInfo_0;
	0,		// unsigned int CommandSpecInfo_1;
	0,		// unsigned int CommandSpecInfo_2;
	0,		// unsigned int CommandSpecInfo_3;

	0x29,	// unsigned int ASC;
	0,		// unsigned int ASCQ;
	0,		// unsigned int FieldReplacableUnitCode;
	0,		// unsigned int SenseKeySpec_0 : 7;
	0,		// unsigned int SenseKeySpecValid : 1;
	0,		// unsigned int SenseKeySpec_1;
	0 		// unsigned int SenseKeySpec_2;

	};

RBC_PROPERTY                    RBC_PropertyData;



#define PARAMETER_LIST_LENGTH   (sizeof(MODE_PARAMETER_HEAD)+sizeof(MODE_PARAMETER_HEAD))


const MODE_PARAMETER_HEAD ParaHeadMask =
{
	PARAMETER_LIST_LENGTH-1,    /* mode data length*/
	0,                          /* medium type*/
	0,                          /* device spec Param*/
	0                           /* block Descriptor length*/
};

const MODE_RBC_DEVICE_PARAMETERS_PAGE ParaPageMask =
{
	MODE_PAGE_RBC_DEVICE_PARAMETERS,
	0,      /*Reserved*/
	0,      /*PageSavable*/

	0x00,   /*PageLength*/

	0,      /*WriteCacheDisable*/
	00,     /*Reserved*/

	{
		/*Logical block Size = 512 Bytes*/
		0x00,
		0x00
	},

	{
		/*Number of logical blocks*/
		0x00,
		0x00,
		0x00,
		0x00,
		0x00
	},

	0x00,   /*Power/Peformance*/

	0,      /*LockDisable*/
	0,      /*FormatDisable*/
	0,      /*WriteDisable*/
	0,      /*ReadDisable*/
	0x0,    /*Reserved*/

	0x00    /*Reserved*/
};

const MODE_PARAMETER_HEAD DefaultParaHead =
{
	PARAMETER_LIST_LENGTH-1,    /* mode data length*/
	0,                          /* medium type*/
	0,                          /* device spec Param*/
	0                           /* block Descriptor length*/
};

const MODE_RBC_DEVICE_PARAMETERS_PAGE DefaultParaPage =
{
	MODE_PAGE_RBC_DEVICE_PARAMETERS,
	0,      /*Reserved*/
	1,      /*PageSavable*/

	0x0B,   /*PageLength*/

	0,      /*WriteCacheDisable*/
	00,     /*Reserved*/

	{
		/*Logical block Size = 512 Bytes*/
		0x02,
		0x00
	},

	{
		/*Number of logical blocks*/
		0x00,
		0x00,
        0x00,
		0x00,
        0x00
    },

    0xFF,   /*Power/Peformance*/

    0,      /*LockDisable*/
    0,      /*FormatDisable*/
    0,      /*WriteDisable*/
    0,      /*ReadDisable*/
    0x0,    /*Reserved*/

	0x00    /*Reserved*/
};

const VPD_SERIAL_PAGE SerialPage =
{
	RBC_DEVICE,
	0x00,

    VPDPAGE_SERIAL_NUMBER,

    0x00,

    24,     //size of SerialNumber

    {
		// SerialNumber
    	'0',0,
	    '0',0,
	    '0',0,
	    '0',0,

    	'0',0,
	    '0',0,
	    '0',0,
	    '0',0,

    	'0',0,
    	'0',0,
	    '0',0,
	    '0',0
    }
};

const VPD_DEVICE_ID_PAGE DeviceIDPage =
{
	RBC_DEVICE,
    0x00,

    VPDPAGE_DEVICE_IDENTITY,

    0x00,

    sizeof(ASCII_ID_DESCRIPTOR),
    {
        0x02,
        0x00,

        0x01,
        0x00,
		0x00,

        0x00,

        sizeof(ASCII_ID_STRING),

		{
			// ASCII_ID_STRING
			'P','h','i','l',
            'i','p','s',' ',
            'S','u','p','e',
			'r',' ','D','i',
            's','k',' '
        }
    }
};

const inquiryData1[]=
{
	0x00, 0x80, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x47, 0x45, 0x4e, 0x45, 0x52, 0x49, 0x43, 0x20,
	0x55, 0x53, 0x42, 0x20, 0x4d, 0x61, 0x73, 0x73, 0x20, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65,
	0x31, 0x2e, 0x30, 0x30 
}; // */
const STD_INQUIRYDATA inquiryData =
{
	0x00,	//-- 0
	0x00,//0x80,	//-- 1
	0x02,	//-- 2
	0x02,	//-- 3
	0x1f,	//-- 4
	0x00,	//-- 5
	0x00,	//-- 6

    0,		// unsigned int SoftReset : 1;
    0,		// unsigned int CommandQueue : 1;
	0,		// unsigned int Reserved5 : 1;
	0,		// unsigned int LinkedCommands : 1;
	0,		// unsigned int Synchronous : 1;
	0,		// unsigned int Wide16Bit : 1;
	0,		// unsigned int Wide32Bit : 1;
	0,		// unsigned int RelativeAddressing : 1;

    //unsigned int VendorId[8];
    {
        'P','H','I','L',
        'I','P','S',' '
    },

	//unsigned int ProductId[16];
    {
        'U','S','B','-',
    	'I','D','E',' ',
    	'A','d','a','p',
    	't','e','r',' '
    },

	//unsigned int ProductRevisionLevel[4];
    {
        '0','.','0','0'
    },


//  Above is 36 bytes
//  can be tranmitted by Bulk



    //unsigned int VendorSpecific[20]; out[64 bytes] within one packet only.
    {
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0
    },


    0,		// unsigned int InfoUnitSupport : 1;
    0,		// unsigned int QuickArbitSupport : 1;
    0,		// unsigned int Clocking : 2;
    0,		// unsigned int Reserved1 : 4;
    0,		// unsigned int  Reserved2 ;

    //USHORT VersionDescriptor[8] ;
    {
        0, 0, 0, 0,
        0, 0, 0, 0
    },


    //unsigned int Reserved3[22];
    {
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0
    }

};


/*
//*************************************************************************
//  Subroutines
//*************************************************************************
*/

unsigned int RBC_Handler( void )
{

#define cdbGeneric TPBulk_CBW.cdbRBC.Cdb_Generic
    unsigned int retStatus = FALSE;
	BOTXfer_wResidue = 0;
	switch(cdbGeneric.OperationCode)
	{
		/* required command */
		case RBC_CMD_READ10:
			retStatus = RBC_Read();
			break;
		case RBC_CMD_READCAPACITY:
			retStatus = RBC_ReadCapacity();
			break;
		case RBC_CMD_STARTSTOPUNIT:
			retStatus = RBC_OnOffUnit();
			break;
        case RBC_CMD_SYNCCACHE:
            retStatus = RBC_SyncCache();
			break;
        case RBC_CMD_VERIFY10:
            retStatus = RBC_Verify();
            break;
        case RBC_CMD_WRITE10:
            retStatus = RBC_Write();
            break;
        case SPC_CMD_INQUIRY:
            retStatus = SPC_Inquiry();
            break;
        case SPC_CMD_MODESELECT6://0x15
            retStatus = SPC_ModeSelect();
            break;
        case SPC_CMD_MODESENSE6:
            retStatus = SPC_ModeSense();//0x1A
            break;
		case SPC_CMD_PRVENTALLOWMEDIUMREMOVAL:
			retStatus = SPC_LockMedia();
            break;
        case 0x00:	//SPC_CMD_TESTUNITREADY: //0x00
            retStatus = SPC_TestUnit();
            break;
        case SPC_CMD_REQUESTSENSE: //0x03
            retStatus = SPC_RequestSense();
            break;
		/* optional commands */
		case RBC_CMD_FORMAT:
			retStatus = RBC_Format();
			break;
		case SPC_CMD_RESERVE6:
			retStatus = SPC_Reserve6();
			break;
		case SPC_CMD_RELEASE6:
			retStatus = SPC_Release6();
			break;
		case SPC_CMD_PERSISTANTRESERVIN:
			retStatus = SPC_PersisReserveIn();
			break;
		case SPC_CMD_PERSISTANTRESERVOUT:
			retStatus = SPC_PersisReserveOut();
			break;
		case SPC_CMD_WRITEBUFFER:
			retStatus = SPC_WriteBuff();
			break;
		case SPC_CMD_READLONG:
			retStatus = SPC_READLONG();//0x23
			break;
		default:
			// Invalid CBW
			TPBulksup_ErrorHandler(CASECBW,0);
			TPBulk_CSWHandler();// Goto USBFSM4BOT_CSWPROC;
			break;
	}

	return retStatus;
#undef cdbGeneric
}

/*
////////////////////////////////////////////////////////////////////////////////////
// Reduced Block Command Support
////////////////////////////////////////////////////////////////////////////////////
*/

unsigned int SPC_READLONG(void)
{
	BOTXfer_wResidue = CBW_wXferLen;		
	TPBulksup_ErrorHandler(CASECMDFAIL,BOTXfer_wResidue);
	TPBulk_CSWHandler();	// Goto USBFSM4BOT_CSWPROC;
}

unsigned int RBC_Read(void)
{
#define cdbRead RBC_CDB.RbcCdb_Read

	g_RWaddress= cdbRead.LBA_0 +
				 cdbRead.LBA_1*0x100 +
				 cdbRead.LBA_2*0x10000 +
				 cdbRead.LBA_3*0x1000000;

#if 1
    BOTXfer_wResidue = CBW_wXferLen;  
	TPBulksup_ErrorHandler(CASE6,BOTXfer_wResidue);
	BOTXfer_wResidue =0x00;
	SectorCount =cdbRead.XferLength_0 + cdbRead.XferLength_1 * 0x100;
    DMA_NFtoD12(g_RWaddress , SectorCount);		
	TPBulk_CSWHandler();	// Goto USBFSM4BOT_CSWPROC;		
#else				 
    BOTXfer_wResidue = CBW_wXferLen;   
	TPBulksup_ErrorHandler(CASE6,BOTXfer_wResidue);
	NF_PageRead(0x0000,g_RWaddress, g_RWBuf);
	BOTXfer_pData = g_RWBuf;	
		
//	BOTXfer_atNF =TRUE;	
	BOTFSMstate=USBFSM4BOT_DATAIN;
	return (TRUE);
#endif	
#undef cdbRead
}

unsigned int RBC_Write(void)
{

⌨️ 快捷键说明

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