Intermediate commit

This commit is contained in:
John Wellbelove 2021-03-24 12:16:01 +00:00
parent 23bf71d06a
commit 33f3d21300
10 changed files with 4115 additions and 3452 deletions

View File

@ -32,11 +32,8 @@ SOFTWARE.
#define ETL_CRC16_EX_INCLUDED
#include "../platform.h"
#include "crc_implementation.h"
#if defined(ETL_COMPILER_KEIL)
#pragma diag_suppress 1300
#endif
#include "crc_implementation_2.h"
#include "crc_parameters.h"
///\defgroup crc16 16 bit CRC calculation
///\ingroup crc
@ -45,8 +42,12 @@ namespace etl
{
namespace crc
{
#if ETL_CPP11_SUPPORTED
template <size_t Table_Size>
class crc16_t : public etl::private_crc::crc_type<uint16_t, 0x8005U, 0x0000U, 0x0000U, true, Table_Size>
using crc16_t = etl::crc_type<etl::private_crc::crc16_parameters, Table_Size>;
#else
template <size_t Table_Size>
class crc16_t : public etl::private_crc::crc_type<etl::private_crc::crc16_parameters, Table_Size>
{
public:
@ -72,6 +73,7 @@ namespace etl
this->add(begin, end);
}
};
#endif
typedef etl::crc::crc16_t<256U> crc16_t256;
typedef etl::crc::crc16_t<16U> crc16_t16;

View File

@ -32,21 +32,19 @@ SOFTWARE.
#define ETL_CRC8_CCITT_EXP_INCLUDED
#include "../platform.h"
#include "crc_implementation.h"
#if defined(ETL_COMPILER_KEIL)
#pragma diag_suppress 1300
#endif
///\defgroup crc8_ccitt 8 bit CRC calculation
///\ingroup crc
#include "crc_implementation_2.h"
#include "crc_parameters.h"
namespace etl
{
namespace crc
{
#if ETL_CPP11_SUPPORTED
template <size_t Table_Size>
class crc8_ccitt_t : public etl::private_crc::crc_type<uint8_t, 0x07U, 0x00U, 0x00U, false, Table_Size>
using crc8_ccitt_t = etl::crc_type<etl::private_crc::crc8_ccitt_parameters, Table_Size>;
#else
template <size_t Table_Size>
class crc8_ccitt_t : public etl::crc_type<etl::private_crc::crc8_ccitt_parameters, Table_Size>
{
public:
@ -72,11 +70,12 @@ namespace etl
this->add(begin, end);
}
};
typedef etl::crc::crc8_ccitt_t<256U> crc8_ccitt_t256;
typedef etl::crc::crc8_ccitt_t<16U> crc8_ccitt_t16;
typedef etl::crc::crc8_ccitt_t<4U> crc8_ccitt_t4;
typedef crc8_ccitt_t256 crc8_ccitt;
#endif
typedef crc8_ccitt_t<256U> crc8_ccitt_t256;
typedef crc8_ccitt_t<16U> crc8_ccitt_t16;
typedef crc8_ccitt_t<4U> crc8_ccitt_t4;
typedef crc8_ccitt_t256 crc8_ccitt;
}
}

View File

