stm32f4xx_crc.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_crc.c
  4. * @author MCD Application Team
  5. * @version V1.5.0
  6. * @date 06-March-2015
  7. * @brief This file provides all the CRC firmware functions.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
  12. *
  13. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  14. * You may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at:
  16. *
  17. * http://www.st.com/software_license_agreement_liberty_v2
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. *
  25. ******************************************************************************
  26. */
  27. /* Includes ------------------------------------------------------------------*/
  28. #include "stm32f4xx_crc.h"
  29. /** @addtogroup STM32F4xx_StdPeriph_Driver
  30. * @{
  31. */
  32. /** @defgroup CRC
  33. * @brief CRC driver modules
  34. * @{
  35. */
  36. /* Private typedef -----------------------------------------------------------*/
  37. /* Private define ------------------------------------------------------------*/
  38. /* Private macro -------------------------------------------------------------*/
  39. /* Private variables ---------------------------------------------------------*/
  40. /* Private function prototypes -----------------------------------------------*/
  41. /* Private functions ---------------------------------------------------------*/
  42. /** @defgroup CRC_Private_Functions
  43. * @{
  44. */
  45. /**
  46. * @brief Resets the CRC Data register (DR).
  47. * @param None
  48. * @retval None
  49. */
  50. void CRC_ResetDR(void)
  51. {
  52. /* Reset CRC generator */
  53. CRC->CR = CRC_CR_RESET;
  54. }
  55. /**
  56. * @brief Computes the 32-bit CRC of a given data word(32-bit).
  57. * @param Data: data word(32-bit) to compute its CRC
  58. * @retval 32-bit CRC
  59. */
  60. uint32_t CRC_CalcCRC(uint32_t Data)
  61. {
  62. CRC->DR = Data;
  63. return (CRC->DR);
  64. }
  65. /**
  66. * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit).
  67. * @param pBuffer: pointer to the buffer containing the data to be computed
  68. * @param BufferLength: length of the buffer to be computed
  69. * @retval 32-bit CRC
  70. */
  71. uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength)
  72. {
  73. uint32_t index = 0;
  74. for(index = 0; index < BufferLength; index++)
  75. {
  76. CRC->DR = pBuffer[index];
  77. }
  78. return (CRC->DR);
  79. }
  80. /**
  81. * @brief Returns the current CRC value.
  82. * @param None
  83. * @retval 32-bit CRC
  84. */
  85. uint32_t CRC_GetCRC(void)
  86. {
  87. return (CRC->DR);
  88. }
  89. /**
  90. * @brief Stores a 8-bit data in the Independent Data(ID) register.
  91. * @param IDValue: 8-bit value to be stored in the ID register
  92. * @retval None
  93. */
  94. void CRC_SetIDRegister(uint8_t IDValue)
  95. {
  96. CRC->IDR = IDValue;
  97. }
  98. /**
  99. * @brief Returns the 8-bit data stored in the Independent Data(ID) register
  100. * @param None
  101. * @retval 8-bit value of the ID register
  102. */
  103. uint8_t CRC_GetIDRegister(void)
  104. {
  105. return (CRC->IDR);
  106. }
  107. /**
  108. * @}
  109. */
  110. /**
  111. * @}
  112. */
  113. /**
  114. * @}
  115. */
  116. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/