Interrupt Controller

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Cy-4AH
Posts: 44
Joined: Wed Jan 31, 2007 9:58 pm
Location: Belarus

Interrupt Controller

Post by Cy-4AH »

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.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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.
adrahil
Posts: 274
Joined: Thu Mar 16, 2006 1:55 am

Post by adrahil »

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...
Cy-4AH
Posts: 44
Joined: Wed Jan 31, 2007 9:58 pm
Location: Belarus

Post by Cy-4AH »

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.
Tinnus
Posts: 67
Joined: Sat Jul 29, 2006 1:12 am

Post by Tinnus »

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.
adrahil
Posts: 274
Joined: Thu Mar 16, 2006 1:55 am

Post by adrahil »

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?
Cy-4AH
Posts: 44
Joined: Wed Jan 31, 2007 9:58 pm
Location: Belarus

Post by Cy-4AH »

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
PSP_MODULE_INFO("Irq Test", PSP_MODULE_USER, 1, 1);
programm even not start,
when
PSP_MODULE_INFO("Irq Test", PSP_MODULE_KERNEL, 1, 1);
programm crash when calling sceKernelRegisterIntrHandler or sceKernelDisableIntr.[/quote]
adrahil
Posts: 274
Joined: Thu Mar 16, 2006 1:55 am

Post by adrahil »

Well, post the app code then...
Cy-4AH
Posts: 44
Joined: Wed Jan 31, 2007 9:58 pm
Location: Belarus

Post by Cy-4AH »

Ok, now I back to problem with Interrupt Controller.
Resently I found in psplink sources

Code: Select all

		sceKernelRegisterIntrHandler(PSP_HPREMOTE_INT, 1, intr_handler, NULL, NULL);
		sceKernelEnableIntr(PSP_HPREMOTE_INT);
And then found topick http://forums.ps2dev.org/viewtopic.php? ... 7f3c53508c with TyRaNiD advice to use void *func = (void *) ((unsigned int) intr_handler | 0x80000000);

So, there is my code:

Code: Select all

#include <CyLib.h>

PSP_MODULE_INFO&#40;"IntTest", PSP_MODULE_KERNEL, 1, 0&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;;

#define SC 200000

static int handler &#40;void *p&#41;
&#123;
    pspDebugScreenPrintf&#40;"handler\n"&#41;;
    return -1;
&#125;

int main&#40;&#41;
&#123;
    bool need_exit;
    SetupCallbacks&#40;&need_exit&#41;;
    pspDebugScreenInit&#40;&#41;;
    
    sceCtrlSetSamplingCycle&#40;SC&#41;;
    sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_DIGITAL&#41;;
    
    SceCtrlLatch latch;  
    
    int res = sceKernelRegisterIntrHandler&#40;PSP_HPREMOTE_INT, 1, &#40;void*&#41;handler, NULL, NULL&#41;;
    pspDebugScreenPrintf&#40;"Intr Init Res&#58; 0x%08X\n", res&#41;;
 
    void *func = &#40;void *&#41; &#40;&#40;unsigned int&#41; handler | 0x80000000&#41;;
    res = sceKernelRegisterIntrHandler&#40;PSP_HPREMOTE_INT, 1, func, NULL, NULL&#41;;
    pspDebugScreenPrintf&#40;"Intr Init Res&#58; 0x%08X\n", res&#41;;

    pspDebugScreenPrintf&#40;"press triangle for exit\n"&#41;;
    while &#40;!need_exit&#41;
    &#123;
        sceCtrlReadLatch&#40;&latch&#41;;
        if &#40;latch.uiMake & PSP_CTRL_TRIANGLE&#41; need_exit = true;
    &#125;
    sceKernelExitGame&#40;&#41;;
    return 0;
&#125;

Code: Select all

TARGET = IntTest
OBJS = IntTest.o ../CyLib/Src/CyLib.o

CFLAGS = -O2 -G0 -Wall -I../CyLib/Include
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBS= -lpspgu

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = IntTest

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
FW 3.03OE-C
In both cases I get error code 0x80020067.
What's wrong with this code?
adrahil
Posts: 274
Joined: Thu Mar 16, 2006 1:55 am

Post by adrahil »

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
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

