Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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