int usb_driver_read(unsigned char * data, int size) { int cnt_bytes = read(usb_device, data, size); if(cnt_bytes<=0) { printf("[Error] L%d %s : %s\n",__LINE__,__FUNCTION__,strerror(errno)); if(usb_driver_init()<0) { return -1; } cnt_bytes = read(usb_device, data, size); } if(cnt_bytes<0) { printf("[Error] L%d %s : %s\n",__LINE__,__FUNCTION__,strerror(errno)); return -1; } #ifdef DEBUG_USB_DRIVER printf("[Debug] L%d %s : %d bytes : ",__LINE__,__FUNCTION__,cnt_bytes); int i; for(i=0 ; i<cnt_bytes ; i++) { printf("0x%X ",data[i]); } printf("(%s)\n",data); #endif return cnt_bytes; }
void usb_init(const usb_profile_t *profile) { usb_driver_init( profile ); usb_msc_init(); usb_dfu_init(); platform_usb_enable(); }
void test_usb_read() { if(usb_driver_init()<0) { return; } unsigned char data[256]; while(1) { usb_driver_read(data,256); } usb_driver_close(); }