diff --git a/drivers/BaseCRC.h b/drivers/BaseCRC.h index bcbe9037836..5f06b99f166 100644 --- a/drivers/BaseCRC.h +++ b/drivers/BaseCRC.h @@ -41,11 +41,11 @@ typedef enum crc_polynomial_type { * CRC value can be 8/16/32 bit */ typedef enum crc_width { - CRC_INVALID = 0, - CRC_7 = 7, - CRC_8 = 8, - CRC_16 = 16, - CRC_32 = 32, + CRC_WIDTH_INVALID = 0, + CRC_WIDTH_7 = 7, + CRC_WIDTH_8 = 8, + CRC_WIDTH_16 = 16, + CRC_WIDTH_32 = 32, } crc_width_t; /** CRC Polynomial value @@ -129,24 +129,24 @@ class BaseCRC crc_polynomial_type_t polynomial = this->get_polynomial_type(); if (CRC_7BIT_SD == polynomial) { - return CRC_7; + return CRC_WIDTH_7; } else if (CRC_8BIT_CCITT == polynomial) { - return CRC_8; + return CRC_WIDTH_8; } else if ((CRC_16BIT_CCITT == polynomial) || (CRC_16BIT_SD == polynomial) || (CRC_16BIT_IBM == polynomial)) { - return CRC_16; + return CRC_WIDTH_16; } else if (CRC_32BIT == polynomial) { - return CRC_32; + return CRC_WIDTH_32; } - return CRC_INVALID; + return CRC_WIDTH_INVALID; } /** Compute CRC for the data input * - * @param [IN] buffer Data bytes - * @param [IN] size Size of data - * @param [OUT] crc CRC + * @param buffer Data bytes + * @param size Size of data + * @param crc CRC is the output value * @return 0 on success, negative error code on failure */ virtual int32_t compute(void *buffer, crc_data_size_t size, uint32_t *crc) = 0; @@ -156,7 +156,7 @@ class BaseCRC * This API should be called before performing any partial computation * with compute_partial API. * - * @param [OUT] crc Initial CRC value set by the API + * @param crc Initial CRC value is the output parameter, value is set by the API * @return 0 on success or a negative when not supported * @note: CRC is an out parameter and must be reused with compute_partial * and compute_partial_stop without any modifications in application. @@ -173,9 +173,9 @@ class BaseCRC * @pre: Call \ref compute_partial_start to start the partial CRC calculation. * @post: Call \ref compute_partial_stop to get the final CRC value. * - * @param[IN] buffer Data bytes - * @param[IN] size Size of data - * @param[OUT] crc CRC value (intermediate CRC ) + * @param buffer Data bytes + * @param size Size of data + * @param crc CRC value is intermediate CRC value filled by API. * @return 0 on success or a negative error code on failure * @note: CRC as output in compute_partial is not final CRC value, call @ref compute_partial_stop * to get final correct CRC value. @@ -191,7 +191,7 @@ class BaseCRC * algorithms require remainder to be reflected and final value to be XORed * This API is used to perform final computation to get correct CRC value. * - * @param[OUT] crc CRC result + * @param crc Final CRC value filled up by API */ virtual int32_t compute_partial_stop(uint32_t *crc) { diff --git a/drivers/SlowCRC.cpp b/drivers/BitwiseCRC.cpp similarity index 86% rename from drivers/SlowCRC.cpp rename to drivers/BitwiseCRC.cpp index 76cfe6eae38..ddcbc55f282 100644 --- a/drivers/SlowCRC.cpp +++ b/drivers/BitwiseCRC.cpp @@ -15,12 +15,12 @@ */ #include "platform/mbed_assert.h" -#include "SlowCRC.h" +#include "BitwiseCRC.h" #include namespace mbed { -SlowCRC::SlowCRC(crc_polynomial_type_t polynomial) : +BitwiseCRC::BitwiseCRC(crc_polynomial_type_t polynomial) : _polynomial_type(polynomial), _inital_value(0x0), _final_xor(0x0), _reflect_data(false), _reflect_remainder(false) { @@ -38,14 +38,14 @@ SlowCRC::SlowCRC(crc_polynomial_type_t polynomial) : } } -SlowCRC::~SlowCRC() { } +BitwiseCRC::~BitwiseCRC() { } -crc_polynomial_type_t SlowCRC::get_polynomial_type(void) const +crc_polynomial_type_t BitwiseCRC::get_polynomial_type(void) const { return _polynomial_type; } -int32_t SlowCRC::compute_partial(void *buffer, crc_data_size_t size, uint32_t *crc) +int32_t BitwiseCRC::compute_partial(void *buffer, crc_data_size_t size, uint32_t *crc) { MBED_ASSERT(crc != NULL); MBED_ASSERT(buffer != NULL); @@ -85,7 +85,7 @@ int32_t SlowCRC::compute_partial(void *buffer, crc_data_size_t size, uint32_t *c return 0; } -int32_t SlowCRC::compute(void *buffer, crc_data_size_t size, uint32_t *crc) +int32_t BitwiseCRC::compute(void *buffer, crc_data_size_t size, uint32_t *crc) { MBED_ASSERT(crc != NULL); int32_t status; @@ -95,21 +95,21 @@ int32_t SlowCRC::compute(void *buffer, crc_data_size_t size, uint32_t *crc) return status; } -int32_t SlowCRC::compute_partial_start(uint32_t *crc) +int32_t BitwiseCRC::compute_partial_start(uint32_t *crc) { MBED_ASSERT(crc != NULL); *crc = _inital_value; return 0; } -int32_t SlowCRC::compute_partial_stop(uint32_t *crc) +int32_t BitwiseCRC::compute_partial_stop(uint32_t *crc) { MBED_ASSERT(crc != NULL); *crc = (reflect_remainder(*crc) ^ _final_xor) & get_crc_mask(); return 0; } -uint32_t SlowCRC::reflect_remainder(uint32_t data) +uint32_t BitwiseCRC::reflect_remainder(uint32_t data) { crc_width_t width = get_width(); if (_reflect_remainder) { @@ -128,7 +128,7 @@ uint32_t SlowCRC::reflect_remainder(uint32_t data) } } -uint32_t SlowCRC::reflect_bytes(uint32_t data) +uint32_t BitwiseCRC::reflect_bytes(uint32_t data) { if(_reflect_data) { uint32_t reflection = 0x0; diff --git a/drivers/SlowCRC.h b/drivers/BitwiseCRC.h similarity index 78% rename from drivers/SlowCRC.h rename to drivers/BitwiseCRC.h index 3f5818a38b6..98478c58d8d 100644 --- a/drivers/SlowCRC.h +++ b/drivers/BitwiseCRC.h @@ -14,31 +14,31 @@ * limitations under the License. */ -#ifndef MBED_SLOW_CRC_H -#define MBED_SLOW_CRC_H +#ifndef MBED_BITWISE_CRC_H +#define MBED_BITWISE_CRC_H #include "BaseCRC.h" namespace mbed { /** \addtogroup drivers */ -/** SlowCRC Class +/** BitwiseCRC Class * - * SlowCRC module does runtime division operation to compute CRC + * BitwiseCRC module does runtime division operation to compute CRC * */ -class SlowCRC : public BaseCRC +class BitwiseCRC : public BaseCRC { public: - /** Lifetime of the slow software CRC module + /** Lifetime of the bitwise software CRC module * - * Slow CRC module does runtime division operation to compute CRC + * Bitwise CRC module does runtime division operation to compute CRC * - * @param[IN] polynomial CRC polynomial + * @param polynomial CRC polynomial */ - SlowCRC(crc_polynomial_type_t polynomial); - virtual ~SlowCRC(); + BitwiseCRC(crc_polynomial_type_t polynomial); + virtual ~BitwiseCRC(); /** Get the current CRC polynomial type * @@ -53,9 +53,9 @@ class SlowCRC : public BaseCRC * @pre: Call \ref compute_partial_start to start the partial CRC calculation. * @post: Call \ref compute_partial_stop to get the final CRC value. * - * @param[IN] buffer Data bytes - * @param[IN] size Size of data - * @param[OUT] crc CRC value (intermediate CRC ) + * @param buffer Data bytes + * @param size Size of data + * @param crc CRC value is intermediate CRC value filled by API. * @return 0 on success or a negative error code on failure * @note: CRC as output in compute_partial is not final CRC value, call @ref compute_partial_stop * to get final correct CRC value. @@ -64,9 +64,9 @@ class SlowCRC : public BaseCRC /** Compute CRC for the data input * - * @param[IN] buffer Data bytes - * @param[IN] size Size of data - * @param[OUT] crc CRC + * @param buffer Data bytes + * @param size Size of data + * @param crc CRC is the output value * @return 0 on success, negative error code on failure */ virtual int32_t compute(void *buffer, crc_data_size_t size, uint32_t *crc); @@ -76,7 +76,7 @@ class SlowCRC : public BaseCRC * This API should be called before performing any partial computation * with compute_partial API. * - * @param[OUT] crc Initial CRC value set by the API + * @param crc Initial CRC value is the output parameter, value is set by the API * @return 0 on success or a negative when not supported * @note: CRC is an out parameter and must be reused with compute_partial * and compute_partial_stop without any modifications in application. @@ -89,7 +89,7 @@ class SlowCRC : public BaseCRC * algorithms require remainder to be reflected and final value to be XORed * This API is used to perform final computation to get correct CRC value. * - * @param[OUT] crc CRC result + * @param crc Final CRC value filled up by API */ virtual int32_t compute_partial_stop(uint32_t *crc); diff --git a/drivers/FastCRC.cpp b/drivers/FastCRC.cpp index 32e1a930555..1edc33ab621 100644 --- a/drivers/FastCRC.cpp +++ b/drivers/FastCRC.cpp @@ -38,7 +38,8 @@ FastCRC::FastCRC(crc_polynomial_type_t polynomial) : } } -FastCRC::~FastCRC() { +FastCRC::~FastCRC() +{ deinit(); } diff --git a/drivers/FastCRC.h b/drivers/FastCRC.h index a0576b34858..448e1c1f904 100644 --- a/drivers/FastCRC.h +++ b/drivers/FastCRC.h @@ -36,7 +36,7 @@ class FastCRC: public BaseCRC { * Fast CRC module generates division table during initialization and uses table * for runtime CRC generation from data input. * - * @param[IN] polynomial CRC polynomial + * @param polynomial CRC polynomial */ FastCRC(crc_polynomial_type_t polynomial); virtual ~FastCRC(); @@ -61,9 +61,9 @@ class FastCRC: public BaseCRC { /** Compute CRC for the data input * - * @param[IN] buffer Data bytes - * @param[IN] size Size of data - * @param[OUT] crc CRC + * @param buffer Data bytes + * @param size Size of data + * @param crc CRC is the output value * @return 0 on success, negative error code on failure */ virtual int32_t compute(void *buffer, crc_data_size_t size, uint32_t *crc); @@ -73,7 +73,7 @@ class FastCRC: public BaseCRC { * This API should be called before performing any partial computation * with compute_partial API. * - * @param[OUT] crc Initial CRC value set by the API + * @param crc Initial CRC value is the output parameter, value is set by the API * @return 0 on success or a negative when not supported * @note: CRC is an out parameter and must be reused with compute_partial * and compute_partial_stop without any modifications in application. @@ -87,9 +87,9 @@ class FastCRC: public BaseCRC { * @pre: Call \ref compute_partial_start to start the partial CRC calculation. * @post: Call \ref compute_partial_stop to get the final CRC value. * - * @param [IN] buffer Data bytes - * @param [IN] size Size of data - * @param [OUT] crc CRC value (intermediate CRC ) + * @param buffer Data bytes + * @param size Size of data + * @param crc CRC value is intermediate CRC value filled by API. * @return 0 on success or a negative error code on failure * @note: CRC as output in compute_partial is not final CRC value, call @ref compute_partial_stop * to get final correct CRC value. @@ -102,7 +102,7 @@ class FastCRC: public BaseCRC { * algorithms require remainder to be reflected and final value to be XORed * This API is used to perform final computation to get correct CRC value. * - * @param[OUT] crc CRC result + * @param crc Final CRC value filled up by API */ virtual int32_t compute_partial_stop(uint32_t *crc); diff --git a/drivers/HalfByteCRC.cpp b/drivers/HalfByteCRC.cpp index ded7888ef55..495df31991b 100644 --- a/drivers/HalfByteCRC.cpp +++ b/drivers/HalfByteCRC.cpp @@ -58,7 +58,7 @@ crc_polynomial_t HalfByteCRC::get_polynomial(void) const crc_width_t HalfByteCRC::get_width(void) const { - return CRC_32; + return CRC_WIDTH_32; } int32_t HalfByteCRC::compute_partial(void *buffer, crc_data_size_t size, uint32_t *crc) diff --git a/drivers/HalfByteCRC.h b/drivers/HalfByteCRC.h index 7b5b48d0730..d09d37dce4e 100644 --- a/drivers/HalfByteCRC.h +++ b/drivers/HalfByteCRC.h @@ -36,9 +36,9 @@ class HalfByteCRC : public BaseCRC * * Half-byte CRC module contains 16-entry lookup table each 4-byte long. * - * @param[IN] polynomial CRC polynomial value in hex - * @param[IN] inital_xor Inital value/seed to Xor (Default ~0x0) - * @param[IN] final_xor Final Xor value (Default ~0x0) + * @param polynomial CRC polynomial value in hex + * @param inital_xor Inital value/seed to Xor (Default ~0x0) + * @param final_xor Final Xor value (Default ~0x0) */ HalfByteCRC(crc_polynomial_t polynomial = POLY_32BIT_ANSI_REVERSE, uint32_t inital_xor = ~0x0, uint32_t final_xor = ~0x0); virtual ~HalfByteCRC(); @@ -80,9 +80,9 @@ class HalfByteCRC : public BaseCRC * @pre: Call \ref compute_partial_start to start the partial CRC calculation. * @post: Call \ref compute_partial_stop to get the final CRC value. * - * @param[IN] buffer Data bytes - * @param[IN] size Size of data - * @param[OUT] crc CRC value (intermediate CRC ) + * @param buffer Data bytes + * @param size Size of data + * @param crc CRC value is intermediate CRC value filled by API * @return 0 on success or a negative error code on failure * @note: CRC as output in compute_partial is not final CRC value, call @ref compute_partial_stop * to get final correct CRC value. @@ -91,9 +91,9 @@ class HalfByteCRC : public BaseCRC /** Compute CRC for the data input * - * @param[IN] buffer Data bytes - * @param[IN] size Size of data - * @param[OUT] crc CRC + * @param buffer Data bytes + * @param size Size of data + * @param crc CRC is the output value * @return 0 on success, negative error code on failure */ virtual int32_t compute(void *buffer, crc_data_size_t size, uint32_t *crc); @@ -103,7 +103,7 @@ class HalfByteCRC : public BaseCRC * This API should be called before performing any partial computation * with compute_partial API. * - * @param[OUT] crc Initial CRC value set by the API + * @param crc Initial CRC value is the output parameter, value is set by the API * @return 0 on success or a negative when not supported * @note: CRC is an out parameter and must be reused with compute_partial * and compute_partial_stop without any modifications in application. @@ -116,7 +116,7 @@ class HalfByteCRC : public BaseCRC * algorithms require remainder to be reflected and final value to be XORed * This API is used to perform final computation to get correct CRC value. * - * @param[OUT] crc CRC result + * @param crc Final CRC value filled up by API */ virtual int32_t compute_partial_stop(uint32_t *crc); diff --git a/drivers/RawCRC.h b/drivers/RawCRC.h new file mode 100644 index 00000000000..2cdcf634e0c --- /dev/null +++ b/drivers/RawCRC.h @@ -0,0 +1,28 @@ +/* mbed Microcontroller Library + * Copyright (c) 2017 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef RAW_CRC_API_H +#define RAW_CRC_API_H + +#include + +#if DEVICE_CRC +#error "Hardware CRC not supported" +#endif + +#include "FastCRC.h" +typedef mbed::FastCRC RawCRC; + +#endif diff --git a/mbed.h b/mbed.h index 1e56e636401..0a72af360db 100644 --- a/mbed.h +++ b/mbed.h @@ -70,6 +70,7 @@ #include "drivers/RawSerial.h" #include "drivers/UARTSerial.h" #include "drivers/FlashIAP.h" +#include "drivers/RawCRC.h" // mbed Internal components #include "drivers/Timer.h"