 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
deniska
Joined: 17 Oct 2005 Posts: 71 Location: New York
|
Posted: Wed Nov 14, 2007 2:35 am Post subject: sio interrupt handling on slim |
|
|
Hi,
I am having problems with interrupt handling for serial IO port.
Basically, the code (below) works fine in kernel mode on the phat. The sio reads work on the slim too, but they don't seem to wait for the interrupt/timeout and return right away, thus making a very tight loop.
I don't see any errors during the registering and enabling the handler.. so the whole thing is a bit puzzling..
Any suggestions are greatly appreciated!
Here is the main.c
| Code: |
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspsdk.h>
#include <pspctrl.h>
#include <stdio.h>
#include <string.h>
PSP_MODULE_INFO("SIO_TESTER", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
//PSP_MODULE_INFO("SIO_TESTER", 0x1000, 1, 1);
//PSP_MAIN_THREAD_ATTR(0);
int sioReadChar();
void sioInit(int,int);
int main(void)
{
int baud=38400;
pspDebugScreenInit();
pspDebugScreenPrintf("PSP GPSlim 236 test - Press X to exit\n");
pspDebugScreenPrintf("Press UP/DOWN to change baud\n");
sceDisplayWaitVblankStart();
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
SceUID mod = pspSdkLoadStartModule("sioprx.prx", PSP_MEMORY_PARTITION_KERNEL);
if (mod < 0)
{
pspDebugScreenPrintf(" Error 0x%08X loading/starting pspremoteprx.prx.\n", mod);
sceKernelDelayThread(3*1000*1000);
sceKernelExitGame();
}
sceKernelDelayThread(1000000);
pspDebugScreenPrintf("module loaded !!!\n");
sioInit(baud,0);
sceKernelDelayThread(1000000);
pspDebugScreenPrintf("INIT DONE!!!\n");
int thid = sceKernelGetThreadId();
sceKernelChangeThreadPriority(thid, 31);
SceCtrlData pad;
int ch=-1;
while(1)
{
sceCtrlPeekBufferPositive(&pad, 1);
if(pad.Buttons & PSP_CTRL_SQUARE) {
sioInit(baud,0);
}
if(pad.Buttons & PSP_CTRL_UP) {
baud*=2;
pspDebugScreenPrintf("setting baud to: %d\n", baud);
sioInit(baud,0);
sceKernelDelayThread(500000);
} else
if(pad.Buttons & PSP_CTRL_DOWN) {
baud/=2;
pspDebugScreenPrintf("setting baud to: %d\n", baud);
sioInit(baud,0);
sceKernelDelayThread(500000);
} else
if(pad.Buttons & PSP_CTRL_CROSS)
{
break;
}
ch = sioReadChar();
if((ch >= 0) && (ch != '\r'))
pspDebugScreenPrintf("%c", ch);
else
pspDebugScreenPrintf(".");
}
sceKernelExitGame();
return 0;
}
|
Makefile:
| Code: |
TARGET = pspgpslim236
OBJS = main.o sioprx.o
BUILD_PRX=1
PSP_FW_VERSION=371
INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = GPSlim236
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
|
main.c for kernel sio calls (greatly influenced by psplink code):
| Code: |
#include <pspsdk.h>
#include <pspintrman_kernel.h>
#include <pspintrman.h>
#include <pspsyscon.h>
PSP_MODULE_INFO("sioprx", 0x1006, 1, 1);
PSP_MAIN_THREAD_ATTR(0);
#define PSP_UART4_DIV1 0xBE500024
#define PSP_UART4_DIV2 0xBE500028
#define PSP_UART4_CTRL 0xBE50002C
#define PSP_UART_CLK 96000000
#define EVENT_SIO 0x01
int sceHprmEnd(void);
int sceSysregUartIoEnable(int uart);
int sceSyscon_driver_44439604(int power);
static SceUID g_eventflag = -1;
void sioSetBaud(int baud)
{
int div1, div2;
div1 = PSP_UART_CLK / baud;
div2 = div1 & 0x3F;
div1 >>= 6;
_sw(div1, PSP_UART4_DIV1);
_sw(div2, PSP_UART4_DIV2);
_sw(0x60, PSP_UART4_CTRL);
}
void _sioInit(void)
{
sceHprmEnd();
sceSysregUartIoEnable(4);
sceSysconCtrlHRPower(1);
}
int intr_handler(void *arg)
{
u32 stat;
/* Read out the interrupt state and clear it */
stat = _lw(0xBE500040);
_sw(stat, 0xBE500044);
sceKernelDisableIntr(PSP_HPREMOTE_INT);
sceKernelSetEventFlag(g_eventflag, EVENT_SIO);
return -1;
}
void sioInit(int baud, int kponly)
{
_sioInit();
if(!kponly)
{
g_eventflag = sceKernelCreateEventFlag("SioShellEvent", 0, 0, 0);
//void *func = (void *) ((unsigned int) intr_handler | 0x80000000);
void *func = (void *) ((unsigned int) intr_handler);
int st=sceKernelRegisterIntrHandler(PSP_HPREMOTE_INT, 1, func, NULL, NULL);
st=sceKernelEnableIntr(PSP_HPREMOTE_INT);
sceKernelDelayThread(2000000);
}
sioSetBaud(baud);
}
int sioReadChar(void)
{
int ch;
u32 result;
SceUInt timeout;
timeout = 1000000;
ch = pspDebugSioGetchar();
if(ch == -1)
{
sceKernelEnableIntr(PSP_HPREMOTE_INT);
sceKernelWaitEventFlag(g_eventflag, EVENT_SIO, 0x21, &result, &timeout);
ch = pspDebugSioGetchar();
}
return ch;
}
int module_start(SceSize args, void *argp)
{
return 0;
}
int module_stop()
{
return 0;
}
|
sioprx.exp:
| Code: |
PSP_BEGIN_EXPORTS
PSP_EXPORT_START(syslib, 0, 0x8000)
PSP_EXPORT_FUNC_HASH(module_start)
PSP_EXPORT_VAR_HASH(module_info)
PSP_EXPORT_END
PSP_EXPORT_START(sioprx, 0, 0x4001)
PSP_EXPORT_FUNC(sioInit)
PSP_EXPORT_FUNC(sioReadChar)
PSP_EXPORT_END
PSP_END_EXPORTS
|
makefile for the sioprx.prx:
| Code: |
TARGET = sioprx
OBJS = main.o
INCDIR =
CFLAGS = -O2 -G0 -Wall -g
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
BUILD_PRX = 1
PRX_EXPORTS = sioprx.exp
USE_KERNEL_LIBC=1
USE_KERNEL_LIBS=1
LIBDIR =
LDFLAGS = -mno-crt0 -nostartfiles
LIBS = -lpspdebug -lpspsdk -lpsphprm_driver
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
all:
echo "$PSPSDK"
psp-build-exports -s sioprx.exp
cp *.S ../
cp *.prx ../
clean:
rm -f $(FINAL_TARGET) $(EXTRA_CLEAN) $(OBJS) $(PSP_EBOOT_SFO) $(PSP_EBOOT) $(EXTRA_TARGETS)
rm -f *.S
|
|
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Wed Nov 14, 2007 4:53 am Post subject: |
|
|
heres your problem on slim
SceUID mod = pspSdkLoadStartModule("sioprx.prx", PSP_MEMORY_PARTITION_KERNEL); // dont do this in userland _________________ 10011011 00101010 11010111 10001001 10111010 |
|
| Back to top |
|
 |
deniska
Joined: 17 Oct 2005 Posts: 71 Location: New York
|
Posted: Wed Nov 14, 2007 5:30 am Post subject: |
|
|
| dot_blank wrote: | heres your problem on slim
SceUID mod = pspSdkLoadStartModule("sioprx.prx", PSP_MEMORY_PARTITION_KERNEL); // dont do this in userland |
I tired it with "PSP_MEMORY_PARTITION_USER" - it gave me same results :-(
Any other ideas? |
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Wed Nov 14, 2007 5:44 am Post subject: |
|
|
i ment do not do that in that same module
do the loadstart in the siokernelprx (which should be all kernel stuff) _________________ 10011011 00101010 11010111 10001001 10111010 |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Wed Nov 14, 2007 5:46 am Post subject: |
|
|
It needs to be kernel since you're messing with the hardware, but try setting k1 at the entry of the functions, and restoring it on exit.
| Code: | funct()
{
unsigned int k1;
k1 = pspSdkSetK1(0);
<stuff>
pspSdkSetK1(k1);
} |
|
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Wed Nov 14, 2007 5:49 am Post subject: |
|
|
yea above is recommended as well as k1 crap is all over
the newer firmwares ...shitty sony _________________ 10011011 00101010 11010111 10001001 10111010 |
|
| Back to top |
|
 |
deniska
Joined: 17 Oct 2005 Posts: 71 Location: New York
|
Posted: Wed Nov 14, 2007 5:51 am Post subject: |
|
|
| dot_blank wrote: | i ment do not do that in that same module
do the loadstart in the siokernelprx (which should be all kernel stuff) |
dot_blank, I am a little confused: I already dumped all the kernel stuff in to a separate module: sioprx.prx. Are you saying that I need to create yet another one? If so, could you sketch a few lines of code or point me to a similar example?
thanks for fast replies! |
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Wed Nov 14, 2007 6:06 am Post subject: |
|
|
no you do not need to create another one
your call to SceUID mod = pspSdkLoadStartModule("sioprx.prx", PSP_MEMORY_PARTITION_KERNEL);
is trying to access kernel partition of memory while in a userthread
so move that module stuff and rest to your (already) existing siokernel.prx _________________ 10011011 00101010 11010111 10001001 10111010 |
|
| Back to top |
|
 |
deniska
Joined: 17 Oct 2005 Posts: 71 Location: New York
|
Posted: Wed Nov 14, 2007 6:21 am Post subject: |
|
|
Setting the K1 fixed the problem.
Thanks a lot J.F. & dot_blank! |
|
| Back to top |
|
 |
|
|
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
|