]> mj.ucw.cz Git - home-hw.git/commitdiff
ModBus: Cleanup
authorMartin Mares <mj@ucw.cz>
Mon, 8 Jul 2019 16:44:17 +0000 (18:44 +0200)
committerMartin Mares <mj@ucw.cz>
Mon, 8 Jul 2019 16:44:17 +0000 (18:44 +0200)
test-modbus/modbus.c
test-modbus/test.c

index a11c6c551849b367b6a72e4ff723e2ff0bbbd332..69fa9802b7d6c77558e84570e80f90babade7a6c 100644 (file)
@@ -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;
index 4dc1f41757f2aaf86d68261ae88e540c9857e050..96da0141e381b38189ae582974d764a589850551 100644 (file)
@@ -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);