1 /**
2  * @file xmc_flash.h
3  * @date 2019-05-06
4  *
5  * @cond
6  *********************************************************************************************************************
7  * XMClib v2.1.24 - XMC Peripheral Driver Library
8  *
9  * Copyright (c) 2015-2019, Infineon Technologies AG
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without modification,are permitted provided that the
13  * following conditions are met:
14  *
15  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following
16  * disclaimer.
17  *
18  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
19  * disclaimer in the documentation and/or other materials provided with the distribution.
20  *
21  * Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE  FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * To improve the quality of the software, users are encouraged to share modifications, enhancements or bug fixes with
33  * Infineon Technologies AG dave@infineon.com).
34  *********************************************************************************************************************
35  *
36  * Change History
37  * --------------
38  *
39  * 2014-12-10:
40  *     - Initial <br>
41  * 2015-02-20:
42  *     - Updated for Documentation related changes<br>
43  * 2015-06-20:
44  *     - Removed version macros and declaration of GetDriverVersion API
45  * 2019-05-06:
46  *     - Moved definitions of XMC_FLASH_ProgramPage() and XMC_FLASH_EraseSector() to xmc1_flash.h and xmc4_flash.h
47  * @endcond
48  *
49  */
50 
51 
52 #ifndef XMC_FLASH_H
53 #define XMC_FLASH_H
54 
55 /*********************************************************************************************************************
56  * HEADER FILES
57  ********************************************************************************************************************/
58 
59 #include "xmc_common.h"
60 
61 #if UC_FAMILY == XMC1
62  #include "xmc1_flash.h"
63 #endif
64 
65 #if UC_FAMILY == XMC4
66  #include "xmc4_flash.h"
67 #endif
68 
69 /**
70  * @addtogroup XMClib XMC Peripheral Library
71  * @{
72  */
73 
74 /**
75  * @addtogroup FLASH
76  * @brief Flash driver for XMC microcontroller family.
77  *
78  * Flash is a non volatile memory module used to store instruction code or constant data.
79  * The flash low level driver provides support to the following functionalities of flash memory.<BR>
80  * <OL>
81  * \if XMC4
82  * <LI>Provides function to program a page. ( XMC_FLASH_ProgramPage() )</LI><BR>
83  * <LI>Provides functions to support read and write protection. ( XMC_FLASH_InstallProtection(),
84  * XMC_FLASH_ConfirmProtection(), XMC_FLASH_VerifyReadProtection(), XMC_FLASH_VerifyWriteProtection() ) </LI><BR>
85  * <LI>Provides function to erase sector. ( XMC_FLASH_EraseSector() ) </LI><BR>
86  * \endif
87  * \if XMC1
88  * <LI>Provides functions to program and verify pages. ( XMC_FLASH_ProgramPage(), XMC_FLASH_ProgramPages()
89  *  XMC_FLASH_ProgramVerifyPage() )</LI><BR>
90  * <LI>Provides functions to write and verify blocks. ( XMC_FLASH_WriteBlocks(), XMC_FLASH_VerifyBlocks() )</LI><BR>
91  * <LI>Provides functions to read data in terms of word and blocks. ( XMC_FLASH_ReadBlocks(), XMC_FLASH_ReadWord() )
92  * </LI><BR>
93  * <LI>Provides function to erase page. ( XMC_FLASH_ErasePage() ) </LI><BR>
94  * \endif
95  * </OL>
96  * @{
97  */
98 
99 /*******************************************************************************
100  * API PROTOTYPE
101  *******************************************************************************/
102 #ifdef __cplusplus
103 extern "C" {
104 #endif
105 
106 /**
107  *
108  * @param None
109  *
110  * @return None
111  *
112  * \par<b>Description:</b><br>
113  * \if XMC1
114  * Clears the previous error status by reseting the ECC and VERR error status bits of NVMSTATUS register.\n\n
115  * Call this API before starting any flash programming / erase related APIs to ensure all previous errors are cleared.
116  * \endif
117  * \if XMC4
118  * Clears the previous error status by reseting the FSR status register.\n\n  Call this API before starting any flash
119  * programming / erase related APIs to ensure all previous errors are cleared.
120  * \endif
121  *
122  * \par<b>Related APIs:</b><BR>
123  * None
124  *
125  */
126 void XMC_FLASH_ClearStatus(void);
127 
128 /**
129  *
130  * @param None
131  *
132  * @return uint32_t Status of the previous flash operation.
133  *
134  * \par<b>Description:</b><br>
135  * \if XMC1
136  * Informs the status of flash by reading the NVMSTATUS register.\n\n  It indicates the ECC, VERR(verification error),
137  * WRPERR (Write protocol error) errors as well as the current flash state. After calling the flash read/write/erase
138  * operation related APIs, call this API to get the verification status. The return value of this API shall be checked
139  * against the members of @ref XMC_FLASH_STATUS_t enumeration to get the relevant status.
140  * \endif
141  * \if XMC4
142  * Informs the status of flash by reading the FSR register.\n\n  It indicates the error status such as PFOPER, SQER,
143  * PROER, PFDBER, ORIER, VER errors as well as the current flash state. After calling the flash read/write/erase
144  * operation related APIs, call this API to verify flash status. The return value of this API shall be checked against
145  * the members of @ref XMC_FLASH_STATUS_t enumeration to get the relevant status.
146  * \endif
147  *
148  * \par<b>Related APIs:</b><BR>
149  * None
150  *
151  */
152 uint32_t XMC_FLASH_GetStatus(void);
153 
154 /**
155  *
156  * @param event_msk ORed values of @ref XMC_FLASH_EVENT_t enumeration
157  *
158  * @return None
159  *
160  * \par<b>Description:</b><br>
161  * Enables the particular flash events as specified in the input parameter.\n
162  *
163  * \par<b>Related APIs:</b><BR>
164  * XMC_FLASH_DisableEvent()\n\n\n
165  *
166  */
167 void XMC_FLASH_EnableEvent(const uint32_t event_msk);
168 
169 /**
170  *
171  * @param event_msk ORed values of @ref XMC_FLASH_EVENT_t enumeration
172  *
173  * @return None
174  *
175  * \par<b>Description:</b><br>
176  * Disables the particular flash events as specified in the input parameter.\n
177  *
178  * \par<b>Related APIs:</b><BR>
179  * XMC_FLASH_EnableEvent()\n\n\n
180  *
181  */
182 void XMC_FLASH_DisableEvent(const uint32_t event_msk);
183 
184 /**
185  *
186  * @param None
187  *
188  * @return true if flash is in busy state else returns \a false.
189  *
190  * \par<b>Description:</b><br>
191  * Checks whether flash is in busy state or not.\n\n  It is checked by calling the XMC_FLASH_GetStatus() API internally.
192  * Refer XMC_FLASH_GetStatus() for more details.\n
193  *
194  * \par<b>Related APIs:</b><BR>
195  * XMC_FLASH_GetStatus()\n\n\n
196  *
197  */
XMC_FLASH_IsBusy(void)198 __STATIC_INLINE bool XMC_FLASH_IsBusy(void)
199 {
200   return (bool)(XMC_FLASH_GetStatus() & XMC_FLASH_STATUS_BUSY);
201 }
202 
203 #ifdef __cplusplus
204 }
205 #endif
206 
207 /**
208  * @}
209  */
210 
211 /**
212  * @}
213  */
214 
215 #endif
216 
217