?? gtsio.c
字號:
/***************************************************************************
*
* $RCSfile: gtSio.c $
*
* Copyright 2001 by Dy 4 Systems, Inc. All Rights Reserved.
*
* $Revision: 1.12 $
*
* $Name: AV4-ISP-R1.2-1 AV4-ISP-R1.2-0 HMTST2 HMTST1 DVT_AV4_4.101 $ $State: Developmental $ $Locker: $
*
* $Source: L:/SWRND/champAV2/src/vx/src/drv/sio/rcs/gtSio.c $
*
* RCS Project Name:
*
* CSC:
*
* Target:
*
* Description:
*
* Usage:
*
* $Log: gtSio.c $
* Revision 1.12 2005/04/28 17:59:52Z dsessler
* Revision 1.11 2005/03/14 21:27:25 ltsui
* If route is bslShmuartGetMaster() (may not be 0) use traditional callback and arg.
* Revision 1.10 2003/05/27 19:11:30Z dsessler
* corrected compile error for sioCallbackInstall
* Revision 1.9 2003/05/21 21:01:32 dsessler
* T2.2 fix for paths of included files under the bsp
* Revision 1.8 2002/10/31 14:03:30 coopertr
* Lower-layer driver and default SIO mode in BSL were changed to
* provide XON/XOFF protocol at the lowest layer. This function was
* changed to disable this feature within the low-level driver, since the
* vxWorks upper level SIO software provides these features.
* Revision 1.7 2002/05/10 07:51:02 coopertr
* Revision 1.6 2002/04/05 05:14:23 coopertr
*
****************************************************************************/
/*
This source file contains the serial I/O device driver for the Champ AV II
boards. This serial driver is built on top of the MPSC unit of the
Galileo Discovery bridge chip.
This driver does support some features like modifying baud rate but does not
support others: modem control signals, hangup, disable h/w flow control.
It also supports both interrupt mode and polled mode.
CALLBACKS
Servicing a "transmitter ready" interrupt involves making a callback to a
higher level library in order to get a character to transmit.
By default, this driver installs dummy callback routines which do
nothing. A higher layer library that wants to use this driver (e.g., ttyDrv)
will install its own callback routine using the SIO_INSTALL_CALLBACK
ioctl command.
Likewise, a receiver interrupt handler makes a callback to pass the
character to the higher layer library.
MODES
The driver supports both polled and interrupt modes, and is
capable of switching modes dynamically.
A communication path to an external mode debug agent (i.e., for monitor
style debugging) can be supported on this driver even if the driver
only supports polled mode.
Adding dynamic mode switching allows the external agent to be activated
whenever a message is sent to it (e.g., to be interrupted on first packet).
For dynamically mode switchable drivers, be aware that the driver may be
asked to switch modes in the middle of its input ISR. A driver's input ISR
will look something like this:
inChar = *pDev->dr; /@ read a char from data register @/
*pDev->cr = GOT_IT; /@ acknowledge the interrupt @/
pDev->putRcvChar (...); /@ give the character to the higher layer @/
If this channel is used as a communication path to an external mode
debug agent, and if the character received is a special "end of packet"
character, then the agent's callback will lock interrupts, switch
the device to polled mode, and use the device in polled mode for awhile.
Later on the agent will unlock interrupts, switch the device back to
interrupt mode, and return to the ISR.
In particular, the callback can cause two mode switches, first to polled mode
and then back to interrupt mode, before it returns.
USAGE
The driver is called only by the BSP. The directly callable
routines in this module are gtSioDevInit(), gtSioDevInit2(),
gtSioIntRcv(), gtSioIntTx().
The BSP calls gtSioDevInit() to initialize or reset the device.
It connects the driver's interrupt handlers (gtSioIntRcv, gtSioIntTx),
using intConnect().
After connecting the interrupt handlers, the BSP calls gtSioDevInit2()
to inform the driver that interrupt mode operation is now possible.
*/
#include "vxWorks.h"
#include "sioLib.h"
#include "intLib.h"
#include "errno.h"
#include "bsl.h"
#include "bslSio.h"
#include "h/drv/sio/gtSio.h"
#define GT_BAUD_MIN 75
#define GT_BAUD_MAX 115200
#define SDMA_PRIORITY 10
#define SDMA0RX 0x003
#define SDMA0TX 0x00C
#define SDMA1RX 0x300
#define SDMA1TX 0xC00
/* Hardware abstraction macros */
#ifndef GT_SIO_REG_READ
# define GT_SIO_REG_READ(pChan, reg, result) \
((result) = *(UCHAR *)(pChan->reg))
#endif /*GT_SIO_REG_READ*/
#ifndef GT_SIO_REG_WRITE
# define GT_SIO_REG_WRITE(pChan, reg, data) \
(*(UCHAR *)(pChan->reg) = data)
#endif /*GT_SIO_REG_WRITE*/
#if 0
/* for backward compatibility */
#ifndef SIO_HUP
# define SIO_OPEN 0x100A /* open channel, raise DTR, RTS */
# define SIO_HUP 0x100B /* hang-up, lower DTR, RTS */
#endif
#endif
/* forward static declarations */
LOCAL int gtSioTxStartup (SIO_CHAN * pSioChan);
LOCAL int gtSioCallbackInstall (SIO_CHAN *pSioChan, int callbackType,
STATUS (*callback)(void *, ...), void *callbackArg);
LOCAL int gtSioPollOutput (SIO_CHAN *pSioChan, char outChar);
LOCAL int gtSioPollInput (SIO_CHAN *pSioChan, char *thisChar);
LOCAL int gtSioIoctl (SIO_CHAN *pSioChan, int request, void *arg);
LOCAL STATUS dummyCallback (void);
/* local variables */
LOCAL SIO_DRV_FUNCS gtSioDrvFuncs =
{
gtSioIoctl,
gtSioTxStartup,
(void *)gtSioCallbackInstall,
gtSioPollInput,
gtSioPollOutput
};
LOCAL BOOL gtIntrMode = FALSE; /* interrupt mode allowed flag */
/******************************************************************************
*
* gtSioDevInit - initialize a GT_DUSART
*
* This routine initializes the driver
* function pointers and then resets the chip in a quiescent state.
* The BSP must have already initialized all the device addresses and the
* baudFreq fields in the GT_DUSART structure before passing it to
* this routine. The lower-level driver is initialized to the mode
* determined by BSLSIO_DEFAULT, except that echo, newline mapping,
* and xon/xoff are disabled in the low-level driver, since the
* VxWorks driver provides these capabilities at a higher level.
*
* RETURNS: N/A
*/
void gtSioDevInit
(
GT_PORT * pPort
)
{
int baud = DEFAULT_BAUD_RATE;
int opts = DEFAULT_SIO_MODE &
~(BSLSIO_ECHO | BSLSIO_NLMAP | BSLSIO_XONXOFF);
/* initialize each channel's driver function pointers */
pPort->pDrvFuncs = >SioDrvFuncs;
/* initialize each channel's baud, and options */
pPort->baud = baud;
pPort->options = opts;
/* install dummy driver callbacks */
pPort->getTxChar = dummyCallback;
pPort->putRcvChar = dummyCallback;
/* initialize dynamic routing options */
pPort->lastRxChar = 0;
pPort->setRoute = 0;
pPort->rxRoute = 0;
pPort->route = 0;
/* reset the chip */
bslSioChInitEnv(pPort->portId, baud, opts);
/* setting polled mode is one way to make the device quiet */
gtSioIoctl ((SIO_CHAN *)pPort, SIO_MODE_SET,
(void *)SIO_MODE_POLL);
}
/******************************************************************************
*
* gtSioDevInit2 - initialize a GT_DUSART, part 2
*
* This routine is called by the BSP after interrupts have been connected.
* The driver can now operate in interrupt mode. Before this routine is
* called only polled mode operations should be allowed.
*
* RETURNS: N/A
* ARGSUSED
*/
void gtSioDevInit2
(
GT_PORT * pPort /* device to initialize */
)
{
/* Interrupt mode is allowed */
gtIntrMode = TRUE;
}
/******************************************************************************
*
* gtSioIntHandler - direct a channel's interrupt to receive or transmit
* handler
*
* RETURNS: N/A
*
* NOTE: chan 0 or 1 should match sdma 0 or 1
*/
void gtSioIntHandler
(
GT_PORT * pChan
)
{
if (pChan->portId == 0)
{
if (bslIntGetSdmaCause (SDMA0RX))
gtSioIntRcv (pChan);
else
gtSioIntTx (pChan);
}
else if (pChan->portId == 1)
{
if (bslIntGetSdmaCause (SDMA1RX))
gtSioIntRcv (pChan);
else
gtSioIntTx (pChan);
}
}
/******************************************************************************
*
* gtSioIntRcv - handle a channel's receive-character interrupt
*
* If dynamic routing is in place, this function looks for <esc><n>
* input sequences, where <n> is the processor to which the serial
* port should be attached. When this sequence is detected, this ISR
* calls the setRoute callback function.
*
* RETURNS: N/A
*/
void gtSioIntRcv
(
GT_PORT * pChan /* channel generating the interrupt */
)
{
int c, status;
/*
* Grab input characters from the chip and hand off via a
* callback. The entire FIFO is emptied.
*/
while ((c = bslSioGetc (pChan->portId)) >= 0)
{
if (pChan->setRoute != 0)
{
status = 0;
if (pChan->lastRxChar == 0x1b)
{
status = (pChan->setRoute)(&pChan->route, c);
/** If routing to 0, use traditional callback and arg **/
if (pChan->route == bslShmuartGetMaster())
{
pChan->putRcvChar = pChan->savePutRcvChar;
pChan->putRcvArg = pChan->savePutRcvArg;
}
else
{
pChan->putRcvChar = (void *) (pChan->rxRoute);
pChan->putRcvArg = (void *) (pChan->route);
}
if (status != 0)
{
(*pChan->putRcvChar) (pChan->putRcvArg, pChan->lastRxChar);
(*pChan->putRcvChar) (pChan->putRcvArg, c);
}
}
else if (c != 0x1b)
(*pChan->putRcvChar) (pChan->putRcvArg, c);
pChan->lastRxChar = c;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -