Subversion Repositories LedShow

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
  * @brief   CRC HAL module driver.
9 mjames 6
  *          This file provides firmware functions to manage the following
2 mjames 7
  *          functionalities of the Cyclic Redundancy Check (CRC) peripheral:
8
  *           + Initialization and de-initialization functions
9 mjames 9
  *           + Peripheral Control functions
2 mjames 10
  *           + Peripheral State functions
11
  *
12
  @verbatim
9 mjames 13
 ===============================================================================
2 mjames 14
                     ##### How to use this driver #####
9 mjames 15
 ===============================================================================
2 mjames 16
    [..]
9 mjames 17
         (+) Enable CRC AHB clock using __HAL_RCC_CRC_CLK_ENABLE();
18
         (+) Initialize CRC calculator
19
             (++) specify generating polynomial (peripheral default or non-default one)
20
             (++) specify initialization value (peripheral default or non-default one)
21
             (++) specify input data format
22
             (++) specify input or output data inversion mode if any
23
         (+) Use HAL_CRC_Accumulate() function to compute the CRC value of the
24
             input data buffer starting with the previously computed CRC as
25
             initialization value
26
         (+) Use HAL_CRC_Calculate() function to compute the CRC value of the
27
             input data buffer starting with the defined initialization value
28
             (default or non-default) to initiate CRC calculation
2 mjames 29
 
30
  @endverbatim
31
  ******************************************************************************
32
  * @attention
33
  *
9 mjames 34
  * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
35
  * All rights reserved.</center></h2>
2 mjames 36
  *
9 mjames 37
  * This software component is licensed by ST under BSD 3-Clause license,
38
  * the "License"; You may not use this file except in compliance with the
39
  * License. You may obtain a copy of the License at:
40
  *                        opensource.org/licenses/BSD-3-Clause
2 mjames 41
  *
42
  ******************************************************************************
43
  */
44
 
45
/* Includes ------------------------------------------------------------------*/
46
#include "stm32f1xx_hal.h"
47
 
48
/** @addtogroup STM32F1xx_HAL_Driver
49
  * @{
50
  */
51
 
52
/** @defgroup CRC CRC
53
  * @brief CRC HAL module driver.
54
  * @{
55
  */
56
 
57
#ifdef HAL_CRC_MODULE_ENABLED
58
 
59
/* Private typedef -----------------------------------------------------------*/
60
/* Private define ------------------------------------------------------------*/
61
/* Private macro -------------------------------------------------------------*/
62
/* Private variables ---------------------------------------------------------*/
63
/* Private function prototypes -----------------------------------------------*/
64
 
9 mjames 65
/* Exported functions --------------------------------------------------------*/
66
 
2 mjames 67
/** @defgroup CRC_Exported_Functions CRC Exported Functions
68
  * @{
69
  */
70
 
9 mjames 71
/** @defgroup CRC_Exported_Functions_Group1 Initialization and de-initialization functions
72
 *  @brief    Initialization and Configuration functions.
2 mjames 73
 *
9 mjames 74
@verbatim
75
 ===============================================================================
2 mjames 76
            ##### Initialization and de-initialization functions #####
9 mjames 77
 ===============================================================================
2 mjames 78
    [..]  This section provides functions allowing to:
9 mjames 79
      (+) Initialize the CRC according to the specified parameters
2 mjames 80
          in the CRC_InitTypeDef and create the associated handle
81
      (+) DeInitialize the CRC peripheral
9 mjames 82
      (+) Initialize the CRC MSP (MCU Specific Package)
83
      (+) DeInitialize the CRC MSP
84
 
2 mjames 85
@endverbatim
86
  * @{
87
  */
88
 
89
/**
9 mjames 90
  * @brief  Initialize the CRC according to the specified
91
  *         parameters in the CRC_InitTypeDef and create the associated handle.
92
  * @param  hcrc CRC handle
2 mjames 93
  * @retval HAL status
94
  */
