MbedCRC.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* mbed Microcontroller Library
  2. * Copyright (c) 2018 ARM Limited
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <stddef.h>
  17. #include "drivers/TableCRC.h"
  18. #include "drivers/MbedCRC.h"
  19. namespace mbed {
  20. /** \addtogroup drivers */
  21. /** @{*/
  22. /* Default values for different types of polynomials
  23. */
  24. template<>
  25. MbedCRC<POLY_32BIT_ANSI, 32>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
  26. _initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
  27. _crc_table((uint32_t *)Table_CRC_32bit_ANSI)
  28. {
  29. mbed_crc_ctor();
  30. }
  31. template<>
  32. MbedCRC<POLY_8BIT_CCITT, 8>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
  33. _initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
  34. _crc_table((uint32_t *)Table_CRC_8bit_CCITT)
  35. {
  36. mbed_crc_ctor();
  37. }
  38. template<>
  39. MbedCRC<POLY_7BIT_SD, 7>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
  40. _initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
  41. _crc_table((uint32_t *)Table_CRC_7Bit_SD)
  42. {
  43. mbed_crc_ctor();
  44. }
  45. template<>
  46. MbedCRC<POLY_16BIT_CCITT, 16>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
  47. _initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
  48. _crc_table((uint32_t *)Table_CRC_16bit_CCITT)
  49. {
  50. mbed_crc_ctor();
  51. }
  52. template<>
  53. MbedCRC<POLY_16BIT_IBM, 16>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
  54. _initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
  55. _crc_table((uint32_t *)Table_CRC_16bit_IBM)
  56. {
  57. mbed_crc_ctor();
  58. }
  59. template<>
  60. MbedCRC<POLY_32BIT_ANSI, 32>::MbedCRC():
  61. _initial_value(~(0x0)), _final_xor(~(0x0)), _reflect_data(true), _reflect_remainder(true),
  62. _crc_table((uint32_t *)Table_CRC_32bit_ANSI)
  63. {
  64. mbed_crc_ctor();
  65. }
  66. template<>
  67. MbedCRC<POLY_16BIT_IBM, 16>::MbedCRC():
  68. _initial_value(0), _final_xor(0), _reflect_data(true), _reflect_remainder(true),
  69. _crc_table((uint32_t *)Table_CRC_16bit_IBM)
  70. {
  71. mbed_crc_ctor();
  72. }
  73. template<>
  74. MbedCRC<POLY_16BIT_CCITT, 16>::MbedCRC():
  75. _initial_value(~(0x0)), _final_xor(0), _reflect_data(false), _reflect_remainder(false),
  76. _crc_table((uint32_t *)Table_CRC_16bit_CCITT)
  77. {
  78. mbed_crc_ctor();
  79. }
  80. template<>
  81. MbedCRC<POLY_7BIT_SD, 7>::MbedCRC():
  82. _initial_value(0), _final_xor(0), _reflect_data(false), _reflect_remainder(false),
  83. _crc_table((uint32_t *)Table_CRC_7Bit_SD)
  84. {
  85. mbed_crc_ctor();
  86. }
  87. template<>
  88. MbedCRC<POLY_8BIT_CCITT, 8>::MbedCRC():
  89. _initial_value(0), _final_xor(0), _reflect_data(false), _reflect_remainder(false),
  90. _crc_table((uint32_t *)Table_CRC_8bit_CCITT)
  91. {
  92. mbed_crc_ctor();
  93. }
  94. /** @}*/
  95. } // namespace mbed