1 /* This header file is part of the ATMEL FREERTOS-0.9.0 Release */
\r
3 /*This file has been prepared for Doxygen automatic documentation generation.*/
\r
4 /*! \file *********************************************************************
\r
6 * \brief Flash Controller driver .h file.
\r
8 * This file defines a useful set of functions for the flash controller
\r
11 * - Compiler: IAR EWAVR32 and GNU GCC for AVR32
\r
12 * - Supported devices: All AVR32A devices.
\r
14 * \author Atmel Corporation: http://www.atmel.com \n
\r
15 * Support email: avr32@atmel.com
\r
17 *****************************************************************************/
\r
19 /* Copyright (c) 2007, Atmel Corporation All rights reserved.
\r
21 * Redistribution and use in source and binary forms, with or without
\r
22 * modification, are permitted provided that the following conditions are met:
\r
24 * 1. Redistributions of source code must retain the above copyright notice,
\r
25 * this list of conditions and the following disclaimer.
\r
27 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
28 * this list of conditions and the following disclaimer in the documentation
\r
29 * and/or other materials provided with the distribution.
\r
31 * 3. The name of ATMEL may not be used to endorse or promote products derived
\r
32 * from this software without specific prior written permission.
\r
34 * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
\r
35 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
36 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
\r
37 * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
\r
38 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
\r
39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
\r
40 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
\r
41 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
42 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
\r
43 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
51 # include <avr32/io.h>
\r
53 # include <avr32/iouc3a0512.h>
\r
54 # include <avr32/uc3a0512.h>
\r
56 # error Unknown compiler
\r
59 #include "compiler.h"
\r
62 /*! Value returned by function when it completed successfully */
\r
63 #define FLASHC_SUCCESS 0
\r
65 /*! Value returned by function when it was unable to complete successfully
\r
66 for some unspecified reason */
\r
67 #define FLASHC_FAILURE -1
\r
69 /*! Value returned by function when the input paramters are out of range */
\r
70 #define FLASHC_INVALID_INPUT 1
\r
73 /*! Get Flash size */
\r
75 __attribute__((__always_inline__))
\r
77 extern __inline__ unsigned int flashc_get_flash_size(void)
\r
79 static const unsigned int FLASHC_SIZE[1 << AVR32_FLASHC_FSR_FSZ_SIZE] =
\r
91 return FLASHC_SIZE[Rd_bitfield(AVR32_FLASHC.fsr, AVR32_FLASHC_FSR_FSZ_MASK)];
\r
94 /*! Get Flash page count */
\r
96 __attribute__((__always_inline__))
\r
98 extern __inline__ unsigned int flashc_get_page_count(void)
\r
100 return flashc_get_flash_size() / AVR32_FLASHC_PAGE_SIZE;
\r
103 /*! Get Flash page count per region */
\r
105 __attribute__((__always_inline__))
\r
107 extern __inline__ unsigned int flashc_get_page_count_per_region(void)
\r
109 return flashc_get_page_count() / 16;
\r
112 /*! Wait flash ready status, the application must wait before running a new command.
\r
113 * Warning: Flash status register (FCR) is read, and error status may be automatically
\r
114 * cleared when reading FCR.
\r
117 __attribute__((__always_inline__))
\r
119 extern __inline__ void flashc_busy_wait(void)
\r
121 while (!Tst_bits(AVR32_FLASHC.fsr, AVR32_FLASHC_FSR_FRDY_MASK));
\r
124 /*! Check if security bit is active.
\r
125 * \warning: Flash status register (FCR) is read, and error status may be automatically
\r
126 * cleared when reading FCR.
\r
129 __attribute__((__always_inline__))
\r
131 extern __inline__ Bool flashc_is_security_active(void)
\r
133 return Tst_bits(AVR32_FLASHC.fsr, AVR32_FLASHC_FSR_SECURITY_MASK);
\r
136 /*! \brief Memcopy function
\r
137 * \param *s1 destination
\r
138 * \param *s2 source
\r
139 * \param n number of words to copy
\r
141 extern U32 *flashc_memcpy(U32 *s1, const U32 *s2, const U32 n);
\r
143 /*! \brief Set number of wait state
\r
144 * \param ws 0 if for no-wait state, for 1 wait-state
\r
145 * \return FLASHC_SUCCESS, FLASHC_INVALID_INPUT or FLASHC_FAILURE
\r
147 extern int flashc_set_wait_state(U16 ws);
\r
149 /*! \brief Page write number n. Assuming page bubuffer is already loaded.
\r
150 * \param n Page number
\r
152 extern void flashc_page_write_n(U16 n);
\r
154 /*! \brief Page write
\r
155 * Assuming the page address is already loaded
\r
157 extern void flashc_page_write(U16 page_n);
\r
159 /*! \brief Clear page buffer
\r
161 extern void flashc_clear_page_buffer(void);
\r
163 /*! \brief Page erase
\r
164 * Assuming the page address is already loaded
\r
166 extern void flashc_erase_page(U16 page_n);
\r
168 /*! \brief Erase all Pages
\r
170 extern void flashc_erase_all(void);
\r
172 /*! \brief Erase a page and check if erase is OK
\r
174 extern int flashc_erase_page_and_check(U16 page_n);
\r
176 /*! \brief Page load and write
\r
177 * \warning Dest is a FLASH address at a page boundary
\r
178 * (assuming the page is already erased)
\r
180 extern void flashc_page_copy_write(U32 *Dest, const U32 *Src) ;
\r
182 /*! \brief This function allows to write up to 65535 bytes in the flash memory.
\r
183 * This function manages alignement issue (byte and page alignements).
\r
185 * \param *src Address of data to write.
\r
186 * \param dst Start address in flash memory where write data
\r
187 * \param n Number of word to write
\r
188 * \return FLASHC_SUCCESS or FLASHC_FAILURE
\r
190 extern int flash_wr_block(U32 * src, U32 dst, U32 n);
\r
193 #endif /* #ifndef _FLASHC_H_*/
\r