]> www.fi.muni.cz Git - openparking.git/blobdiff - firmware/modbus.c
Clock handling factored out to a separate file.
[openparking.git] / firmware / modbus.c
index a49bd877e1c778357e5f3f39f3f1b5ece6defbec..0c238c2a9b00d655522bcafee847753a2b80ba2d 100644 (file)
@@ -11,6 +11,7 @@
 #include <util/atomic.h>
 #include <util/delay.h>
 
+#include "clock.h"
 #include "modbus.h"
 
 #define BUFSIZE 128    // must be a power of two
@@ -44,13 +45,11 @@ static uint8_t mb_unit_id;
 #define UBRR_VAL        ((F_CPU + 8UL * UART_BAUD) / (16UL*UART_BAUD) - 1)
 #define wait_one_byte()        _delay_us(10*1000000/UART_BAUD)
 
-#define get_clock()    (TCNT1)
-#define CLOCK_SPEED    (F_CPU/1024)
 /*
  * According to Wikipedia, it is indeed 28 bits = 3.5 bytes without
  * start- and stopbits.
  */
-#define TIMEOUT                (28*CLOCK_SPEED/UART_BAUD)
+#define REQ_TIMEOUT            (28*CLOCK_HZ/UART_BAUD)
 
 uint16_t hold_regs[MB_N_HOLD_REGS];
 
@@ -196,7 +195,7 @@ void modbus_poll()
                if (rx_bytes == 0) // nothing received yet
                        return;
 
-               if (get_clock() - last_rx < TIMEOUT) // still receiving
+               if (get_clock() - last_rx < REQ_TIMEOUT) // still receiving
                        return;
 
                if (rx_bytes < 4) { // too short