diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-01-26 23:46:09 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-01-26 23:46:09 +0000 |
commit | 53cb9f23346c4969c5d9cc30de45840391ce5d78 (patch) | |
tree | adeb2273c442b722fe34e31fc48fe7779f9df0f1 /nuttx/drivers/serial.c | |
parent | 7e229d14b101765bf25eea8e5661ed2e47900065 (diff) | |
download | px4-nuttx-53cb9f23346c4969c5d9cc30de45840391ce5d78.tar.gz px4-nuttx-53cb9f23346c4969c5d9cc30de45840391ce5d78.tar.bz2 px4-nuttx-53cb9f23346c4969c5d9cc30de45840391ce5d78.zip |
Structure serial driver interface to support different interrupt architectures
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@571 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/drivers/serial.c')
-rw-r--r-- | nuttx/drivers/serial.c | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/nuttx/drivers/serial.c b/nuttx/drivers/serial.c index 7c8f454d3..3d805e7a2 100644 --- a/nuttx/drivers/serial.c +++ b/nuttx/drivers/serial.c @@ -349,17 +349,19 @@ static int uart_close(struct file *filep) /* And wait for the TX fifo to drain */ - while (!uart_txfifoempty(dev)) + while (!uart_txempty(dev)) { usleep(500*1000); } /* Free the IRQ and disable the UART */ - flags = irqsave(); /* Disable interrupts */ - up_disable_irq(dev->irq); - irq_detach(dev->irq); - uart_shutdown(dev); + flags = irqsave(); /* Disable interrupts */ + uart_detach(dev); /* Detach interrupts */ + if (!dev->isconsole) /* Check for the serial console UART */ + { + uart_shutdown(dev); /* Disable the UART */ + } irqrestore(flags); uart_givesem(&dev->closesem); @@ -380,9 +382,7 @@ static int uart_open(struct file *filep) uart_dev_t *dev = inode->i_private; int ret = OK; - /* If the port is the middle of closing, wait until the close - * is finished - */ + /* If the port is the middle of closing, wait until the close is finished */ uart_takesem(&dev->closesem); @@ -392,22 +392,18 @@ static int uart_open(struct file *filep) { irqstate_t flags = irqsave(); - /* If this is the console, then the UART has already - * been initialized. - */ + /* If this is the console, then the UART has already been initialized. */ if (!dev->isconsole) { uart_setup(dev); } - /* But, in any event, we do have to configure for - * interrupt driven mode of operation. + /* In any event, we do have to configure for interrupt driven mode of + * operation. Attach the hardware IRQ(s) */ - /* Attache and enabled the IRQ */ - - ret = irq_attach(dev->irq, dev->ops->handler); + ret = uart_attach(dev); if (ret == OK) { /* Mark the io buffers empty */ @@ -417,9 +413,8 @@ static int uart_open(struct file *filep) dev->recv.head = 0; dev->recv.tail = 0; - /* Finally, enable interrupts */ + /* Finally, enable the RX interrupt */ - up_enable_irq(dev->irq); uart_enablerxint(dev); } irqrestore(flags); @@ -468,7 +463,7 @@ void uart_xmitchars(uart_dev_t *dev) { /* Send while we still have data & room in the fifo */ - while (dev->xmit.head != dev->xmit.tail && uart_txfifonotfull(dev)) + while (dev->xmit.head != dev->xmit.tail && uart_txready(dev)) { uart_send(dev, dev->xmit.buffer[dev->xmit.tail]); @@ -515,7 +510,7 @@ void uart_recvchars(uart_dev_t *dev) nexthead = 0; } - while (nexthead != dev->recv.tail && uart_rxfifonotempty(dev)) + while (nexthead != dev->recv.tail && uart_rxavailable(dev)) { dev->recv.buffer[dev->recv.head] = uart_receive(dev, &status); |