コード例 #1
0
ファイル: sys_uart.c プロジェクト: JorgeGzm/JAGA
PUBLIC void init_uart(void)
{
    //Inicializa pinos UART
    uart_attach(21, 20);

    //Configura funcionamento da UART1   
    uart_set_baudRate(_UART0, BAUD_9600);
    uart_set_enable(_UART0, UART_ENABLE, UART_ENABLE_RX, UART_ENABLE_TX);
    uart_set_conf(_UART0, UART_ASYNC, UART_HIGH_COM, UART_RX_8BITS, UART_TX_8BITS, UART_BD_16BITS);

    //Configura interrupcao UART1   
    uart_setup_interrupt(_UART0, ENABLE, DISABLE);
    uart_priority_interrupt(_UART0, HIGH_PRIORITY, LOW_PRIORITY);
    uart_rx_set_callback(_UART0, uart_rx);
    uart_tx_set_callback(_UART0, uart_tx);  
   
}
コード例 #2
0
static int uart_open(FAR struct file *filep)
{
    struct inode *inode = filep->f_inode;
    uart_dev_t   *dev   = inode->i_private;
    uint8_t       tmp;
    int           ret   = OK;

    /* If the port is the middle of closing, wait until the close is finished */

    uart_takesem(&dev->closesem);

    /* Start up serial port */
    /* Increment the count of references to the device. */

    tmp = dev->open_count + 1;
    if (tmp == 0)
    {
        /* More than 255 opens; uint8_t overflows to zero */

        ret = -EMFILE;
        goto errout_with_sem;
    }

    /* Check if this is the first time that the driver has been opened. */

    if (tmp == 1)
    {
        irqstate_t flags = irqsave();

        /* If this is the console, then the UART has already been initialized. */

        if (!dev->isconsole)
        {
            /* Perform one time hardware initialization */

            ret = uart_setup(dev);
            if (ret < 0)
            {
                irqrestore(flags);
                goto errout_with_sem;
            }
        }

        /* In any event, we do have to configure for interrupt driven mode of
         * operation.  Attach the hardware IRQ(s). Hmm.. should shutdown() the
         * the device in the rare case that uart_attach() fails, tmp==1, and
         * this is not the console.
         */

        ret = uart_attach(dev);
        if (ret < 0)
        {
            uart_shutdown(dev);
            irqrestore(flags);
            goto errout_with_sem;
        }

        /* Mark the io buffers empty */

        dev->xmit.head = 0;
        dev->xmit.tail = 0;
        dev->recv.head = 0;
        dev->recv.tail = 0;

        /* Enable the RX interrupt */

        uart_enablerxint(dev);
        irqrestore(flags);
    }

    /* Save the new open count on success */

    dev->open_count = tmp;

errout_with_sem:
    uart_givesem(&dev->closesem);
    return ret;
}
コード例 #3
0
ファイル: serial.c プロジェクト: nuttx/nuttx_ieee80211
static int uart_open(FAR struct file *filep)
{
    struct inode *inode = filep->f_inode;
    uart_dev_t   *dev   = inode->i_private;
    uint8_t       tmp;
    int           ret;

    /* If the port is the middle of closing, wait until the close is finished.
     * If a signal is received while we are waiting, then return EINTR.
     */

    ret = uart_takesem(&dev->closesem, true);
    if (ret < 0)
    {
        /* A signal received while waiting for the last close operation. */

        return ret;
    }

#ifdef CONFIG_SERIAL_REMOVABLE
    /* If the removable device is no longer connected, refuse to open the
     * device.  We check this after obtaining the close semaphore because
     * we might have been waiting when the device was disconnected.
     */

    if (dev->disconnected)
    {
        ret = -ENOTCONN;
        goto errout_with_sem;
    }
#endif

    /* Start up serial port */
    /* Increment the count of references to the device. */

    tmp = dev->open_count + 1;
    if (tmp == 0)
    {
        /* More than 255 opens; uint8_t overflows to zero */

        ret = -EMFILE;
        goto errout_with_sem;
    }

    /* Check if this is the first time that the driver has been opened. */

    if (tmp == 1)
    {
        irqstate_t flags = irqsave();

        /* If this is the console, then the UART has already been initialized. */

        if (!dev->isconsole)
        {
            /* Perform one time hardware initialization */

            ret = uart_setup(dev);
            if (ret < 0)
            {
                irqrestore(flags);
                goto errout_with_sem;
            }
        }

        /* In any event, we do have to configure for interrupt driven mode of
         * operation.  Attach the hardware IRQ(s). Hmm.. should shutdown() the
         * the device in the rare case that uart_attach() fails, tmp==1, and
         * this is not the console.
         */

        ret = uart_attach(dev);
        if (ret < 0)
        {
            uart_shutdown(dev);
            irqrestore(flags);
            goto errout_with_sem;
        }

        /* Mark the io buffers empty */

        dev->xmit.head = 0;
        dev->xmit.tail = 0;
        dev->recv.head = 0;
        dev->recv.tail = 0;

        /* Initialise termios state */

#ifdef CONFIG_SERIAL_TERMIOS
        dev->tc_iflag = 0;
        if (dev->isconsole == true)
        {
            /* Enable \n -> \r\n translation for the console */

            dev->tc_oflag = OPOST | ONLCR;
        }
        else
        {
            dev->tc_oflag = 0;
        }
#endif

        /* Enable the RX interrupt */

        uart_enablerxint(dev);
        irqrestore(flags);
    }

    /* Save the new open count on success */

    dev->open_count = tmp;

errout_with_sem:
    uart_givesem(&dev->closesem);
    return ret;
}