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

📄 am85c30serial.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    SCC_DELAY;    *cr = SCC_WR0_SEL_WR14;		/* clock source : BRG */    SCC_DELAY;    *cr = pTyCoDv->clockModeWR14;    SCC_DELAY;    *cr = SCC_WR0_SEL_WR3;		/* write reg 3 - receive params */    SCC_DELAY;    *cr = SCC_WR3_RX_8_BITS | SCC_WR3_RX_EN;    SCC_DELAY;    *cr = SCC_WR0_SEL_WR5;		/* tx params */    SCC_DELAY;    *cr = SCC_WR5_TX_8_BITS | SCC_WR5_TX_EN | SCC_WR5_DTR | SCC_WR5_RTS;    SCC_DELAY;    *cr = SCC_WR0_SEL_WR15;		/* external/status interrupt control */    SCC_DELAY;    *cr = zero;    SCC_DELAY;    *cr = SCC_WR0_RST_INT;		/* reset external interrupts */    SCC_DELAY;    *cr = SCC_WR0_SEL_WR1;		/* int and xfer mode */    SCC_DELAY;    *cr = SCC_WR1_INT_ALL_RX | SCC_WR1_TX_INT_EN;    SCC_DELAY;    *cr = SCC_WR0_SEL_WR9;		/* master interrupt control */    SCC_DELAY;    *cr = SCC_WR9_MIE | pTyCoDv->intType; /* enable interrupts */    SCC_DELAY;    *cr = zero;				/* reset SCC register counter */    SCC_DELAY;    intUnlock (oldlevel);    }/********************************************************************************* tyCoOpen - open file to USART*/LOCAL int tyCoOpen    (    TY_CO_DEV * pTyCoDv,    char      * name,    int         mode    )    {    return ((int) pTyCoDv);    }/********************************************************************************* tyCoIoctl - special device control** This routine handles FIOBAUDRATE requests and passes all others to tyIoctl().** RETURNS: OK, or ERROR if invalid baud rate, or whatever tyIoctl() returns.*/LOCAL STATUS tyCoIoctl    (    TY_CO_DEV * pTyCoDv,	/* device to control */    int         request,	/* request code */    int         arg		/* some argument */    )    {    int			oldlevel;	/* current interrupt level mask */    int			baudConstant;    STATUS		status;    volatile char *	cr;		/* SCC control reg adr */    switch (request)	{	case FIOBAUDRATE:	    if (arg < 50 || arg > 38400)	        {		status = ERROR;		/* baud rate out of range */		break;	        }	    /* Calculate the baud rate constant for the new baud rate	     * from the input clock frequency.  This assumes that the	     * divide-by-16 bit is set in the Am85C30 WR4 register (done	     * in tyCoInitChannel).	     */	    baudConstant = ((pTyCoDv->baudFreq / 32) / arg) - 2;	    cr = pTyCoDv->cr;	    /* disable interrupts during chip access */	    oldlevel = intLock ();	    *cr = SCC_WR0_SEL_WR12;	/* LSB of baud constant */	    SCC_DELAY;	    *cr = (char)baudConstant;	/* write LSB */	    SCC_DELAY;	    *cr = SCC_WR0_SEL_WR13;	/* MSB of baud constant */	    SCC_DELAY;	    *cr = (char)(baudConstant >> 8); /* write MSB */	    SCC_DELAY;	    intUnlock (oldlevel);	    status = OK;	    break;	default:	    status = tyIoctl (&pTyCoDv->tyDev, request, arg);	    break;	}    return (status);    }/********************************************************************************* tyCoIntWr - interrupt level processing** This routine handles write interrupts from the SCC.** RETURNS: N/A** NOMANUAL*/void tyCoIntWr    (    int channel			/* interrupting serial channel */    )    {    char		outChar;    TY_CO_DEV *		pTyCoDv = &tyCoDv [channel];    volatile char *	cr = pTyCoDv->cr;    if (pTyCoDv->created && tyITx (&pTyCoDv->tyDev, &outChar) == OK)	{	*pTyCoDv->dr = outChar;	}    else	{	/* no more chars to xmit now.  reset the tx int,	 * so the SCC does not keep interrupting.	 */	*cr = SCC_WR0_RST_TX_INT;	SCC_DELAY;	}    *cr = SCC_WR0_RST_HI_IUS;	/* end the interrupt acknowledge */    SCC_DELAY;    }/******************************************************************************* tyCoIntRd - interrupt level input processing** This routine handles read interrupts from the SCC** RETURNS: N/A** NOMANUAL*/void tyCoIntRd    (    int channel			/* interrupting serial channel */    )    {    TY_CO_DEV *		pTyCoDv = &tyCoDv [channel];    volatile char *	cr = pTyCoDv->cr;    char		inchar;    inchar = *pTyCoDv->dr;    if (pTyCoDv->created)	tyIRd (&pTyCoDv->tyDev, inchar);    *cr = SCC_WR0_RST_HI_IUS;	/* reset the interrupt in the Am85C30 */    SCC_DELAY;    }/************************************************************************ tyCoIntEx - miscellaneous interrupt processing** This routine handles miscellaneous interrupts on the SCC** RETURNS: N/A** NOMANUAL*/void tyCoIntEx    (    int channel			/* interrupting serial channel */    )    {    TY_CO_DEV *		pTyCoDv = &tyCoDv [channel];    volatile char *	cr = pTyCoDv->cr;    *cr = SCC_WR0_ERR_RST;	/* reset errors */    SCC_DELAY;    *cr = SCC_WR0_RST_HI_IUS;	/* reset the interrupt in the Am85C30 */    SCC_DELAY;    }/********************************************************************************* tyCoInt - interrupt level processing** This routine handles interrupts from both of the SCCs.* We determine from the parameter which SCC interrupted, then look at* the code to find out which channel and what kind of interrupt.** NOMANUAL*/void tyCoInt    (    int sccNum    )    {    volatile char *	cr;    char		intStatus;    TY_CO_DEV *		pTyCoDv;    char		outChar;    /* We need to find out which channel interrupted.  We need to read     * the B channel of the interrupting SCC to find out which channel     * really interrupted.  Note that things are set up so that the A     * channel is channel 0, even though on the chip it is the one with     * the higher address     */      pTyCoDv = &tyCoDv [(sccNum * 2) + 1];    cr = pTyCoDv->cr;    SCC_DELAY;    *cr = SCC_WR0_SEL_WR2;                      /* read reg 2 */    SCC_DELAY;    intStatus = *cr;    if ((intStatus & 0x08) != 0)        {                               /* the A channel interrupted */        --pTyCoDv;        cr = pTyCoDv->cr;        }    switch (intStatus & 0x06)        {        case 0x04:                      /* RxChar Avail */            if (pTyCoDv->created)                tyIRd (&pTyCoDv->tyDev, *pTyCoDv->dr);            SCC_DELAY;            break;         case 0x00:                      /* Tx Buffer Empty */            if (pTyCoDv->created && (tyITx (&pTyCoDv->tyDev, &outChar) == OK))                *pTyCoDv->dr = outChar;            else                {                /* no more chars to xmit now.  reset the tx int,                 * so the SCC doesn't keep interrupting us.		 */                 *cr = SCC_WR0_RST_TX_INT;                }            SCC_DELAY;            break;         case 0x02:                      /* External Status Change */            *cr = SCC_WR0_ERR_RST;            SCC_DELAY;            outChar = *pTyCoDv->dr;          /* throw away char */            break;         case 0x06:                      /* Special receive condition */            *cr = SCC_WR0_ERR_RST;            SCC_DELAY;            break;                      /* ignore */         }     *cr = SCC_WR0_RST_HI_IUS;   /* Reset the Highest interrupt in the AM85C30 */    SCC_DELAY;    }/********************************************************************************* tyCoStartup - transmitter startup routine** Call interrupt level character output routine.*/LOCAL void tyCoStartup    (    TY_CO_DEV * pTyCoDv 		/* ty device to start up */    )    {    char outChar;    if (tyITx (&pTyCoDv->tyDev, &outChar) == OK)	*pTyCoDv->dr = outChar;    }

⌨️ 快捷键说明

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