/* CC-USB Demo program * * Copyright (C) 2005-2009 Jan Toke (toke@chem.rochester.edu) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, version 2. * * This program demonstrates the use of libusb to communicate with CC-USB. * The prerequisites are: * (i) EHCI driver installed - it is part of newer distributions of Linux * (ii) libusb package installed - it is installed automatically by newer * distributions (I amd using Mandriva 10.2). * * The program calls first usb_init(), usb_find_busses(), and usb_find_devices(), * passing relevant arguments to structures bus and dev. * * compile as: * gcc -o flahvmusb flashvmusb.c -I/usr/local/include -L. -Insl -lm -lc -L/usr/local/lib -lusb */ #include #include #include #include #include "libxxusb.h" int main(int argc, char *fname[]) { if(argc != 2) { printf("\n\n Must provide a firmware file name as an argument\n\n"); } struct usb_device *dev; xxusb_device_type devices[100]; time_t t1, t2; int i; long fwid; usb_dev_handle *udev; unsigned char *pconfig; unsigned char *p; int chint; long ik; FILE *fptr; int ret; printf("\n*************************************************************************\n\n"); printf(" WIENER VM_USB Firmware upgrade\n"); xxusb_devices_find(devices); dev = devices[0].usbdev; udev = xxusb_device_open(dev); if(!udev) { printf("\nUnable to open a VM_USB device\n"); return 0; } ik=0; if ((fptr=fopen(fname[1],"rb"))==NULL) { printf("\n File not Found\n"); return 0; } pconfig=(unsigned char*)malloc(220000); p=pconfig; while((chint=getc(fptr)) != EOF) { *p=(unsigned char)chint; p++; ik=ik+1; } printf("\n"); for (i=0; i < 512; i++) { ret=xxusb_flashblock_program(udev,pconfig); pconfig=pconfig+256; t1=(time_t)(.03*CLOCKS_PER_SEC); t1=clock()+(time_t)(.03*CLOCKS_PER_SEC); while (t1>clock()); t2=clock(); printf("."); if (i>0) if ((i & 63)==63) printf("\n"); } while (clock() < t1) ; t2=clock(); ret = xxusb_reset_toggle(udev); ret=VME_register_read(udev,0,&fwid); printf("\n\nThe New Firmware ID is %lx\n\n\n",fwid); if (udev) xxusb_device_close(udev); return 1; }