]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A5_SAMA5D3x_Xplained_IAR/AtmelFiles/libchip_sama5d3x/source/fuse.c
Start of SAMA5D3 XPlained demo.
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D3x_Xplained_IAR / AtmelFiles / libchip_sama5d3x / source / fuse.c
1 /* ----------------------------------------------------------------------------\r
2  *         ATMEL Microcontroller Software Support\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2011, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\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
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\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
16  *\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
28  */\r
29 \r
30  \r
31 /** \addtogroup fuse_module Working with FUSE\r
32  * The Fuse driver provides the Interface for configuration the FUSE \r
33  * peripheral.\r
34  *\r
35  * For more accurate information, please look at the FUSE section of the\r
36  * Datasheet.\r
37  *\r
38  * Related files :\n\r
39  * \ref fuse.c\n\r
40  * \ref fuse.h.\n\r
41 */\r
42 /*@{*/\r
43 /*@}*/\r
44 \r
45 /**\r
46  * \file\r
47  *\r
48  * Implementation of FUSE controller.\r
49  *\r
50  */\r
51 /*------------------------------------------------------------------------------\r
52  *         Headers\r
53  *------------------------------------------------------------------------------*/\r
54 #include "chip.h"\r
55 \r
56 /*------------------------------------------------------------------------------\r
57  *         Exported functions\r
58  *------------------------------------------------------------------------------*/\r
59 \r
60  /**\r
61  * \brief Read fuse vlaue by given word position. \r
62  *\r
63  * \param wordPosition  select the 32-bit word 0 to 9.\r
64  */\r
65 \r
66 uint32_t FUSE_Read (uint8_t wordPosition )\r
67 {\r
68     uint32_t fuse;\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
81     return fuse;\r
82 }\r
83 \r
84 /**\r
85  * \brief Program fuse vlaue by given word position. \r
86  *\r
87  * \param data  word to be program.\r
88  * \param wordPosition  select the 32-bit word 0 to 9.\r
89  */\r
90 \r
91 void FUSE_Write (uint32_t data, uint8_t wordPosition )\r
92 {\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
105     is over. */\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
109 }\r