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