@ -32,11 +32,8 @@ SOFTWARE.
#define ETL_CRC8_ROHC_EXP_INCLUDED
#include "../platform.h"
#include "crc_implementation.h"
#if defined(ETL_COMPILER_KEIL)
#pragma diag_suppress 1300
#endif
#include "crc_implementation_2.h"
#include "crc_parameters.h"
///\defgroup rohc 8 bit CRC calculation
///\ingroup crc
@ -45,8 +42,12 @@ namespace etl
{
namespace crc
{
#if ETL_CPP11_SUPPORTED
template <size_t Table_Size>
class crc8_rohc_t : public etl::private_crc::crc_type<uint8_t, 0x07U, 0xFFU, 0x00U, true, Table_Size>
using crc8_rohc_t = etl::crc_type<etl::private_crc::crc8_rohc_parameters, Table_Size>;
#else
template <size_t Table_Size>
class crc8_rohc_t : public etl::private_crc::crc_type<etl::private_crc::crc8_rohc_parameters, Table_Size>
{
public:
@ -72,6 +73,7 @@ namespace etl
this->add(begin, end);
}
};
#endif
typedef etl::crc::crc8_rohc_t<256U> crc8_rohc_t256;
typedef etl::crc::crc8_rohc_t<16U> crc8_rohc_t16;

View File

@ -0,0 +1,650 @@
#pragma once
#include "../platform.h"
#include "../frame_check_sequence.h"
#include "../static_assert.h"
#include "../binary.h"
#include "stdint.h"
namespace etl
{
namespace private_crc
{
//*****************************************************************************
/// CRC Traits
//*****************************************************************************
template <size_t Table_Size>
struct crc_traits;
//*********************************
// Traits for table size of 4.
template <>
struct crc_traits<4U>
{
static ETL_CONSTANT uint8_t Chunk_Mask = 0x03U;
static ETL_CONSTANT size_t Chunk_Bits = 2U;
};
//*********************************
// Traits for table size of 16.
template <>
struct crc_traits<16U>
{
static ETL_CONSTANT uint8_t Chunk_Mask = 0x0FU;
static ETL_CONSTANT size_t Chunk_Bits = 4U;
};
//*********************************
// Traits for table size of 256.
template <>
struct crc_traits<256U>
{
static ETL_CONSTANT uint8_t Chunk_Mask = 0xFFU;
static ETL_CONSTANT size_t Chunk_Bits = 8U;
};
//*****************************************************************************
/// CRC Entry
//*****************************************************************************
template <typename TCrcParameters, typename TCrcParameters::accumulator_type Entry>
class crc_entry
{
private:
typename typedef TCrcParameters::accumulator_type accumulator_type;
static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits;
static ETL_CONSTANT accumulator_type Polynomial = TCrcParameters::Polynomial;
static ETL_CONSTANT bool Reflect = TCrcParameters::Reflect;
static ETL_CONSTANT bool Do_Poly = Reflect ? (Entry & accumulator_type(1U)) != 0U
: (Entry & (accumulator_type(1U) << (Accumulator_Bits - 1U))) != 0U;
public:
static ETL_CONSTANT accumulator_type value = Reflect ? accumulator_type(Do_Poly ? (Entry >> 1U) ^ etl::reverse_bits_const<accumulator_type, Polynomial>::value : (Entry >> 1U))
: accumulator_type(Do_Poly ? (Entry << 1U) ^ Polynomial : (Entry << 1U));
};
//*****************************************************************************
/// CRC Table Entry
//*****************************************************************************
template <typename TCrcParameters, size_t Index, uint8_t Chunk_Bits>
class crc_table_entry
{
ETL_STATIC_ASSERT((Chunk_Bits == 2U) || (Chunk_Bits == 4U) || (Chunk_Bits == 8U), "Chunk bits must be 2, 4 or 8");
};
//*********************************
// Chunk bit size of 8.
template <typename TCrcParameters, size_t Index>
class crc_table_entry<TCrcParameters, Index, 8U>
{
public:
typedef typename TCrcParameters::accumulator_type accumulator_type;
static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits;
static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - 8U);
static ETL_CONSTANT accumulator_type Entry = TCrcParameters::Reflect ? accumulator_type(Index) : accumulator_type(accumulator_type(Index) << Shift_Bits);
static ETL_CONSTANT accumulator_type value = crc_entry<TCrcParameters,
crc_entry<TCrcParameters,
crc_entry<TCrcParameters,
crc_entry<TCrcParameters,
crc_entry<TCrcParameters,
crc_entry<TCrcParameters,
crc_entry<TCrcParameters,
crc_entry<TCrcParameters, Entry>::value>::value>::value>::value>::value>::value>::value>::value;
};
//*********************************
// Chunk bit size of 4.
template <typename TCrcParameters, size_t Index>
class crc_table_entry<TCrcParameters, Index, 4U>
{
public:
typedef typename TCrcParameters::accumulator_type accumulator_type;
static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits;
static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - 4U);
static ETL_CONSTANT accumulator_type Entry = TCrcParameters::Reflect ? accumulator_type(Index) : accumulator_type(accumulator_type(Index) << Shift_Bits);
static const accumulator_type value = crc_entry<TCrcParameters,
crc_entry<TCrcParameters,
crc_entry<TCrcParameters,
crc_entry<TCrcParameters, Entry>::value>::value>::value>::value;
};
//*********************************
// Chunk bit size of 2.
template <typename TCrcParameters, size_t Index>
class crc_table_entry<TCrcParameters, Index, 2U>
{
public:
typedef typename TCrcParameters::accumulator_type accumulator_type;
static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits;
static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - 2U);
static ETL_CONSTANT accumulator_type Entry = TCrcParameters::Reflect ? accumulator_type(Index) : accumulator_type(accumulator_type(Index) << Shift_Bits);
static const accumulator_type value = crc_entry<TCrcParameters,
crc_entry<TCrcParameters, Entry>::value>::value;
};
//*************************************************************************
// Accumulator_Bits > Chunk_Bits and not reflected
template <typename TAccumulator, uint8_t Chunk_Mask, uint8_t Chunk_Bits, uint8_t Accumulator_Bits, bool Reflect>
typename etl::enable_if<(Accumulator_Bits > Chunk_Bits) && !Reflect, TAccumulator>::type
crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[])
{
size_t index = (crc >> (Accumulator_Bits - Chunk_Bits)) ^ value;
crc <<= Chunk_Bits;
crc ^= table[index];
return crc;
}
//*************************************************************************
// Accumulator_Bits > Chunk_Bits and reflected
template <typename TAccumulator, uint8_t Chunk_Mask, uint8_t Chunk_Bits, uint8_t Accumulator_Bits, bool Reflect>
typename etl::enable_if<(Accumulator_Bits > Chunk_Bits) && Reflect, TAccumulator>::type
crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[])
{
size_t index = (crc & Chunk_Mask) ^ value;
crc >>= Chunk_Bits;
crc ^= table[index];
return crc;
}
//*************************************************************************
// Accumulator_Bits == Chunk_Bits and not reflected
template <typename TAccumulator, uint8_t Chunk_Mask, uint8_t Chunk_Bits, uint8_t Accumulator_Bits, bool Reflect>
typename etl::enable_if<(Accumulator_Bits == Chunk_Bits) && !Reflect, TAccumulator>::type
crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[])
{
size_t index = (crc >> (Accumulator_Bits - Chunk_Bits)) ^ value;
crc = table[index];
return crc;
}
//*************************************************************************
// Accumulator_Bits == Chunk_Bits and reflected
template <typename TAccumulator, uint8_t Chunk_Mask, uint8_t Chunk_Bits, uint8_t Accumulator_Bits, bool Reflect>
typename etl::enable_if<(Accumulator_Bits == Chunk_Bits) && Reflect, TAccumulator>::type
crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[])
{
size_t index = (crc & Chunk_Mask) ^ value;
crc = table[index];
return crc;
}
//*****************************************************************************
//
//*****************************************************************************
template <typename TCrcParameters, size_t Table_Size>
struct crc_policy;
//*********************************
// Policy for 256 sized table.
template <typename TCrcParameters>
struct crc_policy<TCrcParameters, 256U>
{
typedef typename TCrcParameters::accumulator_type accumulator_type;
typedef accumulator_type value_type;
static ETL_CONSTANT size_t Table_Size = 256U;
static ETL_CONSTANT uint8_t Chunk_Mask = crc_traits<Table_Size>::Chunk_Mask;
static ETL_CONSTANT uint8_t Chunk_Bits = crc_traits<Table_Size>::Chunk_Bits;
static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits;
//*************************************************************************
ETL_CONSTEXPR accumulator_type initial() const
{
return TCrcParameters::Initial;
}
//*************************************************************************
accumulator_type add(accumulator_type crc, uint8_t value) const
{
static ETL_CONSTANT accumulator_type table[Table_Size] =
{
crc_table_entry<TCrcParameters, 0U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 1U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 2U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 3U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 4U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 5U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 6U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 7U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 8U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 9U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 10U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 11U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 12U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 13U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 14U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 15U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 16U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 17U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 18U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 19U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 20U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 21U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 22U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 23U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 24U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 25U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 26U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 27U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 28U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 29U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 30U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 31U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 32U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 33U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 34U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 35U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 36U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 37U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 38U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 39U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 40U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 41U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 42U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 43U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 44U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 45U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 46U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 47U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 48U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 49U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 50U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 51U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 52U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 53U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 54U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 55U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 56U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 57U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 58U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 59U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 60U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 61U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 62U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 63U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 64U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 65U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 66U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 67U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 68U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 69U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 70U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 71U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 72U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 73U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 74U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 75U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 76U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 77U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 78U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 79U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 80U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 81U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 82U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 83U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 84U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 85U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 86U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 87U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 88U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 89U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 90U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 91U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 92U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 93U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 94U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 95U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 96U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 97U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 98U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 99U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 100U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 101U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 102U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 103U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 104U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 105U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 106U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 107U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 108U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 109U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 110U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 111U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 112U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 113U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 114U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 115U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 116U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 117U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 118U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 119U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 120U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 121U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 122U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 123U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 124U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 125U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 126U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 127U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 128U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 129U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 130U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 131U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 132U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 133U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 134U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 135U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 136U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 137U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 138U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 139U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 140U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 141U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 142U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 143U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 144U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 145U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 146U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 147U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 148U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 149U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 150U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 151U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 152U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 153U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 154U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 155U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 156U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 157U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 158U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 159U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 160U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 161U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 162U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 163U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 164U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 165U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 166U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 167U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 168U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 169U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 170U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 171U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 172U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 173U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 174U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 175U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 176U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 177U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 178U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 179U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 180U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 181U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 182U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 183U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 184U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 185U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 186U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 187U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 188U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 189U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 190U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 191U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 192U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 193U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 194U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 195U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 196U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 197U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 198U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 199U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 200U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 201U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 202U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 203U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 204U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 205U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 206U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 207U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 208U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 209U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 210U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 211U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 212U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 213U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 214U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 215U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 216U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 217U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 218U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 219U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 220U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 221U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 222U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 223U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 224U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 225U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 226U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 227U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 228U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 229U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 230U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 231U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 232U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 233U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 234U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 235U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 236U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 237U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 238U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 239U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 240U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 241U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 242U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 243U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 244U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 245U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 246U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 247U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 248U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 249U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 250U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 251U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 252U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 253U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 254U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 255U, Chunk_Bits>::value
};
crc = crc_update_chunk<accumulator_type, Chunk_Mask, Chunk_Bits, Accumulator_Bits, TCrcParameters::Reflect>(crc, value, table);
return crc;
}
//*************************************************************************
accumulator_type final(accumulator_type crc) const
{
return crc ^ TCrcParameters::Xor_Out;
}
};
//*********************************
// Policy for 16 sized table.
template <typename TCrcParameters>
struct crc_policy<TCrcParameters, 16U>
{
typedef typename TCrcParameters::accumulator_type accumulator_type;
typedef accumulator_type value_type;
static ETL_CONSTANT size_t Table_Size = 16U;
static ETL_CONSTANT uint8_t Chunk_Mask = crc_traits<Table_Size>::Chunk_Mask;
static ETL_CONSTANT uint8_t Chunk_Bits = crc_traits<Table_Size>::Chunk_Bits;
static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits;
typedef accumulator_type value_type;
//*************************************************************************
ETL_CONSTEXPR accumulator_type initial() const
{
return TCrcParameters::Initial;
}
//*************************************************************************
static accumulator_type update_chunk(accumulator_type crc, uint8_t value, const accumulator_type table[])
{
// Extract the most significant nibble of the crc and xor with the value nibble.
size_t index = (crc >> (etl::integral_limits<uint8_t>::bits - Chunk_Bits)) ^ value;
crc <<= Chunk_Bits;
crc ^= table[index];
return crc;
}
//*************************************************************************
accumulator_type add(accumulator_type crc, uint8_t value) const
{
static ETL_CONSTANT accumulator_type table[Table_Size] =
{
crc_table_entry<TCrcParameters, 0U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 1U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 2U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 3U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 4U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 5U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 6U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 7U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 8U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 9U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 10U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 11U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 12U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 13U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 14U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 15U, Chunk_Bits>::value
};
crc = update_chunk(crc, (value >> Chunk_Bits) & Chunk_Mask, table);
crc = update_chunk(crc, value & Chunk_Mask, table);
return crc;
}
//*************************************************************************
accumulator_type final(accumulator_type crc) const
{
return crc ^ TCrcParameters::Xor_Out;
}
};
//*********************************
// Policy for 4 sized table.
template <typename TCrcParameters>
struct crc_policy<TCrcParameters, 4U>
{
typedef typename TCrcParameters::accumulator_type accumulator_type;
typedef accumulator_type value_type;
static ETL_CONSTANT size_t Table_Size = 4U;
static ETL_CONSTANT uint8_t Chunk_Mask = crc_traits<Table_Size>::Chunk_Mask;
static ETL_CONSTANT uint8_t Chunk_Bits = crc_traits<Table_Size>::Chunk_Bits;
static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits;
//*************************************************************************
ETL_CONSTEXPR accumulator_type initial() const
{
return TCrcParameters::Initial;
}
//*************************************************************************
static accumulator_type update_chunk(accumulator_type crc, uint8_t value, const accumulator_type table[])
{
// Extract the most significant nibble of the crc and xor with the value nibble.
size_t index = (crc >> (etl::integral_limits<uint8_t>::bits - Chunk_Bits)) ^ value;
crc <<= Chunk_Bits;
crc ^= table[index];
return crc;
}
//*************************************************************************
accumulator_type add(accumulator_type crc, uint8_t value) const
{
static ETL_CONSTANT accumulator_type table[Table_Size] =
{
crc_table_entry<TCrcParameters, 0U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 1U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 2U, Chunk_Bits>::value,
crc_table_entry<TCrcParameters, 3U, Chunk_Bits>::value
};
crc = update_chunk(crc, (value >> (Chunk_Bits * 3U)) & Chunk_Mask, table);
crc = update_chunk(crc, (value >> (Chunk_Bits * 2U)) & Chunk_Mask, table);
crc = update_chunk(crc, (value >> (Chunk_Bits * 1U)) & Chunk_Mask, table);
crc = update_chunk(crc, value & Chunk_Mask, table);
return crc;
}
//*************************************************************************
accumulator_type final(accumulator_type crc) const
{
return crc ^ TCrcParameters::Xor_Out;
}
};
}
//*****************************************************************************
/// Basic parameterised CRC type.
//*****************************************************************************
template <typename TCrcParameters, size_t Table_Size>
class crc_type : public etl::frame_check_sequence<private_crc::crc_policy<TCrcParameters, Table_Size> >
{
public:
ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256");
//*************************************************************************
/// Default constructor.
//*************************************************************************
crc_type()
{
this->reset();
}
//*************************************************************************
/// Constructor from range.
/// \param begin Start of the range.
/// \param end End of the range.
//*************************************************************************
template<typename TIterator>
crc_type(TIterator begin, const TIterator end)
{
this->reset();
this->add(begin, end);
}
};
}