95
HAL_StatusTypeDef HAL_CRC_Init(CRC_HandleTypeDef *hcrc)
96
{
97
  /* Check the CRC handle allocation */
9 mjames 98
  if (hcrc == NULL)
2 mjames 99
  {
100
    return HAL_ERROR;
101
  }
102
 
103
  /* Check the parameters */
104
  assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
105
 
9 mjames 106
  if (hcrc->State == HAL_CRC_STATE_RESET)
2 mjames 107
  {
108
    /* Allocate lock resource and initialize it */
109
    hcrc->Lock = HAL_UNLOCKED;
110
    /* Init the low level hardware */
111
    HAL_CRC_MspInit(hcrc);
112
  }
113
 
114
  /* Change CRC peripheral state */
115
  hcrc->State = HAL_CRC_STATE_READY;
9 mjames 116
 
2 mjames 117
  /* Return function status */
118
  return HAL_OK;
119
}
120
 
121
/**
9 mjames 122
  * @brief  DeInitialize the CRC peripheral.
123
  * @param  hcrc CRC handle
2 mjames 124
  * @retval HAL status
125
  */
126
HAL_StatusTypeDef HAL_CRC_DeInit(CRC_HandleTypeDef *hcrc)
127
{
128
  /* Check the CRC handle allocation */
9 mjames 129
  if (hcrc == NULL)
2 mjames 130
  {
131
    return HAL_ERROR;
132
  }
133
 
134
  /* Check the parameters */
135
  assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
136
 
9 mjames 137
  /* Check the CRC peripheral state */
138
  if (hcrc->State == HAL_CRC_STATE_BUSY)
139
  {
140
    return HAL_BUSY;
141
  }
142
 
2 mjames 143
  /* Change CRC peripheral state */
144
  hcrc->State = HAL_CRC_STATE_BUSY;
145
 
9 mjames 146
  /* Reset CRC calculation unit */
2 mjames 147
  __HAL_CRC_DR_RESET(hcrc);
148
 
149
  /* Reset IDR register content */
150
  CLEAR_BIT(hcrc->Instance->IDR, CRC_IDR_IDR);
151
 
9 mjames 152
  /* DeInit the low level hardware */
153
  HAL_CRC_MspDeInit(hcrc);
154
 
2 mjames 155
  /* Change CRC peripheral state */
156
  hcrc->State = HAL_CRC_STATE_RESET;
157
 
9 mjames 158
  /* Process unlocked */
2 mjames 159
  __HAL_UNLOCK(hcrc);
160
 
161
  /* Return function status */
162
  return HAL_OK;
163
}
164
 
165
/**
166
  * @brief  Initializes the CRC MSP.
9 mjames 167
  * @param  hcrc CRC handle
2 mjames 168
  * @retval None
169
  */
170
__weak void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc)
171
{
172
  /* Prevent unused argument(s) compilation warning */
173
  UNUSED(hcrc);
9 mjames 174
 
175
  /* NOTE : This function should not be modified, when the callback is needed,
176
            the HAL_CRC_MspInit can be implemented in the user file
2 mjames 177
   */
178
}
179
 
180
/**
9 mjames 181
  * @brief  DeInitialize the CRC MSP.
182
  * @param  hcrc CRC handle
2 mjames 183
  * @retval None
184
  */
185
__weak void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc)
186
{
187
  /* Prevent unused argument(s) compilation warning */
188
  UNUSED(hcrc);
9 mjames 189
 
190
  /* NOTE : This function should not be modified, when the callback is needed,
191
            the HAL_CRC_MspDeInit can be implemented in the user file
2 mjames 192
   */
193
}
194
 
195
/**
196
  * @}
197
  */
198
 
9 mjames 199
/** @defgroup CRC_Exported_Functions_Group2 Peripheral Control functions
200
 *  @brief    management functions.
2 mjames 201
 *
9 mjames 202
@verbatim
203
 ===============================================================================
2 mjames 204
                      ##### Peripheral Control functions #####
9 mjames 205
 ===============================================================================
2 mjames 206
    [..]  This section provides functions allowing to:
9 mjames 207
      (+) compute the 32-bit CRC value of a 32-bit data buffer
2 mjames 208
          using combination of the previous CRC value and the new one.
9 mjames 209
 
210
       [..]  or
211
 
212
      (+) compute the 32-bit CRC value of a 32-bit data buffer
2 mjames 213
          independently of the previous CRC value.
214
 
215
@endverbatim
216
  * @{
217
  */
218
 
219
/**
9 mjames 220
  * @brief  Compute the 32-bit CRC value of a 32-bit data buffer
221
  *         starting with the previously computed CRC as initialization value.
222
  * @param  hcrc CRC handle
223
  * @param  pBuffer pointer to the input data buffer.
224
  * @param  BufferLength input data buffer length (number of uint32_t words).
225
  * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
2 mjames 226
  */
227
uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
228
{
9 mjames 229
  uint32_t index;      /* CRC input data buffer index */
230
  uint32_t temp = 0U;  /* CRC output (read from hcrc->Instance->DR register) */
2 mjames 231
 
232
  /* Change CRC peripheral state */
233
  hcrc->State = HAL_CRC_STATE_BUSY;
234
 
235
  /* Enter Data to the CRC calculator */
9 mjames 236
  for (index = 0U; index < BufferLength; index++)
2 mjames 237
  {
238
    hcrc->Instance->DR = pBuffer[index];
239
  }
9 mjames 240
  temp = hcrc->Instance->DR;
2 mjames 241
 
242
  /* Change CRC peripheral state */
243
  hcrc->State = HAL_CRC_STATE_READY;
244
 
245
  /* Return the CRC computed value */
9 mjames 246
  return temp;
2 mjames 247
}
248
 
249
/**
9 mjames 250
  * @brief  Compute the 32-bit CRC value of a 32-bit data buffer
251
  *         starting with hcrc->Instance->INIT as initialization value.
252
  * @param  hcrc CRC handle
253
  * @param  pBuffer pointer to the input data buffer.
254
  * @param  BufferLength input data buffer length (number of uint32_t words).
255
  * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
2 mjames 256
  */
257
uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
258
{
9 mjames 259
  uint32_t index;      /* CRC input data buffer index */
260
  uint32_t temp = 0U;  /* CRC output (read from hcrc->Instance->DR register) */
2 mjames 261
 
262
  /* Change CRC peripheral state */
263
  hcrc->State = HAL_CRC_STATE_BUSY;
264
 
9 mjames 265
  /* Reset CRC Calculation Unit (hcrc->Instance->INIT is
266
  *  written in hcrc->Instance->DR) */
2 mjames 267
  __HAL_CRC_DR_RESET(hcrc);
268
 
9 mjames 269
  /* Enter 32-bit input data to the CRC calculator */
270
  for (index = 0U; index < BufferLength; index++)
2 mjames 271
  {
272
    hcrc->Instance->DR = pBuffer[index];
273
  }
9 mjames 274
  temp = hcrc->Instance->DR;
2 mjames 275
 
276
  /* Change CRC peripheral state */
277
  hcrc->State = HAL_CRC_STATE_READY;
278
 
279
  /* Return the CRC computed value */
9 mjames 280
  return temp;
2 mjames 281
}
282
 
283
/**
284
  * @}
285
  */
286
 
9 mjames 287
/** @defgroup CRC_Exported_Functions_Group3 Peripheral State functions
288
 *  @brief    Peripheral State functions.
2 mjames 289
 *
9 mjames 290
@verbatim
291
 ===============================================================================
2 mjames 292
                      ##### Peripheral State functions #####
9 mjames 293
 ===============================================================================
2 mjames 294
    [..]
295
    This subsection permits to get in run-time the status of the peripheral.
296
 
297
@endverbatim
298
  * @{
299
  */
300
 
301
/**
9 mjames 302
  * @brief  Return the CRC handle state.
303
  * @param  hcrc CRC handle
2 mjames 304
  * @retval HAL state
305
  */
306
HAL_CRC_StateTypeDef HAL_CRC_GetState(CRC_HandleTypeDef *hcrc)
307
{
9 mjames 308
  /* Return CRC handle state */
2 mjames 309
  return hcrc->State;
310
}
311
 
312
/**
313
  * @}
314
  */
315
 
316
/**
317
  * @}
318
  */
319
 
9 mjames 320
 
2 mjames 321
#endif /* HAL_CRC_MODULE_ENABLED */
322
/**
323
  * @}
324
  */
325
 
326
/**
327
  * @}
328
  */
329
 
330
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/