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

📄 ixm1200sio.c

📁 vxworks的BSP开发配置文件
💻 C
📖 第 1 页 / 共 2 页
字号:
                status = EIO;           /* baud rate out of range */                break;                }            /* disable interrupts during chip access */            oldlevel = intLock ();            pChan->uartCR &= ~UART_BDR_MASK;            pChan->uartCR |= brd << UART_BDR_OFFSET;            IXM1200_REG_WRITE( UART_CR, pChan->uartCR );                    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 */                                pChan->uartCR |= UART_RX_INT_EN | UART_TX_INT_EN;                IXM1200_REG_WRITE( UART_CR, pChan->uartCR );                }            else                {                /* Disable the interrupt */                 pChan->uartCR &= ~(UART_RX_INT_EN | UART_TX_INT_EN);                IXM1200_REG_WRITE( UART_CR, pChan->uartCR | UART_INT_CLR);                }            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;    }/********************************************************************************* ixm1200UartInt - handle an interrupt** This routine handles interrupts from the UART.** RETURNS: N/A*/ void ixm1200UartInt    (    IXM1200_CHAN *       pChan   /* ptr to IXM1200_CHAN describing this channel */    )    {    UINT32      ch;             /* Possible char to be in/output */    UINT32      statusReg;      /* Status from UART */    int         gotOne;    char        c;    /* read status registers */    IXM1200_REG_READ( UART_SR, statusReg );        /*     * loop, removing characters from the rx FIFO (other Sio drivers do this     * so it must be OK)     */    while (statusReg & UART_RX_RDY)                        /* data? */        {        IXM1200_REG_READ ( UART_DR, ch);            /* read character */        (*pChan->putRcvChar) (pChan->putRcvArg, (char)ch); /* pass it on */        IXM1200_REG_READ( UART_SR, statusReg );   /* update status */        }    /*     * if tx FIFO is interrupting, loop, writing characters to the FIFO     * until the FIFO is full or there are no more characters to transmit     */    if (statusReg & UART_TX_EMPTY)              /* tx FIFO needs filling? */        {        do            {            gotOne = (*pChan->getTxChar) (pChan->getTxArg, &c) != ERROR;            if (gotOne)                IXM1200_REG_WRITE(UART_DR, c);          /* tx char */            IXM1200_REG_READ( UART_SR, statusReg );     /* update status */            }        while (gotOne && (statusReg & UART_TX_RDY));    /* while not full */        if (!gotOne)            {            /* no more chars to send - disable transmitter interrupts */                        pChan->uartCR &= ~UART_TX_INT_EN;            }        }    if (sysCpuRev < 1) {        /* Clear interrupts */        /* Note that if an interrupt comes through during the above processing,           then since the UART interrupts are level-sensitive, not edge-sensitive,           we won't lose an interrupt */        IXM1200_REG_WRITE( UART_CR, pChan->uartCR | UART_INT_CLR);    } else {        IXM1200_REG_WRITE( UART_CR, pChan->uartCR);    }    }/********************************************************************************* ixm1200UartTxStartup - transmitter startup routine** Call interrupt level char output routine and enable interrupt** RETURNS: OK on success, ENOSYS if the device is polled-only, or* EIO on hardware error.*/LOCAL int ixm1200UartTxStartup    (    SIO_CHAN *  pSioChan        /* ptr to SIO_CHAN describing this channel */    )    {    IXM1200_CHAN * pChan = (IXM1200_CHAN *)pSioChan;    UINT oldlevel;    if (pChan->channelMode == SIO_MODE_INT)        {        /* Enable Transmitter interrupts */                oldlevel = intLock ();        pChan->uartCR |= UART_TX_INT_EN;        IXM1200_REG_WRITE (UART_CR, pChan->uartCR);                intUnlock (oldlevel);        return OK;        }    else        {        return ENOSYS;        }    }/******************************************************************************** ixm1200UartPollOutput - 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 ixm1200UartPollOutput    (    SIO_CHAN *  pSioChan,       /* ptr to SIO_CHAN describing this channel */    char        outChar         /* char to output */    )    {    /* IXM1200_CHAN * pChan = (IXM1200_CHAN *)pSioChan; */    UINT32 pollStatus;    IXM1200_REG_READ (UART_SR, pollStatus);    /* is the transmitter ready to accept a character? */    if (pollStatus & UART_TX_FULL)        return EAGAIN;    /* write out the character */    IXM1200_REG_WRITE (UART_DR, outChar);        /* transmit character */    return OK;    }/******************************************************************************** ixm1200UartPollInput - 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 ixm1200UartPollInput    (    SIO_CHAN *  pSioChan,       /* ptr to SIO_CHAN describing this channel */    char *      thisChar        /* pointer to where to return character */    )    {    /* IXM1200_CHAN * pChan = (IXM1200_CHAN *)pSioChan; */    UINT32 pollStatus;    IXM1200_REG_READ (UART_SR, pollStatus);    if (!(pollStatus & UART_RX_RDY))        return EAGAIN;    /* got a character */    IXM1200_REG_READ (UART_DR, *thisChar);#ifdef IXM1200_A0    IXM1200_REG_READ (UART_DR, *thisChar); /* pass-1 bug */#endif    return OK;    }/******************************************************************************** ixm1200UartCallbackInstall - 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 ixm1200UartCallbackInstall    (    SIO_CHAN *  pSioChan,       /* ptr to SIO_CHAN describing this channel */    int         callbackType,   /* type of callback */    STATUS      (*callback)(),  /* callback */    void *      callbackArg     /* parameter to callback */                     )    {    IXM1200_CHAN * pChan = (IXM1200_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;        }    }/********************************************************************************* ixm1200UartDevReset - Reset an IXM1200 channel** This routine resets the UART to a quiet state. We do this here because* there is no real interrupt controller to do it in a generic way** RETURNS: N/A*/void ixm1200UartDevReset    (    IXM1200_CHAN *       pChan   /* ptr to IXM1200_CHAN describing this channel */    )    {    int oldlevel = intLock();    pChan->uartCR &= ~( UART_TX_INT_EN | UART_EN | UART_RX_INT_EN );    IXM1200_REG_WRITE( UART_CR, pChan->uartCR | UART_INT_CLR );    intUnlock (oldlevel);    }

⌨️ 快捷键说明

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