2 **************************************************************************
3 * @file at32f435_437_crc.c
6 * @brief contains all the functions for the crc firmware library
7 **************************************************************************
8 * Copyright notice & Disclaimer
10 * The software Board Support Package (BSP) that is made available to
11 * download from Artery official website is the copyrighted work of Artery.
12 * Artery authorizes customers to use, copy, and distribute the BSP
13 * software and its related documentation for the purpose of design and
14 * development in conjunction with Artery microcontrollers. Use of the
15 * software is governed by this copyright notice and the following disclaimer.
17 * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
18 * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
19 * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
20 * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
21 * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
24 **************************************************************************
27 #include "at32f435_437_conf.h"
29 /** @addtogroup AT32F435_437_periph_driver
34 * @brief CRC driver modules
38 #ifdef CRC_MODULE_ENABLED
40 /** @defgroup CRC_private_functions
45 * @brief reset the crc data register.
49 void crc_data_reset(void)
51 /* reset crc generator */
52 CRC
->ctrl_bit
.rst
= 0x1;
56 * @brief compute the 32-bit crc of a given data word(32-bit).
57 * @param data: data word(32-bit) to compute its crc
60 uint32_t crc_one_word_calculate(uint32_t data
)
67 * @brief compute the 32-bit crc of a given buffer of data word(32-bit).
68 * @param pbuffer: pointer to the buffer containing the data to be computed
69 * @param length: length of the buffer to be computed
72 uint32_t crc_block_calculate(uint32_t *pbuffer
, uint32_t length
)
76 for(index
= 0; index
< length
; index
++)
78 CRC
->dt
= pbuffer
[index
];
85 * @brief return the current crc value.
89 uint32_t crc_data_get(void)
95 * @brief store a 8-bit data in the common data register.
96 * @param cdt_value: 8-bit value to be stored in the common data register
99 void crc_common_data_set(uint8_t cdt_value
)
101 CRC
->cdt_bit
.cdt
= cdt_value
;
105 * @brief return the 8-bit data stored in the common data register
107 * @retval 8-bit value of the common data register
109 uint8_t crc_common_data_get(void)
111 return (CRC
->cdt_bit
.cdt
);
115 * @brief set the 32-bit initial data of crc
116 * @param value: initial data
119 void crc_init_data_set(uint32_t value
)
125 * @brief control the reversal of the bit order in the input data
127 * this parameter can be one of the following values:
128 * - CRC_REVERSE_INPUT_NO_AFFECTE
129 * - CRC_REVERSE_INPUT_BY_BYTE
130 * - CRC_REVERSE_INPUT_BY_HALFWORD
131 * - CRC_REVERSE_INPUT_BY_WORD
134 void crc_reverse_input_data_set(crc_reverse_input_type value
)
136 CRC
->ctrl_bit
.revid
= value
;
140 * @brief control the reversal of the bit order in the output data
142 * this parameter can be one of the following values:
143 * - CRC_REVERSE_OUTPUT_NO_AFFECTE
144 * - CRC_REVERSE_OUTPUT_DATA
147 void crc_reverse_output_data_set(crc_reverse_output_type value
)
149 CRC
->ctrl_bit
.revod
= value
;