| Xmega IEC60730 Class B Library 1.0 |

All Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
classb_crc_hw.h
Go to the documentation of this file.
1 /**
2 * \file
3 *
4 * \brief Definitions and settings for the CRC hardware module driver
5 *
6 * Copyright (C) 2012 Atmel Corporation. All rights reserved.
7 *
8 * \page License
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 *
20 * 3. The name of Atmel may not be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * 4. This software may only be redistributed and used in connection with an
24 * Atmel AVR product.
25 *
26 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
29 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
36 * DAMAGE.
37 */
38 #ifndef __CRC_H_HW__
39 #define __CRC_H_HW__
40
41 #include "avr_compiler.h"
42 #include "classb_crc.h"
43
44
45 /**
46 * \ingroup classb_crc
47 *
48 * \defgroup classb_crc_hw CRC hardware implementation
49 *
50 * \brief Low-level driver implementation for the AVR XMEGA AU CRC module.
51 *
52 * The CRC computation is done by the hardware CRC module. Even if this hardware
53 * module computes the checksum, the CPU can still be required to read the data.
54 * In the case of 32-bit CRC computation for flash memory, the whole process can
55 * be run without support from the CPU. However, for the 16-bit computation the
56 * CPU would have to read from Flash memory and transfer data to the CRC module.
57 * For CRC computations of data in SRAM, EEPROM or peripherals, the CPU will have
58 * to transfer data to the CRC module unless a DMA transaction is setup. The
59 * CRC-CCITT polynomial is 0x1021 and the IEEE 802.3 polynomial is 0x04C11DB7.
60 * More details on the CRC implementation can be found in the XMEGA AU manual.
61 *
62 * \note \li The CRC module driver requires one of the new XMEGA AU devices.
63 * \li The CPU is locked while the CRC module is set to compute a checksum from
64 * Flash.
65 * \li CRC32 in Flash can only check an even number of bytes.
66 * \li When specifying Flash or EEPROM addresses, 0x000000 denotes the start of
67 * physical memory.
68 *
69 */
70
71 //@{
72
73
74 //! \name NVM Commands
75 //!
76 //! \brief NVMcommands related to 32-bit CRC for flash memory. This is only used by \ref CLASSB_CRC32_Flash_HW.
77 //@{
78 //! Compute a CRC checksum on an address range
79 #define CRC_FLASH_RANGE NVM_CMD_FLASH_RANGE_CRC_gc
80 //! Compute a CRC checksum on the application section
81 #define CRC_BOOT NVM_CMD_BOOT_CRC_gc
82 //! Compute a CRC checksum on the boot section
83 #define CRC_APP NVM_CMD_APP_CRC_gc
84 //@}
85
86
87 //! \name CRC tests
88 //!
89 //! \brief Invariant memory tests based on CRC that are compliant with IEC60730 Class B.
90 //@{
91 uint16_t CLASSB_CRC16_EEPROM_HW (eepromptr_t dataptr, const crcbytenum_t numBytes, eeprom_uint16ptr_t pchecksum);
92 uint16_t CLASSB_CRC16_Flash_HW (flashptr_t dataptr, const crcbytenum_t numBytes, eeprom_uint16ptr_t pchecksum);
93 uint32_t CLASSB_CRC32_EEPROM_HW (eepromptr_t dataptr, const crcbytenum_t numBytes, eeprom_uint32ptr_t pchecksum);
94 uint32_t CLASSB_CRC32_Flash_HW (NVM_CMD_t crc_type, flashptr_t dataptr, const crcbytenum_t numBytes, eeprom_uint32ptr_t pchecksum);
95 //@}
96
97 //! \internal
98 // \brief This indicates whether to use 16- or 32-bits CRC
99 enum crc_16_32_t {
100 CRC_16BIT,
101 CRC_32BIT
102 };
103
104 //! \internal
105 //!
106 //! \name Internal functions
107 //!
108 //! \brief These are functions from the CRC module driver.
109 //@{
110 void crc_set_initial_value(uint32_t value);
111 void crc32_append_value(uint32_t value, void *ptr);
112 void crc16_append_value(uint16_t value, void *ptr);
113 uint32_t crc_flash_checksum(NVM_CMD_t crc_type, flash_addr_t flash_addr, uint32_t len);
114 uint32_t crc_io_checksum(void *data, uint16_t len, enum crc_16_32_t crc_16_32);
115 void crc_io_checksum_byte_start(enum crc_16_32_t crc_16_32);
116 void crc_io_checksum_byte_add(uint8_t data);
117 uint32_t crc_io_checksum_byte_stop(void);
118 void nvm_issue_flash_range_crc(flash_addr_t start_addr, flash_addr_t end_addr);
119 //@}
120
121 //@}
122
123
124 #endif /* CRC_H_INCLUDED */