before merging master
[inav.git] / lib / main / AT32F43x / Drivers / AT32F43x_StdPeriph_Driver / src / at32f435_437_crc.c
blob326ed49ebea1c7440c78547f9b3680256ca213bc
1 /**
2 **************************************************************************
3 * @file at32f435_437_crc.c
4 * @version v2.1.0
5 * @date 2022-08-16
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
30 * @{
33 /** @defgroup CRC
34 * @brief CRC driver modules
35 * @{
38 #ifdef CRC_MODULE_ENABLED
40 /** @defgroup CRC_private_functions
41 * @{
44 /**
45 * @brief reset the crc data register.
46 * @param none
47 * @retval none
49 void crc_data_reset(void)
51 /* reset crc generator */
52 CRC->ctrl_bit.rst = 0x1;
55 /**
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
58 * @retval 32-bit crc
60 uint32_t crc_one_word_calculate(uint32_t data)
62 CRC->dt = data;
63 return (CRC->dt);
66 /**
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
70 * @retval 32-bit crc
72 uint32_t crc_block_calculate(uint32_t *pbuffer, uint32_t length)
74 uint32_t index = 0;
76 for(index = 0; index < length; index++)
78 CRC->dt = pbuffer[index];
81 return (CRC->dt);
84 /**
85 * @brief return the current crc value.
86 * @param none
87 * @retval 32-bit crc
89 uint32_t crc_data_get(void)
91 return (CRC->dt);
94 /**
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
97 * @retval none
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
106 * @param none
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
117 * @retval none
119 void crc_init_data_set(uint32_t value)
121 CRC->idt = value;
125 * @brief control the reversal of the bit order in the input data
126 * @param value
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
132 * @retval none.
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
141 * @param value
142 * this parameter can be one of the following values:
143 * - CRC_REVERSE_OUTPUT_NO_AFFECTE
144 * - CRC_REVERSE_OUTPUT_DATA
145 * @retval none.
147 void crc_reverse_output_data_set(crc_reverse_output_type value)
149 CRC->ctrl_bit.revod = value;
153 * @}
156 #endif
159 * @}
163 * @}