ADuCM302x Device Drivers API Reference Manual
Release 3.1.2.0
|
Cyclic Redundancy Check (CRC) peripheral driver More...
Modules | |
Static Configuration | |
Macros | |
#define | ADI_CRC_MEMORY_SIZE (32u) |
Typedefs | |
typedef struct __ADI_CRC_DEVICE * | ADI_CRC_HANDLE |
Functions | |
ADI_CRC_RESULT | adi_crc_Open (uint32_t DeviceNum, void *pMemory, uint32_t MemorySize, ADI_CRC_HANDLE *phDevice) |
Opens a CRC device instance. More... | |
ADI_CRC_RESULT | adi_crc_Close (ADI_CRC_HANDLE const hDevice) |
Closes CRC device instance opened for use. More... | |
ADI_CRC_RESULT | adi_crc_RegisterCallback (ADI_CRC_HANDLE const hDevice, ADI_CALLBACK pfCallback, void *const pCBParam) |
Registers or unregisters a callback with the CRC device. More... | |
ADI_CRC_RESULT | adi_crc_SetPolynomialVal (ADI_CRC_HANDLE const hDevice, uint32_t PolynomialVal) |
Sets the 32-bit polynomial for CRC operations. More... | |
ADI_CRC_RESULT | adi_crc_Compute (ADI_CRC_HANDLE const hDevice, void *pCrcBuf, uint32_t NumBytes, uint32_t NumBits) |
Submits data buffer for CRC computation. More... | |
ADI_CRC_RESULT | adi_crc_IsCrcInProgress (ADI_CRC_HANDLE const hDevice, bool *pbCrcInProgress) |
Gets the current CRC peripheral status. More... | |
ADI_CRC_RESULT | adi_crc_GetFinalCrcVal (ADI_CRC_HANDLE const hDevice, uint32_t *pFinalCrcVal) |
Gets the final CRC result computed for a data stream. More... | |
ADI_CRC_RESULT | adi_crc_GetCurrentCrcVal (ADI_CRC_HANDLE const hDevice, uint32_t *pCurrentCrcVal) |
Gets the current/intermediate CRC result computed for a data stream. More... | |
ADI_CRC_RESULT | adi_crc_SetBitMirroring (ADI_CRC_HANDLE const hDevice, const bool bEnable) |
Set the bit mirroring. This function should be called only when device is idle, i.e. when no data are being processd by the CRC. More... | |
ADI_CRC_RESULT | adi_crc_SetByteMirroring (ADI_CRC_HANDLE const hDevice, const bool bEnable) |
Set the byte mirroring. This function should be called only when device is disabled. More... | |
ADI_CRC_RESULT | adi_crc_EnableWordSwap (ADI_CRC_HANDLE const hDevice, const bool bEnable) |
To enable/disable the word Swap. This function should be called only when device is disabled. More... | |
ADI_CRC_RESULT | adi_crc_SetCrcSeedVal (ADI_CRC_HANDLE const hDevice, uint32_t CrcSeedVal) |
Sets the initial seed value for the CRC operation that is about to take place. More... | |
ADI_CRC_RESULT | adi_crc_SetLSBFirst (ADI_CRC_HANDLE const hDevice, const bool bEnable) |
Enable the LSB first. More... | |
Cyclic Redundancy Check (CRC) peripheral driver
The CRC peripheral is used to perform the Cyclic Redundancy Check (CRC) of the block of data that is presented to the peripheral. The peripheral provides a means to periodically verify the integrity of the system memory and it is based on a CRC32 engine that computes the signature of 32-bit data presented to the hardware engine. CRC operations can be core driven or DMA driven depending on static configuration.
- #ADI_CRC_CFG_ENABLE_DMA_SUPPORT set to 0 defines a core driven CRC driver - #ADI_CRC_CFG_ENABLE_DMA_SUPPORT set to a non 0 value defines a DMA driven CRC driver
Core driven CRC operations
The adi_crc_Compute function executes core driven CRC operations to calculate the CRC on the buffer input with the CRC parameters set in the driver. In this mode, data in the submitted buffer is transmitted to the CRC directly by the core.
Memory DMA driver CRC operations
The adi_crc_Compute function executes DMA driven CRC operations to calculate the CRC on the buffer input with the CRC parameters set in the driver. In this mode, data in the submitted buffer is transmitted to the CRC through DMA transfers.
The software DMA channel reserved for the CRC driver is defined by a macro, ADI_CFG_CRC_SOFTWARE_DMA_CHANNEL_ID, which can take a value between 0 and 7. If this macro is not defined, e.g. in a configuration file, then its value is defaulted to 7: in this case, DMA channel SIP7 is used by the CRC driver and DMA_SIP7_Int_Handler becomes the interrupt used by the DMA when a transfer to the CRC is complete.
Computing CRC
The CRC engine performs a 32-bit CRC operation on the incoming data stream.
Sequence of function calls for Computing CRC :
adi_crc_GetFinalCrcVal() to get the CRC value of the data stream if its CRC value is unknown. (Note that adi_crc_GetFinalCrcVal resets the CRC seed to the ADI_CFG_CRC_SEED_VALUE default value.)
Note that using statically configured parameters such as ADI_CFG_CRC_ENABLE_BYTE_MIRRORING, ADI_CFG_CRC_ENABLE_BIT_MIRRORING, ADI_CFG_CRC_POLYNOMIAL and ADI_CFG_CRC_SEED_VALUE, functions adi_crc_SetBitMirroring, adi_crc_SetByteMirroring, adi_crc_SetPolynomialVal and adi_crc_SetBitMirroring don't need to be called explicitly in your application: the parameters will be assigned when opening the driver.
#define ADI_CRC_MEMORY_SIZE (32u) |
The size of types may vary between building tools (int, char, enumerator, etc.). This impacts the memory size required by a CRC driver. Consequently, ADI_CRC_MEMORY_SIZE is environment dependent. The amount of application supplied memory required to operate a core driven CRC device using a CRC driver built in a generic built environment. Note: Create a new macro definition for your targetted development environment if this generic value was not appropriate in your development environment.
Definition at line 92 of file adi_crc.h.
Referenced by adi_crc_Open().
typedef struct __ADI_CRC_DEVICE* ADI_CRC_HANDLE |
enum ADI_CRC_RESULT |
CRC driver return codes
ADI_CRC_RESULT adi_crc_Open | ( | uint32_t | DeviceNum, |
void * | pMemory, | ||
uint32_t | MemorySize, | ||
ADI_CRC_HANDLE * | phDevice | ||
) |
Opens a CRC device instance.
[in] | DeviceNum | Number identifying the CRC Device to open. |
[in] | pMemory | Pointer to a ADI_CRC_MEMORY_SIZE. sized buffer to manage the device instance. |
[in] | MemorySize | Size of the buffer to which "pMemory" points. |
[out] | phDevice | Pointer to a location where CRC device handle to be written. |
ADI_CRC_RESULT adi_crc_Close | ( | ADI_CRC_HANDLE const | hDevice | ) |
Closes CRC device instance opened for use.
[in] | hDevice | Handle to CRC Device instance to close. |
ADI_CRC_RESULT adi_crc_RegisterCallback | ( | ADI_CRC_HANDLE const | hDevice, |
ADI_CALLBACK | pfCallback, | ||
void *const | pCBParam | ||
) |
Registers or unregisters a callback with the CRC device.
It is not required to register a callback for the operation of the driver. Data compare or DMA error will be notified via the adi_crc_IsCrcInProgress() API. But if an application requires the errors/events to be notified immediately it can register a callback with the driver which will be called to notify errors/events.
When a callback is registered the API adi_crc_IsCrcInProgress() will not return error.
[in] | hDevice | Handle to CRC device instance to work on |
[in] | pfCallback | Pointer to application callback function. The callback function has the prototype void callback(void *pCBParam, uint32_t nEvent, void *pArg) To unregister a callback pass the the pointer to the callback function as NULL. |
[in] | pCBParam | Callback parameter which will be returned back to the application when the callback function is called. |
ADI_CRC_RESULT adi_crc_SetPolynomialVal | ( | ADI_CRC_HANDLE const | hDevice, |
uint32_t | PolynomialVal | ||
) |
Sets the 32-bit polynomial for CRC operations.
[in] | hDevice | Handle to CRC device instance to work on. |
[in] | PolynomialVal | 32-bit CRC polynomial to use for CRC operation. |
ADI_CRC_RESULT adi_crc_Compute | ( | ADI_CRC_HANDLE const | hDevice, |
void * | pCrcBuf, | ||
uint32_t | NumBytes, | ||
uint32_t | NumBits | ||
) |
Submits data buffer for CRC computation.
This API can be used to submit data buffer for CRC computation. If NumBits is in [0..7] then the number of bytes to be processed is NumBytes plus one partial byte containing NumBits bits. If DMA mode of operation is selected, buffer is processed using the specified DMA channel.
[in] | hDevice | Handle of CRC device |
[in] | pCrcBuf | Address of CRC data buffer |
[in] | NumBytes | Number of whole bytes in CRC data buffer |
[in] | NumBits | Number of bits, 0 to 7, in the last partial byte in CRC data buffer |
ADI_CRC_RESULT adi_crc_IsCrcInProgress | ( | ADI_CRC_HANDLE const | hDevice, |
bool * | pbCrcInProgress | ||
) |
Gets the current CRC peripheral status.
[in] | hDevice | Handle to CRC device instance to work on |
[in] | pbCrcInProgress | Pointer to location to store the current status of CRC peripheral. 'true' when CRC peripheral is in currently performing a CRC operation. |
ADI_CRC_RESULT adi_crc_GetFinalCrcVal | ( | ADI_CRC_HANDLE const | hDevice, |
uint32_t * | pFinalCrcVal | ||
) |
Gets the final CRC result computed for a data stream.
This API gets the final CRC result computed for a data stream and clears the current and final CRC results register. The CRC Current result register holds the current or intermediate CRC result. Whenever a CRC operation is initiated, the CRC peripheral takes the CRC Current register value as initial seed for CRC computation. This API clears both results register to start a fresh CRC computation. Use the adi_crc_GetCurrentCrcVal() API to get an intermediate CRC result without clearing the results register.
[in] | hDevice | Handle to CRC device instance to work on |
[out] | pFinalCrcVal | Pointer to location where the final CRC result of a data stream to be processed will be written. |
ADI_CRC_RESULT adi_crc_GetCurrentCrcVal | ( | ADI_CRC_HANDLE const | hDevice, |
uint32_t * | pCurrentCrcVal | ||
) |
Gets the current/intermediate CRC result computed for a data stream.
[in] | hDevice | Handle to CRC device instance to work on |
[out] | pCurrentCrcVal | Pointer to location where the intermediate CRC result of a data stream to be processed will be written. |
ADI_CRC_RESULT adi_crc_SetBitMirroring | ( | ADI_CRC_HANDLE const | hDevice, |
const bool | bEnable | ||
) |
Set the bit mirroring. This function should be called only when device is idle, i.e. when no data are being processd by the CRC.
[in] | hDevice | Device handle obtained from adi_crc_Open(). |
[in] | bEnable | Boolean flag to enable/disable bit mirroring. true : To Enable bit mirroring. false : To Disable bit mirroring. |
ADI_CRC_RESULT adi_crc_SetByteMirroring | ( | ADI_CRC_HANDLE const | hDevice, |
const bool | bEnable | ||
) |
Set the byte mirroring. This function should be called only when device is disabled.
[in] | hDevice | Device handle obtained from adi_crc_Open(). |
[in] | bEnable | Boolean flag to enable/disable byte mirroring. true : To Enable byte mirroring. false : To Disable byte mirroring. |
ADI_CRC_RESULT adi_crc_EnableWordSwap | ( | ADI_CRC_HANDLE const | hDevice, |
const bool | bEnable | ||
) |
To enable/disable the word Swap. This function should be called only when device is disabled.
[in] | hDevice | Device handle obtained from adi_crc_Open(). |
[in] | bEnable | Boolean flag to enable/disable word swap. true : To Enable word swap. false : To Disable word swap. |
ADI_CRC_RESULT adi_crc_SetCrcSeedVal | ( | ADI_CRC_HANDLE const | hDevice, |
uint32_t | CrcSeedVal | ||
) |
Sets the initial seed value for the CRC operation that is about to take place.
[in] | hDevice | Handle to CRC device instance to work on. |
[in] | CrcSeedVal | Initial seed value for the CRC operation that is about to take place. |
ADI_CRC_RESULT adi_crc_SetLSBFirst | ( | ADI_CRC_HANDLE const | hDevice, |
const bool | bEnable | ||
) |
Enable the LSB first.
[in] | hDevice | Device handle obtained from adi_crc_Open(). |
[in] | bEnable | Boolean flag which indicate whether LSB first OR MSB first for CRC calculation. true : For LSB First CRC calculation false : For MSB First CRC calculation |