Preview only show first 10 pages with watermark. For full document please download

Usb Device Library User Manual

   EMBED


Share

Transcript

USB Device Library User Manual V1.0 –September 22, 2006 2/F.,R2-B Building,Hi-Tech S.7 th Road ,High - Tech Industrial Park ,Shenzhen,P.R.China % +86-755-26737048 ¨ +86-755-26984688 + www.Generalplus.com PRELIMINARY USB Device Library User’s Manual Table of Content PAGE USB DEVICE LIBRARY USER MANUAL .......................................................................................................................... 1 1 FUNCTION LIST .................................................................................................................................................. 4 2 USB DEVICE INTERFACE ................................................................................................................................. 5 2.1 USB_Reset....................................................................................................................................................................... 5 2.2 USB_ServiceLoop........................................................................................................................................................... 5 2.3 USB_Insert_TimeOut..................................................................................................................................................... 5 2.4 Check_SDC_Present ...................................................................................................................................................... 6 2.5 Request_GetPassWord................................................................................................................................................... 6 2.6 Responsion_PassWord ................................................................................................................................................... 6 2.7 USB_TimeOut_Enable................................................................................................................................................... 7 2.8 USB_TimeOut_Disable .................................................................................................................................................. 7 3 USB DEVICE DEMO............................................................................................................................................ 8 © Generalplus Technology Co., Ltd. PAGE 2 USB Device Library User Manual V1.0 - Sep 22, 2006 PRELIMINARY USB Device Library User’s Manual Revision History Revision Date V1.0 2006/09/22 By pengtj © Generalplus Technology Co., Ltd. Remark first revision for GPL162002 PAGE 3 USB Device Library User Manual V1.0 - Sep 22, 2006 PRELIMINARY USB Device Library User’s Manual 1 Function List name Index 1 USB_Reset 2 USB_ServiceLoop 3 USB_Insert_TimeOut 4 Check_SDC_Present 5 Request_GetPassWord 6 Responsion_PassWord 7 USB_TimeOut_Enable 8 USB_TimeOut_Disable © Generalplus Technology Co., Ltd. PAGE 4 USB Device Library User Manual V1.0 - Sep 22, 2006 2 USB Device Interface 2.1 USB_Reset API Name USB_Reset Function Initial for USB Description Header File C USBD_MSDC.h ASM C Syntax void USB_Reset (void) ASM Parameters N/A Return Values N/A Remarks N/A 2.2 USB_ServiceLoop API Name USB_ServiceLoop Function USB Transmit Process Description Header File C USBD_MSDC.h ASM C Syntax unsigned int USB_ServiceLoo (void) ASM Parameters N/A Return Values 0: USB mass storage Pull out ; -1 :Time out Remarks N/A 2.3 USB_Insert_TimeOut API Name USB_Insert_TimeOut Function If the USB Device Process is Running , but the connection to PC is not ready, the MCU will call this function and exit USB Device Process. Description Header File C USBD_MSDC.h ASM C Syntax void USB_Insert_TimeOut (void) ASM Parameters N/A Return Values N/A 2/F.,R2-B Building,Hi-Tech S.7 th Road ,High - Tech Industrial Park ,Shenzhen,P.R.China % +86-755-26737048 ¨ +86-755-26984688 + www.Generalplus.com PRELIMINARY USB Device Library User’s Manual 2.4 Check_SDC_Present API Name Check_SDC_Present Function Check SD Card is ready or not Description Header File C USBD_MSDC.h ASM C Syntax void Check_SDC_Present (void) ASM Parameters N/A Return Values N/A 2.5 Request_GetPassWord API Name Request_GetPassWord Function Get the operation authentication for special function. Description Header File C USBD_MSDC.h ASM C Syntax int* Request_GetPassWord(void) ASM Parameters N/A Return Values N/A 2.6 Responsion_PassWord API Name Responsion_PassWord Function check the operation authentication for special function. Description Header File C USBD_MSDC.h ASM C Syntax int Responsion_PassWord(int *p) ASM Parameters N/A Return Values N/A © Generalplus Technology Co., Ltd. PAGE 6 USB Device Library User Manual V1.0 - Sep 22, 2006 PRELIMINARY USB Device Library User’s Manual 2.7 USB_TimeOut_Enable API Name USB_TimeOut_Enable Function Set USB_Insert_TimeOut interrupt source Description Header File C USBD_MSDC.h ASM C Syntax Void USB_TimeOut_Enable (void) ASM Parameters N/A Return Values N/A 2.8 USB_TimeOut_Disable API Name USB_TimeOut_Disable Function Turn off USB_Insert_TimeOut interrupt source Description Header File C USBD_MSDC.h ASM C Syntax Void USB_TimeOut_Disable (void) ASM Parameters N/A Return Values N/A © Generalplus Technology Co., Ltd. PAGE 7 USB Device Library User Manual V1.0 - Sep 22, 2006 PRELIMINARY USB Device Library User’s Manual 3 USB Device DEMO extern void USB_Reset(void); extern unsigned int USB_ServiceLoop(void); void USB_TimeOut_Disable(void); void USB_TimeOut_Enable(void); const unsigned long Nand_Part0_Offset = 0x0000; const unsigned long Nand_Part0_Size = 0x14000; //0x14000; const unsigned short Nand_Part0_Mode = DEVICE_READ_ALLOW|DEVICE_WRITE_ALLOW; const unsigned long Nand_Part1_Offset = 0x15000; //0x15000; const unsigned long Nand_Part1_Size = 0x15000; const unsigned short Nand_Part1_Mode = DEVICE_READ_ALLOW|DEVICE_WRITE_ALLOW; const unsigned long Nand_Part2_Offset = 0x3B000; // 0x1E500; const unsigned long Nand_Part2_Size = 0x0; const unsigned short Nand_Part2_Mode = DEVICE_READ_ALLOW|DEVICE_WRITE_ALLOW; const unsigned long Nand_Reserve_Offset = 0; extern unsigned int R_Write_protect; extern unsigned int CurDrv; char cAddr_PassWord[16]; unsigned int R_USB_DisplayTime; int USBTask(void) { int ret; int i; fs_init(); #ifdef OS_vension DrvSDCCreatSem(); USB_RW_Buffer= (unsigned long )ucBSMalloc(512); //256 //by zhangxh for two Buffer 2006/01/23 SysDisableWaitMode(INT_USB); © Generalplus Technology Co., Ltd. PAGE 8 USB Device Library User Manual V1.0 - Sep 22, 2006 PRELIMINARY USB Device Library User’s Manual SysIntoHighSpeed(); #endif // CurDrv = 1; //设置 nand Flash 部分对应到 U 盘 CurDrvA = 1; //设置 nand Flash part1 对应到 U 盘 A CurDrvB = 2; //设置 nand Flash part1 对应到 U 盘 B for(;;) { R_NANDA_Present=0; R_NANDB_Present=0; R_SDC_Present=0; USB_DiskTotalNum = 1; USB_DiskNandNum = 1; //Nand 的 U 盘数,可以设置 1,2 i = 0; if (i) { _Nand_Initial(); for(i=0;i<4096;i++) { ret = _Nand_ErasePhysicalBlock(i); if(ret&0x01) { SetBadBlock(i); } } } ret = _Nand_Initial(); ret = InitMapTable(); if(ret!=0) { _Nand_Reset(); _Nand_Initial(); ret = BuildMapTable(); } © Generalplus Technology Co., Ltd. PAGE 9 USB Device Library User Manual V1.0 - Sep 22, 2006 PRELIMINARY USB Device Library User’s Manual if(ret==0) { R_NANDA_Present=1; R_NANDB_Present=1; } //设置 U 盘 A,B 的 size,如果 nandflash 只显示一个盘则 B 不用设置 if (CurDrvA == 1) NandTotalSectorA= Nand_Part0_Size;// FileSysDrv[CurDrv].Drv_GetMemSize(); if (CurDrvA == 2) NandTotalSectorA= Nand_Part1_Size;// FileSysDrv[CurDrv].Drv_GetMemSize(); if (CurDrvA == 3) NandTotalSectorA= Nand_Part2_Size;// FileSysDrv[CurDrv].Drv_GetMemSize(); USB_DiskTotalNum = 0; if (USB_DiskNandNum==2) { if (CurDrvB == 1&&CurDrvA!=1) NandTotalSectorB= Nand_Part0_Size;// FileSysDrv[CurDrv].Drv_GetMemSize(); if (CurDrvB == 2&&CurDrvA!=2) NandTotalSectorB= Nand_Part1_Size;// FileSysDrv[CurDrv].Drv_GetMemSize(); if (CurDrvB == 3&&CurDrvA!=3) NandTotalSectorB= Nand_Part2_Size;// FileSysDrv[CurDrv].Drv_GetMemSize(); USB_DiskTotalNum = 1; } //NandTotalSector = _NAND_GetSize(); for(i=0 ; i<5 ; i++) { ret = DrvSDCInitial(); if(ret==0) { R_SDC_Present=1; // SD Card Initial Success USB_DiskTotalNum++; break; } © Generalplus Technology Co., Ltd. PAGE 10 USB Device Library User Manual V1.0 - Sep 22, 2006 PRELIMINARY USB Device Library User’s Manual } // *P_TimerA_Preload=0x10000-(4096*10); // *P_TimerA_Ctrl=0xe064; USB_TimeOut_Enable();//设置当 USB 线与 PC 没连接好时,退出的中断源。用可以更改 R_USB_NandWriterData = 0x00; USB_Reset(); //初始化 USB ret=USB_ServiceLoop(); //进入 USB 程序 USB_TimeOut_Disable();//关闭当 USB 线与 PC 没连接好时退出的中断源。 *P_USBD_Config=0x00; *P_USBD_INTEN=0x00; } while(1); return 0; } //检查 SD 卡是否已经被强制拔出。用户可以修改,下面程序时 demo 用 void Check_SDC_Present(void) { int ret; if(0) { ret = *((volatile unsigned int*)(0x7060)); ret &= 0x0001; //ret 表示这一次循环,SD 卡状态 1:insert, 0:pull out //R_SDC_Present 表示上一循环 SD 卡状态 if (R_SDC_Present == 0 && ret ==1)//insert { ret = DrvSDCInitial(); if(ret == 0) { © Generalplus Technology Co., Ltd. PAGE 11 USB Device Library User Manual V1.0 - Sep 22, 2006 PRELIMINARY USB Device Library User’s Manual R_SDC_Present = 1; R_Media_Change = 1; R_Write_protect = 0x80; } } else if (R_SDC_Present == 1 && ret ==0)//pull out { R_SDC_Present = 0; R_Media_Change = 0; } } // User have to implement this API. // If SDC is inserted, please initialize the SDC and set R_SDC_Present to 1. // If SDC is removed, please clear R_SDC_Present to 0. } void USB_TimeOut_Enable(void) { *P_TimerA_Preload=0x10000-(4096*10); *P_TimerA_Ctrl=0xe064; } void USB_TimeOut_Disable(void) { *P_TimerA_Ctrl=0x8000; } //当 USB 线与 PC 没连接好时,退出的中断源的处理函数。 void USB_Insert_TimeOut(void) { int temp; temp=*P_TimerA_Ctrl; *P_TimerA_Ctrl=temp; //clear timerA int flag R_USB_Suspend=1; } © Generalplus Technology Co., Ltd. PAGE 12 USB Device Library User Manual V1.0 - Sep 22, 2006 PRELIMINARY USB Device Library User’s Manual //以下两函数为特殊功能函数,写特定地址时校验用,一般按下面写就可以了,需要时 请联系凌嘉科技 int* Request_GetPassWord(void) { //int Addr[16]; int i; for(i= 0x00;i<16;i++) { cAddr_PassWord[i] = 1; } return (int*)cAddr_PassWord; } int Responsion_PassWord(int *p) { int i; for (i=0x0;i<16;i++) { if (*(p+i)!=0x0001) return 0; } return 1; } © Generalplus Technology Co., Ltd. PAGE 13 USB Device Library User Manual V1.0 - Sep 22, 2006