libyggdrasil  v1.0.0
hash.hpp
Go to the documentation of this file.
1  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * _____.___. .___ .__.__ *
3  * \__ | | ____ ____ __| _/___________ _____|__| | *
4  * / | |/ ___\ / ___\ / __ |\_ __ \__ \ / ___/ | | *
5  * \____ / /_/ > /_/ > /_/ | | | \// __ \_\___ \| | |__ *
6  * / ______\___ /\___ /\____ | |__| (____ /____ >__|____/ *
7  * \/ /_____//_____/ \/ \/ \/ *
8  * - Common - *
9  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
10  * This software can be used by students and other personal of the *
11  * Bern University of Applied Sciences under the terms of the MIT *
12  * license. *
13  * For other persons this software is under the terms of the GNU *
14  * General Public License version 2. *
15  * *
16  * Copyright © 2021, Bern University of Applied Sciences. *
17  * All rights reserved. *
18  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
26 #pragma once
27 
28 #include <cpp/common/registers.hpp>
30 
31 #include <array>
32 
33 namespace bsp::drv {
34 
41  template<auto Context, template<addr_t> typename HashImpl>
42  struct Hash {
43  Hash() = delete;
44  Hash(const Hash&) = delete;
45  auto operator=(const Hash&) = delete;
46 
47  using Impl = HashImpl<Context>;
48 
55  static auto init(auto ... args) {
56  return Impl::init(args...);
57  }
58 
65  static auto deinit(auto ... args) {
66  return Impl::deinit(args...);
67  }
68 
79  [[nodiscard]] static u8 getCRC8(const auto &data, u8 initValue = 0x00, u8 polynomial = 0x07, u8 xorOut = 0x00) noexcept {
80  return Impl::getCRC8(data, initValue, polynomial) ^ xorOut;
81  }
82 
93  [[nodiscard]] static u16 getCRC16(const auto &data, u16 initValue = 0x0000, u16 polynomial = 0x8005, u16 xorOut = 0x0000) noexcept {
94  return Impl::getCRC16(data, initValue, polynomial) ^ xorOut;
95  }
96 
107  [[nodiscard]] static u32 getCRC32(const auto &data, u32 initValue = 0xFFFF'FFFF, u32 polynomial = 0x04C11DB7, u32 xorOut = 0xFFFFFFFF) noexcept {
108  return Impl::getCRC32(data, initValue, polynomial) ^ xorOut;
109  }
110 
111  };
112 
113 }
bsp::drv::Hash::Hash
Hash(const Hash &)=delete
u16
uint16_t u16
Definition: types.h:37
u8
uint8_t u8
Unsigned integer definitions.
Definition: types.h:36
bsp::drv::Hash::init
static auto init(auto ... args)
Hash initialization.
Definition: hash.hpp:55
bsp::drv::Hash::Hash
Hash()=delete
bsp::drv::Hash::Impl
HashImpl< Context > Impl
Definition: hash.hpp:47
u32
uint32_t u32
Definition: types.h:38
bsp::drv::Hash
Base class for the Hash abstraction.
Definition: hash.hpp:42
bsp::drv::Hash::getCRC16
static u16 getCRC16(const auto &data, u16 initValue=0x0000, u16 polynomial=0x8005, u16 xorOut=0x0000) noexcept
Hardware accelerated CRC16 caluclation.
Definition: hash.hpp:93
bsp::drv::Hash::getCRC32
static u32 getCRC32(const auto &data, u32 initValue=0xFFFF 'FFFF, u32 polynomial=0x04C11DB7, u32 xorOut=0xFFFFFFFF) noexcept
Hardware accelerated CRC32 caluclation.
Definition: hash.hpp:107
bsp::drv::Hash::getCRC8
static u8 getCRC8(const auto &data, u8 initValue=0x00, u8 polynomial=0x07, u8 xorOut=0x00) noexcept
Hardware accelerated CRC8 caluclation.
Definition: hash.hpp:79
registers.hpp
Zero-cost abstraction for accessing registers and bits/bitfields within them.
bsp::drv::Hash::operator=
auto operator=(const Hash &)=delete
bsp::drv::Hash::deinit
static auto deinit(auto ... args)
Hash deinitialization.
Definition: hash.hpp:65
attributes.hpp
Commonly used C++ and GNU attributes.
bsp::drv
Definition: display.hpp:37