Skip to content

Commit

Permalink
Added constexpr to CRC1
Browse files Browse the repository at this point in the history
  • Loading branch information
jwellbelove committed Jan 24, 2025
1 parent 14b50c6 commit b3f7d82
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
10 changes: 5 additions & 5 deletions include/etl/crc1.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ namespace etl
};

//*********************************
value_type initial() const
ETL_CONSTEXPR14 value_type initial() const
{
return even_parity;
}

//*********************************
uint8_t add(int parity, uint8_t value) const
ETL_CONSTEXPR14 uint8_t add(int parity, uint8_t value) const
{
return parity ^ etl::parity(value);
}

//*********************************
uint8_t final(uint8_t parity) const
ETL_CONSTEXPR14 uint8_t final(uint8_t parity) const
{
return parity;
}
Expand All @@ -83,7 +83,7 @@ namespace etl
//*************************************************************************
/// Default constructor.
//*************************************************************************
crc1()
ETL_CONSTEXPR14 crc1()
{
this->reset();
}
Expand All @@ -94,7 +94,7 @@ namespace etl
/// \param end End of the range.
//*************************************************************************
template<typename TIterator>
crc1(TIterator begin, const TIterator end)
ETL_CONSTEXPR14 crc1(TIterator begin, const TIterator end)
{
this->reset();
this->add(begin, end);
Expand Down
3 changes: 2 additions & 1 deletion include/etl/frame_check_sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ namespace etl
//*************************************************************************
/// Default constructor.
//*************************************************************************
ETL_CONSTEXPR14 frame_check_sequence() : frame_check()
ETL_CONSTEXPR14 frame_check_sequence()
: frame_check()
{
reset();
}
Expand Down
11 changes: 11 additions & 0 deletions test/test_crc1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ namespace
CHECK_EQUAL(calculate_parity(data.begin(), data.end()), int(crc));
}

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

CHECK_EQUAL(calculate_parity(data, data + 9), int(crc));
}
#endif

//*************************************************************************
TEST(test_crc1_add_values)
{
Expand Down

0 comments on commit b3f7d82

Please sign in to comment.