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

📄 primecellsio.c

📁 2410 BSP vxworks xia下
💻 C
📖 第 1 页 / 共 2 页
字号:
	     * Set the baud rate. Return EIO for an invalid baud rate, or	     * OK on success.	     */									    /* disable interrupts during chip access */	    	   	    oldlevel = intLock ();		    pclk = Get_Pclk();            ndiv = (int)(pclk/(arg*16))-1;            AMBA_UART_REG_WRITE(pChan,OFFUBRDIV0,ndiv);	    pChan->baudRate = arg; 	    intUnlock (oldlevel);	    break;	case SIO_BAUD_GET:	    /* Get the baud rate and return OK */	    	    *(int *)arg = pChan->baudRate;	    break; 	case SIO_MODE_SET:	    /*	     * Set the mode (e.g., to interrupt or polled). Return OK	     * or EIO for an unknown or unsupported mode.	     */	    if ((arg != SIO_MODE_POLL) && (arg != SIO_MODE_INT))		{		status = EIO;		break;		}	   	    oldlevel = intLock ();	    if (arg == SIO_MODE_INT)		{					/*enable uart's interrupt*/    			if( pChan->levelRx == INT_LVL_UART_0 )    			{    				rINTSUBMSK &= ~(BIT_SUB_RXD0|BIT_SUB_ERR0);    				/*rINTMSK &= ~(BIT_UART0 );*/				/* Enable appropriate interrupts. */				intEnable (pChan->levelRx);			}			if( pChan->levelRx == INT_LVL_UART_1 )    			{    				rINTSUBMSK &= ~(BIT_SUB_RXD1|BIT_SUB_ERR1);    				/*rINTMSK &= ~(BIT_UART1 );*/				/* Enable appropriate interrupts. */				intEnable (pChan->levelRx);			}		/*		 * There is no point in enabling the Tx interrupt, as it		 * will interrupt immediately and be disabled.		 */  		}	    else		{		/* Disable all interrupts for this UART. */ 			intDisable (pChan->levelRx);			    			if( pChan->levelRx == INT_LVL_UART_0 )    			{    				rINTSUBMSK |= (BIT_SUB_TXD0|BIT_SUB_RXD0|BIT_SUB_ERR0); 				/*rINTMSK |= (BIT_UART0 );*/ 			} 			if( pChan->levelRx == INT_LVL_UART_1 )    			{    				rINTSUBMSK |= (BIT_SUB_TXD1|BIT_SUB_RXD1|BIT_SUB_ERR1); 				/*rINTMSK |= (BIT_UART1 );*/ 			}    					}	    pChan->channelMode = arg;		    intUnlock (oldlevel);	    break;	    	case SIO_MODE_GET:	    /* 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.	     */	     /*(*(volatile unsigned char *)0x50000020) = 'h';	     break;*/	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).	     	     */	     /*(*(volatile unsigned char *)0x50000020) = 'g';	     break;*/                    default:	    status = ENOSYS;	}    return status;    }/********************************************************************************* primeCellSioIntTx - handle a transmitter interrupt ** This routine handles write interrupts from the UART.** RETURNS: N/A*/void primeCellSioIntTx     (    AMBA_CHAN *	pChan	/* ptr to AMBA_CHAN describing this channel */    )    {    char outChar;          if ((*pChan->getTxChar) (pChan->getTxArg, &outChar) != ERROR)    {		if(!UART_TXFIFO_FULL(pChan))    		AMBA_UART_REG_WRITE(pChan,OFFUTXH0,outChar);    	    	/*if( pChan->levelRx == INT_LVL_UART_0 )    	{    		rINTSUBMSK &= ~(BIT_SUB_TXD0);    	}    	    	if( pChan->levelRx == INT_LVL_UART_1 )    	{    		rINTSUBMSK &= ~(BIT_SUB_TXD1);    	}*/    	    	/*AMBA_UART_REG_WRITE(pChan,OFFUTXH0,'O');*/    }    else	{		/*while(UART_TXFIFO_FULL(pChan));    		AMBA_UART_REG_WRITE(pChan,OFFUTXH0,XON);*/	if( pChan->levelRx == INT_LVL_UART_0 )    	{		rINTSUBMSK |= BIT_SUB_TXD0;	}	if( pChan->levelRx == INT_LVL_UART_1 )    	{		rINTSUBMSK |= BIT_SUB_TXD1;	}		}	   }/******************************************************************************* primeCellSioIntRx - handle a receiver interrupt ** This routine handles read interrupts from the UART.** RETURNS: N/A*/void primeCellSioIntRx    (    AMBA_CHAN *	pChan	/* ptr to AMBA_CHAN describing this channel */    )    {    char inchar;           /* read characters from Receive Holding Reg. */   		while( ! UART_RXFIFO_EMPTY(pChan) )	{				inchar = UART_FIFO_RXDATA(pChan);		    		(*pChan->putRcvChar) (pChan->putRcvArg, inchar);					}		        }/******************************************************************************** primeCellSioInt - handle any UART interrupt** This routine handles interrupts from the UART and determines whether* the source is a transmit interrupt or receive/receive-timeout interrupt.** The Prime Cell UART generates a receive interrupt when the RX FIFO is* half-full, and a receive-timeout interrupt after 32 bit-clocks have* elapsed with no incoming data.** RETURNS: N/A*/void primeCellSioInt    (    AMBA_CHAN * pChan   /* ptr to AMBA_CHAN describing this channel */    )    {    UINT32   reg_cont;        	if( pChan->levelRx == INT_LVL_UART_0 )    	{    		/*rINTMSK |= BIT_UART0;*/    		reg_cont = rSUBSRCPND;    	    		if (reg_cont & BIT_SUB_TXD0)        	{    					rSUBSRCPND = BIT_SUB_TXD0;			primeCellSioIntTx (pChan);			}    		if (reg_cont & BIT_SUB_RXD0 || reg_cont & BIT_SUB_ERR0)    			{    			rSUBSRCPND = BIT_SUB_RXD0|BIT_SUB_ERR0;			primeCellSioIntRx (pChan);			}		/*rINTSUBMSK &= ~(BIT_SUB_RXD0|BIT_SUB_ERR0);*/		/*ClearPending(BIT_UART0);*/			/*rINTMSK &= ~(BIT_UART0);*/	}		if( pChan->levelRx == INT_LVL_UART_1 )    	{    		/*rINTMSK |= BIT_UART1;*/    		reg_cont = rSUBSRCPND;    	    		if (reg_cont & BIT_SUB_TXD1)        	{    					rSUBSRCPND = BIT_SUB_TXD1;			primeCellSioIntTx (pChan);			}    		if (reg_cont & BIT_SUB_RXD1 || reg_cont & BIT_SUB_ERR1)    			{    			rSUBSRCPND = BIT_SUB_RXD1|BIT_SUB_ERR1;			primeCellSioIntRx (pChan);			}		/*rINTSUBMSK &= ~(BIT_SUB_RXD1|BIT_SUB_ERR1);*/		/*ClearPending(BIT_UART1);*/			/*rINTMSK &= ~(BIT_UART1);*/	}    } /********************************************************************************* ambaTxStartup - 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.*/LOCAL int ambaTxStartup    (    SIO_CHAN *	pSioChan	/* ptr to SIO_CHAN describing this channel */    )    {    AMBA_CHAN * pChan = (AMBA_CHAN *)pSioChan;        if (pChan->channelMode == SIO_MODE_INT)	{	if( pChan->levelRx == INT_LVL_UART_0 )    	{		rINTMSK &= ~(BIT_UART0);		rINTSUBMSK &= ~(BIT_SUB_TXD0);	}	if( pChan->levelRx == INT_LVL_UART_1 )    	{		rINTMSK &= ~(BIT_UART1);		rINTSUBMSK &= ~(BIT_SUB_TXD1);	}		return OK;	}    else	return ENOSYS;    }/******************************************************************************** ambaPollOutput - 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.*/LOCAL int ambaPollOutput    (    SIO_CHAN *	pSioChan,	/* ptr to SIO_CHAN describing this channel */    char	outChar 	/* char to output */    )    {    AMBA_CHAN * pChan = (AMBA_CHAN *)pSioChan;       if(pChan->channelMode == SIO_MODE_POLL)    {    	/*while(UART_TXFIFO_FULL(pChan));*/    	if(UART_TXFIFO_FULL(pChan))    	{    		return EAGAIN;    	}    	    	AMBA_UART_REG_WRITE(pChan,OFFUTXH0,outChar);    }    else    	return  ENOSYS;        return OK;    }/******************************************************************************** ambaPollInput - 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.*/LOCAL int ambaPollInput    (    SIO_CHAN *	pSioChan,	/* ptr to SIO_CHAN describing this channel */    char *	thisChar	/* pointer to where to return character */    )    {            AMBA_CHAN * pChan = (AMBA_CHAN *)pSioChan;    FAST UINT32 pollStatus;           if(pChan->channelMode == SIO_MODE_POLL)    {    	AMBA_UART_REG_READ(pChan, OFFUFSTAT0, pollStatus);    	if((pollStatus & 0xf) != 0x00)    	{   /* got a character */		/*for(i = 0 ; i < (pollStatus & 0xf) ; i++)*/    		AMBA_UART_REG_READ(pChan, OFFURXH0, *thisChar);    	}    	else    	{    		return EAGAIN;    	}    }    else    	return	ENOSYS;        return OK;    }/******************************************************************************** ambaCallbackInstall - 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 ambaCallbackInstall    (    SIO_CHAN *	pSioChan,	/* ptr to SIO_CHAN describing this channel */    int		callbackType,	/* type of callback */    STATUS	(*callback)(),	/* callback */    void *	callbackArg	/* parameter to callback */		     )    {    AMBA_CHAN * pChan = (AMBA_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 + -