// CRC. c
/*************************************** **************************************** ******************/
/* Stm32 CRC
*/
// 20120427
# Include "stm32f10x_map.h"
# Include "system. H"
# Include "CRC. H"
/*************************************** **************************************** **************************************** **
* Function:
Void crc_reset (void)
* Function:
Reset CRC
* Parameters:
None
* Return value:
None
* Dependency:
Underlying macro definition
* Author:
Chen Peng
* Time:
20120427
* Last modification time: 20120427
* Description: reset CRC.
**************************************** **************************************** **************************************** */
Void crc_reset (void)
{
CRC-> Cr = 0x00000001;
// Reset crc_dr
}
/*************************************** **************************************** **************************************** **
* Function:
Void crc_init (void)
* Function:
Initialize the CRC Module
* Parameters:
None
* Return value:
None
* Dependency:
Underlying macro definition
* Author:
Chen Peng
* Time:
20120427
* Last modification time: 20120427
* Description: enables CRC clock.
**************************************** **************************************** **************************************** */
Void crc_init (void)
{
Deviceclockenable (dev_crc, enable );
// Enable CRC clock
Crc_reset ();
// Reset CRC
}
/*************************************** **************************************** **************************************** **
* Function:
U32 crc_calculatecrc (u32 data)
* Function:
Calculate 32-bit CRC of a single data
* Parameters:
Calculated value
* Return value:
32bit CRC Check Value
* Dependency:
Underlying macro definition
* Author:
Chen Peng
* Time:
20120427
* Last modification time: 20120427
* Description: calculates the CRC value. registers must be cleared before each write, that is, CRC is reset.
**************************************** **************************************** **************************************** */
U32 crc_calculatecrc (u32 data)
{
Crc_reset ();
// Reset CRC
CRC-> DR = data;
// Write the data to generate CRC
Return CRC-> Dr;
// Return CRC
}
/*************************************** **************************************** **************************************** **
* Function:
U32 crc_calculateblockcrc (u8 pbuffer [], u32 bufferlength)
* Function:
Calculate the CRC of the data in the buffer.
* Parameters:
Pbuffer []: buffer pointer, bufferlength: buffer size
* Return value:
32bit CRC Check Value
* Dependency:
Underlying macro definition
* Author:
Chen Peng
* Time:
20120502
* Last modification time: 20120502
* Note: reset CRC before writing
**************************************** **************************************** **************************************** */
U32 crc_calculateblockcrc (u8 pbuffer [], u32 bufferlength)
{
U32 I;
Crc_reset ();
// Reset CRC
For (I = 0; I <bufferlength; I ++)
CRC-> DR = (u32) pbuffer [I];
// Write data cyclically
Return CRC-> Dr;
// Return CRC
}
// CRC. h
/*************************************** **************************************** ******************/
/* Stm32 CRC
*/
// 20120427
# Ifndef _ crc_h _
# DEFINE _ crc_h _
# Include "stm32f10x_map.h"
# Include "system. H"
# Include "CRC. H"
Void crc_init (void); // initialize the CRC Module
Void crc_reset (void); // reset CRC
U32 crc_calculatecrc (u32 data); // calculate 32bit CRC
U32 crc_calculateblockcrc (u8 pbuffer [], u32 bufferlength );
// Calculate the CRC of the data in the buffer.
# Endif