summaryrefslogtreecommitdiff
path: root/nuttx/arch/arm/src/dm320
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-01-26 23:46:09 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-01-26 23:46:09 +0000
commit53cb9f23346c4969c5d9cc30de45840391ce5d78 (patch)
treeadeb2273c442b722fe34e31fc48fe7779f9df0f1 /nuttx/arch/arm/src/dm320
parent7e229d14b101765bf25eea8e5661ed2e47900065 (diff)
downloadpx4-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/arch/arm/src/dm320')
-rw-r--r--nuttx/arch/arm/src/dm320/dm320_serial.c240
1 files changed, 146 insertions, 94 deletions
diff --git a/nuttx/arch/arm/src/dm320/dm320_serial.c b/nuttx/arch/arm/src/dm320/dm320_serial.c
index c74264b8d..2eea71dd0 100644
--- a/nuttx/arch/arm/src/dm320/dm320_serial.c
+++ b/nuttx/arch/arm/src/dm320/dm320_serial.c
@@ -1,7 +1,7 @@
-/************************************************************
+/****************************************************************************
* dm320/dm320_serial.c
*
- * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -14,7 +14,7 @@
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
- * 3. Neither the name Gregory Nutt nor the names of its contributors may be
+ * 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -31,11 +31,11 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Included Files
- ************************************************************/
+ ****************************************************************************/
#include <nuttx/config.h>
@@ -57,63 +57,64 @@
#if CONFIG_NFILE_DESCRIPTORS > 0
-/************************************************************
+/****************************************************************************
* Definitions
- ************************************************************/
+ ****************************************************************************/
#define BASE_BAUD 115200
-/************************************************************
+/****************************************************************************
* Private Types
- ************************************************************/
+ ****************************************************************************/
struct up_dev_s
{
- uint32 uartbase; /* Base address of UART
- * registers */
+ uint32 uartbase; /* Base address of UART registers */
uint32 baud; /* Configured baud */
uint16 msr; /* Saved MSR value */
- ubyte irq; /* IRQ associated with
- * this UART */
+ ubyte irq; /* IRQ associated with this UART */
ubyte parity; /* 0=none, 1=odd, 2=even */
ubyte bits; /* Number of bits (7 or 8) */
boolean stopbits2; /* TRUE: Configure with 2
* stop bits instead of 1 */
};
-/************************************************************
+/****************************************************************************
* Private Function Prototypes
- ************************************************************/
+ ****************************************************************************/
static int up_setup(struct uart_dev_s *dev);
static void up_shutdown(struct uart_dev_s *dev);
+static int up_attach(struct uart_dev_s *dev);
+static void up_detach(struct uart_dev_s *dev);
static int up_interrupt(int irq, void *context);
static int up_ioctl(struct file *filep, int cmd, unsigned long arg);
static int up_receive(struct uart_dev_s *dev, uint32 *status);
static void up_rxint(struct uart_dev_s *dev, boolean enable);
-static boolean up_rxfifonotempty(struct uart_dev_s *dev);
+static boolean up_rxavailable(struct uart_dev_s *dev);
static void up_send(struct uart_dev_s *dev, int ch);
static void up_txint(struct uart_dev_s *dev, boolean enable);
-static boolean up_txfifonotfull(struct uart_dev_s *dev);
-static boolean up_txfifoempty(struct uart_dev_s *dev);
+static boolean up_txready(struct uart_dev_s *dev);
+static boolean up_txempty(struct uart_dev_s *dev);
-/************************************************************
+/****************************************************************************
* Private Variables
- ************************************************************/
+ ****************************************************************************/
struct uart_ops_s g_uart_ops =
{
.setup = up_setup,
.shutdown = up_shutdown,
- .handler = up_interrupt,
+ .attach = up_attach,
+ .detach = up_detach,
.ioctl = up_ioctl,
.receive = up_receive,
.rxint = up_rxint,
- .rxfifonotempty = up_rxfifonotempty,
+ .rxavailable = up_rxavailable,
.send = up_send,
.txint = up_txint,
- .txfifonotfull = up_txfifonotfull,
- .txfifoempty = up_txfifoempty,
+ .txready = up_txready,
+ .txempty = up_txempty,
};
/* I/O buffers */
@@ -129,6 +130,7 @@ static struct up_dev_s g_uart0priv =
{
.uartbase = DM320_UART0_REGISTER_BASE,
.baud = CONFIG_UART0_BAUD,
+ .irq = DM320_IRQ_UART0,
.parity = CONFIG_UART0_PARITY,
.bits = CONFIG_UART0_BITS,
.stopbits2 = CONFIG_UART0_2STOP,
@@ -136,7 +138,6 @@ static struct up_dev_s g_uart0priv =
static uart_dev_t g_uart0port =
{
- .irq = DM320_IRQ_UART0,
.recv =
{
.size = CONFIG_UART0_RXBUFSIZE,
@@ -157,6 +158,7 @@ static struct up_dev_s g_uart1priv =
{
.uartbase = DM320_UART1_REGISTER_BASE,
.baud = CONFIG_UART1_BAUD,
+ .irq = DM320_IRQ_UART1,
.parity = CONFIG_UART1_PARITY,
.bits = CONFIG_UART1_BITS,
.stopbits2 = CONFIG_UART1_2STOP,
@@ -164,7 +166,6 @@ static struct up_dev_s g_uart1priv =
static uart_dev_t g_uart1port =
{
- .irq = DM320_IRQ_UART1,
.recv =
{
.size = CONFIG_UART1_RXBUFSIZE,
@@ -191,31 +192,31 @@ static uart_dev_t g_uart1port =
# define TTYS1_DEV g_uart1port
#endif
-/************************************************************
+/****************************************************************************
* Private Functions
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Name: up_serialin
- ************************************************************/
+ ****************************************************************************/
static inline uint16 up_serialin(struct up_dev_s *priv, uint32 offset)
{
return getreg16(priv->uartbase + offset);
}
-/************************************************************
+/****************************************************************************
* Name: up_serialout
- ************************************************************/
+ ****************************************************************************/
static inline void up_serialout(struct up_dev_s *priv, uint32 offset, uint16 value)
{
putreg16(value, priv->uartbase + offset);
}
-/************************************************************
+/****************************************************************************
* Name: up_disableuartint
- ************************************************************/
+ ****************************************************************************/
static inline void up_disableuartint(struct up_dev_s *priv, uint16 *msr)
{
@@ -228,9 +229,9 @@ static inline void up_disableuartint(struct up_dev_s *priv, uint16 *msr)
up_serialout(priv, UART_MSR, priv->msr);
}
-/************************************************************
+/****************************************************************************
* Name: up_restoreuartint
- ************************************************************/
+ ****************************************************************************/
static inline void up_restoreuartint(struct up_dev_s *priv, uint16 msr)
{
@@ -238,11 +239,11 @@ static inline void up_restoreuartint(struct up_dev_s *priv, uint16 msr)
up_serialout(priv, UART_MSR, priv->msr);
}
-/************************************************************
- * Name: up_waittxfifonotfull
- ************************************************************/
+/****************************************************************************
+ * Name: up_waittxready
+ ****************************************************************************/
-static inline void up_waittxfifonotfull(struct up_dev_s *priv)
+static inline void up_waittxready(struct up_dev_s *priv)
{
int tmp;
@@ -255,9 +256,9 @@ static inline void up_waittxfifonotfull(struct up_dev_s *priv)
}
}
-/************************************************************
+/****************************************************************************
* Name: up_enablebreaks
- ************************************************************/
+ ****************************************************************************/
static inline void up_enablebreaks(struct up_dev_s *priv, boolean enable)
{
@@ -273,7 +274,7 @@ static inline void up_enablebreaks(struct up_dev_s *priv, boolean enable)
up_serialout(priv, UART_LCR, lcr);
}
-/************************************************************
+/****************************************************************************
* Name: up_setup
*
* Description:
@@ -281,7 +282,7 @@ static inline void up_enablebreaks(struct up_dev_s *priv, boolean enable)
* method is called the first time that the serial port is
* opened.
*
- ************************************************************/
+ ****************************************************************************/
static int up_setup(struct uart_dev_s *dev)
{
@@ -385,14 +386,14 @@ static int up_setup(struct uart_dev_s *dev)
return OK;
}
-/************************************************************
+/****************************************************************************
* Name: up_shutdown
*
* Description:
* Disable the UART. This method is called when the serial
* port is closed
*
- ************************************************************/
+ ****************************************************************************/
static void up_shutdown(struct uart_dev_s *dev)
{
@@ -400,7 +401,58 @@ static void up_shutdown(struct uart_dev_s *dev)
up_disableuartint(priv, NULL);
}
-/************************************************************
+/****************************************************************************
+ * Name: up_attach
+ *
+ * Description:
+ * Configure the UART to operation in interrupt driven mode. This method is
+ * called when the serial port is opened. Normally, this is just after the
+ * the setup() method is called, however, the serial console may operate in
+ * a non-interrupt driven mode during the boot phase.
+ *
+ * RX and TX interrupts are not enabled when by the attach method (unless the
+ * hardware supports multiple levels of interrupt enabling). The RX and TX
+ * interrupts are not enabled until the txint() and rxint() methods are called.
+ *
+ ****************************************************************************/
+
+static int up_attach(struct uart_dev_s *dev)
+{
+ struct up_dev_s *priv = (struct up_dev_s*)dev->priv;
+ int ret;
+
+ /* Attach and enable the IRQ */
+
+ ret = irq_attach(priv->irq, up_interrupt);
+ if (ret == OK)
+ {
+ /* Enable the interrupt (RX and TX interrupts are still disabled
+ * in the UART
+ */
+
+ up_enable_irq(priv->irq);
+ }
+ return ret;
+}
+
+/****************************************************************************
+ * Name: up_detach
+ *
+ * Description:
+ * Detach UART interrupts. This method is called when the serial port is
+ * closed normally just before the shutdown method is called. The exception is
+ * the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void up_detach(struct uart_dev_s *dev)
+{
+ struct up_dev_s *priv = (struct up_dev_s*)dev->priv;
+ up_disable_irq(priv->irq);
+ irq_detach(priv->irq);
+}
+
+/****************************************************************************
* Name: up_interrupt
*
* Description:
@@ -411,7 +463,7 @@ static void up_shutdown(struct uart_dev_s *dev)
* must be able to map the 'irq' number into the approprite
* uart_dev_s structure in order to call these functions.
*
- ************************************************************/
+ ****************************************************************************/
static int up_interrupt(int irq, void *context)
{
@@ -420,11 +472,11 @@ static int up_interrupt(int irq, void *context)
uint16 status;
int passes = 0;
- if (g_uart1port.irq == irq)
+ if (g_uart1priv.irq == irq)
{
dev = &g_uart1port;
}
- else if (g_uart0port.irq == irq)
+ else if (g_uart0priv.irq == irq)
{
dev = &g_uart0port;
}
@@ -474,13 +526,13 @@ static int up_interrupt(int irq, void *context)
}
}
-/************************************************************
+/****************************************************************************
* Name: up_ioctl
*
* Description:
* All ioctl calls will be routed through this method
*
- ************************************************************/
+ ****************************************************************************/
static int up_ioctl(struct file *filep, int cmd, unsigned long arg)
{
@@ -532,7 +584,7 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg)
return ret;
}
-/************************************************************
+/****************************************************************************
* Name: up_receive
*
* Description:
@@ -540,7 +592,7 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg)
* character from the UART. Error bits associated with the
* receipt are provided in the the return 'status'.
*
- ************************************************************/
+ ****************************************************************************/
static int up_receive(struct uart_dev_s *dev, uint32 *status)
{
@@ -552,13 +604,13 @@ static int up_receive(struct uart_dev_s *dev, uint32 *status)
return dtrr & UART_DTRR_DTR_MASK;
}
-/************************************************************
+/****************************************************************************
* Name: up_rxint
*
* Description:
* Call to enable or disable RX interrupts
*
- ************************************************************/
+ ****************************************************************************/
static void up_rxint(struct uart_dev_s *dev, boolean enable)
{
@@ -576,27 +628,27 @@ static void up_rxint(struct uart_dev_s *dev, boolean enable)
up_serialout(priv, UART_MSR, priv->msr);
}
-/************************************************************
- * Name: up_rxfifonotempty
+/****************************************************************************
+ * Name: up_rxavailable
*
* Description:
* Return TRUE if the receive fifo is not empty
*
- ************************************************************/
+ ****************************************************************************/
-static boolean up_rxfifonotempty(struct uart_dev_s *dev)
+static boolean up_rxavailable(struct uart_dev_s *dev)
{
struct up_dev_s *priv = (struct up_dev_s*)dev->priv;
return ((up_serialin(priv, UART_SR) & UART_SR_RFNEF) != 0);
}
-/************************************************************
+/****************************************************************************
* Name: up_send
*
* Description:
* This method will send one byte on the UART
*
- ************************************************************/
+ ****************************************************************************/
static void up_send(struct uart_dev_s *dev, int ch)
{
@@ -604,13 +656,13 @@ static void up_send(struct uart_dev_s *dev, int ch)
up_serialout(priv, UART_DTRR, (uint16)ch);
}
-/************************************************************
+/****************************************************************************
* Name: up_txint
*
* Description:
* Call to enable or disable TX interrupts
*
- ************************************************************/
+ ****************************************************************************/
static void up_txint(struct uart_dev_s *dev, boolean enable)
{
@@ -628,39 +680,39 @@ static void up_txint(struct uart_dev_s *dev, boolean enable)
up_serialout(priv, UART_MSR, priv->msr);
}
-/************************************************************
- * Name: up_txfifonotfull
+/****************************************************************************
+ * Name: up_txready
*
* Description:
* Return TRUE if the tranmsit fifo is not full
*
- ************************************************************/
+ ****************************************************************************/
-static boolean up_txfifonotfull(struct uart_dev_s *dev)
+static boolean up_txready(struct uart_dev_s *dev)
{
struct up_dev_s *priv = (struct up_dev_s*)dev->priv;
return ((up_serialin(priv, UART_SR) & UART_SR_TFTI) != 0);
}
-/************************************************************
- * Name: up_txfifoempty
+/****************************************************************************
+ * Name: up_txempty
*
* Description:
* Return TRUE if the transmit fifo is empty
*
- ************************************************************/
+ ****************************************************************************/
-static boolean up_txfifoempty(struct uart_dev_s *dev)
+static boolean up_txempty(struct uart_dev_s *dev)
{
struct up_dev_s *priv = (struct up_dev_s*)dev->priv;
return ((up_serialin(priv, UART_SR) & UART_SR_TREF) == 0);
}
-/************************************************************
+/****************************************************************************
* Public Funtions
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
+/****************************************************************************
* Name: up_serialinit
*
* Description:
@@ -668,7 +720,7 @@ static boolean up_txfifoempty(struct uart_dev_s *dev)
* debug so that the serial console will be available
* during bootup. This must be called before up_serialinit.
*
- ************************************************************/
+ ****************************************************************************/
void up_earlyserialinit(void)
{
@@ -679,14 +731,14 @@ void up_earlyserialinit(void)
up_setup(&CONSOLE_DEV);
}
-/************************************************************
+/****************************************************************************
* Name: up_serialinit
*
* Description:
* Register serial console and serial ports. This assumes
* that up_earlyserialinit was called previously.
*
- ************************************************************/
+ ****************************************************************************/
void up_serialinit(void)
{
@@ -695,14 +747,14 @@ void up_serialinit(void)
(void)uart_register("/dev/ttyS1", &TTYS1_DEV);
}
-/************************************************************
+/****************************************************************************
* Name: up_putc
*
* Description:
* Provide priority, low-level access to support OS debug
* writes
*
- ************************************************************/
+ ****************************************************************************/
int up_putc(int ch)
{
@@ -710,7 +762,7 @@ int up_putc(int ch)
uint16 ier;
up_disableuartint(priv, &ier);
- up_waittxfifonotfull(priv);
+ up_waittxready(priv);
up_serialout(priv, UART_DTRR, (uint16)ch);
/* Check for LF */
@@ -719,20 +771,20 @@ int up_putc(int ch)
{
/* Add CR */
- up_waittxfifonotfull(priv);
+ up_waittxready(priv);
up_serialout(priv, UART_DTRR, '\r');
}
- up_waittxfifonotfull(priv);
+ up_waittxready(priv);
up_restoreuartint(priv, ier);
return ch;
}
#else /* CONFIG_NFILE_DESCRIPTORS > 0 */
-/************************************************************
+/****************************************************************************
* Definitions
- ************************************************************/
+ ****************************************************************************/
# ifdef CONFIG_UART1_SERIAL_CONSOLE
# define DM320_REGISTER_BASE DM320_UART1_REGISTER_BASE
@@ -740,11 +792,11 @@ int up_putc(int ch)
# define DM320_REGISTER_BASE DM320_UART0_REGISTER_BASE
# endif
-/************************************************************
+/****************************************************************************
* Private Functions
- ************************************************************/
+ ****************************************************************************/
-static inline void up_waittxfifonotfull(void)
+static inline void up_waittxready(void)
{
int tmp;
@@ -758,13 +810,13 @@ static inline void up_waittxfifonotfull(void)
}
}
-/************************************************************
+/****************************************************************************
* Public Functions
- ************************************************************/
+ ****************************************************************************/
int up_putc(int ch)
{
- up_waittxfifonotfull();
+ up_waittxready();
putreg16((uint16)ch, DM320_REGISTER_BASE + UART_DTRR);
/* Check for LF */
@@ -773,11 +825,11 @@ int up_putc(int ch)
{
/* Add CR */
- up_waittxfifonotfull();
+ up_waittxready();
putreg16((uint16)'\r', DM320_REGISTER_BASE + UART_DTRR);
}
- up_waittxfifonotfull();
+ up_waittxready();
return ch;
}