From 8069aa82ef3ec6d5198c3449104a59e8534bb2d4 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 8 Jul 2019 18:44:17 +0200 Subject: [PATCH] ModBus: Cleanup --- test-modbus/modbus.c | 22 ++-------------------- test-modbus/test.c | 2 +- 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/test-modbus/modbus.c b/test-modbus/modbus.c index a11c6c5..69fa980 100644 --- a/test-modbus/modbus.c +++ b/test-modbus/modbus.c @@ -35,17 +35,6 @@ static u16 tx_pos; #define MB_OUR_ADDRESS 42 -static void UNUSED xx_write_char(uint c) // FIXME -{ - usart_set_mode(USART2, USART_MODE_TX); - gpio_set(GPIOA, GPIO1); - usart_send_blocking(USART2, c); - while (!usart_get_flag(USART2, USART_SR_TC)) - ; - gpio_clear(GPIOA, GPIO1); - usart_set_mode(USART2, USART_MODE_RX); -} - static void rx_init(void) { state = STATE_RX; @@ -110,17 +99,12 @@ void usart2_isr(void) { u32 status = USART_SR(USART2); - // FIXME: Optimize - if (status & USART_SR_RXNE) { uint ch = usart_recv(USART2); if (state == STATE_RX) { -#if 0 if (status & (USART_SR_FE | USART_SR_ORE | USART_SR_NE)) { rx_bad = 1; - } else -#endif - if (rx_size < RX_BUFSIZE) { + } else if (rx_size < RX_BUFSIZE) { rx_buf[rx_size++] = ch; } else { // Frame too long @@ -144,9 +128,7 @@ void usart2_isr(void) state = STATE_TX_LAST; } } - } - - if (state == STATE_TX_LAST) { + } else if (state == STATE_TX_LAST) { if (status & USART_SR_TC) { // Transfer of the last byte is complete. Release the bus. USART_CR1(USART2) &= ~USART_CR1_TCIE; diff --git a/test-modbus/test.c b/test-modbus/test.c index 4dc1f41..96da014 100644 --- a/test-modbus/test.c +++ b/test-modbus/test.c @@ -98,7 +98,7 @@ int main(void) // gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO8); for (;;) { - //gpio_toggle(GPIOC, GPIO13); + gpio_toggle(GPIOC, GPIO13); delay_ms(50); // gpio_toggle(GPIOA, GPIO8); //timer_set_oc_mode(TIM4, TIM_OC1, TIM_OCM_FORCE_LOW); -- 2.39.5