转自:http://biancheng.dnbcw.info/linux/257411.html
【1】 如何编译X86下的 uBuntu APP---非常简单:
gcc -o testusb testusb.c
编译完成后即可生成 testusb ,这就是可执行文件。
【2】下面制作一个APP,目的是读取4740的内存。只要能实现这个目标,测试基本就算完成。
#include <stdio.h>
#include <string.h>
#include <ftw.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/usbdevice_fs.h>
int usb_boot_fd;
#define USBTEST_REQUEST _IOWR(‘U‘, 100, struct usbtest_param)
int read_from_4740()
{
unsigned char Buffer0[256];
unsigned char Buffer1[512];
int res,i;
if ((usb_boot_fd = open ("/dev/usb_boot", O_RDWR)) < 0) {
perror ("can‘t open dev file r/w");
return -1;
}
Buffer0[0]=0x40;
Buffer0[1]=0x01; //Reqest 01===>SET DATA ADDRESS
Buffer0[2]=0xC0; //Byte2
Buffer0[3]=0xBF; //Byte3
Buffer0[4]=0x00; //Byte0
Buffer0[5]=0x00; //Byte1
Buffer0[6]=0x00;
Buffer0[7]=0x00;
res=ioctl (usb_boot_fd, USBDEVFS_IOCTL, Buffer0);
//==========
Buffer1[0]=0x40;
Buffer1[1]=0x02; //Reqest 02===>SET DATA LENGTH
Buffer1[2]=0x00; //Byte2
Buffer1[3]=0x00; //Byte3
Buffer1[4]=0x00; //Byte0
Buffer1[5]=0x02; //Byte1
Buffer1[6]=0x00;
Buffer1[7]=0x00;
res=ioctl (usb_boot_fd, USBDEVFS_IOCTL, Buffer1);
memset(Buffer1,0x00,0x200);
res=read(usb_boot_fd,Buffer1,0x20);
LinuxUSB驱动程序调试--009:编写应用程序---验证协议【转】
原文:http://www.cnblogs.com/sky-heaven/p/5066492.html