/*******************************************************************/ /* */ /* Advanced Communication Borad Developer Toolkit */ /* (c)Copyright 1993-1995, Sealevel Systems Incorporated */ /* */ /*******************************************************************/ /* Please read the program abstract for details on this */ /* program. */ /* POLL3.C */ /* 08-23-96 vsg updated Rx. sync/hunt operation */ /*******************************************************************/ #include #include #include #include "acb.h" /*build with ACB.OBJ */ #define Z85230 #define Z85C30 #include "Z8530.h" #include "ASCII.h" /* or #include "EBCDIC.h" */ /*******************************************************************/ /* Things to make the program "compiler friendly"! */ /*******************************************************************/ #ifndef _BORLAND #define IN _inp #define OUT _outp #define FAR __far #define KBHIT _kbhit #else #define IN inportb #define OUT outportb #define FAR far #define KBHIT kbhit #endif /*******************************************************************/ /* Functions Prototypes */ /*******************************************************************/ int main(void); /*******************************************************************/ #define LOBYTE(w) ((unsigned char)(w)) #define HIBYTE(w) ((unsigned char)(((unsigned short)(w) >> 8) & 0xFF)) #define PORT 0x238 /* base address of 238 hex */ #define ESCKEY 27 /* keyboard character to terminate program */ #define F1KEY 0x3B /* keyboard character to terminate program */ #define MAXFRAME 100 /* Maximum BISYNC Message to receive */ /*******************************************************************/ /* Z85x30 Init Values */ /*******************************************************************/ #define PRAM_COUNT 54 unsigned char init[PRAM_COUNT]= { WR0,NULL_CODE, /* MODES */ WR4, X1_CLOCK | SYNC_MODE_ENABLE | SYNC_16_BIT, WR1, WAIT_DMA_DISABLE | INT_DISABLE, WR2, 0x00, /* not used in polled mode */ WR3, RX_8_BITS | RX_CRC_ENABLE | SYNC_CHAR_LOAD_INHIBIT , WR5, TX_8_BITS | CRC_16 | TX_CRC_ENABLE, WR6, SYN, /* SYNC Flag Low*/ WR7, SYN, /* SYCN Flag High*/ WR9, MI_DISABLE, WR10, CRC_PRESET_TO_ZERO, WR11, TX_CLK_BRG | RX_CLK_RTXC_PIN | TRXC_IS_OUTPUT | TRXC_OUT_BRG, WR12, 0xfe, /*time constant-low byte 4800 bps*/ WR13, 0x01, /*time constant-high byte */ WR14, BRG_SOURCE_PCLK | DPLL_NULL, WR14, BRG_SOURCE_PCLK | DPLL_NULL, WR14, BRG_SOURCE_PCLK | DPLL_NULL, WR14, BRG_ENABLE | BRG_SOURCE_PCLK | DPLL_NULL, /* ENABLES */ WR3, RX_8_BITS | SYNC_CHAR_LOAD_INHIBIT | RX_ENABLE | ENTER_HUNT_MODE, /* vsg */ WR5, TX_8_BITS | CRC_16 | TX_ENABLE, WR0, RESET_TX_CRC, WR0, ERROR_RESET, WR1, WAIT_DMA_DISABLE | INT_DISABLE, WR15, NO_EXT_STAT_INT, /*INTERRUPT*/ WR0, RESET_EXT_STATUS_INT, WR0, RESET_EXT_STATUS_INT, WR1, WAIT_DMA_DISABLE | INT_DISABLE, WR9, MI_DISABLE }; /*******************************************************************/ /* end of init table, adjust variable PRAM_COUNT after modifying */ /*******************************************************************/ unsigned char rxbuff[MAXFRAME]; unsigned short rxptr = 0; unsigned short Active = 0; /*******************************************************************/ /* Start of main program */ /*******************************************************************/ int main(void) { unsigned char cl = 0; unsigned char ch = 0; unsigned int s = 0; unsigned char c; int ESCC = 0; void FAR *p; /*******************************************************************/ /* Verify Address of SCC (85x30) */ /*******************************************************************/ SCCout(PORT, WR2, 0x55); /*write to WR2*/ if (SCCin(PORT, RR2) != 0x55) /*read back RR2*/ { printf("\nError: Device not found at address %x HEX.\n",PORT); return(1); /*return code 1 for ERROR*/ } else { printf("\nDevice verified at address %x HEX.\n",PORT); } /*******************************************************************/ /* Initialize ACB card */ /*******************************************************************/ SCCout(PORT, WR9, FORCE_HW_RESET); /* channel reset A and B */ /*******************************************************************/ /* Test for ESCC (85230) */ /*******************************************************************/ SCCout(PORT, WR15, WR7P_ACCESS); c = SCCin(PORT, RR15); if(c & 0x01) { SCCout(PORT, WR15, 0x00); c = SCCin(PORT, RR15); if((c & 0x01) == 0) ESCC = 1; } if( ESCC ) /* 85230 specific actions */ { printf("Detected an 85230.\n"); SCCout(PORT, WR15, WR7P_ACCESS); SCCout(PORT, WR7_PRIME, AUTO_EOM_RST | EX_READ_ENABLE ); SCCout(PORT, WR15, 0x00); } else { printf("Detected an 8530.\n"); SCCout(PORT, WR15, 0x00); } p = &init[0]; SCCInitEx(PORT, p, PRAM_COUNT); /* Initialize ACB */ /*******************************************************************/ /* Terminal */ /*******************************************************************/ printf("Type on the keyboard to send characters, press Esc to end the\n" \ "program or press F1 to enter SYNC/HUNT Mode.\n"); printf("\n"); do { if (KBHIT()) /*SW INT 16 hex function 1*/ { s = getch(); cl = LOBYTE(s); ch = HIBYTE(s); if (ch == F1KEY) { SCCout(PORT, WR3, RX_8_BITS | SYNC_CHAR_LOAD_INHIBIT | RX_ENABLE | ENTER_HUNT_MODE); } if (cl != ESCKEY) { OUT(PORT, STX); /* Start of Text */ while (!(SCCin(PORT, RR0) & TX_BUFFER_EMPTY)) { } OUT(PORT, cl); /* write character to data port */ while (!(SCCin(PORT, RR0) & TX_BUFFER_EMPTY)) { } OUT(PORT, ETX); /* End of Text or ETB*/ while (!(SCCin(PORT, RR0) & TX_BUFFER_EMPTY)) { } #ifdef ECHO printf("%c",cl); #endif } } /* end if */ if (SCCin(PORT, RR0) & RX_CHAR_AVAIL) /*RX char available? */ { cl = (unsigned char)IN(PORT); switch (cl) { case STX: Active = 1; break; case ETB: case ETX: SCCout(PORT, WR3, RX_8_BITS | SYNC_CHAR_LOAD_INHIBIT | RX_ENABLE | ENTER_HUNT_MODE); Active = 0; break; default: if (Active) { printf("%c", cl); } else { /* vsg - re-enter hunt mode if idle sync. broken */ /* program would quit receiving if int3 was stopped */ /* and restarted on other PC. - i.e. broken sync. idle */ SCCout( PORT,WR3, RX_8_BITS | SYNC_CHAR_LOAD_INHIBIT | RX_ENABLE | ENTER_HUNT_MODE); } break; } } /* end if */ } while (cl != ESCKEY); /* end do while*/ return(0); } /*******************************************************************/ /* End of File */ /*******************************************************************/