annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_pccard.c @ 75:2b3f8ed4a0b8

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