]> begriffs open source - cmsis/blob - CMSIS/DoxyGen/Driver/src/Driver_MCI.c
Merge branch 'feature/Incorporate_Storage_Driver_into_Documentation' into develop
[cmsis] / CMSIS / DoxyGen / Driver / src / Driver_MCI.c
1 /* -----------------------------------------------------------------------------\r
2  * Copyright (c) 2013-2014 ARM Limited. All rights reserved.\r
3  *  \r
4  * $Date:        2. January 2014\r
5  * $Revision:    V2.00\r
6  *  \r
7  * Project:      MCI Driver API\r
8  * -------------------------------------------------------------------------- */\r
9 \r
10 \r
11 /**\r
12 \defgroup mci_interface_gr MCI Interface\r
13 \brief    Driver API for Memory Card Interface using SD/MMC interface (%Driver_MCI.h)\r
14 \r
15 \details\r
16 The <b>Memory Card Interface</b> (MCI) implements the hardware abstraction layer for Secure Digital (SD) and Multi Media Card (MMC)\r
17 memory that is typically used as file storage. For embedded systems, SD/MMC devices are available as memory cards in several \r
18 forms (SD, miniSD, microSD, MMC, MMCmicro) or as non-removable devic\r
19 es that are directly soldered to the PCB (eMMC).  \r
20 \r
21 \b References:\r
22 - Wikipedia offers more information about the <a href="http://en.wikipedia.org/wiki/SD_card" target="_blank"><b>Secure Digital</b> memory</a>.\r
23 - Wikipedia offers more information about the <a href="http://en.wikipedia.org/wiki/MultiMediaCard" target="_blank"><b>MultiMediaCard</b></a>.\r
24 - The SD Association provides detailed documentation under <a href="http://www.sdcard.org">www.sdcard.org</a>.\r
25 - The MultiMediaCard Association (merged with JEDEC) provides detailed documentation under <a href="http://www.jedec.org">www.jedec.org</a>.\r
26 \r
27 **Block Diagram**\r
28 \r
29 The MCI driver allows you to exchange data of the SD/MMC memory via SD/MMC interface.\r
30 \r
31 The following modes are supported by SD/MMC memory cards:\r
32 \r
33 - SPI bus mode: Serial Peripheral Interface Bus supported by most microcontrollers.\r
34 - 1-bit SD/MMC Bus mode: proprietary data transfer protocol supported by SD/MMC interfaces.\r
35 - 4-bit SD/MMC Bus mode: high-speed version of the SD/MMC interface using 4 data I/O pins. \r
36 - 8-bit SD/MMC Bus mode: high-speed version of the SD/MMC interface using 8 data I/O pins. \r
37 \r
38 \image html SPI_BusMode.png  "SD memory connected via SPI interface"\r
39 <p>&nbsp;</p>\r
40 \image html SD_1BitBusMode.png  "SD memory connected via 1-bit SD Bus Mode"\r
41 <p>&nbsp;</p>\r
42 \image html SD_4BitBusMode.png  "SD memory connected via 4-bit SD Bus Mode"\r
43 \r
44 \r
45 **MCI API**\r
46 \r
47 The following header files define the Application Programming Interface (API) for the MCI interface:\r
48   - \b %Driver_MCI.h : Driver API for Memory Card Interface using SD/MMC interface\r
49 \r
50 The driver implementation is a typical part of the Device Family Pack (DFP) that supports the \r
51 peripherals of the microcontroller family.\r
52 \r
53 \note\r
54 For parameters, the value marked with (default) is the setting after the driver initialization.\r
55 \r
56  \r
57 **Driver Functions**\r
58 \r
59 The driver functions are published in the access struct as explained in \ref DriverFunctions\r
60   - \ref ARM_DRIVER_MCI : access struct for MCI driver functions\r
61 @{\r
62 */\r
63 /*\r
64 A typical setup sequence for the driver is shown below:\r
65 \r
66 <b>Example Code:</b>\r
67 \r
68 \todo example\r
69 \r
70 \r
71 \r
72 */\r
73 \r
74 /*************   Structures ******************************************************************************************************/\r
75 /** \r
76 \struct     ARM_DRIVER_MCI \r
77 \details \r
78 The functions of the MCI are accessed by function pointers exposed by this structure. Refer to \ref DriverFunctions for overview information.\r
79 \r
80 Each instance of an MCI provides such an access structure. \r
81 The instance is identified by a postfix number in the symbol name of the access structure, for example:\r
82  - \b Driver_MCI0 is the name of the access struct of the first instance (no. 0).\r
83  - \b Driver_MCI1 is the name of the access struct of the second instance (no. 1).\r
84 \r
85 A configuration setting in the middleware allows connecting the middleware to a specific driver instance <b>Driver_MCI<i>n</i></b>.\r
86 The default is \token{0}, which connects a middleware to the first instance of a driver.\r
87 *******************************************************************************************************************/\r
88 \r
89 /** \r
90 \struct     ARM_MCI_CAPABILITIES \r
91 \details \r
92 A MCI driver can be implemented with different capabilities.  \r
93 The data fields of this struct encode the capabilities implemented by this driver.\r
94 \r
95 <b>Returned by:</b>\r
96   - \ref ARM_MCI_GetCapabilities\r
97 *******************************************************************************************************************/\r
98 \r
99 /**\r
100 \defgroup mci_event_gr MCI Events\r
101 \brief The MCI driver generates call back events that are notified via the function \ref ARM_MCI_SignalEvent.\r
102 \details\r
103 This section provides the event values for the \ref ARM_MCI_SignalEvent callback function.\r
104 \r
105 The following call back notification events are generated:\r
106 @{\r
107 \def ARM_MCI_EVENT_CARD_INSERTED   \r
108 \sa \ref ARM_MCI_SignalEvent\r
109 \def ARM_MCI_EVENT_CARD_REMOVED    \r
110 \sa \ref  ARM_MCI_SignalEvent\r
111 \def ARM_MCI_EVENT_COMMAND_COMPLETE \r
112 \sa \ref ARM_MCI_SignalEvent\r
113 \def ARM_MCI_EVENT_COMMAND_TIMEOUT  \r
114 \sa \ref ARM_MCI_SignalEvent\r
115 \def ARM_MCI_EVENT_COMMAND_ERROR    \r
116 \sa \ref ARM_MCI_SignalEvent\r
117 \def ARM_MCI_EVENT_TRANSFER_COMPLETE\r
118 \sa \ref ARM_MCI_SignalEvent\r
119 \def ARM_MCI_EVENT_TRANSFER_TIMEOUT \r
120 \sa \ref ARM_MCI_SignalEvent\r
121 \def ARM_MCI_EVENT_TRANSFER_ERROR   \r
122 \sa \ref ARM_MCI_SignalEvent\r
123 \def ARM_MCI_EVENT_SDIO_INTERRUPT   \r
124 \sa \ref ARM_MCI_SignalEvent\r
125 \def ARM_MCI_EVENT_CCS              \r
126 \sa \ref ARM_MCI_SignalEvent\r
127 \def ARM_MCI_EVENT_CCS_TIMEOUT      \r
128 \sa \ref ARM_MCI_SignalEvent\r
129 @}\r
130 *******************************************************************************************************************/\r
131 \r
132 //open mci_contorl_gr\r
133 /**  \r
134 @{\r
135 */\r
136 /**\r
137 \defgroup mci_control_gr MCI Control Codes\r
138 \ingroup mci_interface_gr\r
139 \brief Configure and control the MCI using the \ref ARM_MCI_Control.\r
140 \details\r
141 @{\r
142 Many parameters of the MCI driver are configured using the \ref ARM_MCI_Control function.\r
143 \r
144 The various MCI control codes define:\r
145   - \ref mci_mode_ctrls configures and controls the MCI interface\r
146   - \ref mci_bus_speed_ctrls specifies the bus speed mode\r
147   - \ref mci_bus_data_width_ctrls specifies the data bus width\r
148   - \ref mci_cmd_line_ctrls specifies the CMD line mode\r
149   - \ref mci_driver_strength_ctrls specifies the driver strength\r
150 \r
151 Refer to the function \ref ARM_MCI_Control for further details.\r
152 @}\r
153 *******************************************************************************************************************/\r
154 \r
155 \r
156 /**\r
157 \defgroup mci_mode_ctrls MCI Controls\r
158 \ingroup mci_control_gr\r
159 \brief Configure and control the MCI interface.\r
160 \details\r
161 The following codes are used as values for the parameter \em control of the function \ref ARM_MCI_Control to setup the MCI interface.\r
162 @{\r
163 \def ARM_MCI_BUS_SPEED       \r
164 \def ARM_MCI_BUS_SPEED_MODE       \r
165 \def ARM_MCI_BUS_CMD_MODE         \r
166 \def ARM_MCI_BUS_DATA_WIDTH       \r
167 \def ARM_MCI_DRIVER_STRENGTH       \r
168 \def ARM_MCI_CONTROL_RESET         \r
169 \def ARM_MCI_CONTROL_CLOCK_IDLE    \r
170 \def ARM_MCI_UHS_TUNING_OPERATION \r
171 \def ARM_MCI_UHS_TUNING_RESULT\r
172 \def ARM_MCI_DATA_TIMEOUT          \r
173 \def ARM_MCI_CSS_TIMEOUT            \r
174 \def ARM_MCI_MONITOR_SDIO_INTERRUPT \r
175 \def ARM_MCI_CONTROL_READ_WAIT      \r
176 \def ARM_MCI_SUSPEND_TRANSFER       \r
177 \def ARM_MCI_RESUME_TRANSFER        \r
178 @}\r
179 *******************************************************************************************************************/\r
180 \r
181 \r
182 /**\r
183 \defgroup mci_bus_speed_ctrls MCI Bus Speed Mode\r
184 \ingroup mci_control_gr\r
185 \brief Specify the bus speed mode.\r
186 \details\r
187 @{\r
188 The function \ref ARM_MCI_Control with \em control = \ref ARM_MCI_BUS_SPEED configures the bus speed of the MCI to the\r
189 requested bits/s specified with \em arg.\r
190 \r
191 The function \ref ARM_MCI_Control with \em control = \ref ARM_MCI_BUS_SPEED_MODE configures the bus speed mode of the MCI\r
192 as specified with \em arg listed bellow.\r
193 \r
194 The function \ref ARM_MCI_GetCapabilities lists the supported bus speed modes. Initially, all SD cards use a 3.3 volt electrical interface. \r
195 Some SD cards can switch to 1.8 volt operation. For example, the use of ultra-high-speed (UHS) \r
196 SD cards requires 1.8 volt operation and a 4-bit bus data width. The data field \em uhs_signaling of the structure ARM_MCI_CAPABILITIES encodes \r
197 whether the driver supports 1.8 volt UHS signaling.\r
198 \r
199 \sa \r
200  - \ref mci_driver_strength_ctrls\r
201 \r
202 The following codes are defined:\r
203 \r
204 \def ARM_MCI_BUS_DEFAULT_SPEED     \r
205 \def ARM_MCI_BUS_HIGH_SPEED        \r
206 \def ARM_MCI_BUS_UHS_SDR12         \r
207 \def ARM_MCI_BUS_UHS_SDR25         \r
208 \def ARM_MCI_BUS_UHS_SDR50         \r
209 \def ARM_MCI_BUS_UHS_SDR104        \r
210 \def ARM_MCI_BUS_UHS_DDR50         \r
211 @}\r
212 *******************************************************************************************************************/\r
213 \r
214 \r
215 /**\r
216 \defgroup mci_bus_data_width_ctrls MCI Bus Data Width\r
217 \ingroup mci_control_gr\r
218 \brief Specify the data bus width.\r
219 \details\r
220 @{\r
221 The function \ref ARM_MCI_Control with \em control = \ref ARM_MCI_BUS_DATA_WIDTH specifies with \em arg the number of data I/O pins on the SD/MMC interface.\r
222 \r
223 For high-speed memory cards, a 4-bit bus data width should be used (or 8-bit for eMMC). The data fields \em data_width_4 and \em data_width_8 \r
224 of the structure ARM_MCI_CAPABILITIES encode whether the driver supports a specific bus data with.\r
225 \r
226 The following codes are defined:\r
227 \r
228 \def ARM_MCI_BUS_DATA_WIDTH_1        \r
229 \def ARM_MCI_BUS_DATA_WIDTH_4        \r
230 \def ARM_MCI_BUS_DATA_WIDTH_8        \r
231 \def ARM_MCI_BUS_DATA_WIDTH_4_DDR    \r
232 \def ARM_MCI_BUS_DATA_WIDTH_8_DDR    \r
233 @}\r
234 *******************************************************************************************************************/\r
235 \r
236 \r
237 /**\r
238 \defgroup mci_cmd_line_ctrls MCI CMD Line Mode\r
239 \ingroup mci_control_gr\r
240 \brief Specify the CMD line mode (Push-Pull or Open Drain).\r
241 \details\r
242 @{\r
243 Set the CMD line type with the function \ref ARM_MCI_Control. \r
244 The CMD line mode is push-pull (default) or open drain (needed for older MMC).\r
245 \r
246 \def ARM_MCI_BUS_CMD_PUSH_PULL       \r
247 \def ARM_MCI_BUS_CMD_OPEN_DRAIN      \r
248 @}\r
249 *******************************************************************************************************************/\r
250 \r
251 \r
252 /**\r
253 \defgroup mci_driver_strength_ctrls MCI Driver Strength\r
254 \ingroup mci_control_gr\r
255 \brief Specify the driver strength.\r
256 \details\r
257 @{\r
258 The function \ref ARM_MCI_Control with \em control = \ref ARM_MCI_DRIVER_STRENGTH specifies with \em arg the driver type of the SD interface.\r
259 \r
260 \sa\r
261   - \ref mci_bus_speed_ctrls\r
262 \r
263 The following codes are defined:\r
264 \r
265 \def ARM_MCI_DRIVER_TYPE_A      \r
266 \def ARM_MCI_DRIVER_TYPE_B      \r
267 \def ARM_MCI_DRIVER_TYPE_C      \r
268 \def ARM_MCI_DRIVER_TYPE_D      \r
269 @}\r
270 *******************************************************************************************************************/\r
271 \r
272 /**\r
273 @}\r
274 */   // close group mci_control_gr\r
275 \r
276 /**\r
277 \defgroup mci_send_command_flags_ctrls MCI Send Command Flags\r
278 \ingroup mci_interface_gr\r
279 \brief Specify various options for sending commands to the card and the expected response.\r
280 \details\r
281 \b ARM_MCI_xxx flags are sent with the function \ref ARM_MCI_SendCommand as the parameter \em flag. \r
282 It controls the behavior of the command sent to the card and provides information about the expected response from the card.\r
283 \r
284 The following codes are defined:\r
285 @{\r
286 \def ARM_MCI_RESPONSE_NONE           \r
287 \def ARM_MCI_RESPONSE_SHORT          \r
288 \def ARM_MCI_RESPONSE_SHORT_BUSY     \r
289 \def ARM_MCI_RESPONSE_LONG           \r
290 \def ARM_MCI_RESPONSE_INDEX          \r
291 \def ARM_MCI_RESPONSE_CRC            \r
292 \def ARM_MCI_WAIT_BUSY             \r
293 \def ARM_MCI_TRANSFER_DATA         \r
294 \def ARM_MCI_CARD_INITIALIZE       \r
295 \def ARM_MCI_INTERRUPT_COMMAND     \r
296 \def ARM_MCI_INTERRUPT_RESPONSE    \r
297 \def ARM_MCI_BOOT_OPERATION        \r
298 \def ARM_MCI_BOOT_ALTERNATIVE      \r
299 \def ARM_MCI_BOOT_ACK              \r
300 \def ARM_MCI_CCSD                  \r
301 \def ARM_MCI_CCS                   \r
302 @}\r
303 *******************************************************************************************************************/\r
304 \r
305 /**\r
306 \defgroup mci_transfer_ctrls MCI Transfer Controls\r
307 \ingroup mci_interface_gr\r
308 \brief  Specify data transfer mode.\r
309 \details\r
310 Data transfer codes specifies the transfer direction and type and are used with the function \ref ARM_MCI_SetupTransfer as the parameter \em mode.\r
311 \r
312 The following codes are defined:\r
313 @{\r
314 \def ARM_MCI_TRANSFER_READ          \r
315 \def ARM_MCI_TRANSFER_WRITE         \r
316 \def ARM_MCI_TRANSFER_BLOCK         \r
317 \def ARM_MCI_TRANSFER_STREAM        \r
318 @}\r
319 *******************************************************************************************************************/\r
320 \r
321 /**\r
322 \defgroup mci_card_power_ctrls MCI Card Power Controls\r
323 \ingroup mci_interface_gr\r
324 \brief Specify Memory Card Power supply voltage\r
325 \details\r
326 Specifies the power supply volatge for a memory card. Used with the function \ref ARM_MCI_CardPower as the parameter \em voltage.\r
327 \r
328 The following codes are defined:\r
329 @{\r
330 \def ARM_MCI_POWER_VDD_OFF      \r
331 \def ARM_MCI_POWER_VDD_3V3      \r
332 \def ARM_MCI_POWER_VDD_1V8      \r
333 \def ARM_MCI_POWER_VCCQ_OFF     \r
334 \def ARM_MCI_POWER_VCCQ_3V3     \r
335 \def ARM_MCI_POWER_VCCQ_1V8     \r
336 \def ARM_MCI_POWER_VCCQ_1V2     \r
337 @}\r
338 *******************************************************************************************************************/\r
339 \r
340 \r
341 /**\r
342 \struct   ARM_MCI_STATUS\r
343 \details \r
344 Structure with information about the status of the MCI.\r
345 \r
346 <b>Returned by:</b>\r
347   - \ref ARM_MCI_GetStatus\r
348 *******************************************************************************************************************/\r
349 \r
350 /**\r
351 \typedef    ARM_MCI_SignalEvent_t\r
352 \details\r
353 Provides the typedef for the callback function \ref ARM_MCI_SignalEvent.\r
354 \r
355 <b>Parameter for:</b>\r
356   - \ref ARM_MCI_Initialize\r
357 *******************************************************************************************************************/\r
358 \r
359 \r
360 //\r
361 //   Functions \r
362 //\r
363 ARM_DRIVER_VERSION ARM_MCI_GetVersion (void)  {\r
364   return { 0, 0 };\r
365 }\r
366 /**\r
367 \fn       ARM_DRIVER_VERSION ARM_MCI_GetVersion (void)\r
368 \details\r
369 The function \b ARM_MCI_GetVersion returns version information of the driver implementation in \ref ARM_DRIVER_VERSION\r
370  - API version is the version of the CMSIS-Driver specification used to implement this driver.\r
371  - Driver version is source code version of the actual driver implementation.\r
372 \r
373 Example:\r
374 \code\r
375 extern ARM_DRIVER_MCI Driver_MCI0;\r
376 ARM_DRIVER_MCI *drv_info;\r
377  \r
378 void setup_mci (void)  {\r
379   ARM_DRIVER_VERSION  version;\r
380  \r
381   drv_info = &Driver_MCI0;\r
382   version = drv_info->GetVersion ();\r
383   if (version.api < 0x10A)   {      // requires at minimum API version 1.10 or higher\r
384     // error handling\r
385     return;\r
386   }\r
387 }\r
388 \endcode\r
389 *******************************************************************************************************************/\r
390 \r
391 ARM_MCI_CAPABILITIES ARM_MCI_GetCapabilities (void)  {\r
392   return { 0 };\r
393 }\r
394 /**\r
395 \fn       ARM_MCI_CAPABILITIES ARM_MCI_GetCapabilities (void)\r
396 \details\r
397 The function \b ARM_MCI_GetCapabilities returns information about capabilities in this driver implementation.\r
398 The data fields of the structure \ref ARM_MCI_CAPABILITIES encode various capabilities, for example\r
399 supported bus modes ...\r
400  \r
401 Example:\r
402 \code\r
403 extern ARM_DRIVER_MCI Driver_MCI0;\r
404 ARM_DRIVER_MCI *drv_info;\r
405   \r
406 void read_capabilities (void)  {\r
407   ARM_MCI_CAPABILITIES drv_capabilities;\r
408  \r
409   drv_info = &Driver_MCI0;  \r
410   drv_capabilities = drv_info->GetCapabilities ();\r
411   // interrogate capabilities\r
412  \r
413 }\r
414 \endcode\r
415 *******************************************************************************************************************/\r
416 \r
417 int32_t ARM_MCI_Initialize (ARM_MCI_SignalEvent_t cb_event)  {\r
418   return ARM_DRIVER_OK;\r
419 }\r
420 /**\r
421 \fn       int32_t ARM_MCI_Initialize (ARM_MCI_SignalEvent_t cb_event)\r
422 \details\r
423 The function \b ARM_MCI_Initialize initializes the MCI interface. \r
424 It is called when the middleware component starts operation.\r
425 \r
426 The function performs the following operations:\r
427   - Initializes the resources needed for the MCI interface.\r
428   - Registers the \ref ARM_MCI_SignalEvent callback function.\r
429 \r
430 The parameter \em cb_event is a pointer to the \ref ARM_MCI_SignalEvent callback function; use a NULL pointer \r
431 when no callback signals are required.\r
432 \r
433 \b Example:\r
434  - see \ref mci_interface_gr - Driver Functions\r
435 \r
436 *******************************************************************************************************************/\r
437 \r
438 int32_t ARM_MCI_Uninitialize (void)  {\r
439   return ARM_DRIVER_OK;\r
440 }\r
441 /**\r
442 \fn       int32_t ARM_MCI_Uninitialize (void)\r
443 \details\r
444 The function \b ARM_MCI_Uninitialize de-initializes the resources of I2C interface.\r
445 \r
446 It is called when the middleware component stops operation and releases the software resources used by the interface.\r
447 *******************************************************************************************************************/\r
448 \r
449 int32_t ARM_MCI_PowerControl (ARM_POWER_STATE state)  {\r
450   return ARM_DRIVER_OK;\r
451 }\r
452 /**\r
453 \fn int32_t ARM_MCI_PowerControl (ARM_POWER_STATE state)\r
454 \details     \r
455 The function \b ARM_MCI_PowerControl operates the power modes of the MCI interface.  \r
456 \r
457 The parameter \em state can have the following values:\r
458   - \ref ARM_POWER_FULL : set-up peripheral for data transfers, enable interrupts (NVIC) and optionally DMA. Can be called multiple times. \r
459                           If the peripheral is already in this mode, then the function performs no operation and returns with \ref ARM_DRIVER_OK.\r
460   - \ref ARM_POWER_LOW : may use power saving. Returns \ref ARM_DRIVER_ERROR_UNSUPPORTED when not implemented.\r
461   - \ref ARM_POWER_OFF : terminates any pending data transfers, disables peripheral, disables related interrupts and DMA.\r
462       \r
463 Refer to \ref CallSequence for more information.\r
464 *******************************************************************************************************************/\r
465 \r
466 int32_t ARM_MCI_CardPower (uint32_t voltage)  {\r
467   return ARM_DRIVER_OK;\r
468 }\r
469 /**\r
470 \fn int32_t ARM_MCI_CardPower (uint32_t voltage)\r
471 \details\r
472 The function \b ARM_MCI_CardPower operates the memory card power supply voltage. \r
473 \r
474 The parameter \em voltage sets the voltage. Not every voltage might be supported by the driver implementation.\r
475 The structure \ref ARM_MCI_CAPABILITIES encodes the supported voltage. Retrieve the information with the function \ref ARM_MCI_GetCapabilities and\r
476 verify the data fields.\r
477 \r
478 The following values:\r
479 \r
480 Parameter \em voltage                 | Description                   | supported when ARM_MCI_CAPABILITIES\r
481 :-------------------------------------|:------------------------------|-----------------------------------------\r
482 \ref ARM_MCI_POWER_VDD_OFF            | VDD (VCC) turned off          | <i>allways supported</i>\r
483 \ref ARM_MCI_POWER_VDD_3V3            | VDD (VCC) = \token{3.3V}      | data field \em vdd = \token{1}\r
484 \ref ARM_MCI_POWER_VDD_1V8            | VDD (VCC) = \token{1.8V}      | data field \em vdd_1v8 = \token{1} \r
485 \ref ARM_MCI_POWER_VCCQ_OFF           | eMMC VCCQ turned off          | <i>allways supported</i>\r
486 \ref ARM_MCI_POWER_VCCQ_3V3           | eMMC VCCQ = \token{3.3V}      | data field \em vccq = \token{1}\r
487 \ref ARM_MCI_POWER_VCCQ_1V8           | eMMC VCCQ = \token{1.8V}      | data field \em vccq_1v8 = \token{1}\r
488 \ref ARM_MCI_POWER_VCCQ_1V2           | eMMC VCCQ = \token{1.2V}      | data field \em vccq_1v2 = \token{1}\r
489 \r
490 *******************************************************************************************************************/\r
491 \r
492 int32_t ARM_MCI_ReadCD (void)  {\r
493   return 0;\r
494 }\r
495 /**\r
496 \fn int32_t ARM_MCI_ReadCD (void)\r
497 \details\r
498 The function \b ARM_MCI_ReadCD reads the status of the Card Detect (CD) pin.\r
499 *******************************************************************************************************************/\r
500 \r
501 int32_t ARM_MCI_ReadWP (void)  {\r
502   return 0;\r
503 }\r
504 /**\r
505 \fn int32_t ARM_MCI_ReadWP (void)\r
506 \details\r
507 The function \b ARM_MCI_ReadWP reads the status of the Write Protect (WP) pin.\r
508 *******************************************************************************************************************/\r
509 \r
510 int32_t ARM_MCI_SendCommand (uint32_t cmd, uint32_t arg, uint32_t flags, uint32_t *response)  {\r
511   return ARM_DRIVER_OK;\r
512 }\r
513 /**\r
514 \fn int32_t ARM_MCI_SendCommand (uint32_t cmd, uint32_t arg, uint32_t flags, uint32_t *response)\r
515 \details\r
516 The function \b ARM_MCI_SendCommand \r
517  - sends commands to the memory card \r
518  - retrieve the response from the card \r
519  - optionally, start the data transfer.\r
520 \r
521 The parameter \em cmd is the command sent to the card. \n\r
522 The parameter \em arg contains arguments for the command \em cmd. \n\r
523 The parameter \em flags controls the behavior of the operation and takes predefined values listed in the table below. \n\r
524 The parameter \em response is a pointer to receive data.\r
525 \r
526 The parameter \em flags can have the following values:\r
527 \r
528 Parameter \em flags                   | Description\r
529 :-------------------------------------|:------------\r
530 \ref ARM_MCI_RESPONSE_NONE            | No response expected (default)\r
531 \ref ARM_MCI_RESPONSE_SHORT           | Short response (\token{48}-bit) expected\r
532 \ref ARM_MCI_RESPONSE_SHORT_BUSY      | Short response with busy signal (\token{48}-bit) expected\r
533 \ref ARM_MCI_RESPONSE_LONG            | Long response (\token{136}-bit) expected\r
534 \ref ARM_MCI_RESPONSE_INDEX           | Check command index in response\r
535 \ref ARM_MCI_RESPONSE_CRC             | Check CRC in response\r
536 \ref ARM_MCI_WAIT_BUSY                | Wait until busy before sending the command\r
537 \ref ARM_MCI_TRANSFER_DATA            | Activate Data transfer\r
538 \ref ARM_MCI_CARD_INITIALIZE          | Execute Memory Card initialization sequence\r
539 \ref ARM_MCI_INTERRUPT_COMMAND        | Send Interrupt command (CMD40 - MMC only)\r
540 \ref ARM_MCI_INTERRUPT_RESPONSE       | Send Interrupt response (CMD40 - MMC only)\r
541 \ref ARM_MCI_BOOT_OPERATION           | Execute Boot operation (MMC only)\r
542 \ref ARM_MCI_BOOT_ALTERNATIVE         | Execute Alternative Boot operation (MMC only)\r
543 \ref ARM_MCI_BOOT_ACK                 | Expect Boot Acknowledge (MMC only)\r
544 \ref ARM_MCI_CCSD                     | Send Command Completion Signal Disable (CCSD) for CE-ATA device\r
545 \ref ARM_MCI_CCS                      | Expect Command Completion Signal (CCS) for CE-ATA device\r
546 \r
547 Calling the function <b>ARM_MCI_SendCommand</b> only starts the operation.\r
548 The function is non-blocking and returns as soon as the driver has started the operation.\r
549 It is not allowed to call this function again until the operation is in progress.\r
550 \r
551 After the command is sent the response is retrieved if specified with <b>ARM_MCI_RESPONSE_xxx</b> flags.\r
552 When the command completes successfully (requested response is received without errors) the \ref ARM_MCI_EVENT_COMMAND_COMPLETE event is generated.\r
553 In case that response is requested but not received the \ref ARM_MCI_EVENT_COMMAND_TIMEOUT event is generated instead.\r
554 In case of invalid response (or CRC error) the \ref ARM_MCI_EVENT_COMMAND_ERROR event is generated instead.\r
555 Progress of command operation can be monitored by calling the \ref ARM_MCI_GetStatus and checking the \em command_active flag.\r
556 \r
557 After the command operation the data transfer operation is started if specified with <b>ARM_MCI_TRANSFER_DATA</b> flag.\r
558 The data transfer needs to be configured before that by calling the \ref ARM_MCI_SetupTransfer.\r
559 When the data transfer completes successfully the \ref ARM_MCI_EVENT_TRANSFER_COMPLETE event is generated.\r
560 In case that data transfer is not completed in-time (specified by \ref ARM_MCI_DATA_TIMEOUT) the \ref ARM_MCI_EVENT_TRANSFER_TIMEOUT event is generated instead.\r
561 In case of CRC errors the \ref ARM_MCI_EVENT_TRANSFER_ERROR event is generated instead.\r
562 Progress of data transfer operation can be monitored by calling the \ref ARM_MCI_GetStatus and checking the \em transfer_active flag.\r
563 \r
564 <b>See also:</b>\r
565  - \ref ARM_MCI_SignalEvent\r
566 *******************************************************************************************************************/\r
567 \r
568 int32_t ARM_MCI_SetupTransfer (uint8_t  *data, uint32_t block_count, uint32_t block_size, uint32_t mode)  {\r
569   return ARM_DRIVER_OK;\r
570 }\r
571 /**\r
572 \fn int32_t ARM_MCI_SetupTransfer (uint8_t  *data, uint32_t block_count, uint32_t block_size, uint32_t mode) \r
573 \details\r
574 The function \b ARM_MCI_SetupTransfer prepares the data transfer operation that is initiated \r
575 by calling the function \ref ARM_MCI_SendCommand with the parameter \em flags = \ref ARM_MCI_TRANSFER_DATA.\r
576 \r
577 The parameter \em data is a pointer to the data to transfer. \n\r
578 The parameter \em block_count is the number of blocks to transfer. \n\r
579 The parameter \em block_size is the size of a block. \n\r
580 The parameter \em mode sets the transfer mode and can have the values liste in the table below:\r
581 \r
582 Transfer Directions                   | Description\r
583 :-------------------------------------|:------------\r
584 \ref ARM_MCI_TRANSFER_READ            | Read data from MCI\r
585 \ref ARM_MCI_TRANSFER_WRITE           | Write data to MCI\r
586 \ref ARM_MCI_TRANSFER_BLOCK (default) | Block Data transfer \r
587 \ref ARM_MCI_TRANSFER_STREAM          | Stream Data transfer (MMC only)\r
588                                     \r
589 *******************************************************************************************************************/\r
590 \r
591 int32_t ARM_MCI_AbortTransfer (void)  {\r
592   return ARM_DRIVER_OK;\r
593 }\r
594 /**\r
595 \fn int32_t ARM_MCI_AbortTransfer (void)\r
596 \details\r
597 The function \b ARM_MCI_AbortTransfer aborts the active data transfer operation initiated with \ref ARM_MCI_SendCommand.\r
598 *******************************************************************************************************************/\r
599 \r
600 \r
601 int32_t ARM_MCI_Control (uint32_t control, uint32_t arg)  {\r
602   return ARM_DRIVER_OK;\r
603 }\r
604 /**\r
605 \fn            int32_t ARM_MCI_Control (uint32_t control, uint32_t arg)\r
606 \details\r
607 Th function \b ARM_MCI_Control controls the MCI interface and executes various operations.\r
608 \r
609 The parameter \em control specifies the operation.  \r
610 Values for \em control cannot be ORed, but must be called separately in the code. \n\r
611 The parameter \em arg provides, depending on the operation, additional information or sets values.\r
612 \r
613 \note\r
614 For parameters, the values marked with (default) are the setting after the driver initialization.\r
615 \r
616 The table lists values for the parameter \em control.\r
617 \r
618 Parameter \em control                 | Operation\r
619 :-------------------------------------|:------------\r
620 \ref ARM_MCI_BUS_SPEED                | Set the Bus Speed. The parameter \em arg specifies the speed in bits/s; The function returns the bus speed configured in bits/s.\r
621 \ref ARM_MCI_BUS_SPEED_MODE           | Set the Bus Speed Mode. Predefined values for \em arg are listed in the table <b>Bus Speed Mode</b>.\r
622 \ref ARM_MCI_BUS_CMD_MODE             | Set the CMD Line Mode. Predefined values for \em arg are listed in the table <b>Bus CMD Line Mode</b>.\r
623 \ref ARM_MCI_BUS_DATA_WIDTH           | Set data bus width. Predefined values for \em arg are encoded in <b>Bus Data Width</b>.\r
624 \ref ARM_MCI_DRIVER_STRENGTH          | Set driver strength. Predefined values for \em arg are listed in the table <b>Driver Type</b>\r
625 \ref ARM_MCI_CONTROL_RESET            | Control optional RST_n Pin (eMMC). The parameter \em arg can have the values \token{[0:inactive(default); 1:active]}\r
626 \ref ARM_MCI_CONTROL_CLOCK_IDLE       | Control clock generation on CLK Pin when idle. The parameter \em arg  can have the values \token{[0:disabled; 1:enabled]}\r
627 \ref ARM_MCI_UHS_TUNING_OPERATION     | Sampling clock Tuning operation (SD UHS-I). The parameter \em arg  can have the values  \token{[0:reset; 1:execute]}\r
628 \ref ARM_MCI_UHS_TUNING_RESULT        | Sampling clock Tuning result (SD UHS-I). Returns \token{[0:done; 1:in progress; -1:error]}\r
629 \ref ARM_MCI_DATA_TIMEOUT             | Set Data timeout;  The parameter \em arg sets the timeout in bus cycles.\r
630 \ref ARM_MCI_CSS_TIMEOUT              | Set Command Completion Signal (CCS) timeout. The parameter \em arg sets timeout in bus cycles.\r
631 \ref ARM_MCI_MONITOR_SDIO_INTERRUPT   | Monitor SD I/O interrupt. The parameter \em arg  can have the values \token{[0:disabled(default); 1:enabled]}. Monitoring is automatically disabled when an interrupt is recognized.\r
632 \ref ARM_MCI_CONTROL_READ_WAIT        | Control Read/Wait states for SD I/O. The parameter \em arg  can have the values \token{[0:disabled(default); 1:enabled]}.\r
633 \ref ARM_MCI_SUSPEND_TRANSFER         | Suspend Data transfer (SD I/O). Returns the number of remaining bytes to transfer.\r
634 \ref ARM_MCI_RESUME_TRANSFER          | Resume Data transfer (SD I/O).\r
635  \r
636  \r
637 <b>Bus Speed Mode</b>\r
638  \r
639 The function \ref ARM_MCI_GetCapabilities lists the supported bus speed modes. Initially, all SD cards use a 3.3 volt electrical interface. \r
640 Some SD cards can switch to 1.8 volt operation. For example, the use of ultra-high-speed (UHS) \r
641 SD cards requires 1.8 volt operation and a 4-bit bus data width. The bit field ARM_MCI_CAPABILITIES.uhs_signaling encodes \r
642 whether the driver supports 1.8 volt UHS signaling.\r
643 \r
644 The \em control operation \b ARM_MCI_BUS_SPEED_MODE  sets the bus speed mode using the parameter \em arg.\r
645 \r
646 Parameter \em arg                                             | Bus Speed Mode\r
647 :-------------------------------------------------------------|:------------------------------------------\r
648 \ref  ARM_MCI_BUS_DEFAULT_SPEED (default)                     | Set the bus speed for SD/MMC cards: Default Speed mode up to \token{[25;26]MHz} \r
649 \ref  ARM_MCI_BUS_HIGH_SPEED                                  | Set the bus speed for SD/MMC: High    Speed mode up to \token{[50;52]MHz}\r
650 \ref  ARM_MCI_BUS_UHS_SDR12                                   | Set the bus speed for SD: SDR12  (Single Data Rate) up to  \token{25MHz,  12.5MB/s: UHS-I (Ultra High Speed) 1.8V signalling}\r
651 \ref  ARM_MCI_BUS_UHS_SDR25                                   | Set the bus speed for SD: SDR25  (Single Data Rate) up to  \token{50MHz,  25  MB/s: UHS-I (Ultra High Speed) 1.8V signalling}\r
652 \ref  ARM_MCI_BUS_UHS_SDR50                                   | Set the bus speed for SD: SDR50  (Single Data Rate) up to \token{100MHz,  50  MB/s: UHS-I (Ultra High Speed) 1.8V signalling}\r
653 \ref  ARM_MCI_BUS_UHS_SDR104                                  | Set the bus speed for SD: SDR104 (Single Data Rate) up to \token{208MHz, 104  MB/s: UHS-I (Ultra High Speed) 1.8V signalling}\r
654 \ref  ARM_MCI_BUS_UHS_DDR50                                   | Set the bus speed for SD: DDR50  (Dual Data Rate)   up to  \token{50MHz,  50  MB/s: UHS-I (Ultra High Speed) 1.8V signalling}\r
655  \r
656  \r
657 <b>Bus CMD Line Mode</b> \r
658  \r
659 The \em control operation \b ARM_MCI_BUS_CMD_MODE sets the bus command line mode using the parameter \em arg.\r
660 \r
661 Parameter \em arg                                             | Bus CMD Line Mode  \r
662 :-------------------------------------------------------------|:------------------------------------------\r
663 \ref ARM_MCI_BUS_CMD_PUSH_PULL  (default)                     | Set the Push-Pull CMD line\r
664 \ref ARM_MCI_BUS_CMD_OPEN_DRAIN                               | Set the Open Drain CMD line (MMC only)\r
665  \r
666  \r
667 <b>Bus Data Width</b> \r
668  \r
669 Specifies the bus data width (the number of data I/O pins on the SD/MMC interface).\r
670  \r
671 For high speed memory cards, a 4-bit bus data width should be used (or 8-bit for eMMC). The bit fields ARM_MCI_CAPABILITIES.data_width_4 and\r
672 ARM_MCI_CAPABILITIES.data_width_8 encode whether the driver supports a specific bus data with.\r
673 \r
674 The \em control operation \b ARM_MCI_BUS_DATA_WIDTH  sets the bus data width using the parameter \em arg.\r
675 \r
676 Parameter \em arg                                             | Bus Data Width\r
677 :-------------------------------------------------------------|:------------------------------------------\r
678 \ref ARM_MCI_BUS_DATA_WIDTH_1 (default)                       | Set the Bus data width to \token{1 bit} \r
679 \ref ARM_MCI_BUS_DATA_WIDTH_4                                 | Set the Bus data width to \token{4 bits}\r
680 \ref ARM_MCI_BUS_DATA_WIDTH_8                                 | Set the Bus data width to \token{8 bits}\r
681 \ref ARM_MCI_BUS_DATA_WIDTH_4_DDR                             | Set the Bus data width to \token{4 bits}, DDR (Dual Data Rate) - MMC only\r
682 \ref ARM_MCI_BUS_DATA_WIDTH_8_DDR                             | Set the Bus data width to \token{8 bits}, DDR (Dual Data Rate) - MMC only\r
683  \r
684  \r
685 <b>Driver Type</b> \r
686  \r
687 Specifies the interface driver type.\r
688 \r
689 The \em control operation \b ARM_MCI_DRIVER_STRENGTH  sets the interface driver type using the parameter \em arg.\r
690 \r
691 Parameter \em arg                                             | Driver Type \r
692 :-------------------------------------------------------------|:------------------------------------------\r
693 \ref ARM_MCI_DRIVER_TYPE_A                                    | Set the interface to SD UHS-I Driver Type A\r
694 \ref ARM_MCI_DRIVER_TYPE_B  (default)                         | Set the interface to SD UHS-I Driver Type B \r
695 \ref ARM_MCI_DRIVER_TYPE_C                                    | Set the interface to SD UHS-I Driver Type C\r
696 \ref ARM_MCI_DRIVER_TYPE_D                                    | Set the interface to SD UHS-I Driver Type D\r
697 \r
698 \b Examples:\r
699 \code\r
700 // Set Bus Speed to 25MHz\r
701 MCIdrv->Control(ARM_MCI_BUS_SPEED, 25000000);\r
702  \r
703 // Set High Speed mode\r
704 MCIdrv->Control(ARM_MCI_BUS_SPEED_MODE, ARM_MCI_BUS_HIGH_SPEED);\r
705  \r
706 // Configure CMD line as Open Drain (MMC only)\r
707 MCIdrv->Control(ARM_MCI_BUS_CMD_MODE, ARM_MCI_BUS_CMD_OPEN_DRAIN);\r
708  \r
709 // Set Bus Data Width = 4bits\r
710 MCIdrv->Control(ARM_MCI_BUS_DATA_WIDTH, ARM_MCI_BUS_DATA_WIDTH_4);\r
711  \r
712 // Set SD UHS-I Driver Type B\r
713 MCIdrv->Control(ARM_MCI_DRIVER_STRENGTH, ARM_MCI_DRIVER_TYPE_B);\r
714  \r
715 // RTS_n Pin is not active by default\r
716 // Assert RTS_n Pin (eMMC)\r
717 MCIdrv->Control(ARM_MCI_CONTROL_RESET, 1);\r
718 // De-assert RTS_n Pin (eMMC)\r
719 MCIdrv->Control(ARM_MCI_CONTROL_RESET, 0);\r
720  \r
721 // Clock generation on CLK when Idle: hardware specific default behavior\r
722 // Enable Clock generation on CLK when Idle\r
723 MCIdrv->Control(ARM_MCI_CONTROL_CLOCK_IDLE, 1);\r
724 // Disable Clock generation on CLK when Idle\r
725 MCIdrv->Control(ARM_MCI_CONTROL_CLOCK_IDLE, 0);\r
726  \r
727 // UHS Tuning\r
728 MCIdrv->Control(ARM_MCI_UHS_TUNING_OPERATION, 1);  // start tuning\r
729 do {\r
730   status = MCIdrv->Control(ARM_MCI_UHS_TUNING_RESULT, 0/*argument not used*/);\r
731   if (status == -1) { break; /* tuning failed */ }\r
732 } while (status == 1);\r
733  \r
734 // Set Data Timeout to 12500000 bus cycles (0.5s @25MHz Bus Speed)\r
735 // Default value is hardware specific (typically 2^32-1)\r
736 MCIdrv->Control(ARM_MCI_DATA_TIMEOUT, 12500000);\r
737   \r
738 // Set CSS Timeout to 1000000 bus cycles\r
739 // Default value is hardware specific\r
740 MCIdrv->Control(ARM_MCI_CSS_TIMEOUT, 1000000);\r
741  \r
742 // SD I/O Interrupt Monitoring is disabled by default\r
743 // Enable SD I/O Interrupt Monitoring\r
744 MCIdrv->Control(ARM_MCI_MONITOR_SDIO_INTERRUPT, 1);\r
745 // Disable SD I/O Interrupt Monitoring\r
746 MCIdrv->Control(ARM_MCI_MONITOR_SDIO_INTERRUPT, 0);\r
747  \r
748 // Read/Wait for SD I/O is disabled by default\r
749 // Enable Read/Wait for SD I/O\r
750 MCIdrv->Control(ARM_MCI_CONTROL_READ_WAIT, 1);\r
751 // Disable Read/Wait for SD I/O\r
752 MCIdrv->Control(ARM_MCI_CONTROL_READ_WAIT, 0);\r
753  \r
754 // Suspend Data transfer (SD I/O)\r
755 MCIdrv->Control(ARM_MCI_SUSPEND_TRANSFER, 0/*argument not used*/);\r
756  \r
757 // Resume Data transfer (SD I/O)\r
758 MCIdrv->Control(ARM_MCI_RESUME_TRANSFER, 0/*argument not used*/);\r
759 \endcode\r
760 *******************************************************************************************************************/\r
761 \r
762 ARM_MCI_STATUS ARM_MCI_GetStatus (void)  {\r
763   return ARM_DRIVER_OK;\r
764 }\r
765 /**\r
766 \fn            ARM_MCI_STATUS ARM_MCI_GetStatus (void)\r
767 \details\r
768 The function \b ARM_MCI_GetStatus returns the current MCI interface status.\r
769 *******************************************************************************************************************/\r
770 \r
771 void ARM_MCI_SignalEvent (uint32_t event)  {\r
772  // function body\r
773 }\r
774 /**\r
775 \fn void ARM_MCI_SignalEvent (uint32_t event)\r
776 \details\r
777 The function \b ARM_MCI_SignalEvent is a callback function registered by the function \ref ARM_MCI_Initialize. \r
778 \r
779 The parameter \em event indicates one or more events that occurred during driver operation.\r
780 Each event is encoded in a separate bit and therefore it is possible to signal multiple events within the same call. \r
781 \r
782 Not every event is necessarily generated by the driver. This depends on the implemented capabilities stored in the \r
783 data fields of the structure \ref ARM_NAND_CAPABILITIES, which can be retrieved with the function \ref ARM_NAND_GetCapabilities.\r
784 \r
785 The following events can be generated:\r
786 \r
787 Parameter \em event                        |Bit | Description                                                           | supported when \ref ARM_NAND_CAPABILITIES\r
788 :------------------------------------------|---:|:----------------------------------------------------------------------|:---------------------------------------------\r
789 \ref ARM_MCI_EVENT_CARD_INSERTED           | 0  | Occurs after Memory Card inserted                                     | <i>always supported</i>\r
790 \ref ARM_MCI_EVENT_CARD_REMOVED            | 1  | Occurs after Memory Card removal                                      | <i>always supported</i>\r
791 \ref ARM_MCI_EVENT_COMMAND_COMPLETE        | 2  | Occurs after command completed successfully                           | <i>always supported</i>\r
792 \ref ARM_MCI_EVENT_COMMAND_TIMEOUT         | 3  | Occurs after command timeout                                          | <i>always supported</i>\r
793 \ref ARM_MCI_EVENT_COMMAND_ERROR           | 4  | Occurs after command response error (CRC error or invalid response)   | <i>always supported</i>\r
794 \ref ARM_MCI_EVENT_TRANSFER_COMPLETE       | 5  | Occurs after data transfer completed successfully                     | <i>always supported</i>\r
795 \ref ARM_MCI_EVENT_TRANSFER_TIMEOUT        | 6  | Occurs after data transfer timeout                                    | <i>always supported</i>\r
796 \ref ARM_MCI_EVENT_TRANSFER_ERROR          | 7  | Occurs after data transfer error (CRC failed)                         | <i>always supported</i>\r
797 \ref ARM_MCI_EVENT_SDIO_INTERRUPT          | 8  | Indicates SD I/O Interrupt                                            | data field \em sdio_interrupt = \token{1}\r
798 \ref ARM_MCI_EVENT_CCS                     | 9  | Indicates a Command Completion Signal (CCS)                           | data field \em ccs = \token{1}\r
799 \ref ARM_MCI_EVENT_CCS_TIMEOUT             |10  | Indicates a Command Completion Signal (CCS) Timeout                   | data field \em css_timeout = \token{1}\r
800 \r
801 <b>See also:</b>\r
802  - \ref ARM_MCI_SendCommand\r
803  \r
804 *******************************************************************************************************************/\r
805 \r
806 \r
807 /**\r
808 @}\r
809 */ \r
810 // End MCI Interface\r