]> www.fi.muni.cz Git - openparking.git/blob - firmware/modbus.h
e762b706a5173542f795e15eb8cdd16674d21eb8
[openparking.git] / firmware / modbus.h
1 #ifndef MODBUS_H__
2 #define MODBUS_H__ 1
3
4 /*
5  * Loosely modelled after AVR-RS485 by Yoshinori Kohyama (http://algobit.jp/),
6  * available at https://github.com/kohyama/AVR-RS485/
7  *
8  * All bugs by Jan "Yenya" Kasprzak <kas@fi.muni.cz> :-)
9  */
10
11 /*
12  * Call this at the beginning of the program.
13  */
14 void modbus_init(uint8_t unit_id);
15
16 /*
17  * Call this frequently. Returns 0 when no data was received
18  * and the processing went on quickly. Returns 1 after potentially lengthy
19  * packet processing.
20  */
21 uint8_t modbus_poll();
22
23 typedef enum {
24         MB_OK = 0,
25         MB_ILLEGAL_FUNC = 1,
26         MB_ILLEGAL_ADDR = 2,
27         MB_ILLEGAL_VAL  = 3,
28 } mb_exception;
29
30 #define MB_HOLD_REGS_BASE       1000
31 #define MB_N_HOLD_REGS          60
32 #define MB_N_HOLD_REGS_EEPROM   20
33 extern uint16_t hold_regs[MB_N_HOLD_REGS];
34 #define mb_unit_id      (hold_regs[0])
35
36 uint8_t hold_reg_is_valid(uint16_t reg, uint16_t val);
37
38 #endif /* MODBUS_H__ */