stm32f4xx_crc.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_crc.c
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 30-September-2011
  7. * @brief This file provides all the CRC firmware functions.
  8. ******************************************************************************
  9. * @attention
  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 2011 STMicroelectronics</center></h2>
  19. ******************************************************************************
  20. */
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "stm32f4xx_crc.h"
  23. /** @addtogroup STM32F4xx_StdPeriph_Driver
  24. * @{
  25. */
  26. /** @defgroup CRC
  27. * @brief CRC driver modules
  28. * @{
  29. */
  30. /* Private typedef -----------------------------------------------------------*/
  31. /* Private define ------------------------------------------------------------*/
  32. /* Private macro -------------------------------------------------------------*/
  33. /* Private variables ---------------------------------------------------------*/
  34. /* Private function prototypes -----------------------------------------------*/
  35. /* Private functions ---------------------------------------------------------*/
  36. /** @defgroup CRC_Private_Functions
  37. * @{
  38. */
  39. /**
  40. * @brief Resets the CRC Data register (DR).
  41. * @param None
  42. * @retval None
  43. */
  44. void CRC_ResetDR(void)
  45. {
  46. /* Reset CRC generator */
  47. CRC->CR = CRC_CR_RESET;
  48. }
  49. /**
  50. * @brief Computes the 32-bit CRC of a given data word(32-bit).
  51. * @param Data: data word(32-bit) to compute its CRC
  52. * @retval 32-bit CRC
  53. */
  54. uint32_t CRC_CalcCRC(uint32_t Data)
  55. {
  56. CRC->DR = Data;
  57. return (CRC->DR);
  58. }
  59. /**
  60. * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit).
  61. * @param pBuffer: pointer to the buffer containing the data to be computed
  62. * @param BufferLength: length of the buffer to be computed
  63. * @retval 32-bit CRC
  64. */
  65. uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength)
  66. {
  67. uint32_t index = 0;
  68. for(index = 0; index < BufferLength; index++)
  69. {
  70. CRC->DR = pBuffer[index];
  71. }
  72. return (CRC->DR);
  73. }
  74. /**
  75. * @brief Returns the current CRC value.
  76. * @param None
  77. * @retval 32-bit CRC
  78. */
  79. uint32_t CRC_GetCRC(void)
  80. {
  81. return (CRC->DR);
  82. }
  83. /**
  84. * @brief Stores a 8-bit data in the Independent Data(ID) register.
  85. * @param IDValue: 8-bit value to be stored in the ID register
  86. * @retval None
  87. */
  88. void CRC_SetIDRegister(uint8_t IDValue)
  89. {
  90. CRC->IDR = IDValue;
  91. }
  92. /**
  93. * @brief Returns the 8-bit data stored in the Independent Data(ID) register
  94. * @param None
  95. * @retval 8-bit value of the ID register
  96. */
  97. uint8_t CRC_GetIDRegister(void)
  98. {
  99. return (CRC->IDR);
  100. }
  101. /**
  102. * @}
  103. */
  104. /**
  105. * @}
  106. */
  107. /**
  108. * @}
  109. */
  110. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/