| View previous topic :: View next topic |
| Author |
Message |
Cy-4AH
Joined: 31 Jan 2007 Posts: 44 Location: Belarus
|
Posted: Wed Jan 31, 2007 11:56 pm Post subject: Interrupt Controller |
|
|
Hi to all. Actualy I am just started PSP Development.
Can somebody promt me where to read in details about Interrupt Controller on PSP and how to programm it, because "The Naked PSP" and "PSPSDK Doc" gives only light mention about it existance.
I tryed using some functions from pspintrman.h and pspintrman_kernel.h but my programms even not loaded.
Great thx for all help. |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Thu Feb 01, 2007 4:31 am Post subject: |
|
|
| Low-level direct access, or kernel function manipulation? The former has some info toward the bottom of the page here. The latter would be better addressed by someone else. |
|
| Back to top |
|
 |
adrahil
Joined: 16 Mar 2006 Posts: 277
|
Posted: Thu Feb 01, 2007 7:07 am Post subject: |
|
|
| uhmm... you just started, and you already want to use IRQs and NMIs? what an idea... Check groepaz's docs (google for yapspd) if needed... And since the PSP got a VERY good API set already, why would you need such low level? It's not a GBA, ya know? Everything is handled thry sce* libs: display, sound, pad... |
|
| Back to top |
|
 |
Cy-4AH
Joined: 31 Jan 2007 Posts: 44 Location: Belarus
|
Posted: Thu Feb 01, 2007 8:47 pm Post subject: |
|
|
I tryed functions sceKernelRegisterIntrHandler and sceKernelDisableIntr in programm with PSP_MODULE_KERNEL attribute but it stopped after calling them. So I'd like to know how to use them.
Also I'd like to know PSP ASM commands. |
|
| Back to top |
|
 |
Tinnus
Joined: 29 Jul 2006 Posts: 67
|
Posted: Thu Feb 01, 2007 9:23 pm Post subject: |
|
|
The PSP is an Allegrex CPU, so look for that or simply MIPS assembly.
There are the VFPU ops--check those out in yapspd and the VFPu diggins topic here. _________________ Let's see what the PSP reserves... well, I'd say anything is better than Palm OS. |
|
| Back to top |
|
 |
adrahil
Joined: 16 Mar 2006 Posts: 277
|
Posted: Fri Feb 02, 2007 4:58 am Post subject: |
|
|
| Cy-4AH wrote: | I tryed functions sceKernelRegisterIntrHandler and sceKernelDisableIntr in programm with PSP_MODULE_KERNEL attribute but it stopped after calling them. So I'd like to know how to use them.
Also I'd like to know PSP ASM commands. |
Bump. Sorry to say it, but if you didn't manage to get it working with sce*, you won't be able to go much further... Did you set the MAIN_THREAD_ATTR to 0? and 0x1000 attr in MODULE_INFO? |
|
| Back to top |
|
 |
Cy-4AH
Joined: 31 Jan 2007 Posts: 44 Location: Belarus
|
Posted: Fri Feb 02, 2007 10:01 pm Post subject: |
|
|
| adrahil wrote: | | Bump. Sorry to say it, but if you didn't manage to get it working with sce*, you won't be able to go much further... Did you set the MAIN_THREAD_ATTR to 0? and 0x1000 attr in MODULE_INFO? |
Yes, when I use
| Quote: | | PSP_MODULE_INFO("Irq Test", PSP_MODULE_USER, 1, 1); | programm even not start,
when
| Quote: | | PSP_MODULE_INFO("Irq Test", PSP_MODULE_KERNEL, 1, 1); |
programm crash when calling sceKernelRegisterIntrHandler or sceKernelDisableIntr.[/quote] |
|
| Back to top |
|
 |
adrahil
Joined: 16 Mar 2006 Posts: 277
|
Posted: Fri Feb 02, 2007 10:22 pm Post subject: |
|
|
| Well, post the app code then... |
|
| Back to top |
|
 |
