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

📄 st16552sio.c

📁 MPC8241:本程序是freescale的824*系列的BSP源程序
💻 C
📖 第 1 页 / 共 2 页
字号:
		/* Disable the interrupts */		ST16552_REG_WRITE(pChan, IER, 0);		}	    pChan->channelMode = arg;	    intUnlock(oldlevel);	    break;	case SIO_MODE_GET:	    *(int *)arg = pChan->channelMode;	    break;	case SIO_AVAIL_MODES_GET:	    *(int *)arg = SIO_MODE_INT | SIO_MODE_POLL;	    break;	case SIO_HW_OPTS_SET:	case SIO_HW_OPTS_GET:	default:	    status = ENOSYS;	}    return status;    }/********************************************************************************* st16552IntWr - handle a transmitter interrupt** This routine handles write interrupts from the UART.** RETURNS: N/A*/void st16552IntWr    (    ST16552_CHAN *	pChan	/* ptr to struct describing channel */    )    {    char outChar;    BOOL gotOne;    UINT32 status;    do    	{    			/* get a character to send, if available */	gotOne = (*pChan->getTxChar) (pChan->getTxArg, &outChar) != ERROR;	if (gotOne)				/* there was one, so send it */	    ST16552_REG_WRITE(pChan, THR, outChar);	/* write char to THR */	ST16552_REG_READ(pChan, LSR, status);	/* read status */	}    while (gotOne && ((status & LSR_THRE) != 0));    if (!gotOne)	{	/* no more chars to send, disable Tx interrupt */	pChan->ier &= (~TxFIFO_BIT);			/* update copy */	ST16552_REG_WRITE(pChan, IER, pChan->ier); 	/* disable Tx int */	}    return;    }/******************************************************************************* st16552IntRd - handle a receiver interrupt** This routine handles read interrupts from the UART.** RETURNS: N/A*/void st16552IntRd    (    ST16552_CHAN *	pChan	/* ptr to struct describing channel */    )    {    char inchar;    UINT32 status;    do	{	/* read character from Receive Holding Reg. */	ST16552_REG_READ(pChan, RBR, inchar);	/* send it on to upper level, via installed callback */	(*pChan->putRcvChar) (pChan->putRcvArg, inchar);	ST16552_REG_READ(pChan, LSR, status);	/* read status, more chars? */	}    while ((status & LSR_DR) != 0);    return;    }/************************************************************************ st16552IntEx - miscellaneous interrupt processing** This routine handles miscellaneous interrupts on the UART.** RETURNS: N/A*/void st16552IntEx    (    ST16552_CHAN *	pChan	/* ptr to struct describing channel */    )    {    /* Nothing for now... */    }/******************************************************************************** st16552Int - interrupt level processing** This routine handles interrupts from the UART.** RETURNS: N/A*/void st16552Int    (    ST16552_CHAN *	pChan	/* ptr to struct describing channel */    )    {    /*     * If this routine has been called from the multiplexed interrupt     * handler, then we have already read the Interrupt Status Register,     * and must not read it again, else this routine has been installled     * directly using intConnect() and we must now read the Interrupt     * Status Register (or Interrupt Identification Register).     */	 	 if(pChan->level ==65 )	 {	 	printf("intStatus:%d\n",intStatus);	 }	      if (!multiplexed)	 {	 ST16552_REG_READ(pChan, IIR, intStatus);	 intStatus &= 0x0F;	 }	 	 	     /*     * This UART chip always produces level active interrupts, and the IIR     * only indicates the highest priority interrupt.     * In the case that receive and transmit interrupts happened at     * the same time, we must clear both interrupt pending to prevent     * edge-triggered interrupt(output from interrupt controller) from locking     * up. One way doing it is to disable all the interrupts at the beginning     * of the ISR and enable at the end.     */    ST16552_REG_WRITE(pChan, IER, 0);	/* disable interrupts */    switch (intStatus)	{	case IIR_RLS:	    /*	     * overrun, parity error and break interrupt:	     *	     * read LSR to reset interrupt	     */	    ST16552_REG_READ(pChan, LSR, intStatus);	    break;	case IIR_RDA:	    /* received data available: FALL THROUGH to timeout */	case IIR_TIMEOUT:	    /*	     * receiver FIFO interrupt. In some cases, IIR_RDA	     * will not be indicated in IIR register when there	     * is more than one char. in FIFO.	     */	    st16552IntRd (pChan);	/* at least one RxChar available */	    break;	case IIR_THRE:	    st16552IntWr (pChan);	/* can transmit at least one char */	    break;	default:	    break;	}    ST16552_REG_WRITE(pChan, IER, pChan->ier); /* enable ints accordingly */    }/******************************************************************************** st16552MuxInt - multiplexed interrupt level processing** This routine handles multiplexed interrupts from the DUART. It assumes that* channels 0 and 1 are connected so that they produce the same interrupt.** RETURNS: N/A*/void st16552MuxInt    (    ST16552_MUX *	pMux	/* ptr to struct describing multiplexed chans */    )    {    ST16552_CHAN *	pChan;    /* get pointer to structure for channel to examine first */    pChan = &(pMux->pChan[pMux->nextChan]);    /*     * Step on the next channel to examine: use round-robin for which to     * examine first.     */    if (pMux->nextChan == 0)	pMux->nextChan = 1;    else	pMux->nextChan = 0;    /*     * Let the st16552Int() routine know it is called from here, not direct     * from intConnect().because only two channels.     */    multiplexed = TRUE;    /* check Interrupt Status Register for this channel */    ST16552_REG_READ(pChan, IIR, intStatus);    intStatus &= 0x0F;    if ((intStatus & 0x01) == 0)	{	/* Call int handler if int active */	st16552Int (pChan);	}    else	{	/* step on again */	pChan = &pMux->pChan[pMux->nextChan];	if (pMux->nextChan == 0)	    pMux->nextChan = 1;	else	    pMux->nextChan = 0;	/* get interrupt status for next channel */	ST16552_REG_READ(pChan, IIR, intStatus);	intStatus &= 0x0F;	/* and call interrupt handler if active */	if ((intStatus & 0x01) == 0)	    st16552Int (pChan);	}    multiplexed = FALSE;    return;    }/********************************************************************************* st16552TxStartup - transmitter startup routine** Call interrupt level character output routine and enable interrupt!** RETURNS: OK on success, ENOSYS if the device is polled-only, or* EIO on hardware error.*/LOCAL int st16552TxStartup    (    SIO_CHAN *		pSioChan  /* ptr to SIO_CHAN describing this channel */    )    {    ST16552_CHAN *	pChan = (ST16552_CHAN *)pSioChan;    if (pChan->channelMode == SIO_MODE_INT)	{	pChan->ier |= TxFIFO_BIT;	ST16552_REG_WRITE(pChan, IER, pChan->ier);	return OK;	}    else	return ENOSYS;    }/******************************************************************************** st16552PollOutput - 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 st16552PollOutput    (    SIO_CHAN *		pSioChan, /* ptr to SIO_CHAN describing this channel */    char		outChar	  /* char to be output */    )    {    ST16552_CHAN *	pChan = (ST16552_CHAN *)pSioChan;    char pollStatus;    ST16552_REG_READ(pChan, LSR, pollStatus);    /* is the transmitter ready to accept a character? */    if ((pollStatus & LSR_THRE) == 0x00)	return EAGAIN;    /* write out the character */    ST16552_REG_WRITE(pChan, THR, outChar);	/* transmit character */    return OK;    }/******************************************************************************** st16552PollInput - 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 st16552PollInput    (    SIO_CHAN *		pSioChan, /* ptr to SIO_CHAN describing this channel */    char *		thisChar  /* ptr to where to return character */    )    {    ST16552_CHAN *	pChan = (ST16552_CHAN *)pSioChan;    char pollStatus;    ST16552_REG_READ(pChan, LSR, pollStatus);    if ((pollStatus & LSR_DR) == 0x00)	return EAGAIN;    /* got a character */    ST16552_REG_READ(pChan, RBR, *thisChar);    return OK;    }/******************************************************************************** st16552CallbackInstall - 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 st16552CallbackInstall    (    SIO_CHAN *	pSioChan,	/* ptr to SIO_CHAN describing this channel */    int		callbackType,	/* type of callback */    STATUS	(*callback)(),	/* callback */    void *	callbackArg	/* parameter to callback */    )    {    ST16552_CHAN * pChan = (ST16552_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 + -