?? m5200pscsio.c
字號(hào):
int lvl; if ((*pChan->getTxChar) (pChan->getTxArg, &outChar) != ERROR) { lvl = intLock (); M5200_WRITE (pChan->cr, PSC_UART_CR_TX_ENABLE); M5200_WRITE (pChan->tb, outChar); intUnlock (lvl); }#else M5200_WRITE (pChan->cr, PSC_UART_CR_TX_ENABLE);#endif return (OK); }/******************************************************************************** m5200CallbackInstall - 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:* Returns OK on success, or ENOSYS for an unsupported callback type.*/LOCAL int m5200CallbackInstall ( M5200_PSC_CHAN * pChan, int callbackType, STATUS (*callback)(), void * callbackArg ) { 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); } }/******************************************************************************** m5200PollOutput - output a character in polled mode.** This routine polls the status register to see if the TxRDY bit has been set.* This signals that the transmit holding register is empty and that the* UART is ready for transmission.** RETURNS:* Returns OK if a character sent, EIO on device error, EAGAIN* if the output buffer is full.*/LOCAL int m5200PollOutput ( M5200_PSC_CHAN *pChan, char outChar ) { USHORT statusReg; statusReg = M5200_READ (pChan->sr); /* is the transitter ready to accept a character? */ if ((statusReg & PSC_UART_SR_TXRDY) == 0x00) return (EAGAIN); /* write out the character */ M5200_WRITE (pChan->tb, outChar); return (OK); }/******************************************************************************** m5200PollInput - poll the device for input.** This routine polls the status register to see if the RxRDY bit is set.* This gets set when the UART receives a character and signals the* pressence of a character in the receive buffer.** RETURNS:* Returns OK if a character arrived, EIO on device error, EAGAIN* if the input buffer if empty.**/LOCAL int m5200PollInput ( M5200_PSC_CHAN *pChan, char * thisChar ) { USHORT statusReg; statusReg = M5200_READ (pChan->sr); if ((statusReg & PSC_UART_SR_RXRDY) == 0x00) return (EAGAIN); *thisChar = (M5200_READ (pChan->rb) & 0xff000000) >> 24; return (OK); }/******************************************************************************** m5200ModeSet - change channel mode setting** This driver supports both polled and interrupt modes and is capable of* switching between modes dynamically. If interrupt mode is desired this* routine enables the channels receiver, transmitter interrupt and the* received break condition interrupt. If polled mode is desired the xmitrs for* the specified channel is enabled.** RETURNS:* Returns a status of OK if the mode was set else ERROR.*/LOCAL STATUS m5200ModeSet ( M5200_PSC_CHAN * pChan, UINT newMode ) { int oldlevel; if ((newMode != SIO_MODE_POLL) && (newMode != SIO_MODE_INT)) return (ERROR); oldlevel = intLock (); if (newMode == SIO_MODE_INT && pChan->intEnable) { /* Enable the interrupts for receiver/transmitter conditions */ m5200ImrSetClr (pChan, PSC_UART_IMR_TXRDY | PSC_UART_IMR_RXRDY, 0); } else { /* Disable interrupts and enable the transmitter for the channel */ m5200ImrSetClr (pChan, 0, PSC_UART_IMR_TXRDY | PSC_UART_IMR_RXRDY); M5200_WRITE (pChan->cr, PSC_UART_CR_TX_ENABLE); } intUnlock (oldlevel); pChan->mode = newMode; return (OK); }/******************************************************************************** m5200BaudSet - change baud rate for channel** This routine sets the baud rate for the UART. The interrupts are disabled* during chip access.** RETURNS:* Returns a status of OK if the baud rate was set else ERROR.*/LOCAL STATUS m5200BaudSet ( M5200_PSC_CHAN * pChan, UINT baud ) { int oldlevel; ULONG aDivisor; ULONG aClockDivisor; if (!baud) return (ERROR); aDivisor = baud *16 * 2; aClockDivisor = (pChan->clkRate + aDivisor/2) / aDivisor; if ((aClockDivisor < 2) || (aClockDivisor > 0xffff)) return (ERROR); oldlevel = intLock (); M5200_WRITE( pChan->dl, aClockDivisor & 0xff); M5200_WRITE( pChan->dp, (aClockDivisor & 0xff00) >> 8); intUnlock (oldlevel); return (OK); }/******************************************************************************** m5200OptsSet - set the serial options** Set the channel operating mode to that specified. All sioLib options* are supported: CLOCAL, CREAD, CSIZE, PARENB, and PARODD.** Note, this routine disables the transmitter. The calling routine* may have to re-enable it.** RETURNS:* Returns OK to indicate success, otherwise ERROR is returned*/LOCAL STATUS m5200OptsSet ( M5200_PSC_CHAN * pChan, /* ptr to channel */ UINT options /* new hardware options */ ) { int mr1Value; int mr2Value; int lvl; if (pChan == NULL || options & 0xffffff00) return (ERROR); /* Reset the transmitters & receivers */ switch (options & CSIZE) { case CS5: mr1Value = PSC_UART_MR1_BITS_CHAR_5; break; case CS6: mr1Value = PSC_UART_MR1_BITS_CHAR_6; break; case CS7: mr1Value = PSC_UART_MR1_BITS_CHAR_7; break; default: case CS8: mr1Value = PSC_UART_MR1_BITS_CHAR_8; break; } if (options & STOPB) mr2Value = PSC_UART_MR2_STOP_BITS_2; else mr2Value = PSC_UART_MR2_STOP_BITS_1; switch (options & (PARENB|PARODD)) { case PARENB|PARODD: mr1Value |= PSC_UART_MR1_ODD_PARITY; break; case PARENB: mr1Value |= PSC_UART_MR1_EVEN_PARITY; break; case PARODD: mr1Value |= PSC_UART_MR1_PAR_MODE_MULTI; break; default: case 0: mr1Value |= PSC_UART_MR1_NO_PARITY; break; } if (options & CLOCAL) { /* clocal enables hardware flow control */ mr1Value |= PSC_UART_MR1_RX_RTS; mr2Value |= PSC_UART_MR2_TX_CTS; } lvl = intLock (); /* now reset the channel mode registers */ M5200_WRITE (pChan->cr, PSC_UART_CR_RESET_MODE_PTR | PSC_UART_CR_RX_DISABLE | PSC_UART_CR_TX_DISABLE); M5200_WRITE (pChan->cr, PSC_UART_CR_RESET_TX); M5200_WRITE (pChan->cr, PSC_UART_CR_RESET_RX); M5200_WRITE (pChan->mr, mr1Value); /* mode register 1 */ M5200_WRITE (pChan->mr, mr2Value); /* mode register 2 */ M5200_WRITE (pChan->cr, PSC_UART_CR_TX_ENABLE); if (options & CREAD) M5200_WRITE (pChan->cr, PSC_UART_CR_RX_ENABLE); intUnlock (lvl); pChan->options = options; return (OK); }/******************************************************************************** m5200Ioctl - special device control** RETURNS:* Returns OK on success, EIO on device error, ENOSYS on unsupported* request.*/LOCAL int m5200Ioctl ( M5200_PSC_CHAN * pChan, /* device to control */ int request, /* request code */ void * someArg /* some argument */ ) { STATUS result; int arg = (int)someArg; switch (request) { case SIO_BAUD_SET: return (m5200BaudSet (pChan, arg) == OK ? OK : EIO); case SIO_BAUD_GET: *(int *)arg = pChan->baudRate; return (OK); case SIO_MODE_SET: return (m5200ModeSet (pChan, arg) == OK ? OK : EIO); case SIO_MODE_GET: *(int *)arg = pChan->mode; return (OK); case SIO_AVAIL_MODES_GET: *(int *)arg = SIO_MODE_INT | SIO_MODE_POLL; return (OK); case SIO_HW_OPTS_SET: /* change options, then set mode to restart chip correctly */ result = m5200OptsSet (pChan, arg); m5200ModeSet (pChan, pChan->mode); return result; case SIO_HW_OPTS_GET: return pChan->options; default: return (ENOSYS); } }/******************************************************************************** m5200IntWr - handle a transmitter interrupt** This routine handles write interrupts from the DUART. This isr is invoked* when the TxRDY bit in the interrupt status register has been set. If there* is no character to transmit the transmitter for the channel is disabled.** RETURNS: N/A*/LOCAL void m5200IntWr ( M5200_PSC_CHAN * pChan ) { char outChar; if ((*pChan->getTxChar) (pChan->getTxArg, &outChar) != ERROR) { /* if char available, tx it */ M5200_WRITE (pChan->tb, outChar); } else { M5200_WRITE (pChan->cr, PSC_UART_CR_TX_DISABLE); } }/******************************************************************************* m5200IntRd - handle a reciever interrupt** This routine handles read interrupts from the UART.* The UART has been programmed to generate read interrupts when the RXRDY* status bit has been set in the interrupt status register. When a character* has been received it is removed from the receive buffer.** RETURNS: N/A*/LOCAL void m5200IntRd ( M5200_PSC_CHAN * pChan ) { UINT16 inchar; while (M5200_READ(pChan->sr) & PSC_UART_SR_RXRDY) { inchar = (M5200_READ (pChan->rb) & 0xff000000) >> 24; (*pChan->putRcvChar) (pChan->putRcvArg, inchar); if (pChan->mode != SIO_MODE_INT) break; } }/********************************************************************************* m5200PscSioInt - handle all interrupts in one vector** All interrupts share a single interrupt vector.* We identify each interrupting source and service it.* We must service all interrupt sources for those systems with edge-* sensitive interrupt controllers.** RETURNS: N/A*/void m5200PscSioInt ( M5200_PSC_CHAN * pChan ) { UINT16 intStatus; /* loop until all sources have been handled */ while ((intStatus = (M5200_READ(pChan->isr) & pChan->imrCopy)) != 0) { if ((intStatus & PSC_UART_ISR_TXRDY) != 0) m5200IntWr (pChan); if ((intStatus & PSC_UART_ISR_RXRDY) != 0) m5200IntRd (pChan); if (pChan->mode != SIO_MODE_INT) break; } }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -