home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
drdobbs
/
1991
/
10
/
embedcp
/
test
/
async2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-03-30
|
3KB
|
144 lines
/* MIO Async test program #2
* -------------------------
*
* Written : March 17th, 1991
* By : Stuart G. Phillips
*
* Sets SCC2 Channel B up in Async mode at 9600 bps and echos any characters
* received. This test program is very similar to ASYNC1 except it uses
* interrupts rather than polling.
*
*/
#include "mio.h"
#include "8530.h"
/* Communication region used to deposit status information about the
* programs progress etc in the shared memory window.
*/
struct comm_region { unsigned short status;
unsigned short scc_status;
unsigned short scc_special;
unsigned short int_cnt;
unsigned short rx_cnt;
unsigned short tx_cnt;
unsigned char command;
};
static void interrupt scc_int();
static void update_nwait(unsigned short);
struct comm_region *creg = (struct comm_region *)0x80;
extern unsigned _stklen = 8192U;
void main()
{
unsigned char data,val;
unsigned short i;
disable();
creg->status = 0;
creg->scc_status = 0;
creg->scc_special = 0;
creg->int_cnt = 0;
creg->rx_cnt = 0;
creg->tx_cnt = 0;
creg->command = 0xff;
/* Enable ICU in the V40 peripheral select register */
data = inportb(OPSEL);
outportb(OPSEL,data|ICU);
data = inportb(OPSEL);
creg->status = data;
/* Initialize the ICU */
outportb(IULA,ICUBASE); /* Set base address */
outportb(IMDW,IIW1|IIW4NR|IEM|IET); /* No IIW4, extended mode,
* edge triggered
*/
outportb(IMDW,IVEC); /* Set vector base for PIC */
outportb(IMDW,SI7); /* IRQ7 is slave */
/* Set up SCC - this takes a while ! */
scc_write(SCC2|CHANB|CMD,R9,FHWRES); /* Reset the SCC */
/* Loop a while to let reset complete */
for (i=0; i<256; i++) ;
/* Set SCC interrupt handler */
setvect(0x40,scc_int);
/* Set SCC interupt vector and enables */
scc_write(SCC2|CHANB|CMD,R2,0x40);
scc_write(SCC2|CHANB|CMD,R9,MIE);
scc_write(SCC2|CHANB|CMD,R1,INT_ALL_Rx);
/* Set Async mode, 8 bits Tx/Rx, 1 stop bit, No parity */
scc_write(SCC2|CHANB|CMD,R4,X16CLK|SB1);
scc_write(SCC2|CHANB|CMD,R5,DTR|Tx8|TxENAB|RTS);
scc_write(SCC2|CHANB|CMD,R3,Rx8|RxENABLE);
/* Set Baud rate generator constant */
scc_write(SCC2|CHANB|CMD,R12,24);
scc_write(SCC2|CHANB|CMD,R13,0);
/* Set Baud rate generator source and enable */
scc_write(SCC2|CHANB|CMD,R11,RCBR|TCBR);
scc_write(SCC2|CHANB|CMD,R14,SSBR|BRSRC|BRENABL);
/* Enable 'slave' interupts */
outportb(IMKW,IRQ7);
enable();
while (1){
creg->status++;
/* Loop - All processing done in the interrupt routine */
}
}
static void interrupt scc_int()
{
unsigned char status,spl,data;
struct comm_region *creg = (struct comm_region *)0x80;
creg->int_cnt++;
status = scc_read(SCC2|CHANB|CMD,R0);
spl = scc_read(SCC2|CHANB|CMD,R1);
creg->scc_special = spl;
scc_write(SCC2|CHANB|CMD,R0,ERR_RES);
if (status & Rx_CH_AV){
data = scc_rdata(SCC2|CHANB|DATA);
creg->rx_cnt++;
creg->scc_status = status;
scc_wdata(SCC2|CHANB|DATA,data);
creg->tx_cnt++;
}
outportb(IMDW,ISEOI|IRQ7);
}
static void update_nwait(unsigned short status)
{
creg->status = status;
creg->command = 0;
while (creg->command == 0) ;
creg->command = 0;
}