stm32f10x_crc.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /**
  2. ******************************************************************************
  3. * @file stm32f10x_crc.c
  4. * @author MCD Application Team
  5. * @version V3.3.0
  6. * @date 04/16/2010
  7. * @brief This file provides all the CRC firmware functions.
  8. ******************************************************************************
  9. * @copy
  10. *
  11. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  12. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  13. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  14. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  15. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  16. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  17. *
  18. * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
  19. */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32f10x_crc.h"
  22. /** @addtogroup STM32F10x_StdPeriph_Driver
  23. * @{
  24. */
  25. /** @defgroup CRC
  26. * @brief CRC driver modules
  27. * @{
  28. */
  29. /** @defgroup CRC_Private_TypesDefinitions
  30. * @{
  31. */
  32. /**
  33. * @}
  34. */
  35. /** @defgroup CRC_Private_Defines
  36. * @{
  37. */
  38. /* CR register bit mask */
  39. #define CR_RESET_Set ((uint32_t)0x00000001)
  40. /**
  41. * @}
  42. */
  43. /** @defgroup CRC_Private_Macros
  44. * @{
  45. */
  46. /**
  47. * @}
  48. */
  49. /** @defgroup CRC_Private_Variables
  50. * @{
  51. */
  52. /**
  53. * @}
  54. */
  55. /** @defgroup CRC_Private_FunctionPrototypes
  56. * @{
  57. */
  58. /**
  59. * @}
  60. */
  61. /** @defgroup CRC_Private_Functions
  62. * @{
  63. */
  64. /**
  65. * @brief Resets the CRC Data register (DR).
  66. * @param None
  67. * @retval None
  68. */
  69. void CRC_ResetDR(void)
  70. {
  71. /* Reset CRC generator */
  72. CRC->CR = CR_RESET_Set;
  73. }
  74. /**
  75. * @brief Computes the 32-bit CRC of a given data word(32-bit).
  76. * @param Data: data word(32-bit) to compute its CRC
  77. * @retval 32-bit CRC
  78. */
  79. uint32_t CRC_CalcCRC(uint32_t Data)
  80. {
  81. CRC->DR = Data;
  82. return (CRC->DR);
  83. }
  84. /**
  85. * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit).
  86. * @param pBuffer: pointer to the buffer containing the data to be computed
  87. * @param BufferLength: length of the buffer to be computed
  88. * @retval 32-bit CRC
  89. */
  90. uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength)
  91. {
  92. uint32_t index = 0;
  93. for(index = 0; index < BufferLength; index++)
  94. {
  95. CRC->DR = pBuffer[index];
  96. }
  97. return (CRC->DR);
  98. }
  99. /**
  100. * @brief Returns the current CRC value.
  101. * @param None
  102. * @retval 32-bit CRC
  103. */
  104. uint32_t CRC_GetCRC(void)
  105. {
  106. return (CRC->DR);
  107. }
  108. /**
  109. * @brief Stores a 8-bit data in the Independent Data(ID) register.
  110. * @param IDValue: 8-bit value to be stored in the ID register
  111. * @retval None
  112. */
  113. void CRC_SetIDRegister(uint8_t IDValue)
  114. {
  115. CRC->IDR = IDValue;
  116. }
  117. /**
  118. * @brief Returns the 8-bit data stored in the Independent Data(ID) register
  119. * @param None
  120. * @retval 8-bit value of the ID register
  121. */
  122. uint8_t CRC_GetIDRegister(void)
  123. {
  124. return (CRC->IDR);
  125. }
  126. /**
  127. * @}
  128. */
  129. /**
  130. * @}
  131. */
  132. /**
  133. * @}
  134. */
  135. /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/