|
From: | Philippe Mathieu-Daudé |
Subject: | Re: [PATCH v3 1/3] hw/i2c: add smbus pec utility function |
Date: | Thu, 1 Jun 2023 22:34:01 +0200 |
User-agent: | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 |
On 31/5/23 13:47, Klaus Jensen wrote:
From: Klaus Jensen <k.jensen@samsung.com> Add i2c_smbus_pec() to calculate the SMBus Packet Error Code for a message. Signed-off-by: Klaus Jensen <k.jensen@samsung.com> --- hw/i2c/smbus_master.c | 28 ++++++++++++++++++++++++++++ include/hw/i2c/smbus_master.h | 2 ++ 2 files changed, 30 insertions(+) diff --git a/hw/i2c/smbus_master.c b/hw/i2c/smbus_master.c index 6a53c34e70b7..47f9eb24e033 100644 --- a/hw/i2c/smbus_master.c +++ b/hw/i2c/smbus_master.c @@ -15,6 +15,34 @@ #include "hw/i2c/i2c.h" #include "hw/i2c/smbus_master.h"+static uint8_t crc8(uint16_t data)+{ +#define POLY (0x1070U << 3)
static const unsigned crc8_poly = ..., but why not inline the single use? data ^= 0x1070U << 3; and data <<= 1;
+ int i; + + for (i = 0; i < 8; i++) { + if (data & 0x8000) { + data = data ^ POLY; + } + + data = data << 1; + } + + return (uint8_t)(data >> 8); +#undef POLY +}
We have "qemu/crc32c.h", maybe we could have a similar crc8.h. Just wondering...
[Prev in Thread] | Current Thread | [Next in Thread] |