From 0af39b3cffe139e18267422e985bdf9aca19dcbe Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Thu, 7 Aug 2014 14:58:08 -0700 Subject: [PATCH] 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 Reviewed-on: https://chromium-review.googlesource.com/211494 Reviewed-by: Vincent Palatin --- chip/stm32/build.mk | 1 - chip/stm32/{crc.h => crc_hw.h} | 20 ++++---------------- common/build.mk | 1 + {chip/stm32 => common}/crc.c | 0 include/crc.h | 27 +++++++++++++++++++++++++++ 5 files changed, 32 insertions(+), 17 deletions(-) rename chip/stm32/{crc.h => crc_hw.h} (63%) rename {chip/stm32 => common}/crc.c (100%) create mode 100644 include/crc.h diff --git a/chip/stm32/build.mk b/chip/stm32/build.mk index d141fa2f60..65fdb58876 100644 --- a/chip/stm32/build.mk +++ b/chip/stm32/build.mk @@ -27,7 +27,6 @@ chip-y=dma.o system.o chip-y+=jtag-$(CHIP_FAMILY).o clock-$(CHIP_FAMILY).o chip-$(CONFIG_SPI)+=spi.o chip-$(CONFIG_SPI_MASTER_PORT)+=spi_master.o -chip-$(CONFIG_SW_CRC)+=crc.o chip-$(CONFIG_COMMON_GPIO)+=gpio.o gpio-$(CHIP_FAMILY).o chip-$(CONFIG_COMMON_TIMER)+=hwtimer$(TIMER_TYPE).o chip-$(CONFIG_I2C)+=i2c-$(CHIP_FAMILY).o diff --git a/chip/stm32/crc.h b/chip/stm32/crc_hw.h similarity index 63% rename from chip/stm32/crc.h rename to chip/stm32/crc_hw.h index df98c35d3b..c1a97da842 100644 --- a/chip/stm32/crc.h +++ b/chip/stm32/crc_hw.h @@ -3,13 +3,9 @@ * found in the LICENSE file. */ -#ifndef _CRC_H -#define _CRC_H -/* CRC-32 implementation with USB constants */ - -/* Note: it's a stateful CRC-32 to match the hardware block interface */ - -#ifdef CONFIG_HW_CRC +#ifndef _CRC_HW_H +#define _CRC_HW_H +/* CRC-32 hardware implementation with USB constants */ #include "registers.h" @@ -39,12 +35,4 @@ static inline uint32_t crc32_result(void) return STM32_CRC_DR ^ 0xFFFFFFFF; } -#else /* !CONFIG_HW_CRC */ -/* Use software implementation */ -void crc32_init(void); -void crc32_hash32(uint32_t val); -void crc32_hash16(uint16_t val); -uint32_t crc32_result(void); -#endif /* CONFIG_HW_CRC */ - -#endif /* _CRC_H */ +#endif /* _CRC_HW_H */ diff --git a/common/build.mk b/common/build.mk index 6b2dd5dbfb..4401c570aa 100644 --- a/common/build.mk +++ b/common/build.mk @@ -62,6 +62,7 @@ common-$(CONFIG_SHA1)+=sha1.o common-$(CONFIG_SOFTWARE_CLZ)+=clz.o common-$(CONFIG_SPI_FLASH)+=spi_flash.o common-$(CONFIG_SWITCH)+=switch.o +common-$(CONFIG_SW_CRC)+=crc.o common-$(CONFIG_TEMP_SENSOR)+=temp_sensor.o thermal.o common-$(CONFIG_USB_PORT_POWER_DUMB)+=usb_port_power_dumb.o common-$(CONFIG_USB_PORT_POWER_SMART)+=usb_port_power_smart.o diff --git a/chip/stm32/crc.c b/common/crc.c similarity index 100% rename from chip/stm32/crc.c rename to common/crc.c diff --git a/include/crc.h b/include/crc.h new file mode 100644 index 0000000000..73289ae213 --- /dev/null +++ b/include/crc.h @@ -0,0 +1,27 @@ +/* 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_H +#define _CRC_H +/* CRC-32 implementation with USB constants */ +/* Note: it's a stateful CRC-32 to match the hardware block interface */ + +#ifdef CONFIG_HW_CRC +#include "crc_hw.h" +#else + +/* Use software implementation */ + +void crc32_init(void); + +void crc32_hash32(uint32_t val); + +void crc32_hash16(uint16_t val); + +uint32_t crc32_result(void); + +#endif /* CONFIG_HW_CRC */ + +#endif /* _CRC_H */