USB bulk write sample
USB bulk write sample
Can anybody give an example of bulk writing on psp? I've been searching net for hours and I haven't found anything useful. What I'd like to know is: how to start connection, send some data with bulk mode and close connection.
Yep, I did, but it's pretty hard to get the code I needed and it didn't work... Take a look:
Activating USB:
I'm sending it:
I tried to send three 64-byte buffers, but it doesn't work either...
Code: Select all
/* Main USB event flags */
enum UsbEvents
{
USB_EVENT_ATTACH = 1,
USB_EVENT_DETACH = 2,
USB_EVENT_ASYNC = 4,
USB_EVENT_CONNECT = 8,
USB_EVENT_ALL = 0xFFFFFFFF
};
/* USB transfer event flags */
enum UsbTransEvents
{
USB_TRANSEVENT_BULKOUT_DONE = 1,
USB_TRANSEVENT_BULKIN_DONE = 2,
};
/* String descriptor */
unsigned char strp[] =
{
0x8, 0x3, '<', 0, '>', 0, 0, 0
};
/* Intefaces */
struct UsbInterface intp = {
0xFFFFFFFF, 0, 1,
};
/* Main USB transfer event flag */
static SceUID g_transevent = -1;
/* Static bulkin request structure */
static struct UsbdDeviceReq g_bulkin_req;
/* Forward define the driver structure */
extern struct UsbDriver g_driver;
/* Async request */
//static struct UsbdDeviceReq g_async_req;
/* Buffers for async data */
//static struct AsyncEndpoint *g_async_chan[MAX_ASYNC_CHANNELS];
/* Endpoint blocks */
struct UsbEndpoint endp[4] = {
{ 0, 0, 0 },
{ 1, 0, 0 },
{ 2, 0, 0 },
{ 3, 0, 0 },
};
/* Setup a bulkin request */
int set_bulkin_req(void *data, int size)
{
sceKernelDcacheWritebackRange(data, size);
memset(&g_bulkin_req, 0, sizeof(g_bulkin_req));
g_bulkin_req.endp = &endp[1];
g_bulkin_req.data = data;
g_bulkin_req.size = size;
g_bulkin_req.func = NULL;
sceKernelClearEventFlag(g_transevent, ~USB_TRANSEVENT_BULKIN_DONE);
return sceUsbbdReqSend(&g_bulkin_req);
}
Code: Select all
LoadStartModule("flash0:/kd/semawm.prx");
LoadStartModule("flash0:/kd/usbstor.prx");
LoadStartModule("flash0:/kd/usbstormgr.prx");
LoadStartModule("flash0:/kd/usbstorms.prx");
LoadStartModule("flash0:/kd/usbstorboot.prx");
retVal = sceUsbStart(PSP_USBBUS_DRIVERNAME, 0, 0);
if (retVal != 0) {
debug_file(0x04);
sceKernelSleepThread();
}
int ret;
ret = sceUsbbdRegister(&g_driver);
if (!(state & PSP_USB_ACTIVATED)){
retVal = sceUsbActivate(0x1d2);
}
Code: Select all
if(sceUsbGetState() & PSP_USB_ACTIVATED){
retVal= set_bulkin_req(&buf, 192);
if(retVal<0){
broadcast= 0x00;
debug_file(retVal);
}
}
Go to your PC and look up PC examples of USB to learn how USB works. Once you're a PC USB wiz, come back and look at the PSP again. Don't try to LEARN anything starting on the PSP. You'll just wind up pulling your hair out.septem wrote:How am I supposed to learn it if you tell me to don't touch it? :>
Hehe, I guess making usb send data isn't as easy as using sockets ;P I was wondering if I can make usb send any data using only pspusbbus.h and not loading any modules like in pspsdk usb sample and not using function like sceUsbActivate, sceUsbDeactivate etc.? I guess they are used while setting usb storage and they're not needed if I want bus to send some bulk data... Also I'd like to know if I have to use all those semaphores if the only thing my prx does is writing (no reading, exchanging commands or nothing like that).
Yes, using USB stuff is nothing remotely like sockets. I am impressed you can even use those :)
You have to call sceUsbActivate etc because that then creates the device. I guess you dont understand how USB works to be asking a question like this. You can't just "use" the USB bus in any meaningful sense without creating a USB device type and then you still need something on the PC side to interact with it.
With USB mass storage the PSP firmware makes a device which looks like a mass storage device and then handles the interactions between that and the PC. The PC just sees it as a normal USB mass storage device and loads the appropriate driver. Similar with usbhostfs.
You have to call sceUsbActivate etc because that then creates the device. I guess you dont understand how USB works to be asking a question like this. You can't just "use" the USB bus in any meaningful sense without creating a USB device type and then you still need something on the PC side to interact with it.
With USB mass storage the PSP firmware makes a device which looks like a mass storage device and then handles the interactions between that and the PC. The PC just sees it as a normal USB mass storage device and loads the appropriate driver. Similar with usbhostfs.
Gimme a break... I know I got whole thing the wrong way and I overestimated myself on that, but you don't need to say that kind of shit to me. You haven't been born as a usb-programming god either (correct me if I'm wrong :] ). But I'm sorry for asking so many fuckin' lame questions, this won't happen again.TyRaNiD wrote:Yes, using USB stuff is nothing remotely like sockets. I am impressed you can even use those :)
I guess the fact there was a smilie was there went over your head ;)
If you really want to use the USB cable to transfer data from PC to PSP or vice versa then really use the stuff already in psplink to provide that very functionality. Look at the echo sample, all you need to do is write a simple "server" on the PSP and a socket client on the PC and you are done. usbhostfs handles the rest for you. Oh and note you dont actually need the rest of psplink to use it, just usbhostfs and usbhostfs_pc
If you really want to use the USB cable to transfer data from PC to PSP or vice versa then really use the stuff already in psplink to provide that very functionality. Look at the echo sample, all you need to do is write a simple "server" on the PSP and a socket client on the PC and you are done. usbhostfs handles the rest for you. Oh and note you dont actually need the rest of psplink to use it, just usbhostfs and usbhostfs_pc
Ok, let's say I use usbhostfs:
1. can usbhostfs guarantee that I get maximum speed? And I don't mean 480 mb/s or nothing like that cause it's almost impossible because of hardware issues. I want to know if it sends any packets other than my prx wants it to e.g some commands packets or something like that, that may slow whole the transmission.
2. what if I want to write pc application which will read what psp writes in language other than c/c++? Do I have to translate whole usbhostfs_pc or make some kind of library of it (dll maybe), or can I use just libusb usb_bulk_read and not pay any attention to packets that usbhostfs may send other than my prx does?
3. if I want to change Pid I have to change it in usbhostfs.h, right?
1. can usbhostfs guarantee that I get maximum speed? And I don't mean 480 mb/s or nothing like that cause it's almost impossible because of hardware issues. I want to know if it sends any packets other than my prx wants it to e.g some commands packets or something like that, that may slow whole the transmission.
2. what if I want to write pc application which will read what psp writes in language other than c/c++? Do I have to translate whole usbhostfs_pc or make some kind of library of it (dll maybe), or can I use just libusb usb_bulk_read and not pay any attention to packets that usbhostfs may send other than my prx does?
3. if I want to change Pid I have to change it in usbhostfs.h, right?
What type of video? Something akin to remotejoy or different? In my tests I have only been able to get the data transfer up to around 18 Megabytes/s and that is an artificial test with no extra framing and literally just pushing out large bulk data transfers. You might be better off trying to use isochronous transfers but I have no idea if the PSP actually supports that anyway.
Good luck on this, you will need it :P
Good luck on this, you will need it :P