📄 ks8695sio.c
字号:
/* Get the current mode and return OK */
*(int *)arg = pChan->channelMode;
break;
case SIO_AVAIL_MODES_GET:
/* Get the available modes and return OK */
*(int *)arg = SIO_MODE_INT | SIO_MODE_POLL;
break;
case SIO_HW_OPTS_SET:
/*
* Optional command to set the hardware options (as defined
* in sioLib.h).
* Return OK, or ENOSYS if this command is not implemented.
* Note: several hardware options are specified at once.
* This routine should set as many as it can and then return
* OK. The SIO_HW_OPTS_GET is used to find out which options
* were actually set.
*/
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).
*/
default:
status = ENOSYS;
}
return status;
}
/*******************************************************************************
*
* ks8695pSioIntTx - handle a transmitter interrupt
*
* This routine handles write interrupts from the UART.
*
* RETURNS: N/A
*/
void ks8695pSioIntTx
(
KS8695P_CHAN * pChan /* ptr to KS8695P_CHAN describing this channel */
)
{
char outChar;
UINT32 isr;
KS8695P_REG_READ (REG_INT_STATUS, isr);
/* if not ours, simply return */
if ((isr & REG_INT_UT) == 0)
return ;
/* disable Tx interrupt first */
KS8695P_REG_BIT_CLR (REG_INT_ENABLE, REG_INT_UT);
/* ACK */
KS8695P_REG_WRITE(REG_INT_STATUS, REG_INT_UT);
if ((*pChan->getTxChar) (pChan->getTxArg, &outChar) != ERROR)
{
/* write char. to Transmit Holding Reg. */
KS8695P_UART_REG_WRITE(pChan, REG_UART_TX_HOLDING, outChar);
KS8695P_REG_BIT_SET (REG_INT_ENABLE, REG_INT_UT);
}
else
{
KS8695P_REG_BIT_CLR (REG_INT_ENABLE, REG_INT_UT);
}
}
/*****************************************************************************
*
* ks8695pSioIntRx - handle a receiver interrupt
*
* This routine handles read interrupts from the UART.
*
* RETURNS: N/A
*/
void ks8695pSioIntRx
(
KS8695P_CHAN * pChan /* ptr to KS8695P_CHAN describing this channel */
)
{
char inchar;
UINT32 flags;
BOOL more_data = FALSE;
UINT32 isr;
KS8695P_REG_READ (REG_INT_STATUS, isr);
/* if not ours, simply return */
if ((isr & REG_INT_UR) == 0)
return ;
/* disable Rx interrupt first */
KS8695P_REG_BIT_CLR (REG_INT_ENABLE, REG_INT_UR);
/* ACK */
KS8695P_REG_WRITE(REG_INT_STATUS, REG_INT_UR);
/* read characters from Receive Holding Reg. */
do
{
/* While RX FIFO isn't empty, we have more data to read */
KS8695P_UART_REG_READ(pChan, REG_UART_LINE_STATUS, flags);
more_data = ( (flags & REG_URLS_RX_DR) != 0);
if (more_data)
{
/* Read from data register. */
KS8695P_UART_REG_READ(pChan, REG_UART_RX_BUFFER, inchar);
(*pChan->putRcvChar) (pChan->putRcvArg, inchar);
}
} while (more_data);
KS8695P_REG_BIT_SET (REG_INT_ENABLE, REG_INT_UR);
}
/*****************************************************************************
*
* ks8695pSioIntErr - handle a uart line error interrupt
*
* This routine handles read interrupts from the UART.
*
* RETURNS: N/A
*/
void ks8695pSioIntErr
(
KS8695P_CHAN * pChan /* ptr to KS8695P_CHAN describing this channel */
)
{
UINT32 isr;
KS8695P_REG_READ (REG_INT_STATUS, isr);
/* if not ours, simply return */
if ((isr & REG_INT_ULE) == 0)
return ;
KS8695P_REG_BIT_CLR (REG_INT_ENABLE, REG_INT_ULE);
KS8695P_REG_WRITE(REG_INT_STATUS, REG_INT_ULE);
KS8695P_REG_BIT_SET (REG_INT_ENABLE, REG_INT_ULE);
}
/*******************************************************************************
*
* ks8695pTxStartup - transmitter startup routine
*
* Enable interrupt so that interrupt-level char output routine will be called.
*
* RETURNS: OK on success, ENOSYS if the device is polled-only, or
* EIO on hardware error.
*/
int ks8695pTxStartup
(
SIO_CHAN * pSioChan /* ptr to SIO_CHAN describing this channel */
)
{
KS8695P_CHAN * pChan = (KS8695P_CHAN *)pSioChan;
char outChar;
if (pChan->channelMode == SIO_MODE_INT)
{
if ((*pChan->getTxChar) (pChan->getTxArg, &outChar) != ERROR)
{
/* write char. to Transmit Holding Reg. */
KS8695P_UART_REG_WRITE(pChan, REG_UART_TX_HOLDING, outChar);
/* intEnable (pChan->levelTx); */
intEnable (INT_LVL_UTS);
}
return OK;
}
else
return ENOSYS;
}
/******************************************************************************
*
* ks8695pPollOutput - output a character in polled mode.
*
* RETURNS: OK if a character arrived, EIO on device error, EAGAIN
* if the output buffer is full, ENOSYS if the device is interrupt-only.
*/
int ks8695pPollOutput
(
SIO_CHAN * pSioChan, /* ptr to SIO_CHAN describing this channel */
char outChar /* char to output */
)
{
KS8695P_CHAN * pChan = (KS8695P_CHAN *)pSioChan;
FAST UINT32 pollStatus;
KS8695P_UART_REG_READ(pChan, REG_UART_LINE_STATUS, pollStatus);
/* is the transmitter ready to accept a character? */
if ((pollStatus & REG_URLS_URTE) == 0)
return EAGAIN;
/* write out the character */
KS8695P_UART_REG_WRITE(pChan, REG_UART_TX_HOLDING, outChar); /* transmit character */
return OK;
}
/******************************************************************************
*
* ks8695pPollInput - poll the device for input.
*
* RETURNS: OK if a character arrived, EIO on device error, EAGAIN
* if the input buffer is empty, ENOSYS if the device is interrupt-only.
*/
int ks8695pPollInput
(
SIO_CHAN * pSioChan, /* ptr to SIO_CHAN describing this channel */
char * thisChar /* pointer to where to return character */
)
{
KS8695P_CHAN * pChan = (KS8695P_CHAN *)pSioChan;
FAST UINT32 pollStatus;
KS8695P_UART_REG_READ(pChan, REG_UART_LINE_STATUS, pollStatus);
if ((pollStatus & REG_URLS_RX_DR) == 0)
return EAGAIN;
/* got a character */
KS8695P_UART_REG_READ(pChan, REG_UART_RX_BUFFER, *thisChar);
return OK;
}
/******************************************************************************
*
* ks8695pCallbackInstall - install ISR callbacks to get/put chars.
*
* This routine installs interrupt callbacks for transmitting characters
* and receiving characters.
*
* RETURNS: OK on success, or ENOSYS for an unsupported callback type.
*
*/
LOCAL int ks8695pCallbackInstall
(
SIO_CHAN * pSioChan, /* ptr to SIO_CHAN describing this channel */
int callbackType, /* type of callback */
STATUS (*callback)(), /* callback */
void * callbackArg /* parameter to callback */
)
{
KS8695P_CHAN * pChan = (KS8695P_CHAN *)pSioChan;
switch (callbackType)
{
case SIO_CALLBACK_GET_TX_CHAR:
pChan->getTxChar = callback;
pChan->getTxArg = callbackArg;
return OK;
case SIO_CALLBACK_PUT_RCV_CHAR:
pChan->putRcvChar = callback;
pChan->putRcvArg = callbackArg;
return OK;
default:
return ENOSYS;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -