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

📄 bulkloop.c

📁 本函数是EZ_USB的固件函数框架,实现通过端点通信
💻 C
📖 第 1 页 / 共 2 页
字号:
   CloseHandle(hOutDevice);
   return;
}

/**************************************************
* Main Dialog proc                               *
**************************************************/

BOOL CALLBACK bMainDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
   HWND    hOutputBox                      = NULL;
   HANDLE  hDevice                         = NULL;
   char    pcDriverName[MAX_DRIVER_NAME]   = "";
   BOOLEAN bResult                         = FALSE;
   int     nBytes                          = 0;
   PVOID   pvBuffer                        = 0;
   int     nItems                          = 0;
   HFONT   hFont                           = NULL;
   ULONG   ulLength                         = 0;
   char    tempbuff[256];
   HWND     hControl = NULL;
   
   // Get a handle to the output box
   ghOutputBox = hOutputBox = GetDlgItem (hDlg, IDC_OUTPUT_BOX);
   
   MAINTAIN_OUTPUT_BOX (hOutputBox, nItems);
   
   switch(message)
   {
   case WM_INITDIALOG:
      // Get a handle to the output box
      hOutputBox = GetDlgItem (hDlg, IDC_OUTPUT_BOX);
      
      // Setup the std system font
      hFont = GetStockObject(ANSI_FIXED_FONT);
      SendMessage (hOutputBox, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE,0));
      sprintf(tempbuff,"Cypress Bulk Loopback - built %s %s",build_time,build_date);
      SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)tempbuff);

      // Set Default Values
      hControl = GetDlgItem(hDlg, IDC_FIRSTPAIR);
      SendMessage(hControl,BM_SETCHECK,BST_CHECKED,0);
      gEndpointSelect = FIRSTPAIR;
      
      hControl = GetDlgItem(hDlg, IDC_CONSTANTBYTE);
      SendMessage(hControl,BM_SETCHECK,BST_CHECKED,0);
      gDataPattern = CONSTANTBYTE;

      SetDlgItemText (hDlg, IDC_DEVICENAME, "EZUSB-0");
      SetDlgItemInt(hDlg,IDC_TRANSFERSIZE,8192,FALSE);
      SetDlgItemInt(hDlg,IDC_STARTVALUE,2,FALSE);
      SetDlgItemInt(hDlg,IDC_TESTPASS,0,FALSE);
      SetDlgItemInt(hDlg,IDC_ERRORS,0,FALSE);

      hControl = GetDlgItem(hDlg, IDC_STOPONERROR);
      SendMessage(hControl,BM_SETCHECK,BST_CHECKED,0);

      hControl = GetDlgItem(hDlg, IDC_VERIFYDATA);
      SendMessage(hControl,BM_SETCHECK,BST_CHECKED,0);
      
      gTestParms = bmSTOPONERROR | bmVERIFYDATA;

      gStopTest = TRUE;

      // Setup the default symbolic name for the device driver           
      
      break; /*end WM_INITDIALOG case*/
      
   case WM_COMMAND:
      switch(LOWORD(wParam))
      {
         case IDCANCEL:         
         case IDC_CLOSE:
            EndDialog(hDlg,0);
            break;
       
         case IDC_FIRSTPAIR:
            gEndpointSelect = FIRSTPAIR;
            break;
         case IDC_SELECTPAIR:
            gEndpointSelect = SELECTPAIR;
            break;
         case IDC_OUTONLY:
            gEndpointSelect = OUTONLY;
            break;
         case IDC_INONLY:
            gEndpointSelect = INONLY;
            break;
         case IDC_INCREMENTINGBYTE:
            gDataPattern = INCREMENTINGBYTE;
            break;
         case IDC_RANDOMBYTE:
            gDataPattern = RANDOMBYTE;
            break;
         case IDC_INCREMENTINGDWORD:
            gDataPattern = INCREMENTINGDWORD;
            break;
         case IDC_CONSTANTBYTE:
            gDataPattern = CONSTANTBYTE;
            break;
         case IDC_VERBOSE:
            if (IsDlgButtonChecked(hDlg,IDC_VERBOSE) == BST_CHECKED)
               gTestParms |= bmVERBOSE;
            else
               gTestParms &= ~bmVERBOSE;
            break;
         case IDC_STOPONERROR:
            if (IsDlgButtonChecked(hDlg,IDC_STOPONERROR) == BST_CHECKED)
               gTestParms |= bmSTOPONERROR;
            else
               gTestParms &= ~bmSTOPONERROR;
            break;
         case IDC_VERIFYDATA:
            if (IsDlgButtonChecked(hDlg,IDC_VERIFYDATA) == BST_CHECKED)
               gTestParms |= bmVERIFYDATA;
            else
               gTestParms &= ~bmVERIFYDATA;
            break;
         case IDC_INCPACKET:
            if (IsDlgButtonChecked(hDlg,IDC_INCPACKET) == BST_CHECKED)
               gTestParms |= bmINCPACKET;
            else
               gTestParms &= ~bmINCPACKET;
            break;
         case IDC_START:
            // make sure the test thread isn't already running before 
            // trying to start it
            if (gStopTest)
            {
               gStopTest = FALSE;
               _beginthread(TestThread,0,hDlg);
            }
            else
            {
               SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"Test is already running");
            }
            break;
         case IDC_STOP:
            gStopTest = TRUE;
            break;
         case IDC_CLEAR:
            SendMessage (hOutputBox, LB_RESETCONTENT, 0, 0);
            break;
         case IDC_GETPIPELIST:
            DisplayPipeInfo(hDlg);
            break;

      } /*end switch wParam*/
    
   break;
          
          
   } /*end switch message*/
    
    return FALSE;
    
} /*end MainDlgProc*/


/**************************************************
* bOpenDriver proc                               *
*                                                *
* Purpose:                                       *  
*      Opens the device driver using symbolic    *
*      name provided                             *
*                                                *
* Input:                                         *
*      phDeviceHandle:                           *
*          Pointer to Device Driver handle where *
*          the file handle is placed.            *
*      devname:                                  *
*          Null terminated string containing the *
*          device name                           *
*                                                *
* Return Value:                                  *
*      Boolean that indicates if the driver was  *
*      successfully opened or not.               *
*                                                *
**************************************************/

BOOLEAN
bOpenDriver (HANDLE * phDeviceHandle, PCHAR devname)
{
   char completeDeviceName[64] = "";
   char pcMsg[64] = "";
   
   strcat (completeDeviceName,
      "\\\\.\\"
      );
   
   strcat (completeDeviceName,
		    devname
          );
   
   *phDeviceHandle = CreateFile(   completeDeviceName,
      GENERIC_WRITE,
      FILE_SHARE_WRITE,
      NULL,
      OPEN_EXISTING,
      0,
      NULL);
   
   if (*phDeviceHandle == INVALID_HANDLE_VALUE) {
      return (FALSE);
   } else {
      return (TRUE);
   } /*else*/
   
   
}//OpenDevice

#define BYTES_PER_LINE 0x10

void
DumpBuffer(PVOID pvBuffer, ULONG length, HWND hOutputBox)
{
   int                    nItems    = 0;
   char                   temp[64]  = "";
   char                   temp2[64]  = "";
   ULONG	i,j;
   PUCHAR	ptr;
   
   MAINTAIN_OUTPUT_BOX (hOutputBox, nItems);
   
   ptr = (PUCHAR) pvBuffer;
   
   for (i = 0; i < ((length + BYTES_PER_LINE - 1) / BYTES_PER_LINE); i++)
   {
      wsprintf(temp,"%04X ",(i*BYTES_PER_LINE));
      for (j = 0; j < BYTES_PER_LINE; j++)
      {
         if (((i * BYTES_PER_LINE) + j) < length)
         {
            wsprintf(temp2,"%02X ",*ptr++);
            strcat(temp,temp2);
         }
      }
      SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)temp);
   }
}

//
// queries the device for its interface information and updates the global
// variable gInterfaceInfo
//
void RetrievePipeInfo(HWND hDlg)
{
   HWND hOutputBox;
   HANDLE  hDevice = NULL;
   char    DeviceName[MAX_DRIVER_NAME]   = "";
   ULONG   nBytes;

   hOutputBox = GetDlgItem (hDlg, IDC_OUTPUT_BOX);

   //
   // get the device handle
   //
   GetDlgItemText (hDlg, IDC_DEVICENAME, DeviceName, MAX_DRIVER_NAME);
   if (bOpenDriver (&hDevice, DeviceName) != TRUE)
   {
      SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"Failed to Open Device");
      return;
   }

   DeviceIoControl (hDevice,
		IOCTL_Ezusb_GET_PIPE_INFO,
		NULL,
		0,
		&gInterfaceInfo,
		sizeof(gInterfaceInfo),
		&nBytes,
		NULL);

   CloseHandle(hDevice);
}

void DisplayPipeInfo(HWND hDlg)
{
   HWND hOutputBox;
   char tempbuff[256];
   PUSBD_INTERFACE_INFORMATION pInterfaceInfo;
   PUSBD_PIPE_INFORMATION pPipeInfo;
   ULONG i;

   hOutputBox = GetDlgItem (hDlg, IDC_OUTPUT_BOX);

   RetrievePipeInfo(hDlg);
   pInterfaceInfo = (PUSBD_INTERFACE_INFORMATION) &gInterfaceInfo;


   SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"Pipe  Endpoint  Direction  Type  Size");
   
   for (i=0;i<pInterfaceInfo->NumberOfPipes;i++)
   {
      pPipeInfo = &pInterfaceInfo->Pipes[i];
      sprintf(tempbuff,"%2d     %2d          %s     %s  %4d",
               i,
               pPipeInfo->EndpointAddress & 0x0F,
               pPipeInfo->EndpointAddress & 0x80 ? "IN " : "OUT",
               PIPE_TYPE_STRINGS[pPipeInfo->PipeType],
               pPipeInfo->MaximumPacketSize);
      SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)tempbuff);



   }
}

//
// returns the index of the first pipe in the interface.  InPipe = TRUE returns the
// first IN pipe, FALSE returns the first OUT pipe
//
ULONG FirstPipe(HWND hDlg, BOOL InPipe)
{
   PUSBD_INTERFACE_INFORMATION pInterfaceInfo;
   PUSBD_PIPE_INFORMATION pPipeInfo;
   ULONG i;

   RetrievePipeInfo(hDlg);
   pInterfaceInfo = (PUSBD_INTERFACE_INFORMATION) &gInterfaceInfo;

   for (i=0;i<pInterfaceInfo->NumberOfPipes;i++)
   {
      pPipeInfo = &pInterfaceInfo->Pipes[i];
      if (InPipe)
      {
         if (pPipeInfo->EndpointAddress & 0x80)
            return(i);
      }
      else
      {
         if (!(pPipeInfo->EndpointAddress & 0x80))
            return(i);
      }
   }
   return(-1);
}

⌨️ 快捷键说明

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