Cy-4AH
Joined: 31 Jan 2007 Posts: 44 Location: Belarus
|
Posted: Fri Mar 16, 2007 3:30 am Post subject: |
|
|
Ok, now I back to problem with Interrupt Controller.
Resently I found in psplink sources
| Code: | sceKernelRegisterIntrHandler(PSP_HPREMOTE_INT, 1, intr_handler, NULL, NULL);
sceKernelEnableIntr(PSP_HPREMOTE_INT); |
And then found topick http://forums.ps2dev.org/viewtopic.php?t=6294&highlight=&sid=195650e91e5af118b0f2367f3c53508c with TyRaNiD advice to use void *func = (void *) ((unsigned int) intr_handler | 0x80000000);
So, there is my code:
| Code: | #include <CyLib.h>
PSP_MODULE_INFO("IntTest", PSP_MODULE_KERNEL, 1, 0);
PSP_MAIN_THREAD_ATTR(0);
#define SC 200000
static int handler (void *p)
{
pspDebugScreenPrintf("handler\n");
return -1;
}
int main()
{
bool need_exit;
SetupCallbacks(&need_exit);
pspDebugScreenInit();
sceCtrlSetSamplingCycle(SC);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL);
SceCtrlLatch latch;
int res = sceKernelRegisterIntrHandler(PSP_HPREMOTE_INT, 1, (void*)handler, NULL, NULL);
pspDebugScreenPrintf("Intr Init Res: 0x%08X\n", res);
void *func = (void *) ((unsigned int) handler | 0x80000000);
res = sceKernelRegisterIntrHandler(PSP_HPREMOTE_INT, 1, func, NULL, NULL);
pspDebugScreenPrintf("Intr Init Res: 0x%08X\n", res);
pspDebugScreenPrintf("press triangle for exit\n");
while (!need_exit)
{
sceCtrlReadLatch(&latch);
if (latch.uiMake & PSP_CTRL_TRIANGLE) need_exit = true;
}
sceKernelExitGame();
return 0;
}
|
| Code: | TARGET = IntTest
OBJS = IntTest.o ../CyLib/Src/CyLib.o
CFLAGS = -O2 -G0 -Wall -I../CyLib/Include
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBS= -lpspgu
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = IntTest
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
|
FW 3.03OE-C
In both cases I get error code 0x80020067.
What's wrong with this code? |
|
| Back to top |
|
 |
adrahil
Joined: 16 Mar 2006 Posts: 277
|
Posted: Fri Mar 16, 2007 8:56 am Post subject: |
|
|
| Lookup the error code on google :) it will tell you "Handler already exists". You're trying to register a handler for an interrrupt being handled already. Sorry :P |
|
| Back to top |
|
 |
hlide
Joined: 10 Sep 2006 Posts: 750
|
Posted: Fri Mar 16, 2007 9:59 am Post subject: |
|
|
| to put it bluntly, you first need to unregister this interrupt handler. |
|
| Back to top |
|
 |
Cy-4AH
Joined: 31 Jan 2007 Posts: 44 Location: Belarus
|
Posted: Fri Mar 16, 2007 8:15 pm Post subject: |
|
|
Thx, adrahil, now I know where find meaning of error codes. BTW, do you know if some one wrote lib, where I can find function that convert error code to readable string?
And now next problem: I want call old irq handler in my handler, so I'd like to know how get its offset.
I was theanking that sceKernelRegisterIntrHandler gives me old handler, but I don't know how, because of
| Code: | arg1 - Unknown (probably a set of flags)
arg2 - Unknown (probably a common pointer) |
May be there is exist flag, that make psp replace irq handler with mine and return old handler in arg2.
So I found function QueryIntrHandlerInfo. And use it in that way:
| Code: | int arg1 = 0, arg2 = 0, res;
PspIntrHandlerOptionParam int_par;
sceKernelDisableIntr(IRQ);
res = QueryIntrHandlerInfo(IRQ, SUB_IRQ, &int_par);
pspDebugScreenPrintf("Query Res: 0x%08X 0x%08X\n", res, int_par.entry);
res = sceKernelReleaseIntrHandler(IRQ);
pspDebugScreenPrintf("Intr Release Res: 0x%08X\n", res);
void *func = (void *) ((unsigned int) handler | 0x80000000);
res = sceKernelRegisterIntrHandler(IRQ, SUB_IRQ, func, NULL, NULL);
pspDebugScreenPrintf("Intr Init Res: 0x%08X\n0x%08X\n", res, arg1);
res = QueryIntrHandlerInfo(IRQ, SUB_IRQ, &int_par);
pspDebugScreenPrintf("Query Res: 0x%08X 0x%08X 0x%08X\n", res, int_par.entry, handler);
sceKernelEnableIntr(IRQ);
|
Functions sceKernelReleaseIntrHandler and sceKernelRegisterIntrHandler return 0, but QueryIntrHandlerInfo return 0x8002006B witch mean ILLEGAL_INTRPARAM. And now I can't understand what is illegal in IRQ, SUB_IRQ and pointer to int_par, if thay worked for sceKernelRegisterIntrHandler and sceKernelReleaseIntrHandler |
|
| Back to top |
|
 |
