Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sat Jun 03 00:22:44 2017 +0000
Revision:
46:b156ef445742
Parent:
18:6a4db94011d3
Final code for internal battlebot competition.

Who changed what in which revision?

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