projects
/
fw
/
altos
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
altos/lpc: Add casts to reduce -Wconversion warnings
[fw/altos]
/
src
/
lpc
/
ao_serial_lpc.c
diff --git
a/src/lpc/ao_serial_lpc.c
b/src/lpc/ao_serial_lpc.c
index 4ecaa175f0cc69f6da06bab4330bed758ee5d3d3..db0e0b0c55a3f2e22513439a4acf2a8a961b239c 100644
(file)
--- a/
src/lpc/ao_serial_lpc.c
+++ b/
src/lpc/ao_serial_lpc.c
@@
-3,7
+3,8
@@
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
@@
-20,7
+21,10
@@
struct ao_fifo ao_usart_rx_fifo;
struct ao_fifo ao_usart_tx_fifo;
struct ao_fifo ao_usart_rx_fifo;
struct ao_fifo ao_usart_tx_fifo;
-uint8_t ao_usart_tx_started;
+uint8_t ao_usart_tx_avail;
+uint8_t ao_usart_tx_avail_min;
+
+#define LPC_USART_TX_FIFO_SIZE 16
void
ao_debug_out(char c)
void
ao_debug_out(char c)
@@
-35,9
+39,10
@@
ao_debug_out(char c)
static void
_ao_serial_tx_start(void)
{
static void
_ao_serial_tx_start(void)
{
- if (!ao_fifo_empty(ao_usart_tx_fifo) & !ao_usart_tx_started)
- {
- ao_usart_tx_started = 1;
+ if (!ao_fifo_empty(ao_usart_tx_fifo) && ao_usart_tx_avail) {
+ ao_usart_tx_avail--;
+ if (ao_usart_tx_avail < ao_usart_tx_avail_min)
+ ao_usart_tx_avail_min = ao_usart_tx_avail;
ao_fifo_remove(ao_usart_tx_fifo, lpc_usart.rbr_thr);
}
}
ao_fifo_remove(ao_usart_tx_fifo, lpc_usart.rbr_thr);
}
}
@@
-45,25
+50,30
@@
_ao_serial_tx_start(void)
void
lpc_usart_isr(void)
{
void
lpc_usart_isr(void)
{
+ uint8_t wake_input = 0;
(void) lpc_usart.iir_fcr;
while (lpc_usart.lsr & (1 << LPC_USART_LSR_RDR)) {
(void) lpc_usart.iir_fcr;
while (lpc_usart.lsr & (1 << LPC_USART_LSR_RDR)) {
- char c = lpc_usart.rbr_thr;
+ char c =
(char)
lpc_usart.rbr_thr;
if (!ao_fifo_full(ao_usart_rx_fifo))
ao_fifo_insert(ao_usart_rx_fifo, c);
if (!ao_fifo_full(ao_usart_rx_fifo))
ao_fifo_insert(ao_usart_rx_fifo, c);
- ao_wakeup(&ao_usart_rx_fifo);
- if (stdin)
- ao_wakeup(&ao_stdin_ready);
+ wake_input = 1;
}
if (lpc_usart.lsr & (1 << LPC_USART_LSR_THRE)) {
}
if (lpc_usart.lsr & (1 << LPC_USART_LSR_THRE)) {
- ao_usart_tx_
started = 0
;
+ ao_usart_tx_
avail = LPC_USART_TX_FIFO_SIZE
;
_ao_serial_tx_start();
ao_wakeup(&ao_usart_tx_fifo);
}
_ao_serial_tx_start();
ao_wakeup(&ao_usart_tx_fifo);
}
+ if (wake_input) {
+ ao_wakeup(&ao_usart_rx_fifo);
+#if USE_SERIAL_0_STDIN
+ ao_wakeup(&ao_stdin_ready);
+#endif
+ }
}
int
}
int
-_ao_serial_pollchar(void)
+_ao_serial
0
_pollchar(void)
{
int c;
{
int c;
@@
-78,18
+88,18
@@
_ao_serial_pollchar(void)
}
char
}
char
-ao_serial_getchar(void)
+ao_serial
0
_getchar(void)
{
int c;
ao_arch_block_interrupts();
{
int c;
ao_arch_block_interrupts();
- while ((c = _ao_serial_pollchar()) == AO_READ_AGAIN)
+ while ((c = _ao_serial
0
_pollchar()) == AO_READ_AGAIN)
ao_sleep(&ao_usart_rx_fifo);
ao_arch_release_interrupts();
return (char) c;
}
void
ao_sleep(&ao_usart_rx_fifo);
ao_arch_release_interrupts();
return (char) c;
}
void
-ao_serial_putchar(char c)
+ao_serial
0
_putchar(char c)
{
ao_arch_block_interrupts();
while (ao_fifo_full(ao_usart_tx_fifo))
{
ao_arch_block_interrupts();
while (ao_fifo_full(ao_usart_tx_fifo))
@@
-100,7
+110,7
@@
ao_serial_putchar(char c)
}
void
}
void
-ao_serial_drain(void)
+ao_serial
0
_drain(void)
{
ao_arch_block_interrupts();
while (!ao_fifo_empty(ao_usart_tx_fifo))
{
ao_arch_block_interrupts();
while (!ao_fifo_empty(ao_usart_tx_fifo))
@@
-111,7
+121,7
@@
ao_serial_drain(void)
#include "ao_serial_lpc.h"
void
#include "ao_serial_lpc.h"
void
-ao_serial_set_speed(uint8_t speed)
+ao_serial
0
_set_speed(uint8_t speed)
{
if (speed > AO_SERIAL_SPEED_115200)
return;
{
if (speed > AO_SERIAL_SPEED_115200)
return;
@@
-125,11
+135,11
@@
ao_serial_set_speed(uint8_t speed)
/* DL MSB */
lpc_usart.ier = (ao_usart_speeds[speed].dl >> 8) & 0xff;
/* DL MSB */
lpc_usart.ier = (ao_usart_speeds[speed].dl >> 8) & 0xff;
- lpc_usart.fdr = ((ao_usart_speeds[speed].divaddval << LPC_USART_FDR_DIVADDVAL) |
- (ao_usart_speeds[speed].mulval << LPC_USART_FDR_MULVAL));
+ lpc_usart.fdr = ((
(uint32_t)
ao_usart_speeds[speed].divaddval << LPC_USART_FDR_DIVADDVAL) |
+ (
(uint32_t)
ao_usart_speeds[speed].mulval << LPC_USART_FDR_MULVAL));
/* Turn access to divisor latches back off */
/* Turn access to divisor latches back off */
- lpc_usart.lcr &= ~(1 << LPC_USART_LCR_DLAB);
+ lpc_usart.lcr &= ~(1
UL
<< LPC_USART_LCR_DLAB);
}
void
}
void
@@
-162,6
+172,9
@@
ao_serial_init(void)
(1 << LPC_USART_FCR_TXFIFORES) |
(LPC_USART_FCR_RXTL_1 << LPC_USART_FCR_RXTL));
(1 << LPC_USART_FCR_TXFIFORES) |
(LPC_USART_FCR_RXTL_1 << LPC_USART_FCR_RXTL));
+ ao_usart_tx_avail = LPC_USART_TX_FIFO_SIZE;
+ ao_usart_tx_avail_min = LPC_USART_TX_FIFO_SIZE;
+
/* 8 n 1 */
lpc_usart.lcr = ((LPC_USART_LCR_WLS_8 << LPC_USART_LCR_WLS) |
(LPC_USART_LCR_SBS_1 << LPC_USART_LCR_SBS) |
/* 8 n 1 */
lpc_usart.lcr = ((LPC_USART_LCR_WLS_8 << LPC_USART_LCR_WLS) |
(LPC_USART_LCR_SBS_1 << LPC_USART_LCR_SBS) |
@@
-186,7
+199,7
@@
ao_serial_init(void)
lpc_usart.hden = ((0 << LPC_USART_HDEN_HDEN));
/* Set baud rate */
lpc_usart.hden = ((0 << LPC_USART_HDEN_HDEN));
/* Set baud rate */
- ao_serial_set_speed(AO_SERIAL_SPEED_9600);
+ ao_serial
0
_set_speed(AO_SERIAL_SPEED_9600);
/* Enable interrupts */
lpc_usart.ier = ((1 << LPC_USART_IER_RBRINTEN) |
/* Enable interrupts */
lpc_usart.ier = ((1 << LPC_USART_IER_RBRINTEN) |
@@
-195,8
+208,8
@@
ao_serial_init(void)
lpc_nvic_set_enable(LPC_ISR_USART_POS);
lpc_nvic_set_priority(LPC_ISR_USART_POS, 0);
#if USE_SERIAL_0_STDIN
lpc_nvic_set_enable(LPC_ISR_USART_POS);
lpc_nvic_set_priority(LPC_ISR_USART_POS, 0);
#if USE_SERIAL_0_STDIN
- ao_add_stdio(_ao_serial_pollchar,
- ao_serial_putchar,
+ ao_add_stdio(_ao_serial
0
_pollchar,
+ ao_serial
0
_putchar,
NULL);
#endif
}
NULL);
#endif
}