View File

@ -1,6 +1,7 @@
#pragma once
#include "../platform.h"
#include "../integral_limits.h"
namespace etl
{
@ -10,10 +11,11 @@ namespace etl
struct crc_parameters
{
typedef TAccumulator accumulator_type;
static ETL_CONSTANT TAccumulator Polynomial = Polynomial_;
static ETL_CONSTANT TAccumulator Initial = Initial_;
static ETL_CONSTANT TAccumulator Xor_Out = Xor_Out_;
static ETL_CONSTANT bool Reflect = Reflect_;
static ETL_CONSTANT TAccumulator Polynomial = Polynomial_;
static ETL_CONSTANT TAccumulator Initial = Initial_;
static ETL_CONSTANT TAccumulator Xor_Out = Xor_Out_;
static ETL_CONSTANT bool Reflect = Reflect_;
static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits<accumulator_type>::bits;
};
// 8 bit.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1286,6 +1286,7 @@
<ClInclude Include="..\..\include\etl\experimental\crc8_rohc.h" />
<ClInclude Include="..\..\include\etl\experimental\crc8_ccitt.h" />
<ClInclude Include="..\..\include\etl\experimental\crc_implementation.h" />
<ClInclude Include="..\..\include\etl\experimental\crc_implementation_2.h" />
<ClInclude Include="..\..\include\etl\experimental\crc_parameters.h" />
<ClInclude Include="..\..\include\etl\file_error_numbers.h" />
<ClInclude Include="..\..\include\etl\flags.h" />
@ -3793,9 +3794,13 @@
<ClCompile Include="..\test_circular_buffer.cpp" />
<ClCompile Include="..\test_circular_buffer_external_buffer.cpp" />
<ClCompile Include="..\test_compiler_settings.cpp" />
<ClCompile Include="..\test_crc_table16.cpp" />
<ClCompile Include="..\test_crc_table16.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\test_crc_table256.cpp" />
<ClCompile Include="..\test_crc_table4.cpp" />
<ClCompile Include="..\test_crc_table4.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\test_cumulative_moving_average.cpp" />
<ClCompile Include="..\test_delegate.cpp" />
<ClCompile Include="..\test_delegate_service.cpp" />

View File

@ -1032,6 +1032,9 @@
<ClInclude Include="..\..\include\etl\experimental\crc_parameters.h">
<Filter>ETL\Maths\Experimental</Filter>
</ClInclude>
<ClInclude Include="..\..\include\etl\experimental\crc_implementation_2.h">
<Filter>ETL\Maths\Experimental</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\main.cpp">