FastCRC.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* FastCRC library code is placed under the MIT license
  2. * Copyright (c) 2014,2015 Frank Bosing
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files (the
  6. * "Software"), to deal in the Software without restriction, including
  7. * without limitation the rights to use, copy, modify, merge, publish,
  8. * distribute, sublicense, and/or sell copies of the Software, and to
  9. * permit persons to whom the Software is furnished to do so, subject to
  10. * the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  19. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  20. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. */
  24. // Teensy 3.0, Teensy 3.1:
  25. // See K20P64M72SF1RM.pdf (Kinetis), Pages 638 - 641 for documentation of CRC
  26. // Device See KINETIS_4N30D.pdf for Errata (Errata ID 2776)
  27. //
  28. // So, ALL HW-calculations are done as 32 bit.
  29. //
  30. //
  31. //
  32. // Thanks to:
  33. // - Catalogue of parametrised CRC algorithms, CRC RevEng
  34. // http://reveng.sourceforge.net/crc-catalogue/
  35. //
  36. // - Danjel McGougan (CRC-Table-Generator)
  37. //
  38. //
  39. // modify from FastCRC library @ 2018/11/20
  40. //
  41. #ifndef FASTCRC_FASTCRC_H_
  42. #define FASTCRC_FASTCRC_H_
  43. #include <stdint.h>
  44. // ================= 16-BIT CRC ===================
  45. class FastCRC16 {
  46. public:
  47. FastCRC16(uint16_t seed);
  48. // change function name from mcrf4xx_upd to mcrf4xx
  49. uint16_t mcrf4xx_calc(
  50. const uint8_t *data,
  51. const uint16_t datalen); // Equivalent to _crc_ccitt_update() in
  52. // crc16.h from avr_libc
  53. private:
  54. uint16_t seed_;
  55. };
  56. // ================= 32-BIT CRC ===================
  57. class FastCRC32 {
  58. public:
  59. FastCRC32(uint32_t seed);
  60. // change function name from crc32_upd to crc32
  61. uint32_t crc32_calc(
  62. const uint8_t *data,
  63. uint16_t len); // Call for subsequent calculations with previous seed
  64. private:
  65. uint32_t seed_;
  66. };
  67. #endif // FASTCRC_FASTCRC_H_