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

📄 at91dbgu.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 AT91DBGU_BAUD_MIN	1200#define AT91DBGU_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 */void AT91_PDC_Close ( PDC_S * pPDC );       LOCAL int	AT91DBGUTxStartup (SIO_CHAN * pSioChan);LOCAL int	AT91DBGUCallbackInstall (SIO_CHAN *pSioChan, int callbackType,				    STATUS (*callback)(), void *callbackArg);LOCAL int	AT91DBGUPollOutput (SIO_CHAN *pSioChan, char	outChar);LOCAL int	AT91DBGUPollInput (SIO_CHAN *pSioChan, char *thisChar);LOCAL int	AT91DBGUIoctl (SIO_CHAN *pSioChan, int request, void *arg );LOCAL STATUS dummyCallback (void);/* local variables */LOCAL	SIO_DRV_FUNCS AT91DBGUDrvFuncs ={    AT91DBGUIoctl,    AT91DBGUTxStartup,    AT91DBGUCallbackInstall,    AT91DBGUPollInput,    AT91DBGUPollOutput,};/******************************************************************************** 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 AT91DBGUDevInit(    AT91_DBGU_CHAN * pChan){    UINT32 dummy;	/* initialize each channel's driver function pointers */    int oldlevel;	    pChan->sio.pDrvFuncs	= &AT91DBGUDrvFuncs;    /* install dummy driver callbacks */    pChan->getTxChar    = dummyCallback;    pChan->putRcvChar	= dummyCallback;        /* reset the chip */	 oldlevel = intLock ();	    pChan->regs->DBGU_CR = DBGU_CR_RESET_RECV | DBGU_CR_RESET_TRAN | DBGU_CR_RX_DIS | DBGU_CR_TX_DIS;	pChan->regs->DBGU_MR = DBGU_MR_PARITY_NONE | DBGU_MR_TEST_NORMAL_MODE;	/*	 *	disable all interrupt source first	 */	pChan->regs->DBGU_IDR = 0xFFFFFFFF;	dummy = pChan ->regs->DBGU_RHR;    intUnlock ( oldlevel );	pChan->intrmode = FALSE;		/*	 *	Init PDC, disable all pdc function	 */	AT91_PDC_Close( &(pChan->regs->DBGU_PDC) );	/*	 *	make a dummy read emtpy the receive buf	 */	    /* setting polled mode is one way to make the device quiet */	AT91DBGUIoctl ( (SIO_CHAN *)pChan, SIO_BAUD_SET, (void *)pChan->baudRate );    AT91DBGUIoctl ( (SIO_CHAN *)pChan, SIO_MODE_SET,(void *)SIO_MODE_POLL );	pChan->regs->DBGU_CR = DBGU_CR_RX_ENA | DBGU_CR_TX_DIS | DBGU_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 AT91DBGUDevInit2    (    AT91_DBGU_CHAN * pChan		/* device to initialize */    ){	pChan ->errcount = 0;	pChan->regs->DBGU_CR = DBGU_CR_RX_ENA | DBGU_CR_TX_DIS | DBGU_CR_RESET_STATUS;	/*	 *	enable DBGU interrupt now.	 */    pChan->regs->DBGU_IER = DBGU_IE_DR_TXRDY | DBGU_IE_DR_RXRDY | DBGU_IE_DR_FRAME 					| DBGU_IE_DR_PARE| DBGU_IE_DR_OVRE;	pChan->intrmode = TRUE;}/******************************************************************************** sndsIntRcv - handle a channel's receive-character interrupt** RETURNS: N/A*/ void AT91DBGUInt    (    AT91_DBGU_CHAN *	pChan		/* channel generating the interrupt */    ){    	char outchar;	UINT32	    status;	DBGU_S* udev = pChan ->regs;		status = udev->DBGU_CSR;	if( status&( DBGU_CSR_FRAME | DBGU_CSR_OVRE| DBGU_CSR_PARE ) )	{		pChan->errcount ++;		udev->DBGU_CR = DBGU_CR_RESET_STATUS;	}	if( status&(DBGU_CSR_RXRDY ) )	{		(*pChan->putRcvChar) ( pChan->putRcvArg, udev ->DBGU_RHR );	}	if( status&( DBGU_CSR_TXRDY ) )	{		if( (*pChan->getTxChar) (pChan->getTxArg, &outchar) != ERROR )		{			udev ->DBGU_THR = (AT91_REG)(outchar);		}		else		{			udev ->DBGU_CR = DBGU_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 AT91DBGUTxStartup    (    SIO_CHAN * pSioChan                 /* channel to start */    ){    AT91_DBGU_CHAN * pChan = (AT91_DBGU_CHAN *)pSioChan;		if( pChan ->intrmode == TRUE )	{		pChan ->regs->DBGU_CR = DBGU_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 AT91DBGUCallbackInstall    (    SIO_CHAN *	pSioChan,               /* channel */    int		callbackType,           /* type of callback */    STATUS	(*callback)(),          /* callback */    void *      callbackArg             /* parameter to callback */    ){    AT91_DBGU_CHAN * pChan = (AT91_DBGU_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 AT91DBGUPollOutput    (    SIO_CHAN *	pSioChan,    char	outChar    ){    AT91_DBGU_CHAN * pChan = (AT91_DBGU_CHAN *)pSioChan;    DBGU_S* udev;	UINT32	status;	udev = pChan ->regs;    /* is the transmitter ready to accept a character? */	status = udev ->DBGU_CSR;	if( status&( DBGU_CSR_FRAME | DBGU_CSR_OVRE| DBGU_CSR_PARE ) )	{		pChan->errcount ++;		udev->DBGU_CR = DBGU_CR_RESET_STATUS;	}	if( status&(DBGU_CSR_TXRDY) )	{		udev ->DBGU_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 AT91DBGUPollInput    (    SIO_CHAN *	pSioChan,    char *	thisChar    ){    AT91_DBGU_CHAN * pChan = (AT91_DBGU_CHAN *)pSioChan;    DBGU_S* udev;	UINT32	status;		udev = pChan ->regs;	status = udev ->DBGU_CSR;		if( status&( DBGU_CSR_FRAME | DBGU_CSR_OVRE| DBGU_CSR_PARE ) )	{		pChan->errcount ++;		udev->DBGU_CR = DBGU_CR_RESET_STATUS;	}		if( status&(DBGU_CSR_RXRDY) )	{		status = udev ->DBGU_RHR;		(*thisChar) = (BYTE)status;	    return (OK);    }	else		return (EAGAIN);}/******************************************************************************** sndsModeSet - toggle between interrupt and polled mode** RETURNS: OK on success, EIO on unsupported mode.*//* *	because DBUG use the system interrupt line, we can not use intDisable/intEnable *	as normal UART  */LOCAL int AT91DBGUModeSet    (    AT91_DBGU_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);

⌨️ 快捷键说明

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