/*******************************************************************/ /* */ /* Advanced Communication Borad Developer Toolkit */ /* (c)Copyright 1993-1995, Sealevel Systems Incorporated */ /* */ /*******************************************************************/ /* Please read the program abstract for details on this */ /* program. */ /* DMA3.C */ /*******************************************************************/ #include #include #include #include "acb.h" #include "dma.h" #include "Z8530.h" #include "ASCII.h" /* or EBCDIC.h for different control characters*/ /*******************************************************************/ /* Things to make the program "compiler friendly"! */ /*******************************************************************/ #ifndef _BORLAND #define IN _inp #define OUT _outp #define FAR __far #else #define IN inportb #define OUT outportb #define FAR far #endif /*******************************************************************/ #define PORT 0x238 #define TERM_COUNT 44 /* Number of characters in buffer excluding STX and ETB */ /*******************************************************************/ /* Prototypes */ /*******************************************************************/ void printBuffer(unsigned char FAR *ptr); int cmp(void); int main(void); /*******************************************************************/ /* Z85x30 Init Values */ /*******************************************************************/ #define PRAM_COUNT 54 unsigned char init[PRAM_COUNT]= /*BISYNC initialization */ { 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, 0x7e, /*time constant-low byte 19.2K 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, 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 */ /*******************************************************************/ /*******************************************************************/ /* Rx and Tx Buffers */ /*******************************************************************/ unsigned char rxbuff[TERM_COUNT+5]; /*RX_BUFFER*/ unsigned char Alt_rxbuff[TERM_COUNT+5]; /*Alternate RX_BUFFER*/ /* Please note that when using BISYNC that the STX (Start of Text) and End Text Buffer control codes must be sent at the start and end of the BISYNC text message. The keyboard combination of Alt+2 (2 should be type from the NumPad) will supply the STX (also in ASCII.H) and Alt+3 (from NumPad) will supply ETB (ASCII.H). */ unsigned char txbuff[TERM_COUNT+5] = "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG"; unsigned char Alt_txbuff[TERM_COUNT+5] = "The Quick Brown Fox Jumped Over The Lazy Dog"; /*45 CHARACTERS INCLUDING /n */ int AltTxBuffer = 0; int AltRxBuffer = 0; unsigned char c; void FAR *fp, *fpA, *fpB; /*Far pointer for DMA buffer*/ unsigned short RxTC; /*******************************************************************/ /*******************************************************************/ int main (void) { printf("\nAdvanced Communication Board DMA Test Program.\n\n"); /*******************************************************************/ /* Verify Address of SCC (85x30) */ /*******************************************************************/ SCCout(PORT, WR2,0x55); /*write to WR2*/ if (SCCin(PORT, WR2)!=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*/ fp = &init[0]; SCCInitEx(PORT ,fp ,PRAM_COUNT); /*Initialize ACB */ printf("\nBase Address: %X",PORT); printf("\nRx DMA channel: 1"); printf("\nTx DMA channel: 3"); printf("\n"); /* Clean SCC FIFO, just a precaution */ while( RX_CHAR_AVAIL & (c = SCCin(PORT, RR0))) { c = (unsigned char) IN(PORT); } SingleMaskDMA(SETDMA1); /* Turn DMA off at the DMA controller */ SingleMaskDMA(SETDMA3); /* before we program the DMA channel*/ /* Program Rx DMA on Channel 1 using WAIT/REQ */ SCCout(PORT, WR1, WAIT_REQ_ENABLE | WAIT_DMA_FUNCTION | WAIT_DMA_RX); fp = rxbuff; if (CheckDMAPageEx(TERM_COUNT,fp)) { fp = Alt_rxbuff; } SetDMAMode(RX1); SetPageRegisterEx(DMA1, fp); SetTC(DMA1,TERM_COUNT+1); /* Normal Terminal Count */ /* Add 2 for 16 bit CRC */ /* Program Tx DMA on Channel 3 using DTR/REQ */ SCCout(PORT, WR14, BRG_ENABLE | BRG_SOURCE_PCLK | REQUEST_FUNCTION); fp = txbuff; if (CheckDMAPageEx(TERM_COUNT,fp)) { fp = Alt_txbuff; } SetDMAMode(TX3); SetPageRegisterEx(DMA3, fp); SetTC(DMA3,TERM_COUNT+1); /* Normal Terminal Count */ /* Add 2 for 16 bit CRC */ /* Unmask DMA channels to begin DMA transfer, NOTE: Rx DMA first */ SingleMaskDMA(CLEARDMA1); SingleMaskDMA(CLEARDMA3); /* Wait in this loop else keyboard or Rx Terminal Count */ while (((RxTC = GetTC(DMA1)) != 0xffff) && (!_bios_keybrd(_KEYBRD_READY))) { printf("."); } if (_bios_keybrd(_KEYBRD_READY)) { c = (unsigned char)_bios_keybrd(_KEYBRD_READ); } printf("\nRx DMA 1 TC = %X ",GetTC(DMA1)); printf("\nTx DMA 3 TC = %X ",GetTC(DMA3)); /*Disable DMA channels at the DMA controller */ SingleMaskDMA(SETDMA1); SingleMaskDMA(SETDMA3); /* Turn off DTR/REQ and WAIT/REQ on the SCC*/ SCCout(PORT, WR14, BRG_ENABLE | BRG_SOURCE_PCLK ); SCCout(PORT, WR1, WAIT_DMA_DISABLE); /* Send End of Text (or ETB) control code for BISYNC*/ OUT(PORT, ETX); /* If were receiveing another message, an ENTER SYNC/HUNT mode command would be inserted here. */ printf("\n\n"); printf("TX DATA: "); if (AltTxBuffer) { printBuffer(Alt_txbuff); } else { printBuffer(txbuff); } printf("\n"); printf("RX DATA: "); if (AltRxBuffer) { printBuffer(Alt_rxbuff); } else { printBuffer(rxbuff); } printf("\n"); if (cmp()) { printf("Data Error.\n"); return(1); } else { printf("Buffers Compare OK.\n"); } return(0); } /*******************************************************************/ /* This routine will compare the transmit and receive */ /* buffers and print and differences */ /*******************************************************************/ int cmp(void) { unsigned char *rp, *tp; int i; int value = 0; if (AltRxBuffer) { rp = Alt_rxbuff; } else { rp = rxbuff; } if (AltTxBuffer) { tp = Alt_txbuff; } else { tp = txbuff; } for (i = 0 ;i <= TERM_COUNT; i++) { if(rp[i] != tp[i]) { printf("Received: %X\tExpected: %X\t\t",rp[i],tp[i]); value=1; } } return value; } /*******************************************************************/ /* This routine will print the specified buffer excluding the */ /* control characters (STX,ETX, and ETB) */ /*******************************************************************/ void printBuffer(unsigned char FAR *ptr) { int i; unsigned char c; for (i = 0; i < TERM_COUNT+2; i++) { c = ptr[i]; switch(c) { case STX: break; case ETX: case ETB: SCCout(PORT, WR3, RX_8_BITS | SYNC_CHAR_LOAD_INHIBIT | RX_ENABLE | ENTER_HUNT_MODE); break; default: printf("%c",c); break; } } } /*******************************************************************/ /* END OF FILE */ /*******************************************************************/