comparison Common/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pccard.c @ 128:c78bcbd5deda FlipDisplay

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