Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | /******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
2 | * File Name : 91x_fmi.c |
||
3 | * Author : MCD Application Team |
||
4 | * Date First Issued : 05/18/2006 : Version 1.0 |
||
5 | * Description : This file provides all the FMI software functions. |
||
6 | ******************************************************************************** |
||
7 | * History: |
||
8 | * 05/22/2007 : Version 1.2 |
||
9 | * 05/24/2006 : Version 1.1 |
||
10 | * 05/18/2006 : Version 1.0 |
||
11 | ******************************************************************************** |
||
12 | * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH |
||
13 | * CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS |
||
14 | * A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT |
||
15 | * OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT |
||
16 | * OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION |
||
17 | * CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
||
18 | *******************************************************************************/ |
||
19 | |||
20 | |||
21 | /* Standard include ----------------------------------------------------------*/ |
||
22 | #include "91x_fmi.h" |
||
23 | |||
24 | /* Include of other module interface headers ---------------------------------*/ |
||
25 | /* Local includes ------------------------------------------------------------*/ |
||
26 | /* Private typedef -----------------------------------------------------------*/ |
||
27 | /* Private define ------------------------------------------------------------*/ |
||
28 | |||
29 | #define TIMEOUT 0xFFFFFF /* Timeout value */ |
||
30 | |||
31 | /* Private macro -------------------------------------------------------------*/ |
||
32 | /* Private variables ---------------------------------------------------------*/ |
||
33 | /* Private function prototypes -----------------------------------------------*/ |
||
34 | /* Interface functions -------------------------------------------------------*/ |
||
35 | /* Private functions ---------------------------------------------------------*/ |
||
36 | |||
37 | |||
38 | /******************************************************************************* |
||
39 | * Function Name : FMI_BankRemapConfig |
||
40 | * Description : Configure the addresses and sizes of bank 0 and bank 1. |
||
41 | * Input1 : FMI_BootBankSize: specifies the boot bank size. |
||
42 | * This parameter can be one of the following values: |
||
43 | * - 0x0: 32KBytes. |
||
44 | * - 0x1: 64KBytes. |
||
45 | * - 0x2: 128KBytes. |
||
46 | * - 0x3: 256KBytes. |
||
47 | * - 0x4: 512KBytes. |
||
48 | * .... |
||
49 | * - 0xB: 64MBytes. |
||
50 | * Input2 : FMI_NonBootBankSize: specifies the non boot bank size. |
||
51 | * This parameter can be one of the following values: |
||
52 | * - 0x0: 8KBytes. |
||
53 | * - 0x1: 16KBytes. |
||
54 | * - 0x2: 32KBytes. |
||
55 | * - 0x3: 64KBytes. |
||
56 | * .... |
||
57 | * - 0xD: 64MBytes. |
||
58 | * Input3 : FMI_BootBankAddress: specifies the address of the boot bank. |
||
59 | * Input4 : FMI_NonBootBankAddress: specifies the address of the non |
||
60 | * boot bank. |
||
61 | * Output : None |
||
62 | * Return : None |
||
63 | *******************************************************************************/ |
||
64 | void FMI_BankRemapConfig(u8 FMI_BootBankSize, u8 FMI_NonBootBankSize, \ |
||
65 | u32 FMI_BootBankAddress, u32 FMI_NonBootBankAddress) |
||
66 | { |
||
67 | FMI->BBSR = FMI_BootBankSize; |
||
68 | FMI->NBBSR = FMI_NonBootBankSize; |
||
69 | FMI->BBADR = (FMI_BootBankAddress >> 2); |
||
70 | FMI->NBBADR = (FMI_NonBootBankAddress >> 2); |
||
71 | FMI->CR |= 0x18; /* Enable bank 1 */ |
||
72 | } |
||
73 | |||
74 | /******************************************************************************* |
||
75 | * Function Name : FMI_Config |
||
76 | * Description : Configure the FMI. |
||
77 | * Input1 : FMI_ReadWaitState: specifies the needed read wait states. |
||
78 | * This parameter can be one of the following values: |
||
79 | * - FMI_READ_WAIT_STATE_1: One read wait state. |
||
80 | * - FMI_READ_WAIT_STATE_2: Two read wait states. |
||
81 | * - FMI_READ_WAIT_STATE_3: Three read wait states. |
||
82 | * Input2 : FMI_WriteWaitState: specifies the needed write wait states. |
||
83 | * This parameter can be one of the following values: |
||
84 | * - FMI_WRITE_WAIT_STATE_1: One write wait state. |
||
85 | * - FMI_WRITE_WAIT_STATE_2: Two write wait states. |
||
86 | * Input3 : FMI_PWD: specifies the power down mode status. |
||
87 | * This parameter can be one of the following values: |
||
88 | * - FMI_PWD_ENABLE: Enable the PWD. |
||
89 | * - FMI_PWD_DISABLE: Disable the PWD. |
||
90 | * Input4 : FMI_LVDEN: specifies the low voltage detector status. |
||
91 | * This parameter can be one of the following values: |
||
92 | * - FMI_LVD_ENABLE: Enable the LVD. |
||
93 | * - FMI_LVD_DISABLE: Disable the LVD. |
||
94 | * Input5 : FMI_FreqRange: specifies the working frequency range. |
||
95 | * This parameter can be one of the following values: |
||
96 | * - FMI_FREQ_LOW: Low working frequency (up to 66MHz). |
||
97 | * - FMI_FREQ_HIGH: High working frequency (above 66MHz) . |
||
98 | * Output : None |
||
99 | * Return : None |
||
100 | *******************************************************************************/ |
||
101 | void FMI_Config(u16 FMI_ReadWaitState, u32 FMI_WriteWaitState, u16 FMI_PWD,\ |
||
102 | u16 FMI_LVDEN, u16 FMI_FreqRange) |
||
103 | { |
||
104 | /* Configure the write wait state value */ |
||
105 | if (FMI_WriteWaitState == FMI_WRITE_WAIT_STATE_1) |
||
106 | { |
||
107 | FMI->CR |= FMI_WRITE_WAIT_STATE_1; |
||
108 | } |
||
109 | else |
||
110 | { |
||
111 | FMI->CR &= FMI_WRITE_WAIT_STATE_0; |
||
112 | } |
||
113 | |||
114 | /* Write a write flash configuration register command */ |
||
115 | *(vu16 *)FMI_BANK_1 = 0x60; |
||
116 | |||
117 | /* Configure the flash configuration register */ |
||
118 | *(vu16 *)(FMI_BANK_1|FMI_ReadWaitState|FMI_PWD|FMI_LVDEN|FMI_FreqRange) = 0x03; |
||
119 | } |
||
120 | |||
121 | /******************************************************************************* |
||
122 | * Function Name : FMI_EraseSector |
||
123 | * Description : Erase the needed sector. |
||
124 | * Input : FMI_Sector: specifies the sector to be erased. |
||
125 | * This parameter can be one of the following values: |
||
126 | * - FMI_B0S0: FMI bank 0 sector 0. |
||
127 | * - FMI_B0S1: FMI bank 0 sector 1. |
||
128 | * - FMI_B0S2: FMI bank 0 sector 2. |
||
129 | * - FMI_B0S3: FMI bank 0 sector 3. |
||
130 | * - FMI_B0S4: FMI bank 0 sector 4. |
||
131 | * - FMI_B0S5: FMI bank 0 sector 5. |
||
132 | * - FMI_B0S6: FMI bank 0 sector 6. |
||
133 | * - FMI_B0S7: FMI bank 0 sector 7. |
||
134 | * - FMI_B1S0: FMI bank 1 sector 0. |
||
135 | * - FMI_B1S1: FMI bank 1 sector 1. |
||
136 | * - FMI_B1S2: FMI bank 1 sector 2. |
||
137 | * - FMI_B1S3: FMI bank 1 sector 3. |
||
138 | * Output : None |
||
139 | * Return : None |
||
140 | *******************************************************************************/ |
||
141 | void FMI_EraseSector(vu32 FMI_Sector) |
||
142 | { |
||
143 | /* Write an erase set-up command to the sector */ |
||
144 | *(vu16 *)FMI_Sector = 0x20; |
||
145 | |||
146 | /* Write an erase confirm command to the sector */ |
||
147 | *(vu16 *)FMI_Sector = 0xD0; |
||
148 | } |
||
149 | |||
150 | /******************************************************************************* |
||
151 | * Function Name : FMI_EraseBank |
||
152 | * Description : Erase the needed bank. |
||
153 | * Input : FMI_Bank: specifies the bank to be erased. |
||
154 | * This parameter can be one of the following values: |
||
155 | * - FMI_BANK_0: FMI bank 0. |
||
156 | * - FMI_BANK_1: FMI bank 1. |
||
157 | * Output : None |
||
158 | * Return : None |
||
159 | *******************************************************************************/ |
||
160 | void FMI_EraseBank(vu32 FMI_Bank) |
||
161 | { |
||
162 | /* Write a bank erase set-up command to the bank */ |
||
163 | *(vu16 *)FMI_Bank = 0x80; |
||
164 | |||
165 | /* Write an erase confirm command to the sector */ |
||
166 | *(vu16 *)FMI_Bank = 0xD0; |
||
167 | } |
||
168 | |||
169 | /******************************************************************************* |
||
170 | * Function Name : FMI_WriteHalfWord |
||
171 | * Description : Write a halfword to the needed Flash memory address. |
||
172 | * Input 1 : FMI_Address: specifies the address offset where the data will |
||
173 | * be written. |
||
174 | * Input 2 : FMI_Data: the needed data. |
||
175 | * Output : None |
||
176 | * Return : None |
||
177 | *******************************************************************************/ |
||
178 | void FMI_WriteHalfWord(u32 FMI_Address, u16 FMI_Data) |
||
179 | { |
||
180 | /* Write a program command to the sector to be written */ |
||
181 | *(vu16 *)(FMI_Address & 0xFFFFFFFC) = 0x40; |
||
182 | |||
183 | /* Write the halfword to the destination address */ |
||
184 | *(vu16 *)FMI_Address = FMI_Data; |
||
185 | } |
||
186 | |||
187 | /******************************************************************************* |
||
188 | * Function Name : FMI_WriteOTPHalfWord |
||
189 | * Description : Write a halfword to the needed OTP sector address. |
||
190 | * Input 1 : FMI_OTPHWAddress: specifies the halfword address offset |
||
191 | * where the data will be written. |
||
192 | * This parameter can be one of the following values: |
||
193 | * - FMI_OTP_LOW_HALFWORD_0: OTP Low halfword 0. |
||
194 | * - FMI_OTP_HIGH_HALFWORD_0: OTP High halfword 0. |
||
195 | * - FMI_OTP_LOW_HALFWORD_1: OTP Low halfword 1. |
||
196 | * - FMI_OTP_HIGH_HALFWORD_1: OTP High halfword 1. |
||
197 | * - FMI_OTP_LOW_HALFWORD_2: OTP Low halfword 2. |
||
198 | * - FMI_OTP_HIGH_HALFWORD_2: OTP High halfword 2. |
||
199 | * - FMI_OTP_LOW_HALFWORD_3: OTP Low halfword 3. |
||
200 | * - FMI_OTP_HIGH_HALFWORD_3: OTP High halfword 3. |
||
201 | * - FMI_OTP_LOW_HALFWORD_4: OTP Low halfword 4. |
||
202 | * - FMI_OTP_HIGH_HALFWORD_4: OTP High halfword 4. |
||
203 | * - FMI_OTP_LOW_HALFWORD_5: OTP Low halfword 5. |
||
204 | * - FMI_OTP_HIGH_HALFWORD_5: OTP High halfword 5. |
||
205 | * - FMI_OTP_LOW_HALFWORD_6: OTP Low halfword 6. |
||
206 | * - FMI_OTP_HIGH_HALFWORD_6: OTP High halfword 6. |
||
207 | * - FMI_OTP_LOW_HALFWORD_7: OTP Low halfword 7. |
||
208 | * - FMI_OTP_HIGH_HALFWORD_7: OTP High halfword 7. |
||
209 | * Input 2 : FMI_OTPData: The needed OTP data. |
||
210 | * Output : None |
||
211 | * Return : None |
||
212 | *******************************************************************************/ |
||
213 | void FMI_WriteOTPHalfWord(u8 FMI_OTPHWAddress, u16 FMI_OTPData) |
||
214 | { |
||
215 | /* Write a write OTP command to the needed address */ |
||
216 | *(vu16 *)(FMI_BANK_1) = 0xC0; |
||
217 | |||
218 | /* Write the halfword to the destination address */ |
||
219 | *(vu16 *)(FMI_BANK_1 + FMI_OTPHWAddress) = FMI_OTPData; |
||
220 | } |
||
221 | |||
222 | /******************************************************************************* |
||
223 | * Function Name : FMI_ReadWord |
||
224 | * Description : Read the correspondent data. |
||
225 | * Input : FMI_Address: specifies the needed address. |
||
226 | * Output : None |
||
227 | * Return : The data contained in the specified address. |
||
228 | *******************************************************************************/ |
||
229 | u32 FMI_ReadWord(u32 FMI_Address) |
||
230 | { |
||
231 | return(*(u32*)FMI_Address); |
||
232 | } |
||
233 | |||
234 | /******************************************************************************* |
||
235 | * Function Name : FMI_ReadOTPData |
||
236 | * Description : Read data from the OTP sector. |
||
237 | * Input : FMI_OTPAddress: specifies the address of the data to be read. |
||
238 | * This parameter can be one of the following values: |
||
239 | * - FMI_OTP_WORD_0: FMI bank 0 sector 0. |
||
240 | * - FMI_OTP_WORD_1: FMI bank 0 sector 1. |
||
241 | * - FMI_OTP_WORD_2: FMI bank 0 sector 2. |
||
242 | * - FMI_OTP_WORD_3: FMI bank 0 sector 3. |
||
243 | * - FMI_OTP_WORD_4: FMI bank 0 sector 4. |
||
244 | * - FMI_OTP_WORD_5: FMI bank 0 sector 5. |
||
245 | * - FMI_OTP_WORD_6: FMI bank 0 sector 6. |
||
246 | * - FMI_OTP_WORD_7: FMI bank 0 sector 7. |
||
247 | * Output : None |
||
248 | * Return : The needed OTP words. |
||
249 | *******************************************************************************/ |
||
250 | u32 FMI_ReadOTPData(u8 FMI_OTPAddress) |
||
251 | { |
||
252 | u32 OTP_Data = 0x0; |
||
253 | /* write a read OTP sector command */ |
||
254 | *(vu16 *)(FMI_BANK_1) = 0x98; |
||
255 | |||
256 | /* Read the correspondent data */ |
||
257 | OTP_Data = (*(vu32*)(FMI_BANK_1 + FMI_OTPAddress)); |
||
258 | |||
259 | /* Write a read array command */ |
||
260 | *(vu16 *)(FMI_BANK_1) = 0xFF; |
||
261 | |||
262 | return OTP_Data; |
||
263 | } |
||
264 | |||
265 | /******************************************************************************* |
||
266 | * Function Name : FMI_GetFlagStatus |
||
267 | * Description : Check whether the specified FMI flag is set or not. |
||
268 | * Input1 : FMI_Flag: flag to check. |
||
269 | * This parameter can be one of the following values: |
||
270 | * - FMI_FLAG_SPS: Sector Protection Status Flag. |
||
271 | * - FMI_FLAG_PSS: Program Suspend Status Flag. |
||
272 | * - FMI_FLAG_PS: Program Status Flag. |
||
273 | * - FMI_FLAG_ES: Erase Status Flag. |
||
274 | * - FMI_FLAG_ESS: Erase Suspend Status Flag. |
||
275 | * - FMI_FLAG_PECS: FPEC Status Flag. |
||
276 | * Input2 : FMI_Bank: specifies the needed bank. |
||
277 | * This parameter can be one of the following values: |
||
278 | * - FMI_BANK_0: FMI bank 0. |
||
279 | * - FMI_BANK_1: FMI bank 1. |
||
280 | * Output : None |
||
281 | * Return : None |
||
282 | *******************************************************************************/ |
||
283 | FlagStatus FMI_GetFlagStatus(u8 FMI_Flag, vu32 FMI_Bank) |
||
284 | { |
||
285 | u16 FMI_Status_Register = 0; |
||
286 | |||
287 | /* Write a read status register command */ |
||
288 | *(vu16 *)FMI_Bank = 0x70; |
||
289 | |||
290 | /* Wait until operation completion */ |
||
291 | while(!((*(vu16 *)FMI_Bank) & 0x80)); |
||
292 | |||
293 | /* Read the status register */ |
||
294 | FMI_Status_Register = *(vu16 *)FMI_Bank; |
||
295 | |||
296 | /* Write a read array command */ |
||
297 | *(vu16 *)FMI_Bank = 0xFF; |
||
298 | |||
299 | if((FMI_Status_Register & FMI_Flag) != RESET) |
||
300 | { |
||
301 | return SET; |
||
302 | } |
||
303 | else |
||
304 | { |
||
305 | return RESET; |
||
306 | } |
||
307 | } |
||
308 | |||
309 | /******************************************************************************* |
||
310 | * Function Name : FMI_GetReadWaitStateValue |
||
311 | * Description : Get the current Read wait state value. |
||
312 | * Input : None |
||
313 | * Output : None |
||
314 | * Return : The current read wait states value. |
||
315 | *******************************************************************************/ |
||
316 | u16 FMI_GetReadWaitStateValue(void) |
||
317 | { |
||
318 | u16 FMI_Configuration_Register = 0; |
||
319 | /* Write a read flash configuration register command */ |
||
320 | *(vu16 *)FMI_BANK_1 = 0x90; |
||
321 | |||
322 | /* Read the flash configuration register */ |
||
323 | FMI_Configuration_Register = *(vu16 *)(FMI_BANK_1 + 0x14); |
||
324 | |||
325 | /* Write a read array command */ |
||
326 | *(vu16 *)FMI_BANK_1 = 0xFF; |
||
327 | |||
328 | FMI_Configuration_Register = ((FMI_Configuration_Register>>11) + 1) & 0x3; |
||
329 | |||
330 | /* Return the wait states value */ |
||
331 | return FMI_Configuration_Register; |
||
332 | } |
||
333 | |||
334 | /******************************************************************************* |
||
335 | * Function Name : FMI_GetWriteWaitStateValue |
||
336 | * Description : Get the current write wait state value. |
||
337 | * Input : None |
||
338 | * Output : None |
||
339 | * Return : The current write wait states value. |
||
340 | *******************************************************************************/ |
||
341 | u16 FMI_GetWriteWaitStateValue(void) |
||
342 | { |
||
343 | return ((u16)((FMI->CR & 0x100) >> 8)); |
||
344 | } |
||
345 | |||
346 | /******************************************************************************* |
||
347 | * Function Name : FMI_SuspendEnable |
||
348 | * Description : Suspend command enable. |
||
349 | * Input : FMI_Bank: specifies the bank to be suspended. |
||
350 | * This parameter can be one of the following values: |
||
351 | * - FMI_BANK_0: FMI bank 0. |
||
352 | * - FMI_BANK_1: FMI bank 1. |
||
353 | * Output : None |
||
354 | * Return : None |
||
355 | *******************************************************************************/ |
||
356 | void FMI_SuspendEnable(vu32 FMI_Bank) |
||
357 | { |
||
358 | /* Write a suspend command to the bank */ |
||
359 | *(vu16 *)FMI_Bank = 0xB0; |
||
360 | } |
||
361 | |||
362 | /******************************************************************************* |
||
363 | * Function Name : FMI_ResumeEnable |
||
364 | * Description : Resume the suspended command. |
||
365 | * Input : FMI_Bank: specifies the suspended bank. |
||
366 | * This parameter can be one of the following values: |
||
367 | * - FMI_BANK_0: FMI bank 0. |
||
368 | * - FMI_BANK_1: FMI bank 1. |
||
369 | * Output : None |
||
370 | * Return : None |
||
371 | *******************************************************************************/ |
||
372 | void FMI_ResumeEnable(vu32 FMI_Bank) |
||
373 | { |
||
374 | /* Write a resume command to the bank */ |
||
375 | *(vu16 *)FMI_Bank = 0xD0; |
||
376 | } |
||
377 | |||
378 | /******************************************************************************* |
||
379 | * Function Name : FMI_ClearFlag |
||
380 | * Description : Clear the FMI Flags on the correspondent bank. |
||
381 | * Input : FMI_Bank: specifies the needed bank. |
||
382 | * This parameter can be one of the following values: |
||
383 | * - FMI_BANK_0: FMI bank 0. |
||
384 | * - FMI_BANK_1: FMI bank 1. |
||
385 | * Output : None |
||
386 | * Return : None |
||
387 | *******************************************************************************/ |
||
388 | void FMI_ClearFlag(vu32 FMI_Bank) |
||
389 | { |
||
390 | /* Write a clear status register command */ |
||
391 | *(vu16 *)FMI_Bank = 0x50; |
||
392 | } |
||
393 | |||
394 | /******************************************************************************* |
||
395 | * Function Name : FMI_WriteProtectionCmd |
||
396 | * Description : Enable or disable the write protection for the needed sector. |
||
397 | * Input1 : FMI_Sector: specifies the sector to be protected or |
||
398 | * unprotected. |
||
399 | * This parameter can be one of the following values: |
||
400 | * - FMI_B0S0: FMI bank 0 sector 0. |
||
401 | * - FMI_B0S1: FMI bank 0 sector 1. |
||
402 | * - FMI_B0S2: FMI bank 0 sector 2. |
||
403 | * - FMI_B0S3: FMI bank 0 sector 3. |
||
404 | * - FMI_B0S4: FMI bank 0 sector 4. |
||
405 | * - FMI_B0S5: FMI bank 0 sector 5. |
||
406 | * - FMI_B0S6: FMI bank 0 sector 6. |
||
407 | * - FMI_B0S7: FMI bank 0 sector 7. |
||
408 | * - FMI_B1S0: FMI bank 1 sector 0. |
||
409 | * - FMI_B1S1: FMI bank 1 sector 1. |
||
410 | * - FMI_B1S2: FMI bank 1 sector 2. |
||
411 | * - FMI_B1S3: FMI bank 1 sector 3. |
||
412 | * Input2 : FMI_NewState: specifies the protection status. |
||
413 | * This parameter can be one of the following values: |
||
414 | * - ENABLE: Enable the protection. |
||
415 | * - DISABLE: Disable the protection. |
||
416 | * Output : None |
||
417 | * Return : None |
||
418 | *******************************************************************************/ |
||
419 | void FMI_WriteProtectionCmd(vu32 FMI_Sector, FunctionalState FMI_NewState) |
||
420 | { |
||
421 | if (FMI_NewState == ENABLE) |
||
422 | { |
||
423 | *(vu16*)FMI_Sector = 0x60; |
||
424 | *(vu16*)FMI_Sector = 0x01; |
||
425 | *(vu16*)FMI_Sector = 0xFF; |
||
426 | } |
||
427 | else /* DISABLE */ |
||
428 | { |
||
429 | *(vu16*)FMI_Sector = 0x60; |
||
430 | *(vu16*)FMI_Sector = 0xD0; |
||
431 | *(vu16*)FMI_Sector = 0xFF; |
||
432 | } |
||
433 | } |
||
434 | |||
435 | /******************************************************************************* |
||
436 | * Function Name : FMI_GetWriteProtectionStatus |
||
437 | * Description : Get the write protection status for the needed sector. |
||
438 | * Input : FMI_Sector_Mask: specifies the needed sector mask. |
||
439 | * This parameter can be one of the following values: |
||
440 | * - FMI_B0S0_MASK: FMI bank 0 sector 0. |
||
441 | * - FMI_B0S1_MASK: FMI bank 0 sector 1. |
||
442 | * - FMI_B0S2_MASK: FMI bank 0 sector 2. |
||
443 | * - FMI_B0S3_MASK: FMI bank 0 sector 3. |
||
444 | * - FMI_B0S4_MASK: FMI bank 0 sector 4. |
||
445 | * - FMI_B0S5_MASK: FMI bank 0 sector 5. |
||
446 | * - FMI_B0S6_MASK: FMI bank 0 sector 6. |
||
447 | * - FMI_B0S7_MASK: FMI bank 0 sector 7. |
||
448 | * - FMI_B1S0_MASK: FMI bank 1 sector 0. |
||
449 | * - FMI_B1S1_MASK: FMI bank 1 sector 1. |
||
450 | * - FMI_B1S2_MASK: FMI bank 1 sector 2. |
||
451 | * - FMI_B1S3_MASK: FMI bank 1 sector 3. |
||
452 | * Output : None |
||
453 | * Return : The Protection Status of the needed sector. |
||
454 | * - RESET: The needed sector is not write protected. |
||
455 | * - SET : The needed sector is write protected. |
||
456 | *******************************************************************************/ |
||
457 | FlagStatus FMI_GetWriteProtectionStatus(u32 FMI_Sector_Mask) |
||
458 | { |
||
459 | u16 Protection_Level_1_Register = 0; |
||
460 | /* Write a read flash protection level 1 register command */ |
||
461 | *(vu16 *)FMI_BANK_1 = 0x90; |
||
462 | |||
463 | /* Read the flash protection level 1 register */ |
||
464 | Protection_Level_1_Register = *(vu16 *)(FMI_BANK_1 + 0x10); |
||
465 | |||
466 | /* Write a read array command */ |
||
467 | *(vu16 *)FMI_BANK_1 = 0xFF; |
||
468 | |||
469 | if (Protection_Level_1_Register &= FMI_Sector_Mask) |
||
470 | { |
||
471 | return SET; |
||
472 | } |
||
473 | else |
||
474 | { |
||
475 | return RESET; |
||
476 | } |
||
477 | } |
||
478 | |||
479 | /******************************************************************************* |
||
480 | * Function Name : FMI_WaitForLastOperation |
||
481 | * Description : Wait until the last operation (Write halfword, Write OTP |
||
482 | * halfword, Erase sector and Erase bank) completion. |
||
483 | * Input : FMI_Bank: specifies the bank where the operation is on going. |
||
484 | * This parameter can be one of the following values: |
||
485 | * - FMI_BANK_0: FMI bank 0. |
||
486 | * - FMI_BANK_1: FMI bank 1. |
||
487 | * Output : None |
||
488 | * Return : The timeout status. |
||
489 | * This parameter can be one of the following values: |
||
490 | * - FMI_TIME_OUT_ERROR: Timeout error occurred. |
||
491 | * - FMI_NO_TIME_OUT_ERROR: No timeout error. |
||
492 | *******************************************************************************/ |
||
493 | u8 FMI_WaitForLastOperation(vu32 FMI_Bank) |
||
494 | { |
||
495 | u32 Time_Out = 0; |
||
496 | |||
497 | /* Write a read status register command */ |
||
498 | *(vu16 *)(FMI_Bank) = 0x70; |
||
499 | |||
500 | /* Wait until operation compeletion */ |
||
501 | while((!((*(vu16 *)FMI_Bank) & 0x80))&&(Time_Out < TIMEOUT )) |
||
502 | { |
||
503 | Time_Out ++; /* Time Out */ |
||
504 | } |
||
505 | |||
506 | /* Write a read array command */ |
||
507 | *(vu16 *)FMI_Bank = 0xFF; |
||
508 | |||
509 | if (Time_Out == TIMEOUT) |
||
510 | { |
||
511 | return FMI_TIME_OUT_ERROR; |
||
512 | } |
||
513 | else |
||
514 | { |
||
515 | return FMI_NO_TIME_OUT_ERROR; |
||
516 | } |
||
517 | } |
||
518 | |||
519 | |||
520 | /******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ |