X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=firmware%2Fmodbus.h;h=3a3fcdf28e6fed2db6f6e929049b68b33d64a8ee;hb=HEAD;hp=937b8e8d71adb618581cd06f10216583ad281f0d;hpb=21e8a8ac43a7de8539e40ef6dfe7e2b7c731176c;p=openparking.git diff --git a/firmware/modbus.h b/firmware/modbus.h old mode 100755 new mode 100644 index 937b8e8..3a3fcdf --- a/firmware/modbus.h +++ b/firmware/modbus.h @@ -8,8 +8,17 @@ * All bugs by Jan "Yenya" Kasprzak :-) */ +/* + * Call this at the beginning of the program. + */ void modbus_init(uint8_t unit_id); -void modbus_poll(); + +/* + * Call this frequently. Returns 0 when no data was received + * and the processing went on quickly. Returns 1 after potentially lengthy + * packet processing. + */ +uint8_t modbus_poll(); typedef enum { MB_OK = 0, @@ -18,11 +27,11 @@ typedef enum { MB_ILLEGAL_VAL = 3, } mb_exception; -#define MB_HOLD_REGS_BASE 1000 -#define MB_N_HOLD_REGS 40 -#define MB_N_HOLD_REGS_EEPROM 20 +#define MB_HOLD_REGS_BASE 0 // first register +#define MB_N_HOLD_REGS 80 // total # of registers +#define MB_N_HOLD_REGS_EEPROM 20 // the first N registers eeprom-backed extern uint16_t hold_regs[MB_N_HOLD_REGS]; -#define mb_unit_id (hold_regs[0]) +#define mb_unit_id (hold_regs[0]) // MODBUS id in the first register uint8_t hold_reg_is_valid(uint16_t reg, uint16_t val);