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 

Calling a function periodically

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



Joined: 25 May 2006
Posts: 8

PostPosted: Sat Nov 11, 2006 4:06 pm    Post subject: Calling a function periodically Reply with quote

Hi,

I need a function to be called every x milliseconds. I have used the following functions on Windows : SetTimer() and KillTimer().

I looked into the PSPSDK documentation and the only two functions that I found (that I think could do the job) are the following: sceKernelSetAlarm() and sceKernelCancelAlarm().

However, I am not sure how to use these. The documentation does not provide too much information on these. I want to know if these are the appropriate functions to do a periodic call.

I was wondering if anyone has already used these and could point me in the right direction on what parameters to pass (small example).

Thanks.
Back to top
View user's profile Send private message
adrahil



Joined: 16 Mar 2006
Posts: 277

PostPosted: Sat Nov 11, 2006 8:07 pm    Post subject: Reply with quote

uhm..... why not do a thread with low priority which has something like:
Code:
while(!quit){
sceKernelDelayThread(milliseconds);
my_function();
}
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Sat Nov 11, 2006 8:23 pm    Post subject: Reply with quote

I dont know what part of the documentation you say is lacking but in my eyes it makes perfect sense.

i.e. do
Code:
SceUInt alarm_handler(void *common)
{
    // Do something, wont run in a thread so will have to set a semaphore or event flag
}

void set_alarm(void)
{
   SceUID uid;

   // Set an alarm for 1 second in the future
   uid = sceKernelSetAlarm(1000000, alarm_handler, NULL);
}
Back to top
View user's profile Send private message
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