Added constexpr to CRC1

This commit is contained in:
John Wellbelove 2025-01-24 17:48:43 +00:00
parent 14b50c6541
commit b3f7d82900
3 changed files with 18 additions and 6 deletions

View File

@ -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;
}
@ -83,7 +83,7 @@ namespace etl
//*************************************************************************
/// Default constructor.
//*************************************************************************
crc1()
ETL_CONSTEXPR14 crc1()
{
this->reset();
}
@ -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);

View File

@ -107,7 +107,8 @@ namespace etl
//*************************************************************************
/// Default constructor.
//*************************************************************************
ETL_CONSTEXPR14 frame_check_sequence() : frame_check()
ETL_CONSTEXPR14 frame_check_sequence()
: frame_check()
{
reset();
}

View File

@ -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)
{