crc32.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /**
  2. *
  3. * \file
  4. *
  5. * \brief SAM DSU CRC32 driver.
  6. *
  7. * Copyright (c) 2016 Atmel Corporation. All rights reserved.
  8. *
  9. * \asf_license_start
  10. *
  11. * \page License
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. *
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. *
  23. * 3. The name of Atmel may not be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * 4. This software may only be redistributed and used in connection with an
  27. * Atmel microcontroller product.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  30. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  31. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  32. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  33. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  34. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  35. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  36. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  37. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  38. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  39. * POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. * \asf_license_stop
  42. *
  43. */
  44. /*
  45. * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
  46. */
  47. #ifndef DSU_CRC32_H_INCLUDED
  48. #define DSU_CRC32_H_INCLUDED
  49. #ifdef __cplusplus
  50. extern "C" {
  51. #endif
  52. /**
  53. * \defgroup asfdoc_sam0_drivers_crc32_group SAM 32-bit cyclic redundancy check (CRC32) Driver
  54. *
  55. * This driver for Atmel&reg; | SMART ARM&reg;-based microcontrollers provides an interface for the configuration
  56. * and management of the device's CRC32 (via DSU) functionality. The following
  57. * driver API modes are covered by this manual:
  58. *
  59. * - Polled APIs
  60. *
  61. * The following peripheral is used by this module:
  62. * - DSU (Device Service Unit)
  63. *
  64. * The following devices can use this module:
  65. * - Atmel | SMART SAM D21
  66. *
  67. * The outline of this documentation is as follows:
  68. * - \ref asfdoc_sam0_drivers_crc32_prerequisites
  69. * - \ref asfdoc_sam0_drivers_crc32_module_overview
  70. * - \ref asfdoc_sam0_drivers_crc32_special_considerations
  71. * - \ref asfdoc_sam0_drivers_crc32_api_overview
  72. *
  73. *
  74. * \section asfdoc_sam0_drivers_crc32_prerequisites Prerequisites
  75. *
  76. * There are no prerequisites for this module.
  77. *
  78. *
  79. * \section asfdoc_sam0_drivers_crc32_module_overview Module Overview
  80. *
  81. * A cyclic redundancy check (CRC) is an error detection technique used to find accidental
  82. * errors in data. It is commonly used to determine whether the data during a transmission,
  83. * or data present in data and programme memories has been corrupted or not. A CRC takes a data
  84. * stream or a block of data as input and generates a 16- or 32-bit output that can be appended
  85. * to the data and used as a checksum. When the same data are later received or read, the device
  86. * or application repeats the calculation.
  87. * If the new CRC result does not match the one calculated earlier, the block contains a data error.
  88. * The application will then detect this and may take a corrective action, such as requesting the data
  89. * to be sent again or simply not using the incorrect data.
  90. *
  91. * The DSU unit provides support for calculating a 32-bit cyclic redundancy check (CRC32)
  92. * value for a memory area (including flash and AHB RAM).
  93. *
  94. * \section asfdoc_sam0_drivers_crc32_special_considerations Special Considerations
  95. *
  96. * There are no special considerations for this module.
  97. *
  98. * \section asfdoc_sam0_drivers_crc32_api_overview API Overview
  99. * @{
  100. */
  101. #include <compiler.h>
  102. #include <system.h>
  103. #ifdef __cplusplus
  104. extern "C" {
  105. #endif
  106. /**
  107. * \brief CRC initialization function
  108. *
  109. * Enables CRC peripheral, clocks and initializes CRC driver.
  110. */
  111. static inline void dsu_crc32_init(void)
  112. {
  113. #if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30)
  114. /* Turn on the digital interface clock */
  115. system_apb_clock_set_mask(SYSTEM_CLOCK_APB_APBB, MCLK_APBBMASK_DSU);
  116. #else
  117. /* Turn on the digital interface clock */
  118. system_apb_clock_set_mask(SYSTEM_CLOCK_APB_APBB, PM_APBBMASK_DSU);
  119. #endif
  120. }
  121. enum status_code dsu_crc32_cal(const uint32_t addr, const uint32_t len, uint32_t *pcrc32);
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125. /** @} */
  126. /**
  127. * \page asfdoc_sam0_drivers_crc32_extra Extra Information for CRC32
  128. *
  129. * \section asfdoc_sam0_drivers_crc32_extra_acronyms Acronyms
  130. * Below is a table listing the acronyms used in this module, along with their
  131. * intended meanings.
  132. *
  133. * <table>
  134. * <tr>
  135. * <th>Acronym</th>
  136. * <th>Definition</th>
  137. * </tr>
  138. * <tr>
  139. * <td>DSU</td>
  140. * <td>Device Service Unit</td>
  141. * </tr>
  142. * <tr>
  143. * <td>CRC32</td>
  144. * <td>32-bit cyclic redundancy check</td>
  145. * </tr>
  146. * </table>
  147. *
  148. *
  149. * \section asfdoc_sam0_drivers_crc32_extra_dependencies Dependencies
  150. * This driver has the following dependencies:
  151. *
  152. * - DSU
  153. *
  154. *
  155. * \section asfdoc_sam0_drivers_crc32_extra_errata Errata
  156. * There are no errata related to this driver.
  157. *
  158. *
  159. * \section asfdoc_sam0_drivers_crc32_extra_history Module History
  160. * An overview of the module history is presented in the table below, with
  161. * details on the enhancements and fixes made to the module since its first
  162. * release. The current version of this corresponds to the newest version in
  163. * the table.
  164. *
  165. * <table>
  166. * <tr>
  167. * <th>Changelog</th>
  168. * </tr>
  169. * <tr>
  170. * <td>Initial release</td>
  171. * </tr>
  172. * </table>
  173. */
  174. /**
  175. * \page asfdoc_sam0_drivers_crc32_exqsg Examples for CRC32
  176. *
  177. * This is a list of the available Quick Start Guides (QSGs) and example
  178. * applications for \ref asfdoc_sam0_drivers_crc32_group. QSGs are simple examples with
  179. * step-by-step instructions to configure and use this driver in a selection of
  180. * use cases. Note that a QSG can be compiled as a standalone application or be
  181. * added to the user application.
  182. *
  183. * - \subpage asfdoc_sam0_crc32_basic_use_case
  184. *
  185. * \page asfdoc_sam0_drivers_crc32_document_revision_history Document Revision History
  186. *
  187. * <table>
  188. * <tr>
  189. * <th>Doc. Rev.</td>
  190. * <th>Date</td>
  191. * <th>Comments</td>
  192. * </tr>
  193. * <tr>
  194. * <td>06/2016</td>
  195. * <td>Initial release</td>
  196. * </tr>
  197. * </table>
  198. *
  199. */
  200. #ifdef __cplusplus
  201. }
  202. #endif
  203. #endif /* DSU_CRC32_H_INCLUDED */