forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

PSP Crashes in exit.

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
angelo



Joined: 29 Aug 2007
Posts: 168

PostPosted: Sat May 03, 2008 7:11 pm    Post subject: PSP Crashes in exit. Reply with quote

Hello everybody. I'm kinda new to PSP programming, and I'm stuck on this one realy anoying issue.

I've edited the piKey Sample so it works and runs in the 3.XX kernel. I've also added a callback.

The anoying thing, is that it freezes on the "Please Wait..." screen after home is pressed.

What could be wrong? I think maybe IRDA is still active and the PSP doesn't like it, but yet a callback has been added which should stop that.

Here's the code:

Code:
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <stdlib.h>
#include <string.h>
#include <pikeylib.h>

#include "../sdk/pikeytypes.h"

/* Define the module info section */
PSP_MODULE_INFO("PIKEYTEST", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);
PSP_MAIN_THREAD_STACK_SIZE_KB(64);

/* Define printf, just to make typing easier */
#define printf   pspDebugScreenPrintf

   /* 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;
}

int done = 0;
int blink = 0;

int main(void)
{
   pspDebugScreenInit();
   SetupCallbacks();
   int ii;

   printf("piKey Sample.\n");

   initPikey();

   sceKernelDelayThread(1000000);

   printf("piKey is detected as %s\n", isPikeyLoaded() ? "running." : "not running.");

   requestExclusive();

   setMode(PIKEY_KEYMODE_KEYPRESS);

   sceKernelDelayThread(1000000);

   pspDebugScreenClear();

   pspDebugScreenSetXY(0, 5);
   printf("Waiting for keys, press ESC to exit...\n\n");

   while(!done)
   {
      sceKernelDelayThread(1000);  // don't tight-loop
      sceDisplayWaitVblank();
blink += 1;
      // clear old display
if(blink > 5){
      pspDebugScreenClear();
      blink = 0;
}

      pspDebugScreenSetXY(0, 5);
      printf("Waiting for keys, press 'Home' to exit...\n\n");

#if 0
      pspDebugScreenSetXY(0,7);
      for (ii = 7; ii < 20; ii++)
      {
         printf("                              \n");
      }
#endif

      // nothing to do if no keys pressed.
      if (numKeysPressed() == 0)
      {
         continue;
      }

      pspDebugScreenSetXY(0,7);
      for (ii = 0; ii < KEY_MAX; ii++)
      {
         if (isKeyPressed(ii))
         {
            printf("Pressed scancode: %d\n", ii);
         }
      }

      int ctrl, alt, shift;
      getMetaKeys(&alt, &ctrl, &shift);

      pspDebugScreenSetXY(0, 20);
      printf("  %s  %s  %s\n",
              ctrl?  "CTRL"  : "    ",
                alt?   "ALT"   : "   ",
                shift? "SHIFT" :   "     ");
   }
   sceKernelSleepThread();
   return 0;
}
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Insert_witty_name



Joined: 10 May 2006
Posts: 376

PostPosted: Sat May 03, 2008 7:50 pm    Post subject: Reply with quote

Well, for one you're creating your callback thread in kernel mode and you're not handling yielding the loop when the callback is called.

I would do something like this, not sure if it helps any or not :)

Code:
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <stdlib.h>
#include <string.h>
#include <pikeylib.h>

#include "../sdk/pikeytypes.h"

/* Define the module info section */
PSP_MODULE_INFO("PIKEYTEST", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);
PSP_MAIN_THREAD_STACK_SIZE_KB(64);

int done = 0; // moved so accessible by exit_callback

/* Define printf, just to make typing easier */
#define printf   pspDebugScreenPrintf

   /* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
        done = 1; // set done to 1 on callback
          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, PSP_THREAD_ATTR_USER, 0); // Changed to user mode
          if(thid >= 0) {
                    sceKernelStartThread(thid, 0, 0);
          }

          return thid;
}

int blink = 0;

int main(void)
{
   pspDebugScreenInit();
   SetupCallbacks();
   int ii;

   printf("piKey Sample.\n");

   initPikey();

   sceKernelDelayThread(1000000);

   printf("piKey is detected as %s\n", isPikeyLoaded() ? "running." : "not running.");

   requestExclusive();

   setMode(PIKEY_KEYMODE_KEYPRESS);

   sceKernelDelayThread(1000000);

   pspDebugScreenClear();

   pspDebugScreenSetXY(0, 5);
   printf("Waiting for keys, press ESC to exit...\n\n");

   while(!done)
   {
      sceKernelDelayThread(1000);  // don't tight-loop
      sceDisplayWaitVblank();
blink += 1;
      // clear old display
if(blink > 5){
      pspDebugScreenClear();
      blink = 0;
}

      pspDebugScreenSetXY(0, 5);
      printf("Waiting for keys, press 'Home' to exit...\n\n");

#if 0
      pspDebugScreenSetXY(0,7);
      for (ii = 7; ii < 20; ii++)
      {
         printf("                              \n");
      }
#endif

      // nothing to do if no keys pressed.
      if (numKeysPressed() == 0)
      {
         continue;
      }

      pspDebugScreenSetXY(0,7);
      for (ii = 0; ii < KEY_MAX; ii++)
      {
         if (isKeyPressed(ii))
         {
            printf("Pressed scancode: %d\n", ii);
         }
      }

      int ctrl, alt, shift;
      getMetaKeys(&alt, &ctrl, &shift);

      pspDebugScreenSetXY(0, 20);
      printf("  %s  %s  %s\n",
              ctrl?  "CTRL"  : "    ",
                alt?   "ALT"   : "   ",
                shift? "SHIFT" :   "     ");
   }
   sceKernelExitGame(); // Exit game when loop is broken
   return 0;
}


One more thing, I'm unsure how pikey works as I've never used it, but stay out of kernel mode whenever possible. If the pikey init is all that requires kernel mode, then spawn a user mode thread after that point to handle everything else.
Back to top
View user's profile Send private message
angelo



Joined: 29 Aug 2007
Posts: 168

PostPosted: Sat May 03, 2008 8:47 pm    Post subject: Broke it... Reply with quote

O.K...

Now it just boots up and freezes with a black screen.

Very odd.
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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