Skip to content

Commit

Permalink
Default Class and few fixes
Browse files Browse the repository at this point in the history
1. Added default CRC case RawCRC
2. Renamed SlowCRC to BitwiseCRC class
3. Resolved doxygen errors
4. Resolved name clashes with different targets
  • Loading branch information
Deepika committed Jan 3, 2018
1 parent 122036a commit 64bb607
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 68 deletions.
36 changes: 18 additions & 18 deletions drivers/BaseCRC.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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)
{
Expand Down
20 changes: 10 additions & 10 deletions drivers/SlowCRC.cpp → drivers/BitwiseCRC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/

#include "platform/mbed_assert.h"
#include "SlowCRC.h"
#include "BitwiseCRC.h"
#include <stdio.h>

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)
{
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
Expand Down
36 changes: 18 additions & 18 deletions drivers/SlowCRC.h → drivers/BitwiseCRC.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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.
Expand All @@ -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);
Expand All @@ -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.
Expand All @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion drivers/FastCRC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ FastCRC::FastCRC(crc_polynomial_type_t polynomial) :
}
}

FastCRC::~FastCRC() {
FastCRC::~FastCRC()
{
deinit();
}

Expand Down
18 changes: 9 additions & 9 deletions drivers/FastCRC.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion drivers/HalfByteCRC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 11 additions & 11 deletions drivers/HalfByteCRC.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand All @@ -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.
Expand All @@ -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);

Expand Down
Loading

0 comments on commit 64bb607

Please sign in to comment.