Subversion Repositories DashDisplay

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/**
2
  ******************************************************************************
3
  * @file    stm32f1xx_hal_crc.c
4
  * @author  MCD Application Team
5 mjames 5
  * @version V1.0.4
6
  * @date    29-April-2016
2 mjames 7
  * @brief   CRC HAL module driver.
8
  *          This file provides firmware functions to manage the following
9
  *          functionalities of the Cyclic Redundancy Check (CRC) peripheral:
10
  *           + Initialization and de-initialization functions
11
  *           + Peripheral Control functions
12
  *           + Peripheral State functions
13
  *
14
  @verbatim
15
  ==============================================================================
16
                     ##### How to use this driver #####
17
  ==============================================================================
18
    [..]
19
      The CRC HAL driver can be used as follows:
20
 
21
      (#) Enable CRC AHB clock using __HAL_RCC_CRC_CLK_ENABLE();
22
 
23
      (#) Use HAL_CRC_Accumulate() function to compute the CRC value of
24
          a 32-bit data buffer using combination of the previous CRC value
25
          and the new one.
26
 
27
      (#) Use HAL_CRC_Calculate() function to compute the CRC Value of
28
          a new 32-bit data buffer. This function resets the CRC computation  
29
          unit before starting the computation to avoid getting wrong CRC values.
30
 
31
  @endverbatim
32
  ******************************************************************************
33
  * @attention
34
  *
5 mjames 35
  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
2 mjames 36
  *
37
  * Redistribution and use in source and binary forms, with or without modification,
38
  * are permitted provided that the following conditions are met:
39
  *   1. Redistributions of source code must retain the above copyright notice,
40
  *      this list of conditions and the following disclaimer.
41
  *   2. Redistributions in binary form must reproduce the above copyright notice,
42
  *      this list of conditions and the following disclaimer in the documentation
43
  *      and/or other materials provided with the distribution.
44
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
45
  *      may be used to endorse or promote products derived from this software
46
  *      without specific prior written permission.
47
  *
48
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
49
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
51
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
52
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
54
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
55
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
56
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
57
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58
  *
59
  ******************************************************************************
60
  */
61
 
62
/* Includes ------------------------------------------------------------------*/
63
#include "stm32f1xx_hal.h"
64
 
65
/** @addtogroup STM32F1xx_HAL_Driver
66
  * @{
67
  */
68
 
69
/** @defgroup CRC CRC
70
  * @brief CRC HAL module driver.
71
  * @{
72
  */
73
 
74
#ifdef HAL_CRC_MODULE_ENABLED
75
 
76
/* Private typedef -----------------------------------------------------------*/
77
/* Private define ------------------------------------------------------------*/
78
/* Private macro -------------------------------------------------------------*/
79
/* Private variables ---------------------------------------------------------*/
80
/* Private function prototypes -----------------------------------------------*/
81
/* Private functions ---------------------------------------------------------*/
82
 
83
/** @defgroup CRC_Exported_Functions CRC Exported Functions
84
  * @{
85
  */
86
 
87
/** @defgroup CRC_Exported_Functions_Group1 Initialization and de-initialization functions
88
 *  @brief    Initialization and Configuration functions.
89
 *
90
@verbatim    
91
  ==============================================================================
92
            ##### Initialization and de-initialization functions #####
93
  ==============================================================================
94
    [..]  This section provides functions allowing to:
95
      (+) Initialize the CRC according to the specified parameters
96
          in the CRC_InitTypeDef and create the associated handle
97
      (+) DeInitialize the CRC peripheral
98
      (+) Initialize the CRC MSP
99
      (+) DeInitialize CRC MSP
100
 
101
@endverbatim
102
  * @{
103
  */
104
 
105
/**
106
  * @brief  Initializes the CRC according to the specified
107
  *         parameters in the CRC_InitTypeDef and creates the associated handle.
108
  * @param  hcrc: pointer to a CRC_HandleTypeDef structure that contains
109
  *         the configuration information for CRC
110
  * @retval HAL status
111
  */
112
HAL_StatusTypeDef HAL_CRC_Init(CRC_HandleTypeDef *hcrc)
113
{
114
  /* Check the CRC handle allocation */
115
  if(hcrc == NULL)
116
  {
117
    return HAL_ERROR;
118
  }
119
 
120
  /* Check the parameters */
121
  assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
122
 
123
  if(hcrc->State == HAL_CRC_STATE_RESET)
124
  {
125
    /* Allocate lock resource and initialize it */
126
    hcrc->Lock = HAL_UNLOCKED;
127
 
128
    /* Init the low level hardware */
129
    HAL_CRC_MspInit(hcrc);
130
  }
131
 
132
  /* Change CRC peripheral state */
133
  hcrc->State = HAL_CRC_STATE_READY;
134
 
135
  /* Return function status */
136
  return HAL_OK;
137
}
138
 
139
/**
140
  * @brief  DeInitializes the CRC peripheral.
141
  * @param  hcrc: pointer to a CRC_HandleTypeDef structure that contains
142
  *         the configuration information for CRC
143
  * @retval HAL status
144
  */
145
HAL_StatusTypeDef HAL_CRC_DeInit(CRC_HandleTypeDef *hcrc)
146
{
147
  /* Check the CRC handle allocation */
148
  if(hcrc == NULL)
149
  {
150
    return HAL_ERROR;
151
  }
152
 
153
  /* Check the parameters */
154
  assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
155
 
156
  /* Change CRC peripheral state */
157
  hcrc->State = HAL_CRC_STATE_BUSY;
158
 
159
  /* DeInit the low level hardware */
160
  HAL_CRC_MspDeInit(hcrc);
161
 
162
  /* Resets the CRC calculation unit and sets the data register to 0xFFFF FFFF */
163
  __HAL_CRC_DR_RESET(hcrc);
164
 
165
  /* Change CRC peripheral state */
166
  hcrc->State = HAL_CRC_STATE_RESET;
167
 
168
  /* Release Lock */
169
  __HAL_UNLOCK(hcrc);
170
 
171
  /* Return function status */
172
  return HAL_OK;
173
}
174
 
175
/**
176
  * @brief  Initializes the CRC MSP.
177
  * @param  hcrc: pointer to a CRC_HandleTypeDef structure that contains
178
  *         the configuration information for CRC
179
  * @retval None
180
  */
181
__weak void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc)
182
{
5 mjames 183
  /* Prevent unused argument(s) compilation warning */
184
  UNUSED(hcrc);
2 mjames 185
  /* NOTE : This function Should not be modified, when the callback is needed,
186
            the HAL_CRC_MspInit could be implemented in the user file
187
   */
188
}
189
 
190
/**
191
  * @brief  DeInitializes the CRC MSP.
192
  * @param  hcrc: pointer to a CRC_HandleTypeDef structure that contains
193
  *         the configuration information for CRC
194
  * @retval None
195
  */
196
__weak void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc)
197
{
5 mjames 198
  /* Prevent unused argument(s) compilation warning */
199
  UNUSED(hcrc);
2 mjames 200
  /* NOTE : This function Should not be modified, when the callback is needed,
201
            the HAL_CRC_MspDeInit could be implemented in the user file
202
   */
203
}
204
 
205
/**
206
  * @}
207
  */
208
 
209
/** @defgroup CRC_Exported_Functions_Group2 Peripheral Control functions
210
 *  @brief    management functions.
211
 *
212
@verbatim  
213
  ==============================================================================
214
                      ##### Peripheral Control functions #####
215
  ==============================================================================  
216
    [..]  This section provides functions allowing to:
217
      (+) Compute the 32-bit CRC value of 32-bit data buffer,
218
          using combination of the previous CRC value and the new one.
219
      (+) Compute the 32-bit CRC value of 32-bit data buffer,
220
          independently of the previous CRC value.
221
 
222
@endverbatim
223
  * @{
224
  */
