I have desperately need of your help, Tyranid.
We have begun to integrate support for USB webcam in our
Nanodesktop library. We want to use the usbhost_fs routines to
create a stable link between Linux PC and PSP, but we have
troubles in USB managing.
This is a code that we have used for a first attempt: we want to send
an hello message to PC and to reveal it on PC monitor.
On PSP, we have the following:
char ND_SWMODE_DisablePhoenixSubsystem = 1;
#define PSP_MODULE_INFO_DISABLED
#include <nanodesktop.h>
/**
* Define the module info section
*
* 2nd arg must 0x1000 so __init is executed in
* kernelmode for our loaderInit function
*/
PSP_MODULE_INFO("USBSample", 0x1000, 1, 0);
/**
* THREAD_ATTR_USER causes the thread that the startup
* code (ctr0.c) starts this program in to be in usermode
* even though the module was started in kernelmode
*/
PSP_MAIN_THREAD_ATTR (0);
/* Define printf, just to make typing easier */
//#define printf pspDebugScreenPrintf
#include <pspkernel.h>
#include <pspiofilemgr.h>
#include <pspmodulemgr.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <pspusb.h>
#include <pspusbstor.h>
#include <pspthreadman.h>
#include <pspctrl.h>
#include <pspsdk.h>
#include "host_driver.c"
//make this global so we can check it in the exit_callback
u32 state;
/**
* Function that is called from _init in kernelmode before the
* main thread is started in usermode.
*/
__attribute__ ((constructor))
void loaderInit()
{
pspKernelSetKernelPC();
pspSdkInstallNoDeviceCheckPatch();
pspDebugInstallKprintfHandler(NULL);
}
/* Exit callback */
/*
int exit_callback(int arg1, int arg2, void *common)
{
int retVal;
//cleanup drivers
if (state & PSP_USB_ACTIVATED) {
retVal = sceUsbDeactivate(0);
if (retVal != 0)
printf("Error calling sceUsbDeactivate (0x%08X)\n", retVal);
}
retVal = sceUsbStop(PSP_USBSTOR_DRIVERNAME, 0, 0);
if (retVal != 0)
printf("Error stopping USB Mass Storage driver (0x%08X)\n",
retVal);
retVal = sceUsbStop(PSP_USBBUS_DRIVERNAME, 0, 0);
if (retVal != 0)
printf("Error stopping USB BUS driver (0x%08X)\n", retVal);
sceKernelExitGame();
return 0;
}
*/
/* Callback thread */
/*
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
*/
/* Sets up the callback thread and returns its thread id */
/*
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread,
0x11, 0xFA0, 0, 0);
if (thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
*/
//helper function to make things easier
int LoadStartModule(char *path)
{
u32 loadResult;
u32 startResult;
int status;
loadResult = sceKernelLoadModule(path, 0, NULL);
if (loadResult & 0x80000000)
return -1;
else
startResult =
sceKernelStartModule(loadResult, 0, NULL, &status, NULL);
if (loadResult != startResult)
return -2;
return 0;
}
int main(void)
{
SceCtrlData pad;
u32 oldButtons = 0;
u32 retVal;
state = 0;
//pspDebugScreenInit();
//pspDebugScreenClear();
//SetupCallbacks();
//setup Pad
//sceCtrlSetSamplingCycle(0);
//sceCtrlSetSamplingMode(0);
//print header now in case we have any errors
printf("USB Sample v1.0 by John_K - Based off work by PSPPet\n");
//start necessary drivers
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");
//setup USB drivers
retVal = sceUsbStart(PSP_USBBUS_DRIVERNAME, 0, 0);
if (retVal != 0)
{
printf("Error starting USB Bus driver (0x%08X)\n", retVal);
sceKernelSleepThread();
}
retVal = sceUsbStart(PSP_USBSTOR_DRIVERNAME, 0, 0);
if (retVal != 0)
{
printf("Error starting USB Mass Storage driver (0x%08X)\n",
retVal);
sceKernelSleepThread();
}
retVal = sceUsbstorBootSetCapacity(0x800000);
if (retVal != 0)
{
printf
("Error setting capacity with USB Mass Storage driver (0x%08X)\n",
retVal);
sceKernelSleepThread();
}
retVal = 0;
//if everything worked we now enter our main loop
sceUsbActivate(0x1c8);
ndDelay (20);
state = sceUsbGetState();
printf("USB Sample v1.0 by John_K - Based off work by PSPPet\n\n");
printf("%-14s: %s\n", "USB Driver",
state & PSP_USB_ACTIVATED ? "activated " :
"deactivated");
printf("%-14s: %s\n", "USB Cable",
state & PSP_USB_CABLE_CONNECTED ? "connected " :
"disconnected");
printf("%-14s: %s\n", "USB Connection",
state & PSP_USB_CONNECTION_ESTABLISHED ? "established" :
"not present");
modulestart ();
send_hello_cmd ();
//Exit program
ndDelay (60);
sceKernelExitGame();
return 0;
}
When we use send_hello_cmd routine, we obtained an error on
XCHG Semaphore.
Why ?
USB: Need help (for Tyranid)
-
- Posts: 160
- Joined: Wed Jul 12, 2006 7:09 am
I am trying a different source code. Now I am beginning to understandTyRaNiD wrote:Well you wont be able to get much done if you try loading the usb mass storage drivers now will you :)
something. This programs works, USB attached/detached works, but
when the cpu try to run sceUsbbdReqRecv () function in
set_bulkout_req I have an hang.
The source use your code, but it includes it directly in the source,
instead of loading hostfs.prx.
The source code is the following:
char ND_SWMODE_DisablePhoenixSubsystem = 1;
#define PSP_MODULE_INFO_DISABLED
#include <nanodesktop.h>
PSP_MODULE_INFO("USBHostFS_to_MS", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR (0);
#include <pspiofilemgr.h>
#include <pspctrl.h>
#include <pspusb.h>
#include <stdio.h>
#include <string.h>
#include <psploadexec.h>
#include <pspsysmem.h>
#include ".\host_driver.c"
__attribute__ ((constructor))
void loaderInit()
{
pspKernelSetKernelPC();
pspSdkInstallNoDeviceCheckPatch();
pspDebugInstallKprintfHandler(NULL);
}
int loadStartModule(char * path) { // load and start a module. return 0 for success, -1 for failing to load, -2 for failing to start
u32 loadResult;
u32 startResult;
int status;
loadResult = sceKernelLoadModule(path, 0, NULL);
if (loadResult & 0x80000000) return -1;
else
startResult = sceKernelStartModule(loadResult, 0, NULL, &status, NULL);
if (loadResult != startResult) return -2;
return 0;
}
int StartUSBHostFSDriver() { // start the USBHostFS driver; return 0 on success, -1 on startbus failure, -2 on startdriver failure, -4 on activate failure, or a combination of the three.
int startbus = 0, startdriver = 0, activate = 0;
startbus = sceUsbStart(PSP_USBBUS_DRIVERNAME, 0, 0) ? -1 : 0;
startdriver = sceUsbStart("USBHostFSDriver", 0, 0) ? -2 : 0;
activate = sceUsbActivate(0x1C9) ? -4 : 0;
return startbus + startdriver + activate;
}
void quitWithMessage(char *str, int err)
{
sceUsbDeactivate(0x1c9);
printf("%s %d \n", str, err);
sceKernelDelayThread(10000);
sceKernelExitGame();
}
int main ()
{
int res;
int Buffer [255];
ndInitSystem ();
printf ("Sistema avviato: Caricamento usb driver \n");
printf ("Caricamento modulo Tyranid \n");
modulestart ();
res = StartUSBHostFSDriver();
//if(res) quitWithMessage("main: StartUSBHostFSDriver fails!", res);
ndDelay (10);
int Counter;
for (Counter=0; Counter<2550; Counter++)
{
printf ("DATA SEND %d \n", Counter);
Buffer [0]=255;
Buffer [1]=254;
Buffer [2]=253;
write_data (&Buffer, 4);
}
}
What is wrong, in your opinion ?
Use:
Code: Select all
[code][/code]