?? usbap.c
字號(hào):
/*************************************************************************/
/* */
/* Copyright (c) 2003, 名人電腦科技有限公司深圳研發(fā)中心 */
/* All rights reserved. */
/* */
/* 文件名稱: USBAP.c */
/* 文件描述: 移動(dòng)硬盤(pán)的應(yīng)用 */
/* */
/* 當(dāng)前版本: 1.0 */
/* 作 者: King */
/* 完成日期: 2003年xx月xx日 */
/* */
/* 函數(shù)列表: */
/* */
/* 更改記錄: */
/* ===================================================================== */
/* 日期 人員 版本 描述 */
/* ===================================================================== */
/* 2003-06-27 King 1.0 創(chuàng)建 */
/* */
/*************************************************************************/
#include "Kernel.h"
#include "mss.h"
#include "hal.h"
//#include "UsbDrv.h"
#define USB_TASK_STACK_SIZE 0x1000 //USB任務(wù)的堆棧大小
#define USB_AUOTEXIT QUIT_USER+1
/* 全局變量定義 */
//static MWindow* g_hUSBWnd;
//MWindow* USBCreateWindow(void);
//UINT32 USBHandleEvent(MWindow* hWnd, MEvent* pEvent);
VOID USB_TASK(UNSIGNED argc, VOID *argv);
extern BOOL PrjDetectUSB(void);
extern BOOL prj_bIsUSB;
extern volatile BOOL UsbConnectCompleted;
extern VOID __UsbCreatePartitionTable(BOOL bFlashOnly);
extern void PrjDestroyVolTimer(void);
STATUS UsbInit(void);
INT FlashUpdate(void);
/*************************************************************************/
/* */
/* 函數(shù)名稱: USBMain */
/* 函數(shù)描述: 移動(dòng)硬盤(pán)的主程序 */
/* */
/* 輸入?yún)?shù): */
/* pEvent - 消息結(jié)構(gòu)指針 */
/* 輸出參數(shù): */
/* NULL */
/* 返回值 : */
/* UINT32 - 函數(shù)返回值 */
/* */
/* ===================================================================== */
/* 日期 人員 版本 描述 */
/* ===================================================================== */
/* 2003-06-29 King 1.0 創(chuàng)建 */
/* */
/*************************************************************************/
extern BOOL g_bUsbStarted;
//UINT32 USBMain(UINT32 hInstance, UINT32 hPrevInst, UINT8* pCmdLine, INT nCmdShow)
INT USBMain(INT Param)
{
UINT32 dwResult;
// g_hUSBWnd = NULL;
dwResult = 0;
g_bUsbStarted=TRUE;
//*************************
// 檢測(cè)USB連線
//*************************
UsbInit();
/*
if (!EstimateCablePluged())
{
HwShowString(1,1,"請(qǐng)先接上USB連線",0x000000ff);
return 0;
}*/
/*************************\
進(jìn)入U(xiǎn)盤(pán)的準(zhǔn)備工作
\*************************/
// prj_bIsUSB = TRUE; // 設(shè)上標(biāo)志,電壓檢測(cè)時(shí)要判斷
// PrjStopOffTimer(); // 停止自動(dòng)關(guān)機(jī)時(shí)間
// 暫時(shí)去掉用于測(cè)試USB, MANN
// PrjDisableAlarm(); // 提供為函數(shù),在格式化的時(shí)候也要用。
// SysWatchEnd(); // close watchdog
/*************************\
創(chuàng)建U盤(pán)窗口
\*************************/
// g_hUSBWnd = USBCreateWindow();
// if (g_hUSBWnd)
/* 創(chuàng)建分區(qū)表 */
__UsbCreatePartitionTable(FALSE);
/* 關(guān)閉SDCard中斷 */
// *((volatile UINT8 *)0x40270) &= ~0x01; // disable interrupt: EP0(D0) = 0
/* 關(guān)閉低電壓檢測(cè) */
// PrjDestroyVolTimer();
/* if (NU_SUCCESS != NU_Create_Task(&Task_USB, "UsbDisk", USB_TASK,
0, NU_NULL, pointer, USB_TASK_STACK_SIZE,
3, 20, NU_PREEMPT, NU_START))
{
goto QUIT;
}
*/
// dwResult = ApRun((MWinView *)g_hUSBWnd);
USB_TASK(0,NULL);
//while (g_uExitMSS == 0)
{
NU_Sleep(1);
}
// prj_bIsUSB = FALSE; // 已經(jīng)退出USB
/*************************\
U盤(pán)退出,系統(tǒng)啟動(dòng)
\*************************/
// MsgBoxRun(NULL, 0, "退出U盤(pán),返回主畫(huà)面。", "USB", MT_ICONINFO);
// PrjEnableAlarm();
// SysWatchHotReset(SYS_INIT_RESTORE);
return dwResult;
}
//#define HwUBIDX (*((volatile unsigned short *)(0x80000538)))
//#define USBMASS_EP_RECV 2 // OUT (PC -> TCC730)
//#define HwOCSR1 (*((volatile unsigned short *)(0x80000550)))
//======================================================================
//======================================================================
// DennyHan Added this for Ap 2006-5-18 15:59
// THis Only be called after MSS_Init();
//----------------------------------------------
extern NU_DRIVER *pndUSB;
static VOID UsbApTerminateConnect(VOID)
{
NU_DRIVER_REQUEST ndrTemp;
if (pndUSB)
{
memset((UINT8*)&ndrTemp,0,sizeof(NU_DRIVER_REQUEST));
ndrTemp.nu_function = NU_STATUS;
ndrTemp.nu_supplemental = USB_IOCTL_DISCONNECT;
ndrTemp.nu_supplemental_ptr = (void*)(UINT32)USB_INIT_MASSSTORAGE;
#ifdef SYS_UPDATE
USBDriver_Func(NULL, &ndrTemp);
uRet = ndrTemp.nu_status;
#else
NU_Request_Driver(pndUSB, &ndrTemp);
#endif
}
}
//======================================================================
//======================================================
//#define UAP_USB_TEST 1
VOID USB_TASK(UNSIGNED argc, VOID *argv)
{
char szBuf[64] = {'U', 'S', 'B', 'C'};
UINT uRet;
DWORD dwStatus;
UINT uEvent[2];
g_uExitMSS = 0; // indicate that the task is terminated.
#ifdef UAP_USB_TEST
GraphDrawText(40,40,0,0,(UINT8*)"EnterTask");
if ( !EstimateCablePluged() )
{
GraphDrawText(40,60,0,0,(UINT8*)"DISConnect");
}
else
{
GraphDrawText(40,80,0,0,(UINT8*)"Connect");
}
#endif
if (0 == MSS_Init())
{
#ifndef _WIN32
// DennyHan added for Cabled pulled out
if ( !EstimateCablePluged() )
{
#ifndef UAP_USB_TEST
// exit
UsbApTerminateConnect();
g_uExitMSS =1;
#else
GraphDrawText(40,80,0,0,(UINT8*)"DISConnect");
}
else
{
GraphDrawText(40,80,0,0,(UINT8*)"Connect");
#endif
}
#endif
while( (! g_uExitMSS)
&& (EstimateCablePluged()) )
{
// if(!UsbCoreCheck())continue;
// uRet=USBMASS_ReceiveData( szBuf, 64 );
// DennyHan added for Messge Pulled
GetOsKnlMsg(&uEvent[0],&uEvent[1]);
uRet= BOL_BulkOut(31, (BYTE *)szBuf);
BOL_BulkCtrl(GETSTATUS, &dwStatus);
if (DEVICE_IDLE != dwStatus)
{
continue;
}
if (uRet)
{
uRet = BOL_OnRecvCmd(uRet, (BYTE *)szBuf);
switch(uRet)
{
case CSW_GOOD:
{
}break;
case CSW_FAIL:
{
// g_uExitMSS = 1;
}break;
case CSW_PHASE_ERROR:
{
}break;
case CSW_WAITFOR_MORE_DATA:
{
}break;
case CSW_NEEDTO_STALL_BULK:
{
BOL_BulkCtrl(STALL, (DWORD *)STALL_BULKALL);
}break;
default:
{
}break;
}
}
}
}
// 檢查到Win98下最后16塊沒(méi)有寫(xiě)入,在這里確保寫(xiě)入
FlashUpdate();
MSS_Stop();
// MsgPost(g_hUSBWnd, EV_QUIT, USB_AUOTEXIT, 0, 0); // 退出對(duì)話框
// MsgPost(g_hUSBWnd, EV_QUIT, USB_AUOTEXIT, 0, 0); // 退出窗口
return;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -