?? gtsio.c
字號:
}
else
(*pChan->putRcvChar) (pChan->putRcvArg, c);
}
}
/******************************************************************************
*
* gtSioIntTx - handle a channel's transmitter-ready interrupt
*
* RETURNS: N/A
*/
void gtSioIntTx
(
GT_PORT * pChan /* channel generating the interrupt */
)
{
char outChar;
/*
* Ack for last transmit.
*/
bslSioTxIntAck(pChan->portId);
/*
* If there's a character to transmit then write it out.
*/
if ((*pChan->getTxChar) (pChan->getTxArg, &outChar) != ERROR)
bslSioPutc(pChan->portId, outChar);
}
/******************************************************************************
*
* gtSioTxStartup - start the interrupt transmitter
*
* RETURNS: OK on success, ENOSYS if the device is polled-only, or
* EIO on hardware error.
*/
LOCAL int gtSioTxStartup
(
SIO_CHAN * pSioChan /* channel to start */
)
{
GT_PORT * pChan = (GT_PORT *)pSioChan;
char outChar;
/*
* Enable tx interrupts. We won't get an interrupt until the
* TX operation is done. Then start a single character output.
*/
if (((*pChan->getTxChar) (pChan->getTxArg, &outChar) != ERROR) &&
(bslSioTxReady(pChan->portId) == 1))
{
bslSioTxIntEnable (pChan->portId);
bslSioPutc(pChan->portId, outChar);
}
return (OK);
}
/******************************************************************************
*
* gtSioCallbackInstall - install ISR callbacks to get/put chars
*
* This driver allows interrupt callbacks for transmitting characters
* and receiving characters. In general, drivers may support other
* types of callbacks too.
*
* RETURNS: OK on success, or ENOSYS for an unsupported callback type.
*/
LOCAL int gtSioCallbackInstall
(
SIO_CHAN * pSioChan, /* channel */
int callbackType, /* type of callback */
STATUS (*callback)(void *, ...), /* callback */
void * callbackArg /* parameter to callback */
)
{
GT_PORT * pChan = (GT_PORT *)pSioChan;
switch (callbackType)
{
case SIO_CALLBACK_GET_TX_CHAR:
pChan->getTxChar = (void *)callback;
pChan->getTxArg = callbackArg;
return (OK);
case SIO_CALLBACK_PUT_RCV_CHAR:
pChan->putRcvChar = (void *)callback;
pChan->putRcvArg = callbackArg;
pChan->savePutRcvChar = pChan->putRcvChar;
pChan->savePutRcvArg = pChan->putRcvArg;
return (OK);
default:
return (ENOSYS);
}
}
/*******************************************************************************
*
* gtSioPollOutput - output a character in polled mode
*
* RETURNS: OK if a character arrived, EIO on device error, EAGAIN
* if the output buffer if full. ENOSYS if the device is
* interrupt-only.
*/
LOCAL int gtSioPollOutput
(
SIO_CHAN * pSioChan,
char outChar
)
{
GT_PORT * pChan = (GT_PORT *)pSioChan;
/* is the transmitter ready to accept a character? */
if (bslSioTxReady(pChan->portId) != 1)
return (EAGAIN);
/* write out the character */
bslSioPutc(pChan->portId, outChar);
return (OK);
}
/******************************************************************************
*
* gtSioPollInput - poll the device for input
*
* RETURNS: OK if a character arrived, EIO on device error, EAGAIN
* if the input buffer if empty, ENOSYS if the device is
* interrupt-only.
*/
LOCAL int gtSioPollInput
(
SIO_CHAN * pSioChan,
char * thisChar
)
{
GT_PORT * pChan = (GT_PORT *)pSioChan;
int status;
status = bslSioGetc(pChan->portId);
if (status == -1)
return (EAGAIN); /* no input available at this time */
else
*thisChar = (char)status;
return (OK);
}
/******************************************************************************
*
* gtSioModeSet - toggle between interrupt and polled mode
*
* RETURNS: OK on success, EIO on unsupported mode.
*/
LOCAL int gtSioModeSet
(
GT_PORT * pChan, /* channel */
uint_t newMode /* new mode */
)
{
if ((newMode != SIO_MODE_POLL) && (newMode != SIO_MODE_INT))
return (EIO);
/* Don't enter interrupt mode unless it is allowed. */
if ((newMode == SIO_MODE_INT) && (!gtIntrMode))
return (EIO);
/* set the new mode */
pChan->mode = newMode;
if (pChan->mode == SIO_MODE_INT)
{
bslSioRxIntEnable(pChan->portId);
bslSioTxIntEnable(pChan->portId);
}
else
{
bslSioRxIntDisable(pChan->portId);
bslSioTxIntDisable(pChan->portId);
}
return (OK);
}
/******************************************************************************
*
* gtSioOptSet - set hardware options
*
* This routine sets up the hardware according to the specified option
* argument. If the hardware cannot support a particular option value,
* this function ignores that portion of the request.
*
* Currently no options are supported.
*
* RETURNS: OK upon success, or EIO for invalid arguments.
*/
LOCAL int gtSioOptSet
(
GT_PORT * pChan, /* channel */
uint_t newOpts /* new options */
)
{
return (OK);
}
/*******************************************************************************
*
* gtSioIoctl - special device control
*
* This routine handles the IOCTL messages from the user. It supports commands
* to get/set baud rate, mode(INT,POLL), hardware options(parity, number of
* data bits).
*
* RETURNS: OK on success, ENOSYS on unsupported request, EIO on failed
* request.
*/
LOCAL int gtSioIoctl
(
SIO_CHAN * pSioChan, /* device to control */
int request, /* request code */
void * someArg /* some argument */
)
{
GT_PORT *pChan = (GT_PORT *) pSioChan;
int arg = (int)someArg;
switch (request)
{
case SIO_BAUD_SET:
/* Set baud rate. Return EIO for invalid baud rate. */
if (arg < GT_BAUD_MIN || arg > GT_BAUD_MAX)
return (EIO);
pChan->baud = arg;
return (OK);
case SIO_BAUD_GET:
/* Get the baud rate and return OK */
*(int *)arg = pChan->baud;
return (OK);
case SIO_MODE_SET:
/*
* Set the mode (e.g., to interrupt or polled). Return OK
* or EIO for an unknown or unsupported mode.
*/
return (gtSioModeSet (pChan, arg));
case SIO_MODE_GET:
/* Get the current mode and return OK. */
*(int *)arg = pChan->mode;
return (OK);
case SIO_AVAIL_MODES_GET:
/* Get the available modes and return OK. */
*(int *)arg = SIO_MODE_INT | SIO_MODE_POLL;
return (OK);
case SIO_HW_OPTS_SET:
/*
* Optional command to set hardware options (as defined
* in sioLib.h).
*/
return (gtSioOptSet (pChan, arg));
case SIO_HW_OPTS_GET:
/*
* Optional command to get the hardware options (as defined
* in sioLib.h). Return OK or ENOSYS if this command is not
* implemented. Note: if this command is unimplemented, it
* will be assumed that the driver options are CREAD | CS8
* (e.g., eight data bits, one stop bit, no parity, ints enabled).
*/
*(int *)arg = pChan->options;
return (OK);
case SIO_HUP:
return (ENOSYS);
case SIO_OPEN:
return (ENOSYS); /* always open */
case SIO_SHMUART_CHAR:
pChan->rxRoute = (void *) arg;
return (OK);
case SIO_ROUTE_SET:
pChan->setRoute = (void *) arg;
return (OK);
default:
return (ENOSYS);
}
}
/*******************************************************************************
*
* dummyCallback - dummy callback routine
*
* RETURNS: ERROR.
*/
LOCAL STATUS dummyCallback (void)
{
return (ERROR);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -