apm32f10x_crc.c 2.6 KB
Newer Older
A
abbcc 已提交
1
/*!
2
 * @file        apm32f10x_crc.c
A
abbcc 已提交
3
 *
4
 * @brief       This file provides all the CRC firmware functions
A
abbcc 已提交
5
 *
6
 * @version     V1.0.4
A
abbcc 已提交
7
 *
8
 * @date        2022-12-01
A
abbcc 已提交
9
 *
10 11 12 13 14 15 16 17
 * @attention
 *
 *  Copyright (C) 2020-2022 Geehy Semiconductor
 *
 *  You may not use this file except in compliance with the
 *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
 *
 *  The program is only for reference, which is distributed in the hope
18
 *  that it will be useful and instructional for customers to develop
19 20 21 22 23
 *  their software. Unless required by applicable law or agreed to in
 *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
 *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
 *  and limitations under the License.
A
abbcc 已提交
24 25 26 27
 */

#include "apm32f10x_crc.h"

28
/** @addtogroup APM32F10x_StdPeriphDriver
A
abbcc 已提交
29 30 31 32
  @{
*/

/** @addtogroup CRC_Driver CRC Driver
33
  * @brief CRC driver modules
A
abbcc 已提交
34 35 36
  @{
*/

37
/** @defgroup CRC_Functions Functions
A
abbcc 已提交
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
  @{
*/

/*!
 * @brief     Reset CRC data register.
 *
 * @param     None
 *
 * @retval    None
 */
void CRC_ResetDATA(void)
{
    CRC->CTRL_B.RST = BIT_SET;
}

/*!
 * @brief     Calculate CRC of a 32bit data word.
 *
 * @param     data: a data word to compute its CRC.
 *                  This parameter can be a 32bit value:
 *
 * @retval    A 32-bit CRC value
 */
uint32_t CRC_CalculateCRC(uint32_t data)
{
    CRC->DATA = data;

    return (CRC->DATA);
}

/*!
 * @brief     Computes the 32-bit CRC of a given buffer of data word(32-bit).
 *
 * @param     buf: Pointer to the buffer containing the data to be computed.
 *
 * @param     bufLen: The length of buffer which is computed.
 *
 * @retval    A 32-bit CRC value
 */
77
uint32_t CRC_CalculateBlockCRC(uint32_t* buf, uint32_t bufLen)
A
abbcc 已提交
78
{
A
Aligagago 已提交
79
    while (bufLen--)
A
abbcc 已提交
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
    {
        CRC->DATA = *buf++;
    }

    return (CRC->DATA);
}

/*!
 * @brief     Returns the current CRC value.
 *
 * @param     None
 *
 * @retval    A 32-bit CRC value
 */
uint32_t CRC_ReadCRC(void)
{
    return (CRC->DATA);
}

/*!
 * @brief     Saves a 8bit data in the Independent Data register(INDATA).
 *
 * @param     inData: a 8-bit value to be stored in the ID register
 *
 * @retval    None
 */
void CRC_WriteIDRegister(uint8_t inData)
{
    CRC->INDATA = inData;
}

/*!
 * @brief      Reads a 8-bit data saved in the Independent Data register(INDATA).
 *
 * @param      None
 *
 * @retval     a 8-bit value from the INDATA register
 */
uint8_t CRC_ReadIDRegister(void)
{
    return (CRC->INDATA);
}

123
/**@} end of group CRC_Functions*/
A
abbcc 已提交
124
/**@} end of group CRC_Driver*/
125
/**@} end of group APM32F10x_StdPeriphDriver */