diff options
author | Sheng-Liang Song <ssl@chromium.org> | 2014-07-24 09:22:11 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-08-29 02:57:00 +0000 |
commit | 7bea5174a19b6d3b4cd9f5a7e96f7d492a24fc8f (patch) | |
tree | 4bf5f92421086f20668dd19d85ee129cfd6e93f7 /common/crc8.c | |
parent | b7f1d5261917c88e734d0e788de74b2bc419c431 (diff) | |
download | chrome-ec-7bea5174a19b6d3b4cd9f5a7e96f7d492a24fc8f.tar.gz |
EC: Add smbus interface read & write APIs
Ref: http://smbus.org/specs/smbus20.pdf
- Support software CRC8 generation and checking.
- Support read/write word (2-bytes)
- Support read/write blocks (up to 32 bytes)
BUG=chrome-os-partner:24741
BRANCH=ToT,glimmer
TEST=Verified with smart battery firmware update application on glimmer.
Passed LGC & Simplo Battery.
Change-Id: Ic2e7f759af80c06741ed49fee1826213429fbf8a
Signed-off-by: Sheng-Liang Song <ssl@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/209747
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'common/crc8.c')
-rw-r--r-- | common/crc8.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/common/crc8.c b/common/crc8.c new file mode 100644 index 0000000000..b752698d14 --- /dev/null +++ b/common/crc8.c @@ -0,0 +1,23 @@ +/* Copyright (c) 2014 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 "common.h" +#include "crc8.h" + +uint8_t crc8(const uint8_t *data, int len) +{ + unsigned crc = 0; + int i, j; + + for (j = len; j; j--, data++) { + crc ^= (*data << 8); + for (i = 8; i; i--) { + if (crc & 0x8000) + crc ^= (0x1070 << 3); + crc <<= 1; + } + } + + return (uint8_t)(crc >> 8); +} |