Subversion Repositories DashDisplay

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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