blob: d356cf17bfd175232604d429b87952fecc266b0d [file] [log] [blame]
Christina Quast8be71e42014-12-02 13:06:01 +01001/* ----------------------------------------------------------------------------
2 * ATMEL Microcontroller Software Support
3 * ----------------------------------------------------------------------------
4 * Copyright (c) 2009, Atmel Corporation
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the disclaimer below.
13 *
14 * Atmel's name may not be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * ----------------------------------------------------------------------------
28 */
29
30/** \addtogroup crccu_module Working with CRCCU
31 * The CRCCU driver provides the interface to configure and use the CRCCU
32 * peripheral.
33 *
34 * It performs a CRC computation on a Memory Area. CRC computation is performed
35 * from the LSB to MSB bit. Three different polynomials are available:
36 * CCIT802.3, CASTAGNOLI and CCIT16.
37 *
38 * To computes CRC of a buffer, the user has to follow these few steps:
39 * <ul>
40 * <li>Reset initial CRC by setting RESET bit in CRCCU_CRC_CR,</li>
41 * <li>Configure CRC descriptor and working mode,</li>
42 * <li>Start to compute CRC by setting DMAEN in CRCCU_DMA_EN,</li>
43 * <li>Get CRC value in CRCCU_CRC_SR.</li>
44 * </ul>
45 *
46 * For more accurate information, please look at the CRCCU section of the
47 * Datasheet.
48 *
49 * Related files :\n
50 * \ref crccu.c\n
51 * \ref crccu.h.\n
52*/
53/*@{*/
54/*@}*/
55
56/**
57 * \file
58 *
59 * Implementation of Cyclic Redundancy Check Calculation Unit (CRCCU).
60 *
61 */
62
63/*----------------------------------------------------------------------------
64 * Headers
65 *----------------------------------------------------------------------------*/
66#include "chip.h"
67
68/*----------------------------------------------------------------------------
69 * Definitions
70 *----------------------------------------------------------------------------*/
71#define CRCCU_TIMEOUT 0xFFFFFFFF
72
73/*----------------------------------------------------------------------------
74 * Exported functions
75 *----------------------------------------------------------------------------*/
76/**
77 * \brief Reset initial CRC to 0xFFFFFFFF.
78 */
79extern void CRCCU_ResetCrcValue( Crccu* pCrccu )
80{
81 pCrccu->CRCCU_CR = CRCCU_CR_RESET;
82}
83
84/**
85 * \brief Configure the CRCCU.
86 *
87 * \param dscrAddr CRC decscriptor address.
88 * \param mode CRC work mode
89 */
90extern void CRCCU_Configure( Crccu* pCrccu, uint32_t dwDscrAddr, uint32_t dwMode )
91{
92 pCrccu->CRCCU_DSCR = dwDscrAddr ;
93 pCrccu->CRCCU_MR = dwMode ;
94}
95
96/**
97 * \brief Start to compute the CRC of a buffer.
98 *
99 * \return The CRC of the buffer.
100 */
101extern uint32_t CRCCU_ComputeCrc( Crccu* pCrccu )
102{
103 uint32_t dwTimeout = 0 ;
104
105 pCrccu->CRCCU_DMA_EN = CRCCU_DMA_EN_DMAEN ;
106
107 while ( ((pCrccu->CRCCU_DMA_SR & CRCCU_DMA_SR_DMASR) == CRCCU_DMA_SR_DMASR) &&
108 (dwTimeout++ < CRCCU_TIMEOUT) ) ;
109
110 return (pCrccu->CRCCU_SR) ;
111}
112