Category : Tutorials + Patches
Archive   : NAT_UART.ZIP
Filename : AFR552.C
written: 8/23/89 Welson Lin
National Semiconductor Corporation
This routine performs a functional test of the Alternate Function
Register Concurrent Write functions of the NS16C552.
*/
#include
#include
#include "ns16550a.h"
int afr552()
{
extern int ubase, ubase2, fatal_error;
int port_number2,count,errors=0,rddata;
printf("\nAlternate Function Register and Concurrent Write test\n");
printf("The other NS16C552 serial channel is :\n\n");
printf("\t1. SERIAL_1 (03f8-03ff)\n\t2. SERIAL_2 (02f8-02ff)\n");
printf("\t3. SERIAL_3 (3220-3227)\n\t4. SERIAL_4 (3228-322f)\n");
printf("\t5. SERIAL_5 (4220-4227)\n\t6. SERIAL_6 (4228-422f)\n");
printf("\t7. SERIAL_7 (5220-5227)\n\t8. SERIAL_8 (5228-522f)\n");
CH2_SEL:
printf("\nEnter number: ");
scanf( "%d", &port_number2 );
switch (port_number2) {
case 1 : ubase2 = SERIAL_1;
break;
case 2 : ubase2 = SERIAL_2;
break;
case 3 : ubase2 = SERIAL_3;
break;
case 4 : ubase2 = SERIAL_4;
break;
case 5 : ubase2 = SERIAL_5;
break;
case 6 : ubase2 = SERIAL_6;
break;
case 7 : ubase2 = SERIAL_7;
break;
case 8 : ubase2 = SERIAL_8;
break;
case 0x0d :
goto CH2_SEL;
break;
default :
goto CH2_SEL;
}
if ( ubase == ubase2 ) {
printf ("\n ** Invalid selection **\n");
goto CH2_SEL;
}
wrLCR (0x80 );
for (count =0 ; count < 8; count ++) /* write 0 - 7 to AFR */
{
wrAFR ( count );
rddata = rdAFR();
if ( rddata != count ) {
printf ("wrAFR failed: wrdata = %2x rddata = %2x\n ",count,rddata);
errors += 1;
}
}
wrAFR ( 0xf7);
rddata = rdAFR ();
if (rddata != 0x07) {
printf ("wrAFR failed: wrdata = f7 rddata = %2x\n ",rddata);
errors += 1;
}
wrLCR2( 0x80);
wrAFR ( 0x01);
wrMCR (0x1f);
rddata = rdMCR2();
if ( rddata != 0x1f ) {
printf( "\nConcurrent write failed : wr %3x 1f, rd %3x %2x",MCR,MCR2,rddata);
errors += 1 ;
}
wrMCR (0x00);
rddata = rdMCR2();
if ( rddata != 0x00 ) {
printf( "\nConcurrent write failed : wr %3x 00, rd 2FC %2x",MCR,MCR2,rddata);
errors += 1 ;
}
wrDLL (0x0aa);
rddata = rdDLL2();
if ( rddata != 0x0aa ) {
printf( "\nConcurrent write failed : wr %3x aa, rd %3x %2x",DLL,DLL2,rddata);
errors += 1 ;
}
wrDLL (0x55);
rddata = rdDLL2();
if ( rddata != 0x55 ) {
printf( "\nConcurrent write failed : wr %3x 55, rd %3x %2x",DLL,DLL2,rddata);
errors += 1 ;
}
wrDLM (0x0aa);
rddata = rdDLM2();
if ( rddata != 0x0aa ) {
printf( "\nConcurrent write failed : wr %3x aa, rd %3x %2x",DLM,DLM2,rddata);
errors += 1 ;
}
wrDLM (0x55);
rddata = rdDLM();
if ( rddata != 0x55 ) {
printf( "\nConcurrent write failed : wr %3x 55, rd %3x %2x",DLM,DLM2,rddata);
errors += 1 ;
}
wrLCR (0xaa);
rddata = rdLCR2();
if ( rddata != 0xaa ) {
printf( "\nConcurrent write failed : wr %3x aa, rd %3x %2x",LCR,LCR2,rddata);
errors += 1 ;
}
wrLCR (0x55);
rddata = rdLCR2();
if ( rddata != 0x55 ) {
printf( "\nConcurrent write failed : wr %3x 55, rd %3x %2x",LCR,LCR2,rddata);
errors += 1 ;
}
wrLCR (0x00);
wrIER (0x0f);
rddata = rdIER2();
if ( rddata != 0x0f ) {
printf( "\nConcurrent write failed : wr %3x 0f, rd %3x %2x",IER,IER2,rddata);
errors += 1 ;
}
wrIER (0x00);
rddata = rdIER2();
if ( rddata != 0x00 ) {
printf( "\nConcurrent write failed : wr %3x 00, rd %3x %2x",IER,IER2,rddata);
errors += 1 ;
}
wrSCR (0x0aa);
rddata = rdSCR2();
if ( rddata != 0x0aa ) {
printf( "\nConcurrent write failed : wr %3x aa, rd %3x %2x",SCR,SCR2,rddata);
errors += 1 ;
}
wrSCR (0x55);
rddata = rdSCR();
if ( rddata != 0x55 ) {
printf( "\nConcurrent write failed : wr %3x 55, rd %3x %2x",SCR,SCR2,rddata);
errors += 1 ;
}
wrLCR (0x80);
wrAFR (0x01);
wrLCR2 (0x80);
wrDLL (0x0c);
wrDLM (0x00);
wrLCR (0x0b);
wrMCR (0x10);
wrTHR (0xa5);
delay ();
delay ();
delay ();
rddata = rdRBR2();
if ( rddata != 0xa5 ) {
printf( "\nLoopback in Concurrent write failed : wr %3x a5, rd %3x %2x",THR,RBR2,rddata);
errors += 1 ;
}
wrTHR (0x5a);
delay ();
delay ();
delay ();
rddata = rdRBR2();
if ( rddata != 0x5a ) {
printf( "\nLoopback in Concurrent write failed : wr %3x 5a, rd %3x %2x",THR,RBR2,rddata);
errors += 1 ;
}
return(errors);
} /* end of afr552.c */
delay() /* function to provide time delay */
{
int n;
for(n=0;n<100;n++);
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
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/