Mercurial > public > ostc4
comparison Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_pccard.c @ 38:5f11787b4f42
include in ostc4 repository
author | heinrichsweikamp |
---|---|
date | Sat, 28 Apr 2018 11:52:34 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
37:ccc45c0e1ea2 | 38:5f11787b4f42 |
---|---|
1 /** | |
2 ****************************************************************************** | |
3 * @file stm32f4xx_hal_pccard.c | |
4 * @author MCD Application Team | |
5 * @version V1.2.0 | |
6 * @date 26-December-2014 | |
7 * @brief PCCARD HAL module driver. | |
8 * This file provides a generic firmware to drive PCCARD memories mounted | |
9 * as external device. | |
10 * | |
11 @verbatim | |
12 =============================================================================== | |
13 ##### How to use this driver ##### | |
14 =============================================================================== | |
15 [..] | |
16 This driver is a generic layered driver which contains a set of APIs used to | |
17 control PCCARD/compact flash memories. It uses the FMC/FSMC layer functions | |
18 to interface with PCCARD devices. This driver is used for: | |
19 | |
20 (+) PCCARD/Compact Flash memory configuration sequence using the function | |
21 HAL_PCCARD_Init()/HAL_CF_Init() with control and timing parameters for | |
22 both common and attribute spaces. | |
23 | |
24 (+) Read PCCARD/Compact Flash memory maker and device IDs using the function | |
25 HAL_PCCARD_Read_ID()/HAL_CF_Read_ID(). The read information is stored in | |
26 the CompactFlash_ID structure declared by the function caller. | |
27 | |
28 (+) Access PCCARD/Compact Flash memory by read/write operations using the functions | |
29 HAL_PCCARD_Read_Sector()/ HAL_PCCARD_Write_Sector() - | |
30 HAL_CF_Read_Sector()/HAL_CF_Write_Sector(), to read/write sector. | |
31 | |
32 (+) Perform PCCARD/Compact Flash Reset chip operation using the function | |
33 HAL_PCCARD_Reset()/HAL_CF_Reset. | |
34 | |
35 (+) Perform PCCARD/Compact Flash erase sector operation using the function | |
36 HAL_PCCARD_Erase_Sector()/HAL_CF_Erase_Sector. | |
37 | |
38 (+) Read the PCCARD/Compact Flash status operation using the function | |
39 HAL_PCCARD_ReadStatus()/HAL_CF_ReadStatus(). | |
40 | |
41 (+) You can monitor the PCCARD/Compact Flash device HAL state by calling | |
42 the function HAL_PCCARD_GetState()/HAL_CF_GetState() | |
43 | |
44 [..] | |
45 (@) This driver is a set of generic APIs which handle standard PCCARD/compact flash | |
46 operations. If a PCCARD/Compact Flash device contains different operations | |
47 and/or implementations, it should be implemented separately. | |
48 | |
49 @endverbatim | |
50 ****************************************************************************** | |
51 * @attention | |
52 * | |
53 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> | |
54 * | |
55 * Redistribution and use in source and binary forms, with or without modification, | |
56 * are permitted provided that the following conditions are met: | |
57 * 1. Redistributions of source code must retain the above copyright notice, | |
58 * this list of conditions and the following disclaimer. | |
59 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
60 * this list of conditions and the following disclaimer in the documentation | |
61 * and/or other materials provided with the distribution. | |
62 * 3. Neither the name of STMicroelectronics nor the names of its contributors | |
63 * may be used to endorse or promote products derived from this software | |
64 * without specific prior written permission. | |
65 * | |
66 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
67 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
68 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
69 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
70 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
71 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
72 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
73 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
74 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
75 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
76 * | |
77 ****************************************************************************** | |
78 */ | |
79 | |
80 /* Includes ------------------------------------------------------------------*/ | |
81 #include "stm32f4xx_hal.h" | |
82 | |
83 /** @addtogroup STM32F4xx_HAL_Driver | |
84 * @{ | |
85 */ | |
86 | |
87 #ifdef HAL_PCCARD_MODULE_ENABLED | |
88 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) | |
89 /** @defgroup PCCARD PCCARD | |
90 * @brief PCCARD HAL module driver | |
91 * @{ | |
92 */ | |
93 /* Private typedef -----------------------------------------------------------*/ | |
94 /* Private define ---------------------------------------------------------*/ | |
95 /* Private macro -------------------------------------------------------------*/ | |
96 /* Private variables ---------------------------------------------------------*/ | |
97 /* Private function ----------------------------------------------------------*/ | |
98 /* Exported functions --------------------------------------------------------*/ | |
99 /** @defgroup PCCARD_Exported_Functions PCCARD Exported Functions | |
100 * @{ | |
101 */ | |
102 | |
103 /** @defgroup PCCARD_Exported_Functions_Group1 Initialization and de-initialization functions | |
104 * @brief Initialization and Configuration functions | |
105 * | |
106 @verbatim | |
107 ============================================================================== | |
108 ##### PCCARD Initialization and de-initialization functions ##### | |
109 ============================================================================== | |
110 [..] | |
111 This section provides functions allowing to initialize/de-initialize | |
112 the PCCARD memory | |
113 | |
114 @endverbatim | |
115 * @{ | |
116 */ | |
117 | |
118 /** | |
119 * @brief Perform the PCCARD memory Initialization sequence | |
120 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains | |
121 * the configuration information for PCCARD module. | |
122 * @param ComSpaceTiming: Common space timing structure | |
123 * @param AttSpaceTiming: Attribute space timing structure | |
124 * @param IOSpaceTiming: IO space timing structure | |
125 * @retval HAL status | |
126 */ | |
127 HAL_StatusTypeDef HAL_PCCARD_Init(PCCARD_HandleTypeDef *hpccard, FMC_NAND_PCC_TimingTypeDef *ComSpaceTiming, FMC_NAND_PCC_TimingTypeDef *AttSpaceTiming, FMC_NAND_PCC_TimingTypeDef *IOSpaceTiming) | |
128 { | |
129 /* Check the PCCARD controller state */ | |
130 if(hpccard == NULL) | |
131 { | |
132 return HAL_ERROR; | |
133 } | |
134 | |
135 if(hpccard->State == HAL_PCCARD_STATE_RESET) | |
136 { | |
137 /* Initialize the low level hardware (MSP) */ | |
138 HAL_PCCARD_MspInit(hpccard); | |
139 } | |
140 | |
141 /* Initialize the PCCARD state */ | |
142 hpccard->State = HAL_PCCARD_STATE_BUSY; | |
143 | |
144 /* Initialize PCCARD control Interface */ | |
145 FMC_PCCARD_Init(hpccard->Instance, &(hpccard->Init)); | |
146 | |
147 /* Init PCCARD common space timing Interface */ | |
148 FMC_PCCARD_CommonSpace_Timing_Init(hpccard->Instance, ComSpaceTiming); | |
149 | |
150 /* Init PCCARD attribute space timing Interface */ | |
151 FMC_PCCARD_AttributeSpace_Timing_Init(hpccard->Instance, AttSpaceTiming); | |
152 | |
153 /* Init PCCARD IO space timing Interface */ | |
154 FMC_PCCARD_IOSpace_Timing_Init(hpccard->Instance, IOSpaceTiming); | |
155 | |
156 /* Enable the PCCARD device */ | |
157 __FMC_PCCARD_ENABLE(hpccard->Instance); | |
158 | |
159 /* Update the PCCARD state */ | |
160 hpccard->State = HAL_PCCARD_STATE_READY; | |
161 | |
162 return HAL_OK; | |
163 | |
164 } | |
165 | |
166 /** | |
167 * @brief Perform the PCCARD memory De-initialization sequence | |
168 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains | |
169 * the configuration information for PCCARD module. | |
170 * @retval HAL status | |
171 */ | |
172 HAL_StatusTypeDef HAL_PCCARD_DeInit(PCCARD_HandleTypeDef *hpccard) | |
173 { | |
174 /* De-Initialize the low level hardware (MSP) */ | |
175 HAL_PCCARD_MspDeInit(hpccard); | |
176 | |
177 /* Configure the PCCARD registers with their reset values */ | |
178 FMC_PCCARD_DeInit(hpccard->Instance); | |
179 | |
180 /* Update the PCCARD controller state */ | |
181 hpccard->State = HAL_PCCARD_STATE_RESET; | |
182 | |
183 /* Release Lock */ | |
184 __HAL_UNLOCK(hpccard); | |
185 | |
186 return HAL_OK; | |
187 } | |
188 | |
189 /** | |
190 * @brief PCCARD MSP Init | |
191 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains | |
192 * the configuration information for PCCARD module. | |
193 * @retval None | |
194 */ | |
195 __weak void HAL_PCCARD_MspInit(PCCARD_HandleTypeDef *hpccard) | |
196 { | |
197 /* NOTE : This function Should not be modified, when the callback is needed, | |
198 the HAL_PCCARD_MspInit could be implemented in the user file | |
199 */ | |
200 } | |
201 | |
202 /** | |
203 * @brief PCCARD MSP DeInit | |
204 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains | |
205 * the configuration information for PCCARD module. | |
206 * @retval None | |
207 */ | |
208 __weak void HAL_PCCARD_MspDeInit(PCCARD_HandleTypeDef *hpccard) | |
209 { | |
210 /* NOTE : This function Should not be modified, when the callback is needed, | |
211 the HAL_PCCARD_MspDeInit could be implemented in the user file | |
212 */ | |
213 } | |
214 | |
215 /** | |
216 * @} | |
217 */ | |
218 | |
219 /** @defgroup PCCARD_Exported_Functions_Group2 Input and Output functions | |
220 * @brief Input Output and memory control functions | |
221 * | |
222 @verbatim | |
223 ============================================================================== | |
224 ##### PCCARD Input and Output functions ##### | |
225 ============================================================================== | |
226 [..] | |
227 This section provides functions allowing to use and control the PCCARD memory | |
228 | |
229 @endverbatim | |
230 * @{ | |
231 */ | |
232 | |
233 /** | |
234 * @brief Read Compact Flash's ID. | |
235 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains | |
236 * the configuration information for PCCARD module. | |
237 * @param CompactFlash_ID: Compact flash ID structure. | |
238 * @param pStatus: pointer to compact flash status | |
239 * @retval HAL status | |
240 * | |
241 */ | |
242 HAL_StatusTypeDef HAL_PCCARD_Read_ID(PCCARD_HandleTypeDef *hpccard, uint8_t CompactFlash_ID[], uint8_t *pStatus) | |
243 { | |
244 uint32_t timeout = 0xFFFF, index; | |
245 uint8_t status; | |
246 | |
247 /* Process Locked */ | |
248 __HAL_LOCK(hpccard); | |
249 | |
250 /* Check the PCCARD controller state */ | |
251 if(hpccard->State == HAL_PCCARD_STATE_BUSY) | |
252 { | |
253 return HAL_BUSY; | |
254 } | |
255 | |
256 /* Update the PCCARD controller state */ | |
257 hpccard->State = HAL_PCCARD_STATE_BUSY; | |
258 | |
259 /* Initialize the PCCARD status */ | |
260 *pStatus = PCCARD_READY; | |
261 | |
262 /* Send the Identify Command */ | |
263 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD) = 0xECEC; | |
264 | |
265 /* Read PCCARD IDs and timeout treatment */ | |
266 do | |
267 { | |
268 /* Read the PCCARD status */ | |
269 status = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE); | |
270 | |
271 timeout--; | |
272 }while((status != 0x58) && timeout); | |
273 | |
274 if(timeout == 0) | |
275 { | |
276 *pStatus = PCCARD_TIMEOUT_ERROR; | |
277 } | |
278 else | |
279 { | |
280 /* Read PCCARD ID bytes */ | |
281 for(index = 0; index < 16; index++) | |
282 { | |
283 CompactFlash_ID[index] = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_DATA); | |
284 } | |
285 } | |
286 | |
287 /* Update the PCCARD controller state */ | |
288 hpccard->State = HAL_PCCARD_STATE_READY; | |
289 | |
290 /* Process unlocked */ | |
291 __HAL_UNLOCK(hpccard); | |
292 | |
293 return HAL_OK; | |
294 } | |
295 | |
296 /** | |
297 * @brief Read sector from PCCARD memory | |
298 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains | |
299 * the configuration information for PCCARD module. | |
300 * @param pBuffer: pointer to destination read buffer | |
301 * @param SectorAddress: Sector address to read | |
302 * @param pStatus: pointer to PCCARD status | |
303 * @retval HAL status | |
304 */ | |
305 HAL_StatusTypeDef HAL_PCCARD_Read_Sector(PCCARD_HandleTypeDef *hpccard, uint16_t *pBuffer, uint16_t SectorAddress, uint8_t *pStatus) | |
306 { | |
307 uint32_t timeout = 0xFFFF, index = 0; | |
308 uint8_t status; | |
309 | |
310 /* Process Locked */ | |
311 __HAL_LOCK(hpccard); | |
312 | |
313 /* Check the PCCARD controller state */ | |
314 if(hpccard->State == HAL_PCCARD_STATE_BUSY) | |
315 { | |
316 return HAL_BUSY; | |
317 } | |
318 | |
319 /* Update the PCCARD controller state */ | |
320 hpccard->State = HAL_PCCARD_STATE_BUSY; | |
321 | |
322 /* Initialize PCCARD status */ | |
323 *pStatus = PCCARD_READY; | |
324 | |
325 /* Set the parameters to write a sector */ | |
326 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_CYLINDER_HIGH) = (uint16_t)0x00; | |
327 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_SECTOR_COUNT) = ((uint16_t)0x0100 ) | ((uint16_t)SectorAddress); | |
328 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD) = (uint16_t)0xE4A0; | |
329 | |
330 do | |
331 { | |
332 /* wait till the Status = 0x80 */ | |
333 status = *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE); | |
334 timeout--; | |
335 }while((status == 0x80) && timeout); | |
336 | |
337 if(timeout == 0) | |
338 { | |
339 *pStatus = PCCARD_TIMEOUT_ERROR; | |
340 } | |
341 | |
342 timeout = 0xFFFF; | |
343 | |
344 do | |
345 { | |
346 /* wait till the Status = 0x58 */ | |
347 status = *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE); | |
348 timeout--; | |
349 }while((status != 0x58) && timeout); | |
350 | |
351 if(timeout == 0) | |
352 { | |
353 *pStatus = PCCARD_TIMEOUT_ERROR; | |
354 } | |
355 | |
356 /* Read bytes */ | |
357 for(; index < PCCARD_SECTOR_SIZE; index++) | |
358 { | |
359 *(uint16_t *)pBuffer++ = *(uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR); | |
360 } | |
361 | |
362 /* Update the PCCARD controller state */ | |
363 hpccard->State = HAL_PCCARD_STATE_READY; | |
364 | |
365 /* Process unlocked */ | |
366 __HAL_UNLOCK(hpccard); | |
367 | |
368 return HAL_OK; | |
369 } | |
370 | |
371 | |
372 /** | |
373 * @brief Write sector to PCCARD memory | |
374 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains | |
375 * the configuration information for PCCARD module. | |
376 * @param pBuffer: pointer to source write buffer | |
377 * @param SectorAddress: Sector address to write | |
378 * @param pStatus: pointer to PCCARD status | |
379 * @retval HAL status | |
380 */ | |
381 HAL_StatusTypeDef HAL_PCCARD_Write_Sector(PCCARD_HandleTypeDef *hpccard, uint16_t *pBuffer, uint16_t SectorAddress, uint8_t *pStatus) | |
382 { | |
383 uint32_t timeout = 0xFFFF, index = 0; | |
384 uint8_t status; | |
385 | |
386 /* Process Locked */ | |
387 __HAL_LOCK(hpccard); | |
388 | |
389 /* Check the PCCARD controller state */ | |
390 if(hpccard->State == HAL_PCCARD_STATE_BUSY) | |
391 { | |
392 return HAL_BUSY; | |
393 } | |
394 | |
395 /* Update the PCCARD controller state */ | |
396 hpccard->State = HAL_PCCARD_STATE_BUSY; | |
397 | |
398 /* Initialize PCCARD status */ | |
399 *pStatus = PCCARD_READY; | |
400 | |
401 /* Set the parameters to write a sector */ | |
402 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_CYLINDER_HIGH) = (uint16_t)0x00; | |
403 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_SECTOR_COUNT) = ((uint16_t)0x0100 ) | ((uint16_t)SectorAddress); | |
404 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD) = (uint16_t)0x30A0; | |
405 | |
406 do | |
407 { | |
408 /* Wait till the Status = 0x58 */ | |
409 status = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE); | |
410 timeout--; | |
411 }while((status != 0x58) && timeout); | |
412 | |
413 if(timeout == 0) | |
414 { | |
415 *pStatus = PCCARD_TIMEOUT_ERROR; | |
416 } | |
417 | |
418 /* Write bytes */ | |
419 for(; index < PCCARD_SECTOR_SIZE; index++) | |
420 { | |
421 *(uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR) = *(uint16_t *)pBuffer++; | |
422 } | |
423 | |
424 do | |
425 { | |
426 /* Wait till the Status = 0x50 */ | |
427 status = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE); | |
428 timeout--; | |
429 }while((status != 0x50) && timeout); | |
430 | |
431 if(timeout == 0) | |
432 { | |
433 *pStatus = PCCARD_TIMEOUT_ERROR; | |
434 } | |
435 | |
436 /* Update the PCCARD controller state */ | |
437 hpccard->State = HAL_PCCARD_STATE_READY; | |
438 | |
439 /* Process unlocked */ | |
440 __HAL_UNLOCK(hpccard); | |
441 | |
442 return HAL_OK; | |
443 } | |
444 | |
445 | |
446 /** | |
447 * @brief Erase sector from PCCARD memory | |
448 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains | |
449 * the configuration information for PCCARD module. | |
450 * @param SectorAddress: Sector address to erase | |
451 * @param pStatus: pointer to PCCARD status | |
452 * @retval HAL status | |
453 */ | |
454 HAL_StatusTypeDef HAL_PCCARD_Erase_Sector(PCCARD_HandleTypeDef *hpccard, uint16_t SectorAddress, uint8_t *pStatus) | |
455 { | |
456 uint32_t timeout = 0x400; | |
457 uint8_t status; | |
458 | |
459 /* Process Locked */ | |
460 __HAL_LOCK(hpccard); | |
461 | |
462 /* Check the PCCARD controller state */ | |
463 if(hpccard->State == HAL_PCCARD_STATE_BUSY) | |
464 { | |
465 return HAL_BUSY; | |
466 } | |
467 | |
468 /* Update the PCCARD controller state */ | |
469 hpccard->State = HAL_PCCARD_STATE_BUSY; | |
470 | |
471 /* Initialize PCCARD status */ | |
472 *pStatus = PCCARD_READY; | |
473 | |
474 /* Set the parameters to write a sector */ | |
475 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_CYLINDER_LOW) = 0x00; | |
476 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_CYLINDER_HIGH) = 0x00; | |
477 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_SECTOR_NUMBER) = SectorAddress; | |
478 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_SECTOR_COUNT) = 0x01; | |
479 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_CARD_HEAD) = 0xA0; | |
480 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD) = ATA_ERASE_SECTOR_CMD; | |
481 | |
482 /* wait till the PCCARD is ready */ | |
483 status = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE); | |
484 | |
485 while((status != 0x50) && timeout) | |
486 { | |
487 status = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE); | |
488 timeout--; | |
489 } | |
490 | |
491 if(timeout == 0) | |
492 { | |
493 *pStatus = PCCARD_TIMEOUT_ERROR; | |
494 } | |
495 | |
496 /* Check the PCCARD controller state */ | |
497 hpccard->State = HAL_PCCARD_STATE_READY; | |
498 | |
499 /* Process unlocked */ | |
500 __HAL_UNLOCK(hpccard); | |
501 | |
502 return HAL_OK; | |
503 } | |
504 | |
505 /** | |
506 * @brief Reset the PCCARD memory | |
507 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains | |
508 * the configuration information for PCCARD module. | |
509 * @retval HAL status | |
510 */ | |
511 HAL_StatusTypeDef HAL_PCCARD_Reset(PCCARD_HandleTypeDef *hpccard) | |
512 { | |
513 | |
514 /* Process Locked */ | |
515 __HAL_LOCK(hpccard); | |
516 | |
517 /* Check the PCCARD controller state */ | |
518 if(hpccard->State == HAL_PCCARD_STATE_BUSY) | |
519 { | |
520 return HAL_BUSY; | |
521 } | |
522 | |
523 /* Provide a SW reset and Read and verify the: | |
524 - PCCard Configuration Option Register at address 0x98000200 --> 0x80 | |
525 - Card Configuration and Status Register at address 0x98000202 --> 0x00 | |
526 - Pin Replacement Register at address 0x98000204 --> 0x0C | |
527 - Socket and Copy Register at address 0x98000206 --> 0x00 | |
528 */ | |
529 | |
530 /* Check the PCCARD controller state */ | |
531 hpccard->State = HAL_PCCARD_STATE_BUSY; | |
532 | |
533 *(__IO uint8_t *)(0x98000202) = 0x01; | |
534 | |
535 /* Check the PCCARD controller state */ | |
536 hpccard->State = HAL_PCCARD_STATE_READY; | |
537 | |
538 /* Process unlocked */ | |
539 __HAL_UNLOCK(hpccard); | |
540 | |
541 return HAL_OK; | |
542 } | |
543 | |
544 /** | |
545 * @brief This function handles PCCARD device interrupt request. | |
546 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains | |
547 * the configuration information for PCCARD module. | |
548 * @retval HAL status | |
549 */ | |
550 void HAL_PCCARD_IRQHandler(PCCARD_HandleTypeDef *hpccard) | |
551 { | |
552 /* Check PCCARD interrupt Rising edge flag */ | |
553 if(__FMC_PCCARD_GET_FLAG(hpccard->Instance, FMC_FLAG_RISING_EDGE)) | |
554 { | |
555 /* PCCARD interrupt callback*/ | |
556 HAL_PCCARD_ITCallback(hpccard); | |
557 | |
558 /* Clear PCCARD interrupt Rising edge pending bit */ | |
559 __FMC_PCCARD_CLEAR_FLAG(hpccard->Instance, FMC_FLAG_RISING_EDGE); | |
560 } | |
561 | |
562 /* Check PCCARD interrupt Level flag */ | |
563 if(__FMC_PCCARD_GET_FLAG(hpccard->Instance, FMC_FLAG_LEVEL)) | |
564 { | |
565 /* PCCARD interrupt callback*/ | |
566 HAL_PCCARD_ITCallback(hpccard); | |
567 | |
568 /* Clear PCCARD interrupt Level pending bit */ | |
569 __FMC_PCCARD_CLEAR_FLAG(hpccard->Instance, FMC_FLAG_LEVEL); | |
570 } | |
571 | |
572 /* Check PCCARD interrupt Falling edge flag */ | |
573 if(__FMC_PCCARD_GET_FLAG(hpccard->Instance, FMC_FLAG_FALLING_EDGE)) | |
574 { | |
575 /* PCCARD interrupt callback*/ | |
576 HAL_PCCARD_ITCallback(hpccard); | |
577 | |
578 /* Clear PCCARD interrupt Falling edge pending bit */ | |
579 __FMC_PCCARD_CLEAR_FLAG(hpccard->Instance, FMC_FLAG_FALLING_EDGE); | |
580 } | |
581 | |
582 /* Check PCCARD interrupt FIFO empty flag */ | |
583 if(__FMC_PCCARD_GET_FLAG(hpccard->Instance, FMC_FLAG_FEMPT)) | |
584 { | |
585 /* PCCARD interrupt callback*/ | |
586 HAL_PCCARD_ITCallback(hpccard); | |
587 | |
588 /* Clear PCCARD interrupt FIFO empty pending bit */ | |
589 __FMC_PCCARD_CLEAR_FLAG(hpccard->Instance, FMC_FLAG_FEMPT); | |
590 } | |
591 | |
592 } | |
593 | |
594 /** | |
595 * @brief PCCARD interrupt feature callback | |
596 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains | |
597 * the configuration information for PCCARD module. | |
598 * @retval None | |
599 */ | |
600 __weak void HAL_PCCARD_ITCallback(PCCARD_HandleTypeDef *hpccard) | |
601 { | |
602 /* NOTE : This function Should not be modified, when the callback is needed, | |
603 the HAL_PCCARD_ITCallback could be implemented in the user file | |
604 */ | |
605 } | |
606 | |
607 /** | |
608 * @} | |
609 */ | |
610 | |
611 /** @defgroup PCCARD_Exported_Functions_Group3 State functions | |
612 * @brief Peripheral State functions | |
613 * | |
614 @verbatim | |
615 ============================================================================== | |
616 ##### PCCARD State functions ##### | |
617 ============================================================================== | |
618 [..] | |
619 This subsection permits to get in run-time the status of the PCCARD controller | |
620 and the data flow. | |
621 | |
622 @endverbatim | |
623 * @{ | |
624 */ | |
625 | |
626 /** | |
627 * @brief return the PCCARD controller state | |
628 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains | |
629 * the configuration information for PCCARD module. | |
630 * @retval HAL state | |
631 */ | |
632 HAL_PCCARD_StateTypeDef HAL_PCCARD_GetState(PCCARD_HandleTypeDef *hpccard) | |
633 { | |
634 return hpccard->State; | |
635 } | |
636 | |
637 /** | |
638 * @brief Get the compact flash memory status | |
639 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains | |
640 * the configuration information for PCCARD module. | |
641 * @retval New status of the PCCARD operation. This parameter can be: | |
642 * - CompactFlash_TIMEOUT_ERROR: when the previous operation generate | |
643 * a Timeout error | |
644 * - CompactFlash_READY: when memory is ready for the next operation | |
645 */ | |
646 HAL_PCCARD_StatusTypeDef HAL_PCCARD_GetStatus(PCCARD_HandleTypeDef *hpccard) | |
647 { | |
648 uint32_t timeout = 0x1000000, status_pccard; | |
649 | |
650 /* Check the PCCARD controller state */ | |
651 if(hpccard->State == HAL_PCCARD_STATE_BUSY) | |
652 { | |
653 return HAL_PCCARD_STATUS_ONGOING; | |
654 } | |
655 | |
656 status_pccard = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE); | |
657 | |
658 while((status_pccard == PCCARD_BUSY) && timeout) | |
659 { | |
660 status_pccard = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE); | |
661 timeout--; | |
662 } | |
663 | |
664 if(timeout == 0) | |
665 { | |
666 status_pccard = PCCARD_TIMEOUT_ERROR; | |
667 } | |
668 | |
669 /* Return the operation status */ | |
670 return (HAL_PCCARD_StatusTypeDef) status_pccard; | |
671 } | |
672 | |
673 /** | |
674 * @brief Reads the Compact Flash memory status using the Read status command | |
675 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains | |
676 * the configuration information for PCCARD module. | |
677 * @retval The status of the Compact Flash memory. This parameter can be: | |
678 * - CompactFlash_BUSY: when memory is busy | |
679 * - CompactFlash_READY: when memory is ready for the next operation | |
680 * - CompactFlash_ERROR: when the previous operation generates error | |
681 */ | |
682 HAL_PCCARD_StatusTypeDef HAL_PCCARD_ReadStatus(PCCARD_HandleTypeDef *hpccard) | |
683 { | |
684 uint8_t data = 0, status_pccard = PCCARD_BUSY; | |
685 | |
686 /* Check the PCCARD controller state */ | |
687 if(hpccard->State == HAL_PCCARD_STATE_BUSY) | |
688 { | |
689 return HAL_PCCARD_STATUS_ONGOING; | |
690 } | |
691 | |
692 /* Read status operation */ | |
693 data = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE); | |
694 | |
695 if((data & PCCARD_TIMEOUT_ERROR) == PCCARD_TIMEOUT_ERROR) | |
696 { | |
697 status_pccard = PCCARD_TIMEOUT_ERROR; | |
698 } | |
699 else if((data & PCCARD_READY) == PCCARD_READY) | |
700 { | |
701 status_pccard = PCCARD_READY; | |
702 } | |
703 | |
704 return (HAL_PCCARD_StatusTypeDef) status_pccard; | |
705 } | |
706 | |
707 /** | |
708 * @} | |
709 */ | |
710 | |
711 /** | |
712 * @} | |
713 */ | |
714 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */ | |
715 #endif /* HAL_PCCARD_MODULE_ENABLED */ | |
716 | |
717 /** | |
718 * @} | |
719 */ | |
720 | |
721 /** | |
722 * @} | |
723 */ | |
724 | |
725 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |