/*******************************************************************/ /* */ /* Advanced Communication Borad Developer Toolkit */ /* (c)Copyright 1993-1995, Sealevel Systems Incorporated */ /* */ /*******************************************************************/ /* Please read the program abstract for details on this */ /* program. */ /* DMA1.C */ /*******************************************************************/ #include #include #include #include "acb.h" #include "dma.h" #include "Z8530.h" /*******************************************************************/ /* Things to make the program "compiler friendly"! */ /*******************************************************************/ #ifndef _BORLAND #define IN _inp #define FAR __far #else #define IN inportb #define FAR far #endif /*******************************************************************/ #define PORT 0x238 #define TERM_COUNT 45 /*******************************************************************/ /* Prototypes */ /*******************************************************************/ int cmp(void); int main(void); /*******************************************************************/ /* 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 */ /*******************************************************************/ /*******************************************************************/ /* Rx and Tx Buffers */ /*******************************************************************/ unsigned char rxbuff[TERM_COUNT+5]; /*RX_BUFFER*/ unsigned char Alt_rxbuff[TERM_COUNT+5]; /*Alternate RX_BUFFER*/ unsigned char txbuff[]="THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG\n"; unsigned char Alt_txbuff[]="The Quick Brown Fox Jumped Over The Lazy Dog\n"; /*45 CHARACTERS INCLUDING /n */ int AltTxBuffer = 0; int AltRxBuffer = 0; unsigned char c; void FAR *fp; /*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); /* 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); /* 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); printf("\n\n"); if (AltTxBuffer) { printf("TX DATA: %s\n",Alt_txbuff); } else { printf("TX DATA: %s\n",txbuff); } if (AltRxBuffer) { printf("RX DATA: %s\n",Alt_rxbuff); } else { printf("RX DATA: %s\n",rxbuff); } 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; } /*******************************************************************/ /* END OF FILE */ /*******************************************************************/