/*******************************************************************/ /* */ /* Advanced Communication Borad Developer Toolkit */ /* (c)Copyright 1993-1995, Sealevel Systems Incorporated */ /* */ /*******************************************************************/ /* Please read the program abstract for details on this */ /* program. */ /* INT1.C */ /*******************************************************************/ #include #include #include #include "acb.h" #include "int.h" #define Z85230 #define Z85C30 #include "Z8530.h" /*******************************************************************/ /* Things to make the program "compiler friendly"! */ /*******************************************************************/ #ifndef _BORLAND #define IN _inp #define OUT _outp #define FAR __far #define INTERRUPT __cdecl __interrupt __far #define KBHIT _kbhit #else #define IN inportb #define OUT outportb #define FAR far #define INTERRUPT interrupt far #define KBHIT kbhit #endif /*******************************************************************/ #define PORT 0x238 /* Base Address of ACB card */ #define IRQ 0x05 /* interrupt request (IRQ 2-15) */ #define ESC 0x1B /* Keyboard "Esc" */ #define MAX_BUFFER 100 /* Size of Rx Buffer */ /*******************************************************************/ /* Z85x30 Init Values */ /*******************************************************************/ #define PRAM_COUNT 54 unsigned char init[PRAM_COUNT]= { WR0,NULL_CODE, /* MODES */ WR4, X16_CLOCK | STOP_BIT_1 | PARITY_DISABLE, WR1, WAIT_DMA_DISABLE | INT_DISABLE, WR2, 0x00, /* not used in polled mode */ WR3, RX_8_BITS, WR5, TX_8_BITS, WR6, 0x00, /* not used-SDLC Address field */ WR7, 0x00, /* not used-SDLC Flag */ WR9, MI_DISABLE, WR10, 0x00, /* not used in asynchronous */ WR11, TX_CLK_BRG | RX_CLK_BRG | TRXC_OUT_BRG, WR12, 0x06, /*time constant-low byte 19.2K Baud*/ WR13, 0x00, /*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 | RX_ENABLE, WR5, TX_8_BITS | TX_ENABLE | RTS_ON, 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 */ /*******************************************************************/ /*******************************************************************/ /* Function Prototypes */ /*******************************************************************/ void INTERRUPT isr(void); int main(void); /*******************************************************************/ unsigned int rx_ptr = 0; unsigned char RX_BUFFER[MAX_BUFFER]; /*******************************************************************/ int main(void) { void FAR *p; /* far void ptr*/ void (INTERRUPT *fp)(void); /* far void function ptr */ unsigned char c = 0; int ESCC = 0; /*******************************************************************/ /* 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, 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 and display the buffer contents.\n"); printf("\n"); /* For ACB-VI un-comment this line to enable on-board interrupts */ /* OUT(PORT+4, 0x40); */ SaveIRQMask(); /* Save the IRQ Mask*/ fp = isr; IRQSetupEx(IRQ ,fp); /*Save/Replace Interrupt Vector, etc. */ /*Interrupt on all Rx Char*/ SCCout(PORT ,WR1 ,RX_INT_ALL_CHAR_SP_COND); SCCout(PORT ,WR9 , MI_ENABLE); /*Master Interrupt Enable ON*/ do { if (KBHIT()) /*SW INT 16 hex function 1*/ { c = getch(); if (c != ESC) { OUT(PORT, c); /* Transmit character */ /*reset TX underrun*/ SCCout(PORT ,WR0, RESET_TX_UR_EOM); } } } while (c != ESC); SCCout(PORT ,WR9 ,MI_DISABLE); /*Master Interrupt Enable OFF*/ SCCout(PORT ,WR1 ,INT_DISABLE); /*All Interrupt conditions OFF*/ IRQUnsetup(IRQ); /*Restore Interrupt Vector, etc. */ ReturnIRQMask(); /*Restore IRQ Mask */ RX_BUFFER[MAX_BUFFER] = 0; /* append NULL to buffer*/ printf("%s\n",RX_BUFFER); /* Print buffer*/ return(0); } /*******************************************************************/ /* Interrupt Service Routine (ISR) */ /*******************************************************************/ void INTERRUPT isr(void) { unsigned char y; while ((SCCin(PORT, RR0)) & RX_CHAR_AVAIL) { /* While Character Avail*/ y = (unsigned char) IN(PORT); /* Read Character */ if(rx_ptr < MAX_BUFFER) /* if there is room in buffer */ { RX_BUFFER[rx_ptr] = y; /* put char in buffer */ rx_ptr++; /* inc buffer ptr */ } } #if (IRQ > 7) OUT(0xa0 ,0x20); /* AT PIC EOI */ #endif OUT(0x20, 0x20); /* XT PIC EOI */ } /*******************************************************************/ /* End of File */ /*******************************************************************/