I am having problems opening file descriptor to the serial port
The code below, mostly ripped of the lua player, always returns with:
"failed create SIO handle"
The PSP remote connector & the headphones are plugged in - They seem to send stuff back thru lua's serial echo script w/o any problems...
Any suggestions would be greatly appreciated...
Code: Select all
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspiofilemgr.h>
#include <pspusb.h>
#include <pspusbstor.h>
#include <psppower.h>
#include <unistd.h>
#include <sys/stat.h>
PSP_MODULE_INFO("Hello SIO", 0, 1, 1);
#define printf pspDebugScreenPrintf
#define SIO_IOCTL_SET_BAUD_RATE 1
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
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;
}
static SceUID sio_fd = -1;
int baudRate = 2400;
char data[256];
int main() {
pspDebugScreenInit();
SetupCallbacks();
printf("Hello SIO\n");
if (sio_fd < 0) sio_fd = sceIoOpen("sio:", PSP_O_RDWR, 0777);
if (sio_fd < 0) {
printf("failed create SIO handle.");
sceKernelSleepThread();
return 0;
}
printf("performing ioctl.\n");
sceIoIoctl(sio_fd, SIO_IOCTL_SET_BAUD_RATE, &baudRate, sizeof(baudRate), NULL, 0);
while (1) {
int count = sceIoRead(sio_fd, data, 256);
if (count > 0) printf("[%s]\n",data);
}
sceKernelSleepThread();
return 0;
}