]> sigrok.org Git - libsigrok.git/blobdiff - src/libsigrok-internal.h
crc: Factor out CRC16 implementation from Modbus
[libsigrok.git] / src / libsigrok-internal.h
index 990d038f72c3a197e14d19adb2aeb264eaf09b3b..0d18bee44d1fe7a184f094ff1a9fd5f821064dc5 100644 (file)
@@ -1783,6 +1783,22 @@ SR_PRIV int bv_get_value(float *out, const struct binary_value_spec *spec, const
 SR_PRIV int bv_send_analog_channel(const struct sr_dev_inst *sdi, struct sr_channel *ch,
                                   const struct binary_analog_channel *spec, const void *data, size_t length);
 
+/*--- crc.c -----------------------------------------------------------------*/
+
+#define SR_CRC16_DEFAULT_INIT 0xffffU
+
+/**
+ * Calculate a CRC16 checksum using the 0x8005 polynomial.
+ *
+ * This CRC16 flavor is also known as CRC16-ANSI or CRC16-MODBUS.
+ *
+ * @param crc Initial value (typically 0xffff)
+ * @param buffer Input buffer
+ * @param len Buffer length
+ * @return Checksum
+ */
+SR_PRIV uint16_t sr_crc16(uint16_t crc, const uint8_t *buffer, int len);
+
 /*--- modbus/modbus.c -------------------------------------------------------*/
 
 struct sr_modbus_dev_inst {