Path: chuka.playstation.co.uk!scea!greg_labrec@interactive.sony.com From: Ed Federmeyer Newsgroups: scea.yaroze.freetalk Subject: Re: I/O on the Yaroze [non-blocking] Date: Fri, 23 Jan 1998 00:03:12 -0600 Organization: (no organization) Lines: 132 Message-ID: <34C832A0.1C35@charlie.cns.iit.edu> References: <34B29D0E.5D23@snrc.uow.edu.au> <34B4300A.3DD5@playstation.sony.com> <34B43B9E.4585@concentric.net> <34B50CA8.88D@playstation.sony.com> <34B70118.2D76@ix.netcom.com> Reply-To: fedeedw@charlie.cns.iit.edu NNTP-Posting-Host: charlie.cns.iit.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 3.0C-GZone (Win95; I) Spellweaver wrote: > It would be truly useful to know how to access the SIO port > directly, as the Yaroze libraries are not particularly swift at > times. This would also allow non-blocking polling of the port, > etc.; if anyone has figured out how to do this (or if Sony might > be persuaded to release some info regarding this), let me know > (or better yet, post it here or in the .hardware group so that > everyone can work on this underused but potentially very > interesting area of PSX development). If you've already figured this out, never mind. If not: here goes! Below is a demo program that polls the "tty" device, without blocking. The key is to "open" the device with the O_NBLOCK attribute. The only problem I've seen so far is that CTRL-S and CTRL-Q are used for flow control, so those characters need to be avoided. Maybe using a different program then "siocons" with "hardware flow control" enabled and "software flow control" disabled will get around this? Maybe there are "siocons" params that turn off Xon/Xoff? (software flow control) I'll also leave it to you to see if the "write" works simmilarly (ie, what happens if you write so much so fast the output buffer fills?), and to measure performance to see if it'll be truly useful. This example is written for clarity not speed. Hey, it's a start! Ed Federmeyer ------------------------ cut here ----------------------------- /* * Demo of NON-BLOCKING serial I/O on the Net Yaroze. * By: Ed Federmeyer */ #include #include #include /* * For some reason, the macros reference _ctype_, which * doesn't exist in the libps.a. So we do this the hard/kludgy way. * If someone knows the trick to making work in the * Yaroze-world, let me know... */ int isprint( char inchar ) { if ( (inchar >= 0x20) && (inchar <= 0x7E) ) { /* The character is 'printable'. */ return( 1 ); } /* The character is NOT 'printable'. */ return( 0 ); } int main( void ) { int ifd; int status; unsigned char inbyte; int toggle = 0; /* * Open the "tty" device in NON-BLOCKING mode, meaning when you * call "read" on it, if there are no characters, it will return * immediatly (with a status of "0", meaning "0" characters read), * instead of waiting for characters. */ ifd = open( "tty", O_RDWR | O_NBLOCK ); if ( ifd < 0 ) { printf( "Cannot open tty\n" ); return( -1 ); } printf( "Type characters (~ to exit):\n" ); while ( 1 ) { /* * Poll the 'tty' device to see if data has arrived. */ status = read( ifd, &inbyte, 1 ); if ( status < 0 ) { printf( "error in read. status=%d\n", status ); close( ifd ); return( -1 ); } if ( status == 1 ) { /* * Yay! Got a byte! Maybe do something cool like * build a protocol packet or something. We'll just * print it out for this demo though. */ printf( "got 0x%02X '%c'\n", inbyte, (isprint(inbyte) ? inbyte : '.') ); if ( inbyte == '~' ) { printf( "Exiting.\n" ); close( ifd ); return( 0 ); } } else if ( status == 0 ) { /* * Normally, do nothing. But for demonstration, * print some stuff so you know we're not blocked * on the 'read'. */ if ( ++toggle > 1000 ) { toggle = 0; printf( "." ); } } else { /* * I don't see how this could ever happen. :-) */ printf( "unexpected status=%d\n", status ); close( ifd ); return( 0 ); } } /* We should never really get here... */ close( ifd ); return( 0 ); }