summaryrefslogtreecommitdiffstats
path: root/app/usart.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/usart.c')
-rw-r--r--app/usart.c87
1 files changed, 47 insertions, 40 deletions
diff --git a/app/usart.c b/app/usart.c
index e826a22..5d5614d 100644
--- a/app/usart.c
+++ b/app/usart.c
@@ -4,11 +4,11 @@
#define BIG_BUFFER_SIZE 600
-volatile ring_t rx3_ring;
-static uint8_t rx3_ring_buf[BUFFER_SIZE];
+volatile ring_t rx2_ring;
+static uint8_t rx2_ring_buf[BUFFER_SIZE];
-volatile ring_t tx3_ring;
-static uint8_t tx3_ring_buf[BUFFER_SIZE];
+volatile ring_t tx2_ring;
+static uint8_t tx2_ring_buf[BUFFER_SIZE];
volatile ring_t rx1_ring;
static uint8_t rx1_ring_buf[BUFFER_SIZE];
@@ -23,62 +23,64 @@ static uint8_t tx1_ring_buf[BUFFER_SIZE];
#define RX1 GPIO10
#define RX1_PORT GPIOA
-#define TX3 GPIO10
-#define TX3_PORT GPIOC
+#define TX2 GPIO5
+#define TX2_PORT GPIOD
-#define RX3 GPIO11
-#define RX3_PORT GPIOC
+#define RX2 GPIO6
+#define RX2_PORT GPIOD
+#define RX2_EN GPIO4
+#define RX2_EN_PORT GPIOG
-void usart3_isr (void)
+void usart2_isr (void)
{
uint8_t data;
/* Check if we were called because of RXNE. */
- if (((USART_CR1 (USART3) & USART_CR1_RXNEIE) != 0) &&
- ((USART_SR (USART3) & USART_SR_RXNE) != 0)) {
+ if (((USART_CR1 (USART2) & USART_CR1_RXNEIE) != 0) &&
+ ((USART_SR (USART2) & USART_SR_RXNE) != 0)) {
/* Retrieve the data from the peripheral. */
- data = usart_recv (USART3);
+ data = usart_recv (USART2);
- ring_write_byte (&rx3_ring, data);
+ ring_write_byte (&rx2_ring, data);
//usart6_queue(data);
}
/* Check if we were called because of TXE. */
- if (((USART_CR1 (USART3) & USART_CR1_TXEIE) != 0) &&
- ((USART_SR (USART3) & USART_SR_TXE) != 0)) {
+ if (((USART_CR1 (USART2) & USART_CR1_TXEIE) != 0) &&
+ ((USART_SR (USART2) & USART_SR_TXE) != 0)) {
- if (ring_read_byte (&tx3_ring, &data)) {
+ if (ring_read_byte (&tx2_ring, &data)) {
/*No more data, Disable the TXE interrupt, it's no longer needed. */
- usart_disable_tx_interrupt (USART3);
+ usart_disable_tx_interrupt (USART2);
} else
- usart_send_blocking (USART3, data);
+ usart_send_blocking (USART2, data);
}
}
void
-usart3_queue (uint8_t d)
+usart2_queue (uint8_t d)
{
- ring_write_byte (&tx3_ring, d);
- usart_enable_tx_interrupt (USART3);
+ ring_write_byte (&tx2_ring, d);
+ usart_enable_tx_interrupt (USART2);
}
void
-usart3_drain (void)
+usart2_drain (void)
{
- while (!ring_empty (&tx3_ring));
+ while (!ring_empty (&tx2_ring));
}
int
-usart3_write (char *ptr, int len, int blocking)
+usart2_write (char *ptr, int len, int blocking)
{
int ret;
- ret = ring_write (&tx3_ring, (uint8_t *) ptr, len, blocking);
- usart_enable_tx_interrupt (USART3);
+ ret = ring_write (&tx2_ring, (uint8_t *) ptr, len, blocking);
+ usart_enable_tx_interrupt (USART2);
return ret;
}
@@ -140,33 +142,38 @@ void
usart_init (void)
{
- ring_init (&rx3_ring, rx3_ring_buf, sizeof (rx3_ring_buf));
- ring_init (&tx3_ring, tx3_ring_buf, sizeof (tx3_ring_buf));
+ ring_init (&rx2_ring, rx2_ring_buf, sizeof (rx2_ring_buf));
+ ring_init (&tx2_ring, tx2_ring_buf, sizeof (tx2_ring_buf));
- MAP_AF (TX3, GPIO_AF7);
- MAP_AF_PU (RX3, GPIO_AF7);
+ MAP_OUTPUT_PP (RX2_EN);
+ SET (RX2_EN);
- usart_set_baudrate (USART3, 9600);
- usart_set_databits (USART3, 8);
- usart_set_stopbits (USART3, USART_STOPBITS_1);
- usart_set_parity (USART3, USART_PARITY_NONE);
- usart_set_flow_control (USART3, USART_FLOWCONTROL_NONE);
- usart_set_mode (USART3, USART_MODE_TX_RX);
+ MAP_INPUT (RX2);
+ MAP_AF (TX2, GPIO_AF7);
+ MAP_AF_PU (RX2, GPIO_AF7);
- usart_enable_rx_interrupt (USART3);
+ usart_set_baudrate (USART2, 38400);
+ usart_set_databits (USART2, 8);
+ usart_set_stopbits (USART2, USART_STOPBITS_1);
+ usart_set_parity (USART2, USART_PARITY_NONE);
+ usart_set_flow_control (USART2, USART_FLOWCONTROL_NONE);
+ usart_set_mode (USART2, USART_MODE_TX_RX);
- usart_enable (USART3);
+ usart_enable_rx_interrupt (USART2);
- nvic_enable_irq (NVIC_USART3_IRQ);
+ usart_enable (USART2);
+
+ nvic_enable_irq (NVIC_USART2_IRQ);
ring_init (&rx1_ring, rx1_ring_buf, sizeof (rx1_ring_buf));
ring_init (&tx1_ring, tx1_ring_buf, sizeof (tx1_ring_buf));
+ MAP_INPUT (RX1);
MAP_AF (TX1, GPIO_AF7);
MAP_AF_PU (RX1, GPIO_AF7);
- usart_set_baudrate (USART1, 38400);
+ usart_set_baudrate (USART1, 9600);
usart_set_databits (USART1, 8);
usart_set_stopbits (USART1, USART_STOPBITS_1);
usart_set_parity (USART1, USART_PARITY_NONE);