⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 at91uart.c

📁 包含makefile config.h rominit romstart userinit 等等文件
💻 C
📖 第 1 页 / 共 2 页
字号:
/* sndsSio.c - Samsung SNDS100 serial driver *//*modification history--------------------*//*DESCRIPTIONINCLUDES:sndsSio.h sioLib.h*/#include "sioLib.h"#include "intLib.h"#include "errno.h"#include "ioLib.h"#define AT91UART_BAUD_MIN	1200#define AT91UART_BAUD_MAX	460800							/* 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/* forward static declarations */LOCAL int	AT91UartTxStartup (SIO_CHAN * pSioChan);LOCAL int	AT91UartCallbackInstall (SIO_CHAN *pSioChan, int callbackType,				    STATUS (*callback)(), void *callbackArg);LOCAL int	AT91UartPollOutput (SIO_CHAN *pSioChan, char	outChar);LOCAL int	AT91UartPollInput (SIO_CHAN *pSioChan, char *thisChar);LOCAL int	AT91UartIoctl (SIO_CHAN *pSioChan, int request, void *arg );/* local variables */LOCAL	SIO_DRV_FUNCS AT91UartDrvFuncs ={    AT91UartIoctl,    AT91UartTxStartup,    AT91UartCallbackInstall,    AT91UartPollInput,    AT91UartPollOutput,};/******************************************************************************** AT91DevInit - initialize a SNDS_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 SNDS_DUSART structure before passing it to* this routine.** RETURNS: N/A*/void AT91UartDevInit(    AT91_CHAN * pChan){    UINT32 dummy;	/* initialize each channel's driver function pointers */    int oldlevel;	    pChan->sio.pDrvFuncs	= &AT91UartDrvFuncs;    /* install dummy driver callbacks */    pChan->getTxChar    = dummyCallback;    pChan->putRcvChar	= dummyCallback;        /* reset the chip */	 oldlevel = intLock ();	    pChan->regs->US_CR = UART_CR_RESET_RECV | UART_CR_RESET_TRAN | UART_CR_RX_DIS | UART_CR_TX_DIS;	pChan->regs->US_MR = UART_MR_CHAR_8BIT | UART_MR_STOP_1BIT | UART_MR_PARITY_NONE				| UART_MR_CLK_USE_MCK | UART_MR_TEST_NORMAL_MODE| UART_MR_UART_MODE_NORMAL;	/*	 *	disable all interrupt source first	 */	pChan->regs->US_IDR = 0xFFFFFFFF;	pChan->regs->US_TTGR = UART_TANS_TIME_GUARD;	dummy = pChan ->regs->US_RHR;    intUnlock ( oldlevel );	pChan->intrmode = FALSE;		/*	 *	Init PDC, disable all pdc function	 */	AT91_PDC_Close( &(pChan->regs->US_PDC) );	/*	 *	make a dummy read emtpy the receive buf	 */	    /* setting polled mode is one way to make the device quiet */	AT91UartIoctl ( (SIO_CHAN *)pChan, SIO_BAUD_SET, (void *)pChan->baudRate );    AT91UartIoctl ( (SIO_CHAN *)pChan, SIO_MODE_SET,(void *)SIO_MODE_POLL );	pChan->regs->US_CR = UART_CR_RX_ENA | UART_CR_TX_DIS | UART_CR_RESET_STATUS;}/******************************************************************************** sndsDevInit2 - initialize a SNDS_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 AT91UartDevInit2    (    AT91_CHAN * pChan		/* device to initialize */    ){	pChan ->errcount = 0;	pChan->regs->US_CR = UART_CR_RX_ENA | UART_CR_TX_DIS | UART_CR_RESET_STATUS;	/*	 *	enable UART interrupt now.	 */    pChan->regs->US_IER = UART_IE_DR_TXRDY | UART_IE_DR_RXRDY | UART_IE_DR_FRAME 					| UART_IE_DR_PARE| UART_IE_DR_OVRE;	pChan->intrmode = TRUE;}/******************************************************************************** sndsIntRcv - handle a channel's receive-character interrupt** RETURNS: N/A*/ void AT91UartInt    (    AT91_CHAN *	pChan		/* channel generating the interrupt */    ){    	char outchar;	UINT32	    status;	UART_S* udev = pChan ->regs;		status = udev->US_CSR;	if( status&( UART_CSR_FRAME | UART_CSR_OVRE| UART_CSR_PARE ) )	{		pChan->errcount ++;		udev->US_CR = UART_CR_RESET_STATUS;	}	if( status&(UART_CSR_RXRDY ) )	{		(*pChan->putRcvChar) ( pChan->putRcvArg, udev ->US_RHR );	}	if( status&( UART_CSR_TXRDY ) )	{		if( (*pChan->getTxChar) (pChan->getTxArg, &outchar) != ERROR )		{			udev ->US_THR = (AT91_REG)(outchar);		}		else		{			udev ->US_CR = UART_CR_TX_DIS;		}	}}/******************************************************************************** sndsTxStartup - start the interrupt transmitter** RETURNS: OK on success, ENOSYS if the device is polled-only, or* EIO on hardware error.*/LOCAL int AT91UartTxStartup    (    SIO_CHAN * pSioChan                 /* channel to start */    ){    AT91_CHAN * pChan = (AT91_CHAN *)pSioChan;		if( pChan ->intrmode == TRUE )	{		pChan ->regs->US_CR = UART_CR_TX_ENA;		return OK;	}	else 		return ENOSYS;}/******************************************************************************** sndsCallbackInstall - 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 AT91UartCallbackInstall    (    SIO_CHAN *	pSioChan,               /* channel */    int		callbackType,           /* type of callback */    STATUS	(*callback)(),          /* callback */    void *      callbackArg             /* parameter to callback */    ){    AT91_CHAN * pChan = (AT91_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);	}}/********************************************************************************* sndsPollOutput - 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 AT91UartPollOutput    (    SIO_CHAN *	pSioChan,    char	outChar    ){    AT91_CHAN * pChan = (AT91_CHAN *)pSioChan;    UART_S* udev;	UINT32	status;	udev = pChan ->regs;    /* is the transmitter ready to accept a character? */	status = udev ->US_CSR;	if( status&( UART_CSR_FRAME | UART_CSR_OVRE| UART_CSR_PARE ) )	{		pChan->errcount ++;		udev->US_CR = UART_CR_RESET_STATUS;	}	if( status&(UART_CSR_TXRDY) )	{		udev ->US_THR = (AT91_REG)(outChar);		return (OK);	}	else		return (EAGAIN);}/******************************************************************************** sndsPollInput - 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 AT91UartPollInput    (    SIO_CHAN *	pSioChan,    char *	thisChar    ){    AT91_CHAN * pChan = (AT91_CHAN *)pSioChan;    UART_S* udev;	UINT32	status;		udev = pChan ->regs;	status = udev ->US_CSR;		if( status&( UART_CSR_FRAME | UART_CSR_OVRE| UART_CSR_PARE ) )	{		pChan->errcount ++;		udev->US_CR = UART_CR_RESET_STATUS;	}		if( status&(UART_CSR_RXRDY) )	{		status = udev ->US_RHR;		(*thisChar) = (BYTE)status;	    return (OK);    }	else		return (EAGAIN);}/******************************************************************************** sndsModeSet - toggle between interrupt and polled mode** RETURNS: OK on success, EIO on unsupported mode.*/LOCAL int At91UartModeSet    (    AT91_CHAN * pChan,		/* channel */    int	newMode        	/* new mode */    ){    UINT32	temp;    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) && ( pChan ->intrmode ) )		return (EIO);    /* set the new mode */	if( newMode == SIO_MODE_INT )		pChan->intrmode = TRUE;	else		pChan->intrmode = FALSE;    if ( pChan->intrmode )	{		/*		 *	TX int still not enabled		 */
		pChan->regs->US_CR = UART_CR_RX_ENA | UART_CR_TX_DIS | UART_CR_RESET_STATUS;
		pChan->regs->US_IER = UART_IE_DR_TXRDY | UART_IE_DR_RXRDY | UART_IE_DR_FRAME 			| UART_IE_DR_PARE| UART_IE_DR_OVRE;		intEnable( pChan ->level );	}	else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -