]> begriffs open source - freertos/blob - Demo/lwIP_AVR32_UC3/DRIVERS/FLASHC/flashc.h
Add AVR32 port and demo files.
[freertos] / Demo / lwIP_AVR32_UC3 / DRIVERS / FLASHC / flashc.h
1 /* This header file is part of the ATMEL FREERTOS-0.9.0 Release */\r
2 \r
3 /*This file has been prepared for Doxygen automatic documentation generation.*/\r
4 /*! \file *********************************************************************\r
5  *\r
6  * \brief Flash Controller driver .h file.\r
7  *\r
8  * This file defines a useful set of functions for the flash controller\r
9  * on AVR32A devices.\r
10  *\r
11  * - Compiler:           IAR EWAVR32 and GNU GCC for AVR32\r
12  * - Supported devices:  All AVR32A devices.\r
13  *\r
14  * \author               Atmel Corporation: http://www.atmel.com \n\r
15  *                       Support email: avr32@atmel.com\r
16  *\r
17  *****************************************************************************/\r
18 \r
19 /* Copyright (c) 2007, Atmel Corporation All rights reserved.\r
20  *\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
23  *\r
24  * 1. Redistributions of source code must retain the above copyright notice,\r
25  * this list of conditions and the following disclaimer.\r
26  *\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
30  *\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
33  *\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
44  */\r
45 \r
46 \r
47 #ifndef _FLASHC_H_\r
48 #define _FLASHC_H_\r
49 \r
50 #if __GNUC__\r
51 #  include <avr32/io.h>\r
52 #elif __ICCAVR32__\r
53 #  include <avr32/iouc3a0512.h>\r
54 #  include <avr32/uc3a0512.h>\r
55 #else\r
56 #  error Unknown compiler\r
57 #endif\r
58 \r
59 #include "compiler.h"\r
60 \r
61 \r
62 /*! Value returned by function when it completed successfully */\r
63 #define FLASHC_SUCCESS 0\r
64 \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
68 \r
69 /*! Value returned by function when the input paramters are out of range */\r
70 #define FLASHC_INVALID_INPUT 1\r
71 \r
72 \r
73 /*! Get Flash size */\r
74 #if __GNUC__\r
75 __attribute__((__always_inline__))\r
76 #endif\r
77 extern __inline__ unsigned int flashc_get_flash_size(void)\r
78 {\r
79   static const unsigned int FLASHC_SIZE[1 << AVR32_FLASHC_FSR_FSZ_SIZE] =\r
80   {\r
81     32 << 10,\r
82     64 << 10,\r
83     128 << 10,\r
84     256 << 10,\r
85     384 << 10,\r
86     512 << 10,\r
87     768 << 10,\r
88     1024 << 10\r
89   };\r
90 \r
91   return FLASHC_SIZE[Rd_bitfield(AVR32_FLASHC.fsr, AVR32_FLASHC_FSR_FSZ_MASK)];\r
92 }\r
93 \r
94 /*! Get Flash page count */\r
95 #if __GNUC__\r
96 __attribute__((__always_inline__))\r
97 #endif\r
98 extern __inline__ unsigned int flashc_get_page_count(void)\r
99 {\r
100   return flashc_get_flash_size() / AVR32_FLASHC_PAGE_SIZE;\r
101 }\r
102 \r
103 /*! Get Flash page count per region */\r
104 #if __GNUC__\r
105 __attribute__((__always_inline__))\r
106 #endif\r
107 extern __inline__ unsigned int flashc_get_page_count_per_region(void)\r
108 {\r
109   return flashc_get_page_count() / 16;\r
110 }\r
111 \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
115  */\r
116 #if __GNUC__\r
117 __attribute__((__always_inline__))\r
118 #endif\r
119 extern __inline__ void flashc_busy_wait(void)\r
120 {\r
121   while (!Tst_bits(AVR32_FLASHC.fsr, AVR32_FLASHC_FSR_FRDY_MASK));\r
122 }\r
123 \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
127  */\r
128 #if __GNUC__\r
129 __attribute__((__always_inline__))\r
130 #endif\r
131 extern __inline__ Bool flashc_is_security_active(void)\r
132 {\r
133   return Tst_bits(AVR32_FLASHC.fsr, AVR32_FLASHC_FSR_SECURITY_MASK);\r
134 }\r
135 \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
140  */\r
141 extern U32 *flashc_memcpy(U32 *s1, const U32 *s2, const U32 n);\r
142 \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
146  */\r
147 extern int flashc_set_wait_state(U16 ws);\r
148 \r
149 /*! \brief Page write number n. Assuming page bubuffer is already loaded.\r
150  * \param n Page number\r
151  */\r
152 extern void flashc_page_write_n(U16 n);\r
153 \r
154 /*! \brief Page write\r
155  * Assuming the page address is already loaded\r
156  */\r
157 extern void flashc_page_write(U16 page_n);\r
158 \r
159 /*! \brief Clear page buffer\r
160  */\r
161 extern void flashc_clear_page_buffer(void);\r
162 \r
163 /*! \brief Page erase\r
164  * Assuming the page address is already loaded\r
165  */\r
166 extern void flashc_erase_page(U16 page_n);\r
167 \r
168 /*! \brief Erase all Pages\r
169  */\r
170 extern void flashc_erase_all(void);\r
171 \r
172 /*! \brief Erase a page and check if erase is OK\r
173  */\r
174 extern int flashc_erase_page_and_check(U16 page_n);\r
175 \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
179  */\r
180 extern void flashc_page_copy_write(U32 *Dest, const U32 *Src) ;\r
181 \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
184  *\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
189  */\r
190 extern int flash_wr_block(U32 * src, U32 dst, U32 n);\r
191 \r
192 \r
193 #endif /* #ifndef _FLASHC_H_*/\r