 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
ZeroAltitude
Joined: 11 Sep 2006 Posts: 5 Location: Worcester, MA
|
Posted: Thu Sep 14, 2006 11:35 am Post subject: Noobish Question: pspDebugSioGetchar() |
|
|
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 |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Thu Sep 14, 2006 2:48 pm Post subject: |
|
|
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 |
|
 |
ZeroAltitude
Joined: 11 Sep 2006 Posts: 5 Location: Worcester, MA
|
Posted: Fri Sep 15, 2006 4:05 am Post subject: |
|
|
Thank you very much. This was very helpful.
~0 |
|
| Back to top |
|
 |
|
|
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
|