1 /* ----------------------------------------------------------------------------
\r
2 * ATMEL Microcontroller Software Support
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2011, Atmel Corporation
\r
6 * All rights reserved.
\r
8 * Redistribution and use in source and binary forms, with or without
\r
9 * modification, are permitted provided that the following conditions are met:
\r
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\r
14 * Atmel's name may not be used to endorse or promote products derived from
\r
15 * this software without specific prior written permission.
\r
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
\r
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
\r
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
27 * ----------------------------------------------------------------------------
\r
31 /** \addtogroup fuse_module Working with FUSE
\r
32 * The Fuse driver provides the Interface for configuration the FUSE
\r
35 * For more accurate information, please look at the FUSE section of the
\r
48 * Implementation of FUSE controller.
\r
51 /*------------------------------------------------------------------------------
\r
53 *------------------------------------------------------------------------------*/
\r
56 /*------------------------------------------------------------------------------
\r
57 * Exported functions
\r
58 *------------------------------------------------------------------------------*/
\r
61 * \brief Read fuse vlaue by given word position.
\r
63 * \param wordPosition select the 32-bit word 0 to 9.
\r
66 uint32_t FUSE_Read (uint8_t wordPosition )
\r
69 /* Enable peripheral clock. */
\r
70 PMC->PMC_PCER1 = (1 << (ID_FUSE - 32 ));
\r
71 /* Request read fuse */
\r
72 FUSE->FUSE_CR = FUSE_CR_RRQ | FUSE_CR_KEY_VALID;
\r
73 /* RS and WS bits of the Fuse Index register (FUSE_IR) must be at level one
\r
74 before issuing the read request */
\r
75 while (!((FUSE->FUSE_IR & (FUSE_IR_WS | FUSE_IR_RS)) == (FUSE_IR_WS | FUSE_IR_RS)));
\r
76 /* Read fuse values, The fuse states are automatically read on CORE startup and are available for reading in the
\r
77 SR_REG_NB Fuse Status (FUSE_SRx) registers. */
\r
78 fuse = FUSE->FUSE_SR[wordPosition];
\r
79 /* Disable peripheral clock.*/
\r
80 PMC->PMC_PCDR1 = (1 << (ID_FUSE -32 ));
\r
85 * \brief Program fuse vlaue by given word position.
\r
87 * \param data word to be program.
\r
88 * \param wordPosition select the 32-bit word 0 to 9.
\r
91 void FUSE_Write (uint32_t data, uint8_t wordPosition )
\r
93 /* Enable peripheral clock. */
\r
94 PMC->PMC_PCER1 = (1 << (ID_FUSE - 32 ));
\r
95 /* Select the word to write, using the SELW field of the Fuse_Index register (FUSE_IR). */
\r
96 FUSE->FUSE_IR = (FUSE_IR_WSEL(wordPosition));
\r
97 /* Write the word to program in the Fuse_Data register (FUSE_DR).*/
\r
98 FUSE->FUSE_DR = data;
\r
99 /* Check that RS and WS bits of the Fuse_Index register are at level one (no read and
\r
100 no write pending). */
\r
101 while (!((FUSE->FUSE_IR & (FUSE_IR_WS | FUSE_IR_RS)) == (FUSE_IR_WS | FUSE_IR_RS)));
\r
102 /* Write the WRQ bit of the Fuse_Control register (FUSE_CR) to begin the fuse programming. */
\r
103 FUSE->FUSE_CR = FUSE_CR_WRQ | FUSE_CR_KEY_VALID;
\r
104 /* Check the WS bit of FUSE_SRx, when WS has a value of ¡°1¡± the fuse write process
\r
106 while (!((FUSE->FUSE_IR & FUSE_IR_WS) == FUSE_IR_WS));
\r
107 /* Disable peripheral clock. */
\r
108 PMC->PMC_PCDR1 = (1 << (ID_FUSE - 32 ));
\r