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

📄 ambasio.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 2 页
字号:
LOCAL STATUS ambaIoctl    (    SIO_CHAN *	pSioChan,	/* ptr to SIO_CHAN describing this channel */    int		request,	/* request code */    int		arg		/* some argument */    )    {    int		oldlevel;	/* current interrupt level mask */    STATUS	status;		/* status to return */    UINT32	brd;		/* baud rate divisor */    AMBA_CHAN * pChan = (AMBA_CHAN *)pSioChan;    status = OK;	/* preset to return OK */    switch (request)	{	case SIO_BAUD_SET:	    /*	     * Set the baud rate. Return EIO for an invalid baud rate, or	     * OK on success.	     */									    /*	     * baudrate divisor must be non-zero and must fit in a 12-bit	     * register.	     */	    brd = (pChan->xtal/(16*arg)) - 1;	/* calculate baudrate divisor */	    if ((brd < 1) || (brd > 0xFFF))		{		status = EIO;		/* baud rate out of range */		break;		}	    /* disable interrupts during chip access */	    oldlevel = intLock ();	    /* Set baud rate divisor in UART */	    AMBA_UART_REG_WRITE(pChan, L_UBRLCR, brd & 0xFF);	    AMBA_UART_REG_WRITE(pChan, M_UBRLCR, (brd >> 8) & 0xF);	    /*	     * Set word format, enable FIFOs: set 8 bits, 1 stop bit, no parity.	     * This also latches the writes to the two (sub)registers above.	     */	    AMBA_UART_REG_WRITE(pChan, H_UBRLCR,		(UINT8)(WORD_LEN_8 | ONE_STOP | PARITY_NONE | FIFO_ENABLE));	    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 appropriate interrupts */		intEnable (pChan->levelRx);		/*		 * There is no point in enabling the Tx interrupt, as it		 * will interrupt immediately and be disabled.		 */  		}	    else		{		/* Disable the interrupts */ 		intDisable (pChan->levelRx);		intDisable (pChan->levelTx);		}	    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.	     */	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;    }/********************************************************************************* ambaIntTx - handle a transmitter interrupt ** This routine handles write interrupts from the UART.** RETURNS: N/A*/void ambaIntTx     (    AMBA_CHAN *	pChan	/* ptr to AMBA_CHAN describing this channel */    )    {    char outChar;    if ((*pChan->getTxChar) (pChan->getTxArg, &outChar) != ERROR)	/* write char. to Transmit Holding Reg. */	AMBA_UART_REG_WRITE(pChan, UARTDR, outChar);    else	intDisable (pChan->levelTx);    }/******************************************************************************* ambaIntRx - handle a receiver interrupt ** This routine handles read interrupts from the UART.** RETURNS: N/A*/void ambaIntRx    (    AMBA_CHAN *	pChan	/* ptr to AMBA_CHAN describing this channel */    )    {    char inchar;    /* read character from Receive Holding Reg. */    AMBA_UART_REG_READ(pChan, UARTDR, inchar);    (*pChan->putRcvChar) (pChan->putRcvArg, inchar);    }/********************************************************************************* 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)	{	intEnable (pChan->levelTx);	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;    FAST UINT32 pollStatus;    AMBA_UART_REG_READ(pChan, UARTFLG, pollStatus);    /* is the transmitter ready to accept a character? */    if ((pollStatus & FLG_UTXFF) != 0x00)	return EAGAIN;    /* write out the character */    AMBA_UART_REG_WRITE(pChan, UARTDR, outChar);	/* transmit character */    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;    AMBA_UART_REG_READ(pChan, UARTFLG, pollStatus);    if ((pollStatus & FLG_URXFE) != 0x00)	return EAGAIN;    /* got a character */    AMBA_UART_REG_READ(pChan, UARTDR, *thisChar);    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 + -