225
 
226
/**
227
  * @brief  Computes the 32-bit CRC of 32-bit data buffer using combination
228
  *         of the previous CRC value and the new one.
229
  * @param  hcrc: pointer to a CRC_HandleTypeDef structure that contains
230
  *         the configuration information for CRC
231
  * @param  pBuffer: pointer to the buffer containing the data to be computed
232
  * @param  BufferLength: length of the buffer to be computed (defined in word, 4 bytes)
233
  * @retval 32-bit CRC
234
  */
235
uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
236
{
237
  uint32_t index = 0;
238
 
239
  /* Process Locked */
240
  __HAL_LOCK(hcrc);
241
 
242
  /* Change CRC peripheral state */
243
  hcrc->State = HAL_CRC_STATE_BUSY;
244
 
245
  /* Enter Data to the CRC calculator */
246
  for(index = 0; index < BufferLength; index++)
247
  {
248
    hcrc->Instance->DR = pBuffer[index];
249
  }
250
 
251
  /* Change CRC peripheral state */
252
  hcrc->State = HAL_CRC_STATE_READY;
253
 
254
  /* Process Unlocked */
255
  __HAL_UNLOCK(hcrc);
256
 
257
  /* Return the CRC computed value */
258
  return hcrc->Instance->DR;
259
}
260
 
261
/**
262
  * @brief  Computes the 32-bit CRC of 32-bit data buffer independently
263
  *         of the previous CRC value.
264
  * @param  hcrc: pointer to a CRC_HandleTypeDef structure that contains
265
  *         the configuration information for CRC
266
  * @param  pBuffer: Pointer to the buffer containing the data to be computed
267
  * @param  BufferLength: Length of the buffer to be computed (defined in word, 4 bytes)
268
  * @retval 32-bit CRC
269
  */
270
uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
271
{
272
  uint32_t index = 0;
273
 
274
  /* Process Locked */
275
  __HAL_LOCK(hcrc);
276
 
277
  /* Change CRC peripheral state */
278
  hcrc->State = HAL_CRC_STATE_BUSY;
279
 
280
  /* Reset CRC Calculation Unit */
281
  __HAL_CRC_DR_RESET(hcrc);
282
 
283
  /* Enter Data to the CRC calculator */
284
  for(index = 0; index < BufferLength; index++)
285
  {
286
    hcrc->Instance->DR = pBuffer[index];
287
  }
288
 
289
  /* Change CRC peripheral state */
290
  hcrc->State = HAL_CRC_STATE_READY;
291
 
292
  /* Process Unlocked */
293
  __HAL_UNLOCK(hcrc);
294
 
295
  /* Return the CRC computed value */
296
  return hcrc->Instance->DR;
297
}
298
 
299
/**
300
  * @}
301
  */
302
 
303
/** @defgroup CRC_Exported_Functions_Group3 Peripheral State functions
304
 *  @brief    Peripheral State functions.
305
 *
306
@verbatim  
307
  ==============================================================================
308
                      ##### Peripheral State functions #####
309
  ==============================================================================  
310
    [..]
311
    This subsection permits to get in run-time the status of the peripheral.
312
 
313
@endverbatim
314
  * @{
315
  */
316
 
317
/**
318
  * @brief  Returns the CRC state.
319
  * @param  hcrc: pointer to a CRC_HandleTypeDef structure that contains
320
  *         the configuration information for CRC
321
  * @retval HAL state
322
  */
323
HAL_CRC_StateTypeDef HAL_CRC_GetState(CRC_HandleTypeDef *hcrc)
324
{
325
  return hcrc->State;
326
}
327
 
328
/**
329
  * @}
330
  */
331
 
332
/**
333
  * @}
334
  */
335
 
336
#endif /* HAL_CRC_MODULE_ENABLED */
337
/**
338
  * @}
339
  */
340
 
341
/**
342
  * @}
343
  */
344
 
345
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/