/*******************************************************************/ /* */ /* 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" #include "Z8530.h" /*******************************************************************/ /* Things to make the program "compiler friendly"! */ /*******************************************************************/ #ifndef _BORLAND #define IN _inp #define OUT _outp #define FAR __far void __cdecl __interrupt FAR isr(void); #else #define IN inportb #define OUT outportb #define FAR far void __interrupt FAR isr(void); #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 */ /*******************************************************************/ int main(void); /*******************************************************************/ unsigned int rx_ptr = 0; unsigned char RX_BUFFER[MAX_BUFFER]; /*******************************************************************/ int main(void) { void FAR *p; /* far void ptr*/ #ifndef _BORLAND void (__cdecl __interrupt FAR *fp)(void); /* far void function ptr */ #else void ( __interrupt FAR *fp)(void); /* far void function ptr */ #endif unsigned char c = 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*/ 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 (_bios_keybrd(_KEYBRD_READY)) /*SW INT 16 hex function 1*/ { c = (unsigned char)(_bios_keybrd(_KEYBRD_READ)); 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) */ /*******************************************************************/ #ifndef _BORLAND void __cdecl __interrupt FAR isr(void) #else void __interrupt FAR isr(void) #endif { unsigned char x, y; while ((x = 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 */ /*******************************************************************/