/* COMM1190.C * * * (c) 1998 Micro/sys, Inc. * Glendale, CA * All rights reserved * * This module contains hardware-specific serial communication example * routines for the SBC1190. * * 8/4/98 */ #include #include #include #define PCB 0x0FF00 /* default base address after reset */ /* serial port registers */ #define B0CMP PCB+0x060 #define B0CNT PCB+0x062 #define S0CON PCB+0x064 #define S0STS PCB+0x066 #define S0RBUF PCB+0x068 #define S0TBUF PCB+0x06A #define UCSST PCB+0x0A4 /* flash */ #define GCS5SP PCB+0x096 #define GCS0SP PCB+0x082 #define B9600_12 155 #define B9600_20 259 #define B9600_25 325 #ifdef __TURBOC__ #ifndef inpw #define inpw inport #endif #ifndef outpw #define outpw outport #endif #endif #define SPEEDBYTE 0xE7FD000FL #define SPEED12MHZ 0xFE #define SPEED20MHZ 0xFC #define SPEED25MHZ 0xF8 #define con_txrdy 0x08 #define con_rxrdy 0x40 /*--------------------------------------------------------------------------- * uart_transmit * * Sends a single character out the COM-B port * * * On entry: xmit_char character to be sent out COM-B * * On exit: - * * Returns: - * *--------------------------------------------------------------------------*/ int uart_transmit (char xmit_char) { while (!(inp(S0STS) & con_txrdy)) /* wait until UART is ready */ ; outp(S0TBUF, xmit_char); /* send the character */ return (0); /* always return no error */ } /*--------------------------------------------------------------------------- * print2 * * this routine prints a null-terminated string out the COM-B port * * * On entry: prstr pointer to a null-terminated string * * On exit: - * * Returns: - * *--------------------------------------------------------------------------*/ void print2(char * prstr) { int n; for(n=0; prstr[n]; n++) { /* change LF to CR-LF */ if(prstr[n] == '\n') uart_transmit('\r'); uart_transmit(prstr[n]); } } /*--------------------------------------------------------------------------- * getch2 * * This routine waits for a character to be received in the COM-B * port and returns that character. * * * On entry: - * * On exit: - * * Returns: character received in the COM-B port * *--------------------------------------------------------------------------*/ int getch2(void) { while (!(inp(S0STS) & con_rxrdy)) /* wait for received byte */ ; return (inp(S0RBUF)); /* return the received byte */ } /*--------------------------------------------------------------------------- * UnhideFlash * * This routine makes the entire flash device visible in the memory * map. During normal operation, the flash is only visible in the * top 64k of the map (F000:0-F000:FFFF). In order to access data * in the lower part of the flash, this routine reprograms the * chip-selects so that the flash is visible in the top 512k * (8000:0-F000:FFFF). * * * On entry: - * * On exit: - * * Returns: - * *--------------------------------------------------------------------------*/ void UnhideFlash(void) { /* set UCS start to 8000:0, use previous number of wait-states */ outpw(UCSST, (inpw(UCSST) & 0x000F) + 0x8000); /* disable offboard memory */ outpw(GCS5SP, 0); /* disable socket */ outpw(GCS0SP, 0); } /*--------------------------------------------------------------------------- * HideFlash * * This routine makes the entire flash device visible in the memory * map. During normal operation, the flash is only visible in the * top 64k of the map (F000:0-F000:FFFF). In order to access data * in the lower part of the flash, this routine reprograms the * chip-selects so that the flash is visible in the top 512k * (8000:0-F000:FFFF). * * * On entry: - * * On exit: - * * Returns: - * *--------------------------------------------------------------------------*/ void HideFlash(void) { /* set UCS start to F000:0, use previous number of wait-states */ outpw(UCSST, (inpw(UCSST) & 0x000F) + 0xF000); /* enable offboard memory */ outpw(GCS5SP, (inp(GCS5SP)& 0x000F) + 0xF000); } /*--------------------------------------------------------------------------- * GetSpeed * * This routine determines the clock speed of the CPU by reading * the byte at E7FD:000F * * On entry: - * * On exit: - * * Returns: SPEED12MHZ 12 MHz CPU clock * SPEED20MHZ 20 MHz CPU clock * SPEED25MHZ 25 MHz CPU clock * *--------------------------------------------------------------------------*/ int GetSpeed(void) { unsigned char far * spdbyteptr; int temp; UnhideFlash(); spdbyteptr = (unsigned char far *) SPEEDBYTE; temp = ((int)*spdbyteptr); HideFlash(); return (temp); } init_comm() { /* initialize COM2 to 9600, 8, 1, N */ switch(GetSpeed()) { case SPEED12MHZ: default: outpw(B0CMP,0x8000+B9600_12); break; case SPEED20MHZ: outpw(B0CMP,0x8000+B9600_20); break; case SPEED25MHZ: outpw(B0CMP,0x8000+B9600_25); break; } } void main(void) { char str[80], key; init_comm(); sprintf(str, "Hello, world!\n"); print2(str); for(;;) { key = getch2(); uart_transmit (key); } }