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