Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow compile time CRC calculation #1016

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions include/etl/frame_check_sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace etl
//*************************************************************************
/// Default constructor.
//*************************************************************************
frame_check_sequence()
ETL_CONSTEXPR14 frame_check_sequence() : frame_check{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI fails for C++03 syntax check.
You will have to change frame_check{} to frame_check() for C++03 compatibility.

{
reset();
}
Expand All @@ -118,7 +118,7 @@ namespace etl
/// \param end End of the range.
//*************************************************************************
template<typename TIterator>
frame_check_sequence(TIterator begin, const TIterator end)
ETL_CONSTEXPR14 frame_check_sequence(TIterator begin, const TIterator end) : frame_check{}
{
ETL_STATIC_ASSERT(sizeof(typename etl::iterator_traits<TIterator>::value_type) == 1, "Type not supported");

Expand All @@ -129,7 +129,7 @@ namespace etl
//*************************************************************************
/// Resets the FCS to the initial state.
//*************************************************************************
void reset()
ETL_CONSTEXPR14 void reset()
{
frame_check = policy.initial();
}
Expand All @@ -140,7 +140,7 @@ namespace etl
/// \param end
//*************************************************************************
template<typename TIterator>
void add(TIterator begin, const TIterator end)
ETL_CONSTEXPR14 void add(TIterator begin, const TIterator end)
{
ETL_STATIC_ASSERT(sizeof(typename etl::iterator_traits<TIterator>::value_type) == 1, "Type not supported");

Expand All @@ -154,31 +154,31 @@ namespace etl
//*************************************************************************
/// \param value The uint8_t to add to the FCS.
//*************************************************************************
void add(uint8_t value_)
ETL_CONSTEXPR14 void add(uint8_t value_)
{
frame_check = policy.add(frame_check, value_);
}

//*************************************************************************
/// Gets the FCS value.
//*************************************************************************
value_type value() const
ETL_CONSTEXPR14 value_type value() const
{
return policy.final(frame_check);
}

//*************************************************************************
/// Conversion operator to value_type.
//*************************************************************************
operator value_type () const
ETL_CONSTEXPR14 operator value_type () const
{
return policy.final(frame_check);
}

//*************************************************************************
/// Gets an add_insert_iterator for input.
//*************************************************************************
add_insert_iterator input()
ETL_CONSTEXPR14 add_insert_iterator input()
{
return add_insert_iterator(*this);
}
Expand Down
602 changes: 304 additions & 298 deletions include/etl/private/crc_implementation.h

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions test/test_crc16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ namespace
CHECK_EQUAL(0xBB3DU, crc);
}

#if ETL_USING_CPP14
//*************************************************************************
TEST(test_crc16_16_constexpr)
{
constexpr char data[] = "123456789";
constexpr uint16_t crc = etl::crc16_t16(data, data + 9);

CHECK_EQUAL(0xBB3DU, crc);
}
#endif

//*************************************************************************
TEST(test_crc16_16_add_values)
{
Expand Down Expand Up @@ -199,6 +210,17 @@ namespace
CHECK_EQUAL(0xBB3DU, crc);
}

#if ETL_USING_CPP14
//*************************************************************************
TEST(test_crc16_4_constexpr)
{
constexpr char data[] = "123456789";
constexpr uint16_t crc = etl::crc16_t4(data, data + 9);

CHECK_EQUAL(0xBB3DU, crc);
}
#endif

//*************************************************************************
TEST(test_crc16_4_add_values)
{
Expand Down
33 changes: 33 additions & 0 deletions test/test_crc16_a.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ namespace
CHECK_EQUAL(0xBF05U, crc);
}

#if ETL_USING_CPP14
//*************************************************************************
TEST(test_crc16_a_constexpr)
{
constexpr char data[] = "123456789";
constexpr uint16_t crc = etl::crc16_a(data, data + 9);

CHECK_EQUAL(0xBF05U, crc);
}
#endif

//*************************************************************************
TEST(test_crc16_a_add_values)
{
Expand Down Expand Up @@ -127,6 +138,17 @@ namespace
CHECK_EQUAL(0xBF05U, crc);
}

#if ETL_USING_CPP14
//*************************************************************************
TEST(test_crc16_a_16_constexpr)
{
constexpr char data[] = "123456789";
constexpr uint16_t crc = etl::crc16_a_t16(data, data + 9);

CHECK_EQUAL(0xBF05U, crc);
}
#endif

//*************************************************************************
TEST(test_crc16_a_16_add_values)
{
Expand Down Expand Up @@ -199,6 +221,17 @@ namespace
CHECK_EQUAL(0xBF05U, crc);
}

#if ETL_USING_CPP14
//*************************************************************************
TEST(test_crc16_a_4_constexpr)
{
constexpr char data[] = "123456789";
constexpr uint16_t crc = etl::crc16_a_t4(data, data + 9);

CHECK_EQUAL(0xBF05U, crc);
}
#endif

//*************************************************************************
TEST(test_crc16_a_4_add_values)
{
Expand Down
33 changes: 33 additions & 0 deletions test/test_crc16_arc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ namespace
CHECK_EQUAL(0xBB3DU, crc);
}

#if ETL_USING_CPP14
//*************************************************************************
TEST(test_crc16_arc_constexpr)
{
constexpr char data[] = "123456789";
constexpr uint16_t crc = etl::crc16_arc(data, data + 9);

CHECK_EQUAL(0xBB3DU, crc);
}
#endif

//*************************************************************************
TEST(test_crc16_arc_add_values)
{
Expand Down Expand Up @@ -127,6 +138,17 @@ namespace
CHECK_EQUAL(0xBB3DU, crc);
}

#if ETL_USING_CPP14
//*************************************************************************
TEST(test_crc16_arc_16_constexpr)
{
constexpr char data[] = "123456789";
constexpr uint16_t crc = etl::crc16_arc_t16(data, data + 9);

CHECK_EQUAL(0xBB3DU, crc);
}
#endif

//*************************************************************************
TEST(test_crc16_arc_16_add_values)
{
Expand Down Expand Up @@ -199,6 +221,17 @@ namespace
CHECK_EQUAL(0xBB3DU, crc);
}

#if ETL_USING_CPP14
//*************************************************************************
TEST(test_crc16_arc_4_constexpr)
{
constexpr char data[] = "123456789";
constexpr uint16_t crc = etl::crc16_arc_t4(data, data + 9);

CHECK_EQUAL(0xBB3DU, crc);
}
#endif

//*************************************************************************
TEST(test_crc16_arc_4_add_values)
{
Expand Down
33 changes: 33 additions & 0 deletions test/test_crc16_aug_ccitt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ namespace
CHECK_EQUAL(0xE5CCU, crc);
}

#if ETL_USING_CPP14
//*************************************************************************
TEST(test_crc16_aug_ccitt_constexpr)
{
constexpr char data[] = "123456789";
constexpr uint16_t crc = etl::crc16_aug_ccitt(data, data + 9);

CHECK_EQUAL(0xE5CCU, crc);
}
#endif

//*************************************************************************
TEST(test_crc16_aug_ccitt_add_values)
{
Expand Down Expand Up @@ -127,6 +138,17 @@ namespace
CHECK_EQUAL(0xE5CCU, crc);
}

#if ETL_USING_CPP14
//*************************************************************************
TEST(test_crc16_aug_ccitt_16_constexpr)
{
constexpr char data[] = "123456789";
constexpr uint16_t crc = etl::crc16_aug_ccitt_t16(data, data + 9);

CHECK_EQUAL(0xE5CCU, crc);
}
#endif

//*************************************************************************
TEST(test_crc16_aug_ccitt_16_add_values)
{
Expand Down Expand Up @@ -199,6 +221,17 @@ namespace
CHECK_EQUAL(0xE5CCU, crc);
}

#if ETL_USING_CPP14
//*************************************************************************
TEST(test_crc16_aug_ccitt_4_constexpr)
{
constexpr char data[] = "123456789";
constexpr uint16_t crc = etl::crc16_aug_ccitt_t4(data, data + 9);

CHECK_EQUAL(0xE5CCU, crc);
}
#endif

//*************************************************************************
TEST(test_crc16_aug_ccitt_4_add_values)
{
Expand Down
33 changes: 33 additions & 0 deletions test/test_crc16_buypass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ namespace
CHECK_EQUAL(0xFEE8U, crc);
}

#if ETL_USING_CPP14
//*************************************************************************
TEST(test_crc16_buypass_constexpr)
{
constexpr char data[] = "123456789";
constexpr uint16_t crc = etl::crc16_buypass(data, data + 9);

CHECK_EQUAL(0xFEE8U, crc);
}
#endif

//*************************************************************************
TEST(test_crc16_buypass_add_values)
{
Expand Down Expand Up @@ -127,6 +138,17 @@ namespace
CHECK_EQUAL(0xFEE8U, crc);
}

#if ETL_USING_CPP14
//*************************************************************************
TEST(test_crc16_buypass_16_constexpr)
{
constexpr char data[] = "123456789";
constexpr uint16_t crc = etl::crc16_buypass_t16(data, data + 9);

CHECK_EQUAL(0xFEE8U, crc);
}
#endif

//*************************************************************************
TEST(test_crc16_buypass_16_add_values)
{
Expand Down Expand Up @@ -199,6 +221,17 @@ namespace
CHECK_EQUAL(0xFEE8U, crc);
}

#if ETL_USING_CPP14
//*************************************************************************
TEST(test_crc16_buypass_4_constexpr)
{
constexpr char data[] = "123456789";
constexpr uint16_t crc = etl::crc16_buypass_t4(data, data + 9);

CHECK_EQUAL(0xFEE8U, crc);
}
#endif

//*************************************************************************
TEST(test_crc16_buypass_4_add_values)
{
Expand Down
33 changes: 33 additions & 0 deletions test/test_crc16_ccitt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ namespace
CHECK_EQUAL(0x29B1U, crc);
}

#if ETL_USING_CPP14
//*************************************************************************
TEST(test_crc16_ccitt_constexpr)
{
constexpr char data[] = "123456789";
constexpr uint16_t crc = etl::crc16_ccitt(data, data + 9);

CHECK_EQUAL(0x29B1U, crc);
}
#endif

//*************************************************************************
TEST(test_crc16_ccitt_add_values)
{
Expand Down Expand Up @@ -127,6 +138,17 @@ namespace
CHECK_EQUAL(0x29B1U, crc);
}

#if ETL_USING_CPP14
//*************************************************************************
TEST(test_crc16_ccitt_16_constexpr)
{
constexpr char data[] = "123456789";
constexpr uint16_t crc = etl::crc16_ccitt_t16(data, data + 9);

CHECK_EQUAL(0x29B1U, crc);
}
#endif

//*************************************************************************
TEST(test_crc16_ccitt_16_add_values)
{
Expand Down Expand Up @@ -199,6 +221,17 @@ namespace
CHECK_EQUAL(0x29B1U, crc);
}

#if ETL_USING_CPP14
//*************************************************************************
TEST(test_crc16_ccitt_4_constexpr)
{
constexpr char data[] = "123456789";
constexpr uint16_t crc = etl::crc16_ccitt_t4(data, data + 9);

CHECK_EQUAL(0x29B1U, crc);
}
#endif

//*************************************************************************
TEST(test_crc16_ccitt_4_add_values)
{
Expand Down
Loading
Loading