From ba63fbd08d40421c63e99ff4fbb5a0b78de3b9bd Mon Sep 17 00:00:00 2001 From: Jett Rink Date: Mon, 9 Nov 2020 14:42:53 -0700 Subject: zephyr: forward cros_crc8 to zephyrs crc8 impl Shim in support for crc8 used in CBI, I2C, and other applications within platform/ec BRANCH=none BUG=b:168032589 TEST=add unit test for platform/ec and zephyr based CRC8 approaches and verify they both pass. Signed-off-by: Jett Rink Change-Id: I9b6112cb83dab81a44a1ac020d4efb1b7bb1df5f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2532692 Reviewed-by: Jack Rosenthal --- zephyr/shim/src/crc.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 zephyr/shim/src/crc.c (limited to 'zephyr/shim/src/crc.c') diff --git a/zephyr/shim/src/crc.c b/zephyr/shim/src/crc.c new file mode 100644 index 0000000000..5c726619ee --- /dev/null +++ b/zephyr/shim/src/crc.c @@ -0,0 +1,21 @@ +/* Copyright 2020 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include + +#include "crc8.h" + +/* Polynomial representation for x^8 + x^2 + x + 1 is 0x07 */ +#define SMBUS_POLYNOMIAL 0x07 + +inline uint8_t cros_crc8(const uint8_t *data, int len) +{ + return crc8(data, len, SMBUS_POLYNOMIAL, 0, false); +} + +uint8_t cros_crc8_arg(const uint8_t *data, int len, uint8_t previous_crc) +{ + return crc8(data, len, SMBUS_POLYNOMIAL, previous_crc, false); +} -- cgit v1.2.1