Skip to content. | Skip to navigation

Personal tools

lcu/ser1190.c

lcu/ser1190.c

lcu/ser1190.c

/////////////////////////////////////////////////////////////////////////////
// SER1190.C
//
//  Last updated: 06/06/2002
//
// This module contains hardware-specific serial communication
// routines for the SBC1190.
/////////////////////////////////////////////////////////////////////////////

#include <conio.h>
#include <string.h>

// Default base address after reset
#define PCB          0xFF00

// Serial port registers
// COMB or Port 0
#define B0CMP        PCB+0x60
#define B0CNT        PCB+0x62
#define S0CON        PCB+0x64
#define S0STS        PCB+0x66
#define S0RBUF       PCB+0x68
#define S0TBUF       PCB+0x6A
// COMA or Port 1
#define B1CMP        PCB+0x70
#define B1CNT        PCB+0x72
#define S1CON        PCB+0x74
#define S1STS        PCB+0x76
#define S1RBUF       PCB+0x78
#define S1TBUF       PCB+0x7A

#define B9600_25     325
#define B19200_25    162

#define con_txrdy       0x08
#define con_rxrdy       0x40

#define CPUCKSPD 25000000

/////////////////////////////////////////////////////////////////////////////
// This routine waits for a character to be received in the COM-B
// port and returns 1 when is ready.
int SerialCharReady(int Port)
// Returns: 1 when char has been received at port Port, 0 otherwise
{
  int sstsrg;

  if (Port)
    sstsrg = S1STS; // COMA
  else
    sstsrg = S0STS; // COMB
        if (!(inp(sstsrg) & con_rxrdy)) // did we receive a byte?
          return(0);
  else
    return(1);
}

////////////////////////////////////////////////////////////////////////////
// This routine waits for a character to be received in the COM-B
// port and returns that character.
unsigned char SerialGetChar(int Port)
// Returns: character received in the COM-B port
{
  int srxbfrg;

  if (Port)
    srxbfrg = S1RBUF; // COMA
  else
    srxbfrg = S0RBUF; // COMB
        return (inp(srxbfrg)); // return the received byte
}

/////////////////////////////////////////////////////////////////////////////
// SerialPutChar
// Sends a single character out the COM-B port
void SerialPutChar(int Port,unsigned char Data)
// Data: character to be sent out COM-B
// This routine don't check for errors
{
  int sstsrg,stxbfrg;

  if (Port)
  {
    sstsrg = S1STS;
    stxbfrg = S1TBUF;
  }
  else
  {
    sstsrg = S0STS;
    stxbfrg = S0TBUF;
        }

        while (!(inp(sstsrg) & con_txrdy)) /* wait until UART is ready */
                ;
  outp(stxbfrg,Data); /* send the character */
}

/////////////////////////////////////////////////////////////////////////////
// This routine prints a null-terminated string out the COM-B port
void SerialPutString(int Port,const char *Data)
// On entry: prstr pointer to a null-terminated string
{
        int i;

        for(i=0; i<strlen(Data); i++)
        {
    //if (Data[i] == '\n')
                //  SerialPutChar(Port,'\r');
                SerialPutChar(Port,Data[i]);
        }
}


////////////////////////////////////////////////////////////////////////////
// Initialize COMA or COMB
// to BaudRate = 19200, 8 data bits, 1 stop bit, no parity
// CPU SPEED is 25MHZ
void InitComPort(int Port)
{
  int sctlrg,brcntrg,brcmprg;

  if (Port)
  {
    sctlrg = S1CON;
    brcntrg = B1CNT;
    brcmprg = B1CMP;
  }
  else
  {
    sctlrg = S0CON;
    brcntrg = B0CNT;
    brcmprg = B0CMP;
  }
  //brval = CPUCKSPD / (BaudRate * 8) - 1;
  // Baud Rate Compare Register
  outpw(brcmprg,0x8000+B19200_25);

  // Serial Port Control Register
  // Mode 1, RX machine enabled
  outpw(sctlrg,0x0021);
}


Generated by GNU Enscript 1.6.5.2.
Document Actions