/*********************************************************************** 
* NOTICE
* All files contained on this disk are subject to the licensing conditions
* issued by MOTOROLA Inc.
*
* All files are copyright 1993 by MOTOROLA Inc. 
************************************************************************/


/********************************************************
 * File:	smc_uart.c
 *
 * Description:
 *	The driver routines for handling a SMC UART port.
 *
 * Routines:
 *	smc_uart_init
 *	smc_uart_status
 *
 * Author:
 *	Ofrit Lesser
 ********************************************************/

#include "gct.h"
#include "msg.h"
#include "config.h"
#include "types.h"
#include "mtypes.h"
#include "bss.h"
#include "quicc.h"
#include "states.h"
#include "smc_uart.h"





/********************************************************
 * routine:	smc_uart_init
 *
 * description:
 *	Initialize the driver tables for
 *	SMC UART ports.
 *
 * arguments:
 *	n		the driver's child number
 *	uart		points to an smc configuration structure
 *
 * return code:
 *
 * side effects:
 *
 ********************************************************/
smc_uart_init(n, smc)
int n;
struct smc *smc;
{
	GCT *gct;
	int (* *protocol)();
	unsigned adr, rom;
	CHILD *child;
	WORK_AREA *wa;
	int i;
	extern int smc_uart_txreq(), smc_uart_rxfr(), smc_uart_conf(),
		smc_return_to_pool(), smc_uart_busy(), smc_uart_status(),
		smc_uart_abort();
	extern int smc_uart_tx0(), smc_uart_tx1();
	extern int smc_uart_txchar(), smc_uart_txbuf(), smc_uart_rxbuf();

	GETGCT(gct);
	protocol = gct->driver->protocol;
	rom = gct->driver->rom;
	adr = (unsigned)smc_uart_txreq + rom;
	child = &gct->driver->child[n];
	wa = (WORK_AREA *)child->work_area;

	adr = (unsigned)smc_uart_txreq + rom;
	protocol[SUB(TX_REQ) | SMC_UART_STATE] = (int (*)())adr;
	adr = (unsigned)smc_uart_rxfr + rom;
	protocol[SUB(RX_IND) | SMC_UART_STATE] = (int (*)())adr;
	adr = (unsigned)smc_uart_conf + rom;
	protocol[SUB(TX_CONF) | SMC_UART_STATE] = (int (*)())adr;
	adr = (unsigned)smc_uart_busy + rom;
	protocol[SUB(BUSY) | SMC_UART_STATE] = (int (*)())adr;
	adr = (unsigned)smc_return_to_pool + rom;
	protocol[SUB(RTP) | SMC_UART_STATE] = (int (*)())adr;
	adr = (unsigned)smc_uart_status + rom;
	protocol[SUB(STATUS) | SMC_UART_STATE] = (int (*)())adr;
	adr = (unsigned)smc_uart_abort + rom;
	protocol[SUB(ABORT) | SMC_UART_STATE] = (int (*)())adr;

	gct->driver->child[n].upper = smc->upper;
	gct->driver->child[n].state = SMC_UART_STATE;
	gct->driver->child[n].smac = &protocol[SMC_UART_STATE];
	wa->minpool = 0;	/* always zero */


	wa->BDfirst = T_I | T_P;
	wa->BDlast = T_I;
	wa->BDrx = R_I;
	wa->intr_rxfr = SMC_UART_RX;
	wa->intr_txbd = SMC_UART_TX;
	wa->intr_terr = 0;
	wa->intr_busy = SMC_UART_BUSY;
	wa->t_error = SMC_UART_T_ERROR;

	/*
	 * initialize uart specific parameter ram
	 */
	wa->pram->pothers.idma_smc.psmc.u.max_idl = smc->pram.u.max_idl;
	wa->pram->pothers.idma_smc.psmc.u.brkln = smc->pram.u.brkln;
	wa->pram->pothers.idma_smc.psmc.u.brkec = smc->pram.u.brkec;
	wa->pram->pothers.idma_smc.psmc.u.brkcr = smc->pram.u.brkcr;



	/*
	 * if the requested pool size is zero,
	 * the uart handler functions in the
	 * character oriented mode.
	 */
	if( smc->psize == 0 ){
		child->flags |= UART_CHARMODE;
		adr = (unsigned)smc_uart_rxbuf + rom;
		protocol[SUB(RX_IND) | UART_STATE] = (int (*)())adr;
		adr = (unsigned)smc_uart_txbuf + rom;
		protocol[SUB(TX_CONF) | UART_STATE] = (int (*)())adr;

		switch( wa->channel ){
		case 0:
			adr = (unsigned)smc_uart_tx0 + rom;
			break;
		case 1:
			adr = (unsigned)smc_uart_tx1 + rom;
			break;
		}

		if( gct )
			if( !gct->cput )
				gct->cput = (int (*)())adr;
	}
}



smc_uart_status()
{
}

smc_uart_tx0(c)
unsigned char c;
{
	smc_uart_txchar(c, 0);
}

smc_uart_tx1(c)
unsigned char c;
{
	smc_uart_txchar(c, 1);
}
