1 /**
2   ******************************************************************************
3   * @file    stm32f4xx_hal_pccard.h
4   * @author  MCD Application Team
5   * @brief   Header file of PCCARD HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2016 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32F4xx_HAL_PCCARD_H
21 #define STM32F4xx_HAL_PCCARD_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #if defined(FMC_Bank4) || defined(FSMC_Bank4)
28 
29 /* Includes ------------------------------------------------------------------*/
30 #if defined(FSMC_Bank4)
31 #include "stm32f4xx_ll_fsmc.h"
32 #else
33 #include "stm32f4xx_ll_fmc.h"
34 #endif /* FSMC_Bank4 */
35 
36 /** @addtogroup STM32F4xx_HAL_Driver
37   * @{
38   */
39 
40 /** @addtogroup PCCARD
41   * @{
42   */
43 
44 /* Exported typedef ----------------------------------------------------------*/
45 /** @defgroup PCCARD_Exported_Types PCCARD Exported Types
46   * @{
47   */
48 
49 /**
50   * @brief  HAL PCCARD State structures definition
51   */
52 typedef enum
53 {
54   HAL_PCCARD_STATE_RESET     = 0x00U,    /*!< PCCARD peripheral not yet initialized or disabled */
55   HAL_PCCARD_STATE_READY     = 0x01U,    /*!< PCCARD peripheral ready                           */
56   HAL_PCCARD_STATE_BUSY      = 0x02U,    /*!< PCCARD peripheral busy                            */
57   HAL_PCCARD_STATE_ERROR     = 0x04U     /*!< PCCARD peripheral error                           */
58 } HAL_PCCARD_StateTypeDef;
59 
60 typedef enum
61 {
62   HAL_PCCARD_STATUS_SUCCESS = 0U,
63   HAL_PCCARD_STATUS_ONGOING,
64   HAL_PCCARD_STATUS_ERROR,
65   HAL_PCCARD_STATUS_TIMEOUT
66 } HAL_PCCARD_StatusTypeDef;
67 
68 /**
69   * @brief  FMC_PCCARD handle Structure definition
70   */
71 #if (USE_HAL_PCCARD_REGISTER_CALLBACKS == 1)
72 typedef struct __PCCARD_HandleTypeDef
73 #else
74 typedef struct
75 #endif /* USE_HAL_PCCARD_REGISTER_CALLBACKS  */
76 {
77   FMC_PCCARD_TypeDef           *Instance;              /*!< Register base address for PCCARD device          */
78 
79   FMC_PCCARD_InitTypeDef       Init;                   /*!< PCCARD device control configuration parameters   */
80 
81   __IO HAL_PCCARD_StateTypeDef State;                  /*!< PCCARD device access state                       */
82 
83   HAL_LockTypeDef              Lock;                   /*!< PCCARD Lock                                      */
84 
85 #if (USE_HAL_PCCARD_REGISTER_CALLBACKS == 1)
86   void (* MspInitCallback)(struct __PCCARD_HandleTypeDef *hpccard);               /*!< PCCARD Msp Init callback              */
87   void (* MspDeInitCallback)(struct __PCCARD_HandleTypeDef *hpccard);             /*!< PCCARD Msp DeInit callback            */
88   void (* ItCallback)(struct __PCCARD_HandleTypeDef *hpccard);                    /*!< PCCARD IT callback                    */
89 #endif
90 } PCCARD_HandleTypeDef;
91 
92 #if (USE_HAL_PCCARD_REGISTER_CALLBACKS == 1)
93 /**
94   * @brief  HAL PCCARD Callback ID enumeration definition
95   */
96 typedef enum
97 {
98   HAL_PCCARD_MSP_INIT_CB_ID       = 0x00U,  /*!< PCCARD MspInit Callback ID          */
99   HAL_PCCARD_MSP_DEINIT_CB_ID     = 0x01U,  /*!< PCCARD MspDeInit Callback ID        */
100   HAL_PCCARD_IT_CB_ID             = 0x02U   /*!< PCCARD IT Callback ID               */
101 } HAL_PCCARD_CallbackIDTypeDef;
102 
103 /**
104   * @brief  HAL PCCARD Callback pointer definition
105   */
106 typedef void (*pPCCARD_CallbackTypeDef)(PCCARD_HandleTypeDef *hpccard);
107 #endif
108 /**
109   * @}
110   */
111 
112 /* Exported constants --------------------------------------------------------*/
113 /* Exported macro ------------------------------------------------------------*/
114 /** @defgroup PCCARD_Exported_Macros PCCARD Exported Macros
115   * @{
116   */
117 /** @brief Reset PCCARD handle state
118   * @param  __HANDLE__ specifies the PCCARD handle.
119   * @retval None
120   */
121 #if (USE_HAL_PCCARD_REGISTER_CALLBACKS == 1)
122 #define __HAL_PCCARD_RESET_HANDLE_STATE(__HANDLE__)       do {                                               \
123                                                                (__HANDLE__)->State = HAL_PCCARD_STATE_RESET; \
124                                                                (__HANDLE__)->MspInitCallback = NULL;         \
125                                                                (__HANDLE__)->MspDeInitCallback = NULL;       \
126                                                              } while(0)
127 #else
128 #define __HAL_PCCARD_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_PCCARD_STATE_RESET)
129 #endif
130 /**
131   * @}
132   */
133 
134 /* Exported functions --------------------------------------------------------*/
135 /** @addtogroup PCCARD_Exported_Functions
136   * @{
137   */
138 
139 /** @addtogroup PCCARD_Exported_Functions_Group1
140   * @{
141   */
142 /* Initialization/de-initialization functions  **********************************/
143 HAL_StatusTypeDef  HAL_PCCARD_Init(PCCARD_HandleTypeDef *hpccard, FMC_NAND_PCC_TimingTypeDef *ComSpaceTiming,
144                                    FMC_NAND_PCC_TimingTypeDef *AttSpaceTiming, FMC_NAND_PCC_TimingTypeDef *IOSpaceTiming);
145 HAL_StatusTypeDef  HAL_PCCARD_DeInit(PCCARD_HandleTypeDef *hpccard);
146 void HAL_PCCARD_MspInit(PCCARD_HandleTypeDef *hpccard);
147 void HAL_PCCARD_MspDeInit(PCCARD_HandleTypeDef *hpccard);
148 /**
149   * @}
150   */
151 
152 /** @addtogroup PCCARD_Exported_Functions_Group2
153   * @{
154   */
155 /* IO operation functions  *****************************************************/
156 HAL_StatusTypeDef  HAL_PCCARD_Read_ID(PCCARD_HandleTypeDef *hpccard, uint8_t CompactFlash_ID[], uint8_t *pStatus);
157 HAL_StatusTypeDef  HAL_PCCARD_Write_Sector(PCCARD_HandleTypeDef *hpccard, uint16_t *pBuffer, uint16_t SectorAddress,
158                                            uint8_t *pStatus);
159 HAL_StatusTypeDef  HAL_PCCARD_Read_Sector(PCCARD_HandleTypeDef *hpccard, uint16_t *pBuffer, uint16_t SectorAddress,
160                                           uint8_t *pStatus);
161 HAL_StatusTypeDef  HAL_PCCARD_Erase_Sector(PCCARD_HandleTypeDef *hpccard, uint16_t SectorAddress, uint8_t *pStatus);
162 HAL_StatusTypeDef  HAL_PCCARD_Reset(PCCARD_HandleTypeDef *hpccard);
163 void               HAL_PCCARD_IRQHandler(PCCARD_HandleTypeDef *hpccard);
164 void               HAL_PCCARD_ITCallback(PCCARD_HandleTypeDef *hpccard);
165 
166 #if (USE_HAL_PCCARD_REGISTER_CALLBACKS == 1)
167 /* PCCARD callback registering/unregistering */
168 HAL_StatusTypeDef  HAL_PCCARD_RegisterCallback(PCCARD_HandleTypeDef *hpccard, HAL_PCCARD_CallbackIDTypeDef CallbackId,
169                                                pPCCARD_CallbackTypeDef pCallback);
170 HAL_StatusTypeDef  HAL_PCCARD_UnRegisterCallback(PCCARD_HandleTypeDef *hpccard,
171                                                  HAL_PCCARD_CallbackIDTypeDef CallbackId);
172 #endif
173 /**
174   * @}
175   */
176 
177 /** @addtogroup PCCARD_Exported_Functions_Group3
178   * @{
179   */
180 /* PCCARD State functions *******************************************************/
181 HAL_PCCARD_StateTypeDef  HAL_PCCARD_GetState(PCCARD_HandleTypeDef *hpccard);
182 HAL_PCCARD_StatusTypeDef HAL_PCCARD_GetStatus(PCCARD_HandleTypeDef *hpccard);
183 HAL_PCCARD_StatusTypeDef HAL_PCCARD_ReadStatus(PCCARD_HandleTypeDef *hpccard);
184 /**
185   * @}
186   */
187 
188 /**
189   * @}
190   */
191 /* Private types -------------------------------------------------------------*/
192 /* Private variables ---------------------------------------------------------*/
193 /* Private constants ---------------------------------------------------------*/
194 /** @defgroup PCCARD_Private_Constants PCCARD Private Constants
195   * @{
196   */
197 #define PCCARD_DEVICE_ADDRESS             0x90000000U
198 #define PCCARD_ATTRIBUTE_SPACE_ADDRESS    0x98000000U              /* Attribute space size to @0x9BFF FFFF */
199 #define PCCARD_COMMON_SPACE_ADDRESS       PCCARD_DEVICE_ADDRESS    /* Common space size to @0x93FF FFFF    */
200 #define PCCARD_IO_SPACE_ADDRESS           0x9C000000U              /* IO space size to @0x9FFF FFFF        */
201 #define PCCARD_IO_SPACE_PRIMARY_ADDR      0x9C0001F0U              /* IO space size to @0x9FFF FFFF        */
202 
203 /* Flash-ATA registers description */
204 #define ATA_DATA                       ((uint8_t)0x00)    /* Data register */
205 #define ATA_SECTOR_COUNT               ((uint8_t)0x02)    /* Sector Count register */
206 #define ATA_SECTOR_NUMBER              ((uint8_t)0x03)    /* Sector Number register */
207 #define ATA_CYLINDER_LOW               ((uint8_t)0x04)    /* Cylinder low register */
208 #define ATA_CYLINDER_HIGH              ((uint8_t)0x05)    /* Cylinder high register */
209 #define ATA_CARD_HEAD                  ((uint8_t)0x06)    /* Card/Head register */
210 #define ATA_STATUS_CMD                 ((uint8_t)0x07)    /* Status(read)/Command(write) register */
211 #define ATA_STATUS_CMD_ALTERNATE       ((uint8_t)0x0E)    /* Alternate Status(read)/Command(write) register */
212 #define ATA_COMMON_DATA_AREA           ((uint16_t)0x0400) /* Start of data area (for Common access only!) */
213 #define ATA_CARD_CONFIGURATION         ((uint16_t)0x0202) /* Card Configuration and Status Register */
214 
215 /* Flash-ATA commands */
216 #define ATA_READ_SECTOR_CMD            ((uint8_t)0x20)
217 #define ATA_WRITE_SECTOR_CMD           ((uint8_t)0x30)
218 #define ATA_ERASE_SECTOR_CMD           ((uint8_t)0xC0)
219 #define ATA_IDENTIFY_CMD               ((uint8_t)0xEC)
220 
221 /* PC Card/Compact Flash status */
222 #define PCCARD_TIMEOUT_ERROR           ((uint8_t)0x60)
223 #define PCCARD_BUSY                    ((uint8_t)0x80)
224 #define PCCARD_PROGR                   ((uint8_t)0x01)
225 #define PCCARD_READY                   ((uint8_t)0x40)
226 
227 #define PCCARD_SECTOR_SIZE             255U               /* In half words */
228 
229 /**
230   * @}
231   */
232 /* Compact Flash redefinition */
233 #define HAL_CF_Init                 HAL_PCCARD_Init
234 #define HAL_CF_DeInit               HAL_PCCARD_DeInit
235 #define HAL_CF_MspInit              HAL_PCCARD_MspInit
236 #define HAL_CF_MspDeInit            HAL_PCCARD_MspDeInit
237 
238 #define HAL_CF_Read_ID              HAL_PCCARD_Read_ID
239 #define HAL_CF_Write_Sector         HAL_PCCARD_Write_Sector
240 #define HAL_CF_Read_Sector          HAL_PCCARD_Read_Sector
241 #define HAL_CF_Erase_Sector         HAL_PCCARD_Erase_Sector
242 #define HAL_CF_Reset                HAL_PCCARD_Reset
243 #define HAL_CF_IRQHandler           HAL_PCCARD_IRQHandler
244 #define HAL_CF_ITCallback           HAL_PCCARD_ITCallback
245 
246 #define HAL_CF_GetState             HAL_PCCARD_GetState
247 #define HAL_CF_GetStatus            HAL_PCCARD_GetStatus
248 #define HAL_CF_ReadStatus           HAL_PCCARD_ReadStatus
249 
250 #define HAL_CF_STATUS_SUCCESS       HAL_PCCARD_STATUS_SUCCESS
251 #define HAL_CF_STATUS_ONGOING       HAL_PCCARD_STATUS_ONGOING
252 #define HAL_CF_STATUS_ERROR         HAL_PCCARD_STATUS_ERROR
253 #define HAL_CF_STATUS_TIMEOUT       HAL_PCCARD_STATUS_TIMEOUT
254 #define HAL_CF_StatusTypeDef        HAL_PCCARD_StatusTypeDef
255 
256 #define CF_DEVICE_ADDRESS           PCCARD_DEVICE_ADDRESS
257 #define CF_ATTRIBUTE_SPACE_ADDRESS  PCCARD_ATTRIBUTE_SPACE_ADDRESS
258 #define CF_COMMON_SPACE_ADDRESS     PCCARD_COMMON_SPACE_ADDRESS
259 #define CF_IO_SPACE_ADDRESS         PCCARD_IO_SPACE_ADDRESS
260 #define CF_IO_SPACE_PRIMARY_ADDR    PCCARD_IO_SPACE_PRIMARY_ADDR
261 
262 #define CF_TIMEOUT_ERROR            PCCARD_TIMEOUT_ERROR
263 #define CF_BUSY                     PCCARD_BUSY
264 #define CF_PROGR                    PCCARD_PROGR
265 #define CF_READY                    PCCARD_READY
266 
267 #define CF_SECTOR_SIZE              PCCARD_SECTOR_SIZE
268 
269 /* Private macros ------------------------------------------------------------*/
270 /**
271   * @}
272   */
273 
274 
275 /**
276   * @}
277   */
278 
279 #endif /*  FMC_Bank4 || FSMC_Bank4 */
280 
281 #ifdef __cplusplus
282 }
283 #endif
284 
285 #endif /* STM32F4xx_HAL_PCCARD_H */
286