libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
crc_v2.c
Go to the documentation of this file.
1/** @addtogroup crc_file CRC peripheral API
2@ingroup peripheral_apis
3
4 @author @htmlonly &copy; @endhtmlonly 2016 Cem Basoglu <cem.basoglu@web.de>
5
6 */
7
8/*
9 * This file is part of the libopencm3 project.
10 *
11 * Copyright (C) 2016 Cem Basoglu <cem.basoglu@web.de>
12 *
13 * This library is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU Lesser General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public License
24 * along with this library. If not, see <http://www.gnu.org/licenses/>.
25 */
26
27
28/**@{*/
29
31
32/*---------------------------------------------------------------------------*/
33/** @brief Enable reverse output data.
34
35 Enables the reversal of the bit order of the output data.
36
37 */
39{
41}
42
43/*---------------------------------------------------------------------------*/
44/** @brief Disable reverse output data.
45
46 Disables the reversal of the bit order of the output data.
47
48 */
50{
51 CRC_CR &= ~CRC_CR_REV_OUT;
52}
53
54/*---------------------------------------------------------------------------*/
55/** @brief Reverse input data.
56
57 Controls the reversal of the bit order of the input data
58
59 @param[in] reverse_in Unsigned int32. Reversal bit order @ref crc_rev_in.
60 */
61void crc_set_reverse_input(uint32_t reverse_in)
62{
63 uint32_t reg32 = CRC_CR;
64 reg32 = (reg32 & ~CRC_CR_REV_IN) | reverse_in;
65 CRC_CR = reg32;
66}
67
68/*---------------------------------------------------------------------------*/
69/** @brief Polynomial size
70
71 Set the size of the polynomial.
72
73 @param[in] polysize Unsigned int32. Size of polynomial @ref crc_polysize.
74 */
75void crc_set_polysize(uint32_t polysize)
76{
77 uint32_t reg32 = CRC_CR;
78 reg32 = (reg32 & ~CRC_CR_POLYSIZE) | polysize;
79 CRC_CR = reg32;
80}
81
82/*---------------------------------------------------------------------------*/
83/** @brief Polynomial coefficient
84
85 Set the coefficients of the polynomial to be used for CRC calculation.
86 If the polynomial size is less than 32-bits, the least significant bits
87 have to be used to program the correct value.
88
89 @note To obtain a reliable CRC calculation, any changes to the polynomial
90 value or size can not be performed during a CRC calculation.
91 As a result, if a CRC calculation is ongoing, the application must either
92 reset the crc unit it or perform a CRC_DR read before changing the polynomial.
93
94 @note The default polynomial value is the CRC-32 (Ethernet) polynomial: 0x4C11DB7.
95
96 @param[in] polynomial Unsigned int32. Polynomial coefficient.
97 */
98void crc_set_polynomial(uint32_t polynomial)
99{
100 CRC_POL = polynomial;
101}
102
103/*---------------------------------------------------------------------------*/
104/** @brief CRC Initial value.
105
106Sets the crc initial value.
107
108 @param[in] initial Unsigned int32. CRC initial value.
109 */
110void crc_set_initial(uint32_t initial)
111{
112 CRC_INIT = initial;
113}
114
115/**@}*/
116
#define CRC_CR_REV_OUT
Definition: crc_v2.h:63
void crc_reverse_output_enable()
Enable reverse output data.
Definition: crc_v2.c:38
void crc_set_polynomial(uint32_t polynomial)
Polynomial coefficient.
Definition: crc_v2.c:98
void crc_set_initial(uint32_t initial)
CRC Initial value.
Definition: crc_v2.c:110
void crc_set_polysize(uint32_t polysize)
Polynomial size.
Definition: crc_v2.c:75
void crc_set_reverse_input(uint32_t reverse_in)
Reverse input data.
Definition: crc_v2.c:61
void crc_reverse_output_disable()
Disable reverse output data.
Definition: crc_v2.c:49
#define CRC_INIT
CRC_INIT Initial CRC Value.
Definition: crc_v2.h:52
#define CRC_POL
CRC_POL CRC Polynomial.
Definition: crc_v2.h:55
#define CRC_CR
CRC_CR Control register.