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 

Noobish Question: pspDebugSioGetchar()

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



Joined: 11 Sep 2006
Posts: 5
Location: Worcester, MA

PostPosted: Thu Sep 14, 2006 11:35 am    Post subject: Noobish Question: pspDebugSioGetchar() Reply with quote

Hello,

I'm new to PSP programming. I have a question about how to make sure my polling of the PSP serial port is synced.

First, is pspDebugSioGetchar() a blocking call? My assumption is 'no' based on the fact that it appears that the call returns -1 when there is 'nothing.'

This leads me to my second question. Suppose I have a 4800 baud communication device hooked up to my PSP (also set to 4800). Now, I want to poll the serial port. But, how do I make sure that my polls are synced to the available chars? For example, should I just,

while(condition)
{
ch = pspDebugSioGetchar();
// do something with ch
// ...
sceKernelDelayThread(1000000/4800);
}

And, does the SIO device have some kind of buffer so that if I, say, do something that takes 100ms, the next time I call Getchar(), I will get one that had been 'waiting' for a little bit?

I guess I'm asking, most simply: what is the canonical way to poll the serial port at an arbitrary baud rate?

Thank you,

~0
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Thu Sep 14, 2006 2:48 pm    Post subject: Reply with quote

The PSP hardware has a small FIFO buffer, yes. The pspDebugSioGetchar function returns -1 if that buffer is empty, otherwise it removes and returns a character from the buffer. See pspsdk/src/debug/sio.c for the source.

A simple way to receive characters (at any baud rate) is to just treat any non-negative result as a character. See samples/debug/sio/main.c for an example, which looks like:
Code:
while(1) {
  ch = pspDebugSioGetchar();
  if(ch >= 0) {
    pspDebugScreenPrintf("Received %\n", ch);
  }
}

A more efficient way to do this (which avoids polling like that) is to use the serial interrupt. See psplink source and the discussion starting around this post.
Back to top
View user's profile Send private message
ZeroAltitude



Joined: 11 Sep 2006
Posts: 5
Location: Worcester, MA

PostPosted: Fri Sep 15, 2006 4:05 am    Post subject: Reply with quote

Thank you very much. This was very helpful.

~0
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger 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