to put it bluntly, you first need to unregister this interrupt handler.
Cy-4AH
Posts: 44
Joined: Wed Jan 31, 2007 9:58 pm
Location: Belarus

Post by Cy-4AH »

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: Select all

arg1 	- Unknown &#40;probably a set of flags&#41; 
arg2 	- Unknown &#40;probably a common pointer&#41;
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: Select all

    int arg1 = 0, arg2 = 0, res;
    PspIntrHandlerOptionParam int_par;   
    sceKernelDisableIntr&#40;IRQ&#41;;
    
    res = QueryIntrHandlerInfo&#40;IRQ, SUB_IRQ, &int_par&#41;;
    pspDebugScreenPrintf&#40;"Query Res&#58; 0x%08X 0x%08X\n", res, int_par.entry&#41;;
    res = sceKernelReleaseIntrHandler&#40;IRQ&#41;;
    pspDebugScreenPrintf&#40;"Intr Release Res&#58; 0x%08X\n", res&#41;;
 
    void *func = &#40;void *&#41; &#40;&#40;unsigned int&#41; handler | 0x80000000&#41;;
    res = sceKernelRegisterIntrHandler&#40;IRQ, SUB_IRQ, func, NULL, NULL&#41;;
    pspDebugScreenPrintf&#40;"Intr Init Res&#58; 0x%08X\n0x%08X\n", res, arg1&#41;;

    res = QueryIntrHandlerInfo&#40;IRQ, SUB_IRQ, &int_par&#41;;
    pspDebugScreenPrintf&#40;"Query Res&#58; 0x%08X 0x%08X 0x%08X\n", res, int_par.entry, handler&#41;;
    
    sceKernelEnableIntr&#40;IRQ&#41;;
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
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

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.
Cy-4AH
Posts: 44
Joined: Wed Jan 31, 2007 9:58 pm
Location: Belarus

Post by Cy-4AH »

Both :(
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

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.
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

just before calling QueryIntrHandlerInfo, try to do :

Code: Select all

memset&#40;&int_par, 0, sizeof&#40;int_par&#41;&#41;;
int_par.size = sizeof&#40;int_par&#41;;
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).
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

An partial answer is given here : http://forums.ps2dev.org/viewtopic.php? ... andlerinfo

this topic said it always returns this error code for system intr, but you can still get infos apparently.

But I strongly suggest for you to try to set the size in int_parm if it discards the error code.
Cy-4AH
Posts: 44
Joined: Wed Jan 31, 2007 9:58 pm
Location: Belarus

Post by Cy-4AH »

Thx, hlide. It's worked!!!
I think I should add by myself to pspsdk: "Before using PspIntrHandlerOptionParam initialize field 'size' of PspIntrHandlerOptionParam"
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

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.
Cy-4AH
Posts: 44
Joined: Wed Jan 31, 2007 9:58 pm
Location: Belarus

Post by Cy-4AH »

Sorry for all day noob questions, but how call old handler?
I have such code, that didn't work:

Code: Select all

int &#40;*old_handler&#41;&#40;void*&#41;;
int handler &#40;void *p&#41;
&#123;
    pspDebugScreenPrintf&#40;"handler 0x%08X\n", old_handler&#41;;
    return &#40;*old_handler&#41;&#40;p&#41;;
&#125;

int main&#40;&#41;
&#123;
...
    memset&#40;&int_par, 0, sizeof&#40;PspIntrHandlerOptionParam&#41;&#41;;
    int_par.size = sizeof&#40;PspIntrHandlerOptionParam&#41;;
    res = QueryIntrHandlerInfo&#40;IRQ, SUB_IRQ, &int_par&#41;;
    old_handler = &#40;int &#40;*&#41;&#40;void*&#41;&#41;int_par.entry;
    pspDebugScreenPrintf&#40;"Query Res&#58; 0x%08X 0x%08X 0x%08X\n", res, int_par.entry, old_handler&#41;;
...
Look like all perfectly inited, but when interrupt occur I see on PSP Screen "handler 0x..." and after few seconds PSP shut down.
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

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.
Cy-4AH
Posts: 44
Joined: Wed Jan 31, 2007 9:58 pm
Location: Belarus

Post by Cy-4AH »

Without pspDebugScreenPrintf programm become more stable, but not enough: at some interrupts programm on exit print debug information, at others crash with reboot PSP.
Post Reply