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

📄 at91uart.c

📁 9200 uart driver串口驱动在vxworks上
💻 C
📖 第 1 页 / 共 4 页
字号:
		pChan->mode = SIO_MODE_INT;	    /* Enable transmit and received of UART Device */	    pUsart->US_CR = AT91RM9200_US_CR_RXEN | AT91RM9200_US_CR_TXEN;	    	    }	else	    {	    /* Whoops, device is not there! */	    free ((char *)pChan);	    errnoSet (S_iosLib_DEVICE_NOT_FOUND);	    	    return;	    }	}    return;    }/********************************************************************************* at91UARTInt - handle an AT91RM9200 UART interrupt** This routine is called to handle AT91RM9200 UART interrupts.*/void at91UARTInt    (    AT91_UART_CHAN *pChan    )    {    AT91PS_USART pUsart = (AT91PS_USART)(pChan->ioBase);	/* point to UART register index by ioBase of pChan */    	UINT32	status;	int errorCode = SIO_ERROR_NONE;	status = pUsart->US_CSR;	if (status)	{		/* we can make below process several times when TXRDY or RXRDY is there */				if (status & (AT91RM9200_US_SR_RXRDY))			at91UARTIntRx (pChan);    	/* Check for error conditions */		if (status & (AT91RM9200_US_SR_PARE | AT91RM9200_US_SR_FRAME | AT91RM9200_US_SR_OVRE))		{		/*		 * Determine precise error condition and perform		 * recovery actions.		 */       	    pUsart->US_CR = AT91RM9200_US_CR_RSTSTA;       	    		    /*		     * If needed, you should acknowledge or reset the interrupt source		     * as soon as possible, usually before passing any error conditions		     * upstream.		     */		    if (status & (AT91RM9200_US_SR_PARE))		    	{		    		errorCode = SIO_ERROR_PARITY;		    	}		    else if (status & (AT91RM9200_US_SR_FRAME))		    	{		    		errorCode = SIO_ERROR_FRAMING;		    	}		    		    if (errorCode != SIO_ERROR_NONE)			(*pChan->errorRtn) (pChan->errorArg, errorCode, NULL, 0);		    if (status & (AT91RM9200_US_SR_OVRE))		    	{		    		errorCode = SIO_ERROR_OFLOW;				(*pChan->errorRtn) (pChan->errorArg, errorCode, NULL, 0);		    	}		}		if (status & (AT91RM9200_US_SR_TXRDY))			at91UARTIntTx (pChan);	}    }/******************************************************************************** at91UARTIntRx - handle a channel's receive-character interrupt** RETURNS: N/A*/ LOCAL void at91UARTIntRx    (    AT91_UART_CHAN *	pChan		/* channel generating the interrupt */    )    {    char   inChar;  /* receive data */    UINT32 rxStatus = 0; /* receive status *//*        STATUS status = OK;    int errorCode = SIO_ERROR_NONE;*/    AT91PS_USART pUsart = (AT91PS_USART)(pChan->ioBase);	/* point to UART register index by ioBase of pChan */        /*     *     * Get status and data from the device. Determine if valid data is ready     * or not.     *     * For PCI devices, do an immediate return if device is not asserting     * an interrupt.     */    rxStatus = pUsart->US_CSR;        while (rxStatus & AT91RM9200_US_SR_RXRDY)    	{		inChar = pUsart->US_RHR;		/* RXRDY bit in US_CSR will be clear when RHR is read */				/* send data character upstream */		(*pChan->putRcvChar) (pChan->putRcvArg, inChar);		if (pChan->mode != SIO_MODE_INT) break;		rxStatus = pUsart->US_CSR;    	}#if 0	/* will be processed in at91UARTIntErr */    if (status == ERROR)	{	/* send error notification upstream */	(*pChan->errorRtn) (pChan->errorArg, SIO_ERROR_UNKNWN, NULL, 0);	}#endif #if 0 /* Keyboard emulation code */	/*	 * TODO - For a keyboard type device we would map the raw scan code	 * to ASCII, or other mapping.  Do that here.	 */	if (pChan->scanMode == SIO_KYBD_MODE_ASCII)	    inChar = templateAsciiTbl[(UINT8)inChar];#endif    }/******************************************************************************** at91UARTIntTx - handle a channels transmitter-ready interrupt** RETURNS: N/A*/ LOCAL void at91UARTIntTx    (    AT91_UART_CHAN *pChan		/* channel generating the interrupt */    )    {    char	outChar;    UINT32 txStatus;	/* status of transmit */    /* BOOL	txReady = TRUE; */    int		errorCode = SIO_ERROR_NONE;    AT91PS_USART pUsart = (AT91PS_USART)(pChan->ioBase);;	/* point to UART register index by ioBase of pChan */            /*     * Check the Tx status     *     * For PCI devices, do an immediate return if device is not asserting     * an interrupt.     */#if 0    /* Check for error conditions */        if (crData & TEMPLATE_CR_TX_ERROR)	{	/*	 * TODO - Typically you should determine the precise error condition	 * and perform all recovery operations here.	 */	TEMPLATE_SIO_WRITE8 (pChan, TEMPLATE_CSR_ID, TEMPLATE_RESET_TX);	errorCode = SIO_ERROR_UNKNWN;	txReady = TRUE; /* set to false if xmitter is not ready now */	}    #endif    /*     * If transmitter is okay and ready to send, lets see if there is a     * data character ready to be sent.     *     * If there's a character to transmit then write it out, else reset (idle)     * the transmitter. For chips with output FIFO's it is more efficient     * to fill the entire FIFO here.     */    txStatus = pUsart->US_CSR;    if (txStatus & AT91RM9200_US_SR_TXRDY)	{	if ((*pChan->getTxChar) (pChan->getTxArg, &outChar) != ERROR)	    {	    /* Output data to device.  */		pUsart->US_THR = outChar;		/* need to insert a wait time for transmit finished ? */	    	txStatus = pUsart->US_CSR;	    /*	     * If a device error occurs at this point, then	     * isolate the precise error type and try to recover.	     */	    }	else	    {	    /*	     * There is no more data to send.	     *	     * Put XMTR in an idle state. Higher layer	     * will call TxStartup entry to resume xmit operations.	     */		pUsart->US_IDR = AT91RM9200_US_INT_TXRDY;		       /*	       pUsart->US_CR = AT91RM9200_US_CR_TXDIS | AT91RM9200_US_CR_RSTTX; */ /* disable transmit */	       	       /* break; */	    }	}    /*     * If needed, you should acknowledge or reset the interrupt source     * as soon as possible, usually before passing any error conditions     * upstream.     */    /* US_TXRDY will be cleared when char is sent */    /* Pass any errorCodes upstream.  */    if (errorCode != SIO_ERROR_NONE)	{	(*pChan->errorRtn) (pChan->errorArg, errorCode, NULL, 0);	}    }#if 0/******************************************************************************** at91UARTIntErr - handle a channels error interrupt** RETURNS: N/A*/ LOCAL void at91UARTIntErr    (    AT91_UART_CHAN *	pChan		/* channel generating the interrupt */    )    {    AT91PS_USART pUsart = (AT91PS_USART)(pChan->ioBase);;	/* point to UART register index by ioBase of pChan */                UINT32 errStatus;    errStatus = pUsart->US_CSR;        /*     * Determine the precise error condition and perform recovery     * operations.     *     * For PCI devices, do an immediate return if device is not asserting     * an interrupt.     */    if (errStatus & (AT91C_US_PARE | AT91C_US_FRAME | AT91C_US_OVRE)    {    }}#endif /******************************************************************************** templateTxStartup - start the interrupt transmitter** This routine exits to inform the device to start transmitting data again.* The actual data will be obtained by calling the TxCharGet callback routine.** This routine is usually just the same as the tx interrupt routine.  This* routine runs at task level context and does not have to be interrupt safe.** RETURNS: OK on success, ENOSYS if the device is polled-only, or* EIO on hardware error.*/LOCAL int at91TxStartup    (    SIO_CHAN * pSioChan                 /* channel to start */    )    {    AT91_UART_CHAN * pChan = (AT91_UART_CHAN *)pSioChan;    AT91PS_USART pUsart = (AT91PS_USART)(pChan->ioBase);	/* point to UART register index by ioBase of pChan */        /* char outChar; */    /* This routine should only be called while in interrupt mode */	/* NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE	   NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE	   NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE	   NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE	 */	/* pChan->mode = SIO_MODE_POLL; */    if (pChan->mode == SIO_MODE_INT)        {#if 0        if (pChan->options & CLOCAL)            {            /* No modem control - start immediately */            }        else            {	    /*	     * Modem controls are active. 	     *	     * If CTS is high, we can start immediately so just enable	     * the TX interrupt.	     *	     * If CTS is low, then we cannot send now.  The driver	     * should be set up to generate a TX interrupt when the CTS	     * line returns to the active state.	     */            }        /*	 * Enable the correct interrupts. A TX interrupt should either	 * occur immediately, or later when CTS becomes active.  That will start	 * the flow of data.	 *	 * There are two usual methods here.  The first is to just enable	 * TX interrupts, which should cause an immediate TX interrupt, which	 * will begin fetching and sending characters.	 *	 * The second method is to call the getTxChara callback here, put	 * the data to the transmitter directly, and then to enable TX	 * interrupts to fetch and send additional characters.	 */#endif #if 0    if ((pUsart->US_CSR & AT91C_US_TXRDY) && \		((*pChan->getTxChar) (pChan->getTxArg, &outChar) != ERROR))	    {	    /* Output data to device.  */		pUsart->US_THR = outChar;	    /*	     * If a device error occurs at this point, then	     * isolate the precise error type and try to recover.	     */	    }#endif	 /* intEnable(pChan->intLevel); */	 /* pUsart->US_CR = AT91C_US_TXEN; */     pUsart->US_IER = AT91RM9200_US_INT_TXRDY;	/* we need set it again here ? */     return OK;        }    else/*         while ((*pChan->getTxChar) (pChan->getTxArg, &outChar) != ERROR)    {    	while (EAGAIN == at91PollOutput ((SIO_CHAN *)pChan, outChar));    }*/    	return ENOSYS;  	/* Not valid for polled mode operation */    return (OK);    }/******************************************************************************** at91CallbackInstall - 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 at91CallbackInstall    (    SIO_CHAN *	pSioChan,               /* channel */    int		callbackType,           /* type of callback */    STATUS	(*callback)(void *,...),  /* callback */    void *      callbackArg             /* parameter to callback */    )    {    AT91_UART_CHAN * pChan = (AT91_UART_CHAN *)pSioChan;    switch (callbackType)	{	case SIO_CALLBACK_GET_TX_CHAR:	    pChan->getTxChar	= (STATUS (*)(void *, char *))callback;	    pChan->getTxArg	= callbackArg;	    return (OK);	case SIO_CALLBACK_PUT_RCV_CHAR:	    pChan->putRcvChar	= (void (*)(void *, char))callback;	    pChan->putRcvArg	= callbackArg;	    return (OK);	case SIO_CALLBACK_ERROR:	    pChan->errorRtn	= (void (*)(void *, int, void *, int))callback;

⌨️ 快捷键说明

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