summaryrefslogtreecommitdiff
path: root/bsp/at32/libraries/AT32F413_Firmware_Library/drivers/src/at32f413_crc.c
blob: 6eed245d7ff7cea0e0a37fa0f2933dd6080f3ae5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/**
  **************************************************************************
  * @file     at32f413_crc.c
  * @version  v2.0.5
  * @date     2022-05-20
  * @brief    contains all the functions for the crc firmware library
  **************************************************************************
  *                       Copyright notice & Disclaimer
  *
  * The software Board Support Package (BSP) that is made available to
  * download from Artery official website is the copyrighted work of Artery.
  * Artery authorizes customers to use, copy, and distribute the BSP
  * software and its related documentation for the purpose of design and
  * development in conjunction with Artery microcontrollers. Use of the
  * software is governed by this copyright notice and the following disclaimer.
  *
  * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  *
  **************************************************************************
  */

#include "at32f413_conf.h"

/** @addtogroup AT32F413_periph_driver
  * @{
  */

/** @defgroup CRC
  * @brief CRC driver modules
  * @{
  */

#ifdef CRC_MODULE_ENABLED

/** @defgroup CRC_private_functions
  * @{
  */

/**
  * @brief  reset the crc data register.
  * @param  none
  * @retval none
  */
void crc_data_reset(void)
{
  /* reset crc generator */
  CRC->ctrl_bit.rst = 0x1;
}

/**
  * @brief  compute the 32-bit crc of a given data word(32-bit).
  * @param  data: data word(32-bit) to compute its crc
  * @retval 32-bit crc
  */
uint32_t crc_one_word_calculate(uint32_t data)
{
  CRC->dt = data;
  return (CRC->dt);
}

/**
  * @brief  compute the 32-bit crc of a given buffer of data word(32-bit).
  * @param  pbuffer: pointer to the buffer containing the data to be computed
  * @param  length: length of the buffer to be computed
  * @retval 32-bit crc
  */
uint32_t crc_block_calculate(uint32_t *pbuffer, uint32_t length)
{
  uint32_t index = 0;

  for(index = 0; index < length; index++)
  {
    CRC->dt = pbuffer[index];
  }

  return (CRC->dt);
}

/**
  * @brief  return the current crc value.
  * @param  none
  * @retval 32-bit crc
  */
uint32_t crc_data_get(void)
{
  return (CRC->dt);
}

/**
  * @brief  store a 8-bit data in the common data register.
  * @param  cdt_value: 8-bit value to be stored in the common data register
  * @retval none
  */
void crc_common_data_set(uint8_t cdt_value)
{
  CRC->cdt_bit.cdt = cdt_value;
}

/**
  * @brief  return the 8-bit data stored in the common data register
  * @param  none
  * @retval 8-bit value of the common data register
  */
uint8_t crc_common_date_get(void)
{
  return (CRC->cdt_bit.cdt);
}

/**
  * @brief  set the 32-bit initial data of crc
  * @param  value: initial data
  * @retval none
  */
void crc_init_data_set(uint32_t value)
{
  CRC->idt = value;
}

/**
  * @brief  control the reversal of the bit order in the input data
  * @param  value
  *         this parameter can be one of the following values:
  *         - CRC_REVERSE_INPUT_NO_AFFECTE
  *         - CRC_REVERSE_INPUT_BY_BYTE
  *         - CRC_REVERSE_INPUT_BY_HALFWORD
  *         - CRC_REVERSE_INPUT_BY_WORD
  * @retval none.
  */
void crc_reverse_input_data_set(crc_reverse_input_type value)
{
  CRC->ctrl_bit.revid = value;
}

/**
  * @brief  control the reversal of the bit order in the output data
  * @param  value
  *         this parameter can be one of the following values:
  *         - CRC_REVERSE_OUTPUT_NO_AFFECTE
  *         - CRC_REVERSE_OUTPUT_DATA
  * @retval none.
  */
void crc_reverse_output_data_set(crc_reverse_output_type value)
{
  CRC->ctrl_bit.revod = value;
}

/**
  * @}
  */

#endif

/**
  * @}
  */

/**
  * @}
  */