Category : Tutorials + Patches
Archive   : NAT_UART.ZIP
Filename : RWT8250.C

 
Output of file : RWT8250.C contained in archive : NAT_UART.ZIP
/* rwt8250.c

written: 1/18/89 by Louis Shay
National Semiconductor Corporation
Microcomputer Systems Division
Technical Support Engineering Center (TSEC)

This program will perform a functional register read/write
test on the NS16450-compatible register set at global base address
"int ubase". This address is defined by the calling program prior
to the function call. The routine will display errors as they are
encountered and return the integer number of errors found. The main
source program should include , , and "ns16550a.h"
header files.

*/
#include
#include
#include "ns16550a.h"

int rwt8250()
{
extern int ubase, fatal_error; /* reference globals */

static int reg[] = { 3, 3, 0, 0, 1, 1, 3, 1, 1, 4, 4 };
static int wrdata[] = { 0x55,0xaa,0x55,0xaa,0x55,0xaa,0x00,0xf5,0x0a,
0xfa,0xf5 };
static int expected[] = { 0x55,0xaa,0x55,0xaa,0x55,0xaa,0x00,0x05,0x0a,
0x1a,0x15 };
int count, rddata, r, errors = 0 ;

printf("NS16450/NS16550A Register Read/Write Test...\n");

/* register read/write test loop */
for( count = 0 ; count <= 10 ; count = count + 1 )
{ /* read/write test loop */

r = reg[count];
outp( ubase+r, wrdata[count] ); /* write uart register */
;
;
if(( rddata = inp( ubase+r )) != expected[count] )
{
printf(" reg = %1d wrdata = %2x expected = %2x rddata = %2x\n",
r, wrdata[count], expected[count], rddata );
errors += 1; /* count an error */
fatal_error = 1 ; /* r/w errors are potentially fatal */
}
}
/* test LSR & MSR r/w */
wrLSR( 0xf5 ); /* write LSR */
rddata = rdLSR(); /* read it back */
if(( rddata & 0x9f ) != 0x15 ) {
errors += 1;
printf(" wrLSR failed: wrdata = f5 rddata = %2x\n", rddata );
}
wrLSR( 0x0a ); /* write LSR */
rddata = rdLSR(); /* read it back */

if(( rddata & 0x9f ) != 0x0a ) {
errors += 1;
printf(" wrLSR failed: wrdata = 0a rddata = %2x\n", rddata );
}
wrMSR( 0x05 ); /* MSR */
rddata = rdMSR(); /* read it back */
if( ( rddata & 0x0f ) != 0x05 ) {
errors += 1;
printf(" wrMSR failed: wrdata = x5 rddata = %2x\n", rddata );
}
wrMSR( 0x0a ); /* write MSR */
rddata = rdMSR(); /* read it back */
if( ( rddata & 0x0f ) != 0x0a ) {
errors += 1;
printf(" wrMSR failed: wrdata = xa rddata = %2x\n", rddata );
}

return( errors );
}


  3 Responses to “Category : Tutorials + Patches
Archive   : NAT_UART.ZIP
Filename : RWT8250.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/