hlide
Joined: 10 Sep 2006 Posts: 750
|
Posted: Fri Mar 16, 2007 8:38 pm Post subject: |
|
|
which of the first or the second QueryIntrHandlerInfo returns 0x8002006B ?
i think SUBIRQ must be between 0 and 31, but here for PSP_HPREMOTE, you don't have subirq, so you probably need to give 0 instead of 1, assuming for IRQ having no subirq have a SUBIRQ # to 0.
Last edited by hlide on Fri Mar 16, 2007 8:50 pm; edited 1 time in total |
|
| Back to top |
|
 |
Cy-4AH
Joined: 31 Jan 2007 Posts: 44 Location: Belarus
|
Posted: Fri Mar 16, 2007 8:43 pm Post subject: |
|
|
| Both :( |
|
| Back to top |
|
 |
hlide
Joined: 10 Sep 2006 Posts: 750
|
Posted: Fri Mar 16, 2007 8:50 pm Post subject: |
|
|
| i think SUBIRQ must be between 0 and 31, but here for PSP_HPREMOTE, you don't have subirq, so you probably need to give 0 instead of 1, assuming for IRQ having no subirq have a SUBIRQ # to 0. |
|
| Back to top |
|
 |
hlide
Joined: 10 Sep 2006 Posts: 750
|
Posted: Fri Mar 16, 2007 8:57 pm Post subject: |
|
|
just before calling QueryIntrHandlerInfo, try to do :
| Code: |
memset(&int_par, 0, sizeof(int_par));
int_par.size = sizeof(int_par);
|
maybe this param needs that you put the size of your structure (in case of different structure for old firmware revisions, meseems to recall something like that). |
|
| Back to top |
|
 |
hlide
Joined: 10 Sep 2006 Posts: 750
|
|
| Back to top |
|
 |
Cy-4AH
Joined: 31 Jan 2007 Posts: 44 Location: Belarus
|
Posted: Fri Mar 16, 2007 9:07 pm Post subject: |
|
|
Thx, hlide. It's worked!!!
I think I should add by myself to pspsdk: "Before using PspIntrHandlerOptionParam initialize field 'size' of PspIntrHandlerOptionParam" |
|
| Back to top |
|
 |
hlide
Joined: 10 Sep 2006 Posts: 750
|
Posted: Fri Mar 16, 2007 9:09 pm Post subject: |
|
|
| By the way, this function doesn't have an usual naming : we should normally have sceKernelQueryIntrHandlerInfo. So i suspect it to be an internal function (exported for only internal usage, i mean). It means that the param structure may change between firmware versions. The size may be a helper for the function to check if a program calls this function with an old param structure (size being different). Only my guess. I may be totally wrong of course. |
|
| Back to top |
|
 |
Cy-4AH
Joined: 31 Jan 2007 Posts: 44 Location: Belarus
|
Posted: Fri Mar 16, 2007 10:57 pm Post subject: |
|
|
Sorry for all day noob questions, but how call old handler?
I have such code, that didn't work:
| Code: | int (*old_handler)(void*);
int handler (void *p)
{
pspDebugScreenPrintf("handler 0x%08X\n", old_handler);
return (*old_handler)(p);
}
int main()
{
...
memset(&int_par, 0, sizeof(PspIntrHandlerOptionParam));
int_par.size = sizeof(PspIntrHandlerOptionParam);
res = QueryIntrHandlerInfo(IRQ, SUB_IRQ, &int_par);
old_handler = (int (*)(void*))int_par.entry;
pspDebugScreenPrintf("Query Res: 0x%08X 0x%08X 0x%08X\n", res, int_par.entry, old_handler);
...
|
Look like all perfectly inited, but when interrupt occur I see on PSP Screen "handler 0x..." and after few seconds PSP shut down. |
|
| Back to top |
|
 |
hlide
Joined: 10 Sep 2006 Posts: 750
|
Posted: Fri Mar 16, 2007 11:12 pm Post subject: |
|
|
| Cy-4AH wrote: |
Look like all perfectly inited, but when interrupt occur I see on PSP Screen "handler 0x..." and after few seconds PSP shut down. |
i would suggest you to have a simple counter instead of pspDebugScreenPrintf in your handler and polling this counter in the main function. That way you will know if pspDebugScreenPrintf is not the trouble. |
|
| Back to top |
|
 |
Cy-4AH
Joined: 31 Jan 2007 Posts: 44 Location: Belarus
|
Posted: Tue Mar 20, 2007 1:09 am Post subject: |
|
|
| Without pspDebugScreenPrintf programm become more stable, but not enough: at some interrupts programm on exit print debug information, at others crash with reboot PSP. |
|
| Back to top |
|
 |
|