Add ir_uart_putc_nocheck and make ir_uart_putc more robust at gobbling echoed data
This commit is contained in:
+23
-7
@@ -43,11 +43,26 @@ ir_uart_write_finished_p (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Write character to IR_UART. This returns zero if
|
/** Write character to IR_UART. This blocks until the character can
|
||||||
the character could not be written. */
|
be written into the transmit buffer. It does not check to see
|
||||||
int8_t
|
if there is any echoed character (see ir_uart_putc). */
|
||||||
|
void
|
||||||
|
ir_uart_putc_nocheck (char ch)
|
||||||
|
{
|
||||||
|
usart1_putc (ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Write character to IR_UART. This blocks until the character is
|
||||||
|
written. It then checks if data has been received and if so, reads
|
||||||
|
the data and throws it away on the assumption that it is electrical
|
||||||
|
or optical echoing. */
|
||||||
|
void
|
||||||
ir_uart_putc (char ch)
|
ir_uart_putc (char ch)
|
||||||
{
|
{
|
||||||
|
/* At 2400 baud with one start bit, 8 data bits, and no parity,
|
||||||
|
this will take 3.75 ms to transmit. Note, the maximum bit rate
|
||||||
|
for the IR receiver is 4000 bps. */
|
||||||
usart1_putc (ch);
|
usart1_putc (ch);
|
||||||
|
|
||||||
/* Gobble echoed character. The echoing is due to an electrical
|
/* Gobble echoed character. The echoing is due to an electrical
|
||||||
@@ -66,13 +81,14 @@ ir_uart_putc (char ch)
|
|||||||
while (! ir_uart_write_finished_p ())
|
while (! ir_uart_write_finished_p ())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Play safe and wait for receive complete flag to be set. */
|
/* The IR receiver has a delay of about 150 microseconds. So need
|
||||||
DELAY_US (1);
|
to wait for UART to have received the data and set its receive
|
||||||
|
complete bit. */
|
||||||
|
DELAY_US (150);
|
||||||
|
|
||||||
|
/* Check is something was inadvertently read. */
|
||||||
if (ir_uart_read_ready_p ())
|
if (ir_uart_read_ready_p ())
|
||||||
ir_uart_getc ();
|
ir_uart_getc ();
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+12
-3
@@ -77,9 +77,18 @@ bool
|
|||||||
ir_uart_write_finished_p (void);
|
ir_uart_write_finished_p (void);
|
||||||
|
|
||||||
|
|
||||||
/* Write character to IR_UART. This returns zero if
|
/** Write character to IR_UART. This blocks until the character can
|
||||||
the character could not be written. */
|
be written into the transmit buffer. It does not check to see
|
||||||
int8_t
|
if there is any echoed character (see ir_uart_putc). */
|
||||||
|
void
|
||||||
|
ir_uart_putc_nocheck (char ch);
|
||||||
|
|
||||||
|
|
||||||
|
/* Write character to IR_UART. This blocks until the character is
|
||||||
|
written. It then checks if data has been received and if so, reads
|
||||||
|
the data and throws it away on the assumption that it is electrical
|
||||||
|
or optical echoing. */
|
||||||
|
void
|
||||||
ir_uart_putc (char ch);
|
ir_uart_putc (char ch);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user