好文档 - 专业文书写作范文服务资料分享网站

利用windriver 开发了个usb的驱动,写个开发心得

天下 分享 时间: 加入收藏 我要投稿 点赞

利用windriver 开发了个usb的驱动,写个开发心得

项目组需要利用2440采集数字电视的采样数据,所以让我开发一个usb的数据采集系统,就两个要求 1 速度要达到500kbyte/s以上 2 稳定

由于之前没有做过windows驱动的经验,所以花了3,4天时间读了读ddk的文档,期间还上chinapub找个本书,读了免费的第1章,按照他配置了vc的 编译环境,呵呵。

然后就吧ddk下面的bulkusb源代码进行了修改,写好usb device的驱动,有些了个应用程序,测试一下,采集数据是ok了,但是发现有时候蓝屏,特别是采集100m左右,就会出现蓝品!这下没办法了,由于我本身就对windows内核编程不熟悉,有调试了大概3,4天确认问题可能处在电源管理方面,联系到自己对这方面不是很熟悉,而且时间紧迫,没办法转向windriver开发 !我安装的是9.21版本(请到迅雷下载)。

1. 驱动的开发:

a 这步开发比较简单,首先确认你的device固件正确能枚举成功,然后将device连接到pc usb host 端。

b 按照向导指引刷出你的设备进行配置,然后点击编译按钮生成代码。这部分内容请参考安装文档的快速开发向导! 2.应用程序开发:

最主要的几个函数是,opendevice 和readwrite 函数:其实大家只要摘录向导生成代码的内容即可,这里贴一个我的

static WDU_DRIVER_HANDLE hDriver = 0;

static DRIVER_CONTEXT DrvCtx ;

static BOOL DLLCALLCONV DeviceAttach(WDU_DEVICE_HANDLE hDevice,

WDU_DEVICE *pDeviceInfo, PVOID pUserData) {

DRIVER_CONTEXT *pDrvCtx = (DRIVER_CONTEXT *)pUserData; DEVICE_CONTEXT *pDevCtx, **ppDevCtx;

DWORD dwInterfaceNum = pDeviceInfo->pActiveInterface[0]->pActiveAltSetting->Descriptor.bInterfaceNumber;

DWORD dwAlternateSetting = pDeviceInfo->pActiveInterface[0]->pActiveAltSetting->Descriptor.bAlternateSetting;

TRACE(\received and accepted attach for vendor id 0x%x, \ \id 0x%x, interface %ld, device handle 0x%p\\n\

pDeviceInfo->Descriptor.idVendor, pDeviceInfo->Descriptor.idProduct, dwInterfaceNum, hDevice);

/* Add our device to the device list */

pDevCtx = (DEVICE_CONTEXT *)malloc(sizeof(DEVICE_CONTEXT)); if (!pDevCtx) {

ERR(\failed allocating memory\\n\ return FALSE; }

BZERO(*pDevCtx);

pDevCtx->hDevice = hDevice;

pDevCtx->dwInterfaceNum = dwInterfaceNum;

pDevCtx->dwVendorId = pDeviceInfo->Descriptor.idVendor; pDevCtx->dwProductId = pDeviceInfo->Descriptor.idProduct; pDevCtx->dwAlternateSetting = dwAlternateSetting;

OsMutexLock(pDrvCtx->hMutex);

for (ppDevCtx = &pDrvCtx->deviceContextList; *ppDevCtx; ppDevCtx = &((*ppDevCtx)->pNext)); *ppDevCtx = pDevCtx; pDrvCtx->dwDeviceCount++; OsMutexUnlock(pDrvCtx->hMutex);

OsEventSignal(pDrvCtx->hEvent); /* Accept control over this device */ return TRUE; }

static VOID DLLCALLCONV DeviceDetach(WDU_DEVICE_HANDLE hDevice, PVOID pUserData) {

DRIVER_CONTEXT *pDrvCtx = (DRIVER_CONTEXT *)pUserData; DEVICE_CONTEXT **pCur; DEVICE_CONTEXT *pTmpDev; BOOL bDetachActiveDev = FALSE;

TRACE(\received detach for device handle 0x%p\\n\hDevice);

OsMutexLock(pDrvCtx->hMutex);

for (pCur = &pDrvCtx->deviceContextList; *pCur && (*pCur)->hDevice != hDevice; pCur = &((*pCur)->pNext));

if (*pCur == pDrvCtx->pActiveDev) {

bDetachActiveDev = TRUE;

pDrvCtx->pActiveDev = NULL; }

pTmpDev = *pCur; *pCur = pTmpDev->pNext; free(pTmpDev);

pDrvCtx->dwDeviceCount--; OsMutexUnlock(pDrvCtx->hMutex);

if (bDetachActiveDev) {

/* When hDeviceUnusedEvent is not signaled, hDevice is possibly in use, * and therefore the detach callback needs to wait on it until it is * certain that it cannot be used.

* When it is signaled - hDevice is no longer used. */ OsEventWait(pDrvCtx->hDeviceUnusedEvent, INFINITE); } }

DWORD DriverInit(WDU_MATCH_TABLE *pMatchTables, DWORD dwNumMatchTables, const PCHAR sDriverName, const PCHAR sLicense, DRIVER_CONTEXT *pDrvCtx) {

DWORD dwError;

WDU_EVENT_TABLE eventTable;

/* Set Driver Name */

if (!WD_DriverName(sDriverName)) {

ERR(\Could not set driver name to %s, exiting\\n\ sDriverName);

return WD_SYSTEM_INTERNAL_ERROR; }

dwError = OsEventCreate(&pDrvCtx->hEvent); if (dwError) {

ERR(\OsEventCreate() failed on event 0x%p: error 0x%lx \ \pDrvCtx->hEvent, dwError, Stat2Str(dwError)); return dwError; }

dwError = OsMutexCreate(&pDrvCtx->hMutex); if (dwError) {

ERR(\OsMutexCreate() failed on mutex 0x%p: error 0x%lx \ \pDrvCtx->hMutex, dwError, Stat2Str(dwError)); return dwError; }

dwError = OsEventCreate(&pDrvCtx->hDeviceUnusedEvent); if (dwError) {

ERR(\OsEventCreate() failed on event 0x%p: error 0x%lx \ \pDrvCtx->hDeviceUnusedEvent, dwError, Stat2Str(dwError)); return dwError; }

利用windriver 开发了个usb的驱动,写个开发心得

利用windriver开发了个usb的驱动,写个开发心得项目组需要利用2440采集数字电视的采样数据,所以让我开发一个usb的数据采集系统,就两个要求1速度要达到500kbyte/s以上2稳定由于之前没有做过windows驱动的经验,所以花了3,4天时间读了读ddk的文档,期间还上chinapub找个本书,读了免费的第1章,按照他配置了vc的编译
推荐度:
点击下载文档文档为doc格式
0wnac3d4pq7px008u2il
领取福利

微信扫码领取福利

微信扫码分享