forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

USB bulk write sample

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
septem



Joined: 29 Aug 2007
Posts: 21

PostPosted: Thu Sep 13, 2007 5:40 am    Post subject: USB bulk write sample Reply with quote

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.
Back to top
View user's profile Send private message
septem



Joined: 29 Aug 2007
Posts: 21

PostPosted: Fri Sep 14, 2007 9:09 pm    Post subject: Reply with quote

*bump*

Anybody? I really need this... :(
Back to top
View user's profile Send private message
weltall



Joined: 20 Feb 2004
Posts: 310

PostPosted: Fri Sep 14, 2007 9:25 pm    Post subject: Reply with quote

did you have a look at psplink?
Back to top
View user's profile Send private message Visit poster's website
septem



Joined: 29 Aug 2007
Posts: 21

PostPosted: Fri Sep 14, 2007 10:02 pm    Post subject: Reply with quote

Yep, I did, but it's pretty hard to get the code I needed and it didn't work... Take a look:
Code:
/* 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);
}

Activating USB:
Code:
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);
                                       }

I'm sending it:
Code:
if(sceUsbGetState() & PSP_USB_ACTIVATED){
                          retVal= set_bulkin_req(&buf, 192);
                          if(retVal<0){
                            broadcast= 0x00;
                            debug_file(retVal);                       
                          }                               
                }

I tried to send three 64-byte buffers, but it doesn't work either...
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Sat Sep 15, 2007 2:26 am    Post subject: Reply with quote

What in dear fucking god.... if you dont know how this works dont touch it :)
Back to top
View user's profile Send private message
septem



Joined: 29 Aug 2007
Posts: 21

PostPosted: Sat Sep 15, 2007 2:43 am    Post subject: Reply with quote

How am I supposed to learn it if you tell me to don't touch it? :>
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Sat Sep 15, 2007 6:23 am    Post subject: Reply with quote

septem wrote:
How am I supposed to learn it if you tell me to don't touch it? :>


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.
Back to top
View user's profile Send private message AIM Address
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Sat Sep 15, 2007 7:05 am    Post subject: Reply with quote

This isn't some kindergarten for wannabe usb coders, you have to earn your stripes. Really if you want to do a bulk transfer then it is surely simpler to use psplink's async/bulk transfer mechanism :)
Back to top
View user's profile Send private message
septem



Joined: 29 Aug 2007
Posts: 21

PostPosted: Sat Sep 15, 2007 6:57 pm    Post subject: Reply with quote

Yeah, I guess you're right ;P
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Sat Sep 15, 2007 9:09 pm    Post subject: Reply with quote

The code you pasted though would only help if you had all the other USB stuff psplink does, just called the send req without setting up the usb driver wont do alot I am afraid.
Back to top
View user's profile Send private message
septem



Joined: 29 Aug 2007
Posts: 21

PostPosted: Sat Sep 15, 2007 10:24 pm    Post subject: Reply with quote

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).
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Sun Sep 16, 2007 12:00 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
septem



Joined: 29 Aug 2007
Posts: 21

PostPosted: Sun Sep 16, 2007 1:15 am    Post subject: Reply with quote

TyRaNiD wrote:
Yes, using USB stuff is nothing remotely like sockets. I am impressed you can even use those :)


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.
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Sun Sep 16, 2007 3:24 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
septem



Joined: 29 Aug 2007
Posts: 21

PostPosted: Mon Sep 17, 2007 1:15 am    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Mon Sep 17, 2007 2:42 am    Post subject: Reply with quote

Go on just for curiosity what are you actually trying to do?
Back to top
View user's profile Send private message
septem



Joined: 29 Aug 2007
Posts: 21

PostPosted: Mon Sep 17, 2007 2:51 am    Post subject: Reply with quote

I won't tell you cause you'll stop taking whole this thing for real (if you ever have :] )
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Mon Sep 17, 2007 3:27 am    Post subject: Reply with quote

Fine be like that then, I wont help you at all. If you are so cagey about it is probably warez related so I dont much care :)
Back to top
View user's profile Send private message
septem



Joined: 29 Aug 2007
Posts: 21

PostPosted: Mon Sep 17, 2007 3:29 am    Post subject: Reply with quote

Oh man... you won. I'm trying to make video streamer.
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Mon Sep 17, 2007 4:16 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
weltall



Joined: 20 Feb 2004
Posts: 310

PostPosted: Mon Sep 17, 2007 6:59 am    Post subject: Reply with quote

remotejoy isn't enough? i can do videos from it without problems
Back to top
View user's profile Send private message Visit poster's website
septem



Joined: 29 Aug 2007
Posts: 21

PostPosted: Mon Sep 17, 2007 7:44 pm    Post subject: Reply with quote

I want to make my own app. I'm trying to stream video buffer, so that pc user sees, what psp user does. I got a question: if I use usbhostfs I have to use my app with psplink or can I just throw it in seplugins and it will work.
Back to top
View user's profile Send private message
weltall



Joined: 20 Feb 2004
Posts: 310

PostPosted: Tue Sep 18, 2007 1:25 am    Post subject: Reply with quote

without psplink, just like remotejoy which doesn't need psplink either
Back to top
View user's profile Send private message Visit poster's website
septem



Joined: 29 Aug 2007
Posts: 21

PostPosted: Tue Sep 18, 2007 4:46 am    Post subject: Reply with quote

For some reason it doesn't work. It's not even detected by pc. I guess i should do something before starting streaming like starting hostfs driver, but I'm not sure what...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group