summaryrefslogtreecommitdiff
path: root/chip/stm32/crc_hw.h
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2014-08-07 14:58:08 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-08-08 03:11:38 +0000
commit0af39b3cffe139e18267422e985bdf9aca19dcbe (patch)
treef52f7150c9bc7393e03230c26a1b994c640c8861 /chip/stm32/crc_hw.h
parent5d208b992494ae4cdeffc0efdf4f341c6ada64e5 (diff)
downloadchrome-ec-0af39b3cffe139e18267422e985bdf9aca19dcbe.tar.gz
Move software CRC implementation to common
There is nothing chip-specific in the software CRC implementation. Let's move it to common so that we can reuse it for other chips and unit tests. BUG=chrome-os-partner:31200 TEST=Define CONFIG_SW_CRC for host. Check crc.c compiles fine. BRANCH=None Change-Id: Icdc1d105c55c38ff07410cb5d733a31dbac53aea Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/211494 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'chip/stm32/crc_hw.h')
-rw-r--r--chip/stm32/crc_hw.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/chip/stm32/crc_hw.h b/chip/stm32/crc_hw.h
new file mode 100644
index 0000000000..c1a97da842
--- /dev/null
+++ b/chip/stm32/crc_hw.h
@@ -0,0 +1,38 @@
+/* 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.
+ */
+
+#ifndef _CRC_HW_H
+#define _CRC_HW_H
+/* CRC-32 hardware implementation with USB constants */
+
+#include "registers.h"
+
+static inline void crc32_init(void)
+{
+ /* switch on CRC controller */
+ STM32_RCC_AHBENR |= 1 << 6; /* switch on CRC controller */
+ /* reset CRC state */
+ STM32_CRC_CR = STM32_CRC_CR_RESET | STM32_CRC_CR_REV_OUT
+ | STM32_CRC_CR_REV_IN_WORD;
+ while (STM32_CRC_CR & 1)
+ ;
+}
+
+static inline void crc32_hash32(uint32_t val)
+{
+ STM32_CRC_DR = val;
+}
+
+static inline void crc32_hash16(uint16_t val)
+{
+ STM32_CRC_DR16 = val;
+}
+
+static inline uint32_t crc32_result(void)
+{
+ return STM32_CRC_DR ^ 0xFFFFFFFF;
+}
+
+#endif /* _CRC_HW_H */