Use USART TX state consistently
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3720 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
5981b3b9a5
commit
bfe2a9555f
@ -100,6 +100,7 @@ static bool usart1_rxavailable(struct uart_dev_s *dev);
|
|||||||
static void usart1_send(struct uart_dev_s *dev, int ch);
|
static void usart1_send(struct uart_dev_s *dev, int ch);
|
||||||
static void usart1_txint(struct uart_dev_s *dev, bool enable);
|
static void usart1_txint(struct uart_dev_s *dev, bool enable);
|
||||||
static bool usart1_txready(struct uart_dev_s *dev);
|
static bool usart1_txready(struct uart_dev_s *dev);
|
||||||
|
static bool usart1_txempty(struct uart_dev_s *dev);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Variables
|
* Private Variables
|
||||||
@ -118,7 +119,7 @@ struct uart_ops_s g_uart1_ops =
|
|||||||
.send = usart1_send,
|
.send = usart1_send,
|
||||||
.txint = usart1_txint,
|
.txint = usart1_txint,
|
||||||
.txready = usart1_txready,
|
.txready = usart1_txready,
|
||||||
.txempty = usart1_txready,
|
.txempty = usart1_txempty,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* I/O buffers */
|
/* I/O buffers */
|
||||||
@ -168,9 +169,12 @@ static void usart1_restoreusartint(uint8_t imr)
|
|||||||
|
|
||||||
static inline void usart1_disableusartint(uint8_t *imr)
|
static inline void usart1_disableusartint(uint8_t *imr)
|
||||||
{
|
{
|
||||||
uint8_t regval = UCSR1B;
|
uint8_t regval;
|
||||||
|
|
||||||
|
regval = UCSR1B;
|
||||||
*imr = regval;
|
*imr = regval;
|
||||||
regval &= ~((1 << RXCIE1) | (1 << TXCIE1) | (1 << UDRIE1));
|
regval &= ~((1 << RXCIE1) | (1 << TXCIE1) | (1 << UDRIE1));
|
||||||
|
UCSR1B = regval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -308,9 +312,11 @@ static int usart1_txinterrupt(int irq, void *context)
|
|||||||
{
|
{
|
||||||
uint8_t ucsr1a = UCSR1A;
|
uint8_t ucsr1a = UCSR1A;
|
||||||
|
|
||||||
/* Handle outgoing, transmit bytes */
|
/* Handle outgoing, transmit bytes when the transmit data buffer is empty.
|
||||||
|
* (There may still be data in the shift register).
|
||||||
|
*/
|
||||||
|
|
||||||
if ((ucsr1a & (1 << TXC1)) != 0)
|
if ((ucsr1a & (1 << UDRE1)) != 0)
|
||||||
{
|
{
|
||||||
/* Transmit data regiser empty ... process outgoing bytes */
|
/* Transmit data regiser empty ... process outgoing bytes */
|
||||||
|
|
||||||
@ -361,7 +367,7 @@ static int usart1_ioctl(struct file *filep, int cmd, unsigned long arg)
|
|||||||
|
|
||||||
static int usart1_receive(struct uart_dev_s *dev, FAR unsigned int *status)
|
static int usart1_receive(struct uart_dev_s *dev, FAR unsigned int *status)
|
||||||
{
|
{
|
||||||
/* Return status information */
|
/* Return status information (error bits will be cleared after reading UDR1) */
|
||||||
|
|
||||||
if (status)
|
if (status)
|
||||||
{
|
{
|
||||||
@ -471,6 +477,7 @@ static void usart1_txint(struct uart_dev_s *dev, bool enable)
|
|||||||
|
|
||||||
UCSR1B &= ~((1 << UDRIE1) | (1 << TXCIE1));
|
UCSR1B &= ~((1 << UDRIE1) | (1 << TXCIE1));
|
||||||
}
|
}
|
||||||
|
|
||||||
irqrestore(flags);
|
irqrestore(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,6 +494,20 @@ static bool usart1_txready(struct uart_dev_s *dev)
|
|||||||
return (UCSR1A & (1 << UDRE1)) != 0;
|
return (UCSR1A & (1 << UDRE1)) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: usart1_txempty
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Return true if the tranmsit data register and shift register are both
|
||||||
|
* empty
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static bool usart1_txempty(struct uart_dev_s *dev)
|
||||||
|
{
|
||||||
|
return (UCSR1A & (1 << TXC1)) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
@ -121,6 +121,7 @@ static bool usart0_rxavailable(struct uart_dev_s *dev);
|
|||||||
static void usart0_send(struct uart_dev_s *dev, int ch);
|
static void usart0_send(struct uart_dev_s *dev, int ch);
|
||||||
static void usart0_txint(struct uart_dev_s *dev, bool enable);
|
static void usart0_txint(struct uart_dev_s *dev, bool enable);
|
||||||
static bool usart0_txready(struct uart_dev_s *dev);
|
static bool usart0_txready(struct uart_dev_s *dev);
|
||||||
|
static bool usart0_txempty(struct uart_dev_s *dev);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_AVR_USART1
|
#ifdef CONFIG_AVR_USART1
|
||||||
@ -137,6 +138,7 @@ static bool usart1_rxavailable(struct uart_dev_s *dev);
|
|||||||
static void usart1_send(struct uart_dev_s *dev, int ch);
|
static void usart1_send(struct uart_dev_s *dev, int ch);
|
||||||
static void usart1_txint(struct uart_dev_s *dev, bool enable);
|
static void usart1_txint(struct uart_dev_s *dev, bool enable);
|
||||||
static bool usart1_txready(struct uart_dev_s *dev);
|
static bool usart1_txready(struct uart_dev_s *dev);
|
||||||
|
static bool usart1_txempty(struct uart_dev_s *dev);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -159,7 +161,7 @@ struct uart_ops_s g_usart0_ops =
|
|||||||
.send = usart0_send,
|
.send = usart0_send,
|
||||||
.txint = usart0_txint,
|
.txint = usart0_txint,
|
||||||
.txready = usart0_txready,
|
.txready = usart0_txready,
|
||||||
.txempty = usart0_txready,
|
.txempty = usart0_txempty,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* USART0 I/O buffers */
|
/* USART0 I/O buffers */
|
||||||
@ -201,7 +203,7 @@ struct uart_ops_s g_usart1_ops =
|
|||||||
.send = usart1_send,
|
.send = usart1_send,
|
||||||
.txint = usart1_txint,
|
.txint = usart1_txint,
|
||||||
.txready = usart1_txready,
|
.txready = usart1_txready,
|
||||||
.txempty = usart1_txready,
|
.txempty = usart1_txempty,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* USART 1 I/O buffers */
|
/* USART 1 I/O buffers */
|
||||||
@ -268,18 +270,24 @@ static void usart1_restoreusartint(uint8_t imr)
|
|||||||
#ifdef CONFIG_AVR_USART0
|
#ifdef CONFIG_AVR_USART0
|
||||||
static inline void usart0_disableusartint(uint8_t *imr)
|
static inline void usart0_disableusartint(uint8_t *imr)
|
||||||
{
|
{
|
||||||
uint8_t regval = UCSR0B;
|
uint8_t regval;
|
||||||
|
|
||||||
|
regval = UCSR0B;
|
||||||
*imr = regval;
|
*imr = regval;
|
||||||
regval &= ~((1 << RXCIE0) | (1 << TXCIE0) | (1 << UDRIE0));
|
regval &= ~((1 << RXCIE0) | (1 << TXCIE0) | (1 << UDRIE0));
|
||||||
|
UCSR0B = regval;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_AVR_USART1
|
#ifdef CONFIG_AVR_USART1
|
||||||
static inline void usart1_disableusartint(uint8_t *imr)
|
static inline void usart1_disableusartint(uint8_t *imr)
|
||||||
{
|
{
|
||||||
uint8_t regval = UCSR1B;
|
uint8_t regval;
|
||||||
|
|
||||||
|
regval = UCSR1B;
|
||||||
*imr = regval;
|
*imr = regval;
|
||||||
regval &= ~((1 << RXCIE1) | (1 << TXCIE1) | (1 << UDRIE1));
|
regval &= ~((1 << RXCIE1) | (1 << TXCIE1) | (1 << UDRIE1));
|
||||||
|
UCSR0B = regval;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -505,9 +513,11 @@ static int usart0_txinterrupt(int irq, void *context)
|
|||||||
{
|
{
|
||||||
uint8_t ucsr0a = UCSR0A;
|
uint8_t ucsr0a = UCSR0A;
|
||||||
|
|
||||||
/* Handle outgoing, transmit bytes */
|
/* Handle outgoing, transmit bytes when the transmit data buffer is empty.
|
||||||
|
* (There may still be data in the shift register).
|
||||||
|
*/
|
||||||
|
|
||||||
if ((ucsr0a & (1 << TXC0)) != 0)
|
if ((ucsr0a & (1 << UDRE0)) != 0)
|
||||||
{
|
{
|
||||||
/* Transmit data regiser empty ... process outgoing bytes */
|
/* Transmit data regiser empty ... process outgoing bytes */
|
||||||
|
|
||||||
@ -523,9 +533,11 @@ static int usart1_txinterrupt(int irq, void *context)
|
|||||||
{
|
{
|
||||||
uint8_t ucsr1a = UCSR1A;
|
uint8_t ucsr1a = UCSR1A;
|
||||||
|
|
||||||
/* Handle outgoing, transmit bytes */
|
/* Handle outgoing, transmit bytes when the transmit data buffer is empty.
|
||||||
|
* (There may still be data in the shift register).
|
||||||
|
*/
|
||||||
|
|
||||||
if ((ucsr1a & (1 << TXC1)) != 0)
|
if ((ucsr1a & (1 << UDRE1)) != 0)
|
||||||
{
|
{
|
||||||
/* Transmit data regiser empty ... process outgoing bytes */
|
/* Transmit data regiser empty ... process outgoing bytes */
|
||||||
|
|
||||||
@ -773,6 +785,7 @@ static void usart0_txint(struct uart_dev_s *dev, bool enable)
|
|||||||
|
|
||||||
UCSR0B &= ~((1 << UDRIE0) | (1 << TXCIE0));
|
UCSR0B &= ~((1 << UDRIE0) | (1 << TXCIE0));
|
||||||
}
|
}
|
||||||
|
|
||||||
irqrestore(flags);
|
irqrestore(flags);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -814,6 +827,7 @@ static void usart1_txint(struct uart_dev_s *dev, bool enable)
|
|||||||
|
|
||||||
UCSR1B &= ~((1 << UDRIE1) | (1 << TXCIE1));
|
UCSR1B &= ~((1 << UDRIE1) | (1 << TXCIE1));
|
||||||
}
|
}
|
||||||
|
|
||||||
irqrestore(flags);
|
irqrestore(flags);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -840,6 +854,29 @@ static bool usart1_txready(struct uart_dev_s *dev)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: usart0/1_txempty
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Return true if the tranmsit data register and shift reqister are both
|
||||||
|
* empty
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_AVR_USART0
|
||||||
|
static bool usart0_txempty(struct uart_dev_s *dev)
|
||||||
|
{
|
||||||
|
return (UCSR0A & (1 << TXC0)) != 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_AVR_USART1
|
||||||
|
static bool usart1_txempty(struct uart_dev_s *dev)
|
||||||
|
{
|
||||||
|
return (UCSR1A & (1 << TXC1)) != 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
Loading…
Reference in New Issue
Block a user