1 /******************************************************************************* 2 * Copyright 2019-2020 Microchip FPGA Embedded Systems Solutions. 3 * 4 * SPDX-License-Identifier: MIT 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to 8 * deal in the Software without restriction, including without limitation the 9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 * sell copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 * IN THE SOFTWARE. 23 * 24 * PolarFire SoC MSS eMMC SD bare metal software driver public API. 25 * 26 */ 27 /*=========================================================================*//** 28 @mainpage PolarFire SoC MSS eMMC SD Bare Metal Driver 29 30 ============================================================================== 31 Introduction 32 ============================================================================== 33 The PolarFire SoC MSS includes an SD host controller and an eMMC/SD PHY. 34 The SD Host Controller can support multiple eMMC/SD standards with bus 35 widths of 1 bit, 4 bits, and 8 bits at clock rates up to 200 MHz. 36 37 The PolarFire SoC MSS eMMC SD software driver, provided as C source code, 38 supports a set of functions for controlling eMMC/SD as part of a bare-metal 39 system where no operating system is available. The driver can be adapted for 40 use as part of an operating system, but the implementation of the adaptation 41 layer between the driver and the operating system's driver model is outside 42 the scope of the driver. 43 44 The PolarFire SoC MSS eMMC SD driver provides the following features: 45 - Configuring the eMMC/SD/SDIO 46 - Single block read and write without DMA. 47 - Multiple or single block read and write with DMA (SDMA, ADMA2). 48 - eMMC command queue block read and write. 49 - eMMC standards LEGACY, SDR, DDR, HS200, HS400 and HS400-ES 50 - SD card standards Default Speed(DS), High Speed(HS), UHS-I(SDR12, SDR25, 51 SDR50, SDR104, DDR50). 52 - Single block read and write operation for SDIO. 53 54 ============================================================================== 55 Theory of Operation 56 ============================================================================== 57 The PolarFire SoC MSS eMMC SD driver functions allow 512-byte blocks of data 58 to be written to and read from a eMMC/SD device connected to the host 59 controller. The blocks can be read/written singly or using the multi block 60 functions. 61 There are two variants of the single block functions. One set are blocking, 62 the other are non-blocking. The multi block functions are non-blocking. 63 64 Note: The eMMC/SD device connected to the eMMC/SD host hardware must support 65 a sector size of 512-bytes. This is the default block size for the 66 eMMC/SD device > 2GB. 67 68 The PolarFire SoC MSS eMMC SD driver functions are grouped into the following 69 categories: 70 - Initialization 71 - Block Transfer Control 72 - Block Transfer Status 73 - Interrupt Handling 74 - Command Queue 75 76 -------------------------------- 77 Initialization 78 -------------------------------- 79 The initialization of the MSS eMMC SD driver involves the following steps: 80 - Initialize the mss_mmc_cfg_t data structure. 81 - Call the MSS_MMC_init() function. 82 83 The configuration data structure mss_mmc_cfg_t should set eMMC/SD/SDIO 84 clock frequency, data width, card type and speed before calling the 85 MSS_MMC_init() function. 86 87 The MSS_MMC_init() function takes a pointer to the configuration data 88 structure of type mss_mmc_cfg_t. 89 90 -------------------------------- 91 Block Transfer Control 92 -------------------------------- 93 The following functions are used for block read and write: 94 - MSS_MMC_single_block_read() 95 - MSS_MMC_single_block_write() 96 - MSS_MMC_sdma_read() 97 - MSS_MMC_sdma_write() 98 - MSS_MMC_adma2_read() 99 - MSS_MMC_adma2_write() 100 - MSS_MMC_sdio_single_block_read() 101 - MSS_MMC_sdio_single_block_write() 102 103 Write Transfer 104 105 To write a single block of data to the eMMC/SD device, a call is made to the 106 MSS_MMC_single_block_write() function. 107 108 To write a single block or multiple blocks of data to the eMMC/SD device, 109 using DMA, a call is made to the MSS_MMC_sdma_write() or MSS_MMC_adma2_write() 110 functions. 111 112 To write a single block of data to the SDIO device, a call is made to the 113 MSS_MMC_sdio_single_block_write() function. 114 115 Read Transfer 116 117 To read a single block of data stored within the eMMC/SD device, a call is 118 made to the MSS_MMC_single_block_read() function. 119 120 To read a single block or multiple blocks of data stored within the eMMC/SD 121 device, using DMA, a call is made to the MSS_MMC_sdma_read() or 122 MSS_MMC_adma2_read() functions. 123 124 To read a single block of data stored within the SDIO device, a call is made 125 to the MSS_MMC_sdio_single_block_read() function. 126 127 -------------------------------- 128 Block Transfer Status 129 -------------------------------- 130 The status of the eMMC SD block read or write transfer can be retrieved 131 using the MSS_MMC_get_transfer_status() function. 132 133 -------------------------------- 134 Interrupt Handling 135 -------------------------------- 136 The MSS_MMC_set_handler() function is used to register a handler function 137 that will be called by the driver when a block transfer completes. The 138 driver passes the outcome of the transfer to the completion handler in 139 the form of a status parameter indicating if the transfer was successful 140 or the type of error that occurred during the transfer. The application 141 must create and register a transfer completion handler function to suit 142 the application. 143 144 -------------------------------- 145 Command Queue 146 -------------------------------- 147 The following functions are used for eMMC command queue operation: 148 - MSS_MMC_cq_init() 149 - MSS_MMC_cq_write() 150 - MSS_MMC_cq_read() 151 152 The MSS_MMC_cq_init() function initializes command queue in the eMMC device 153 and the host controller. 154 155 To write a single block or multiple blocks of data to the eMMC device using 156 a command queue, a call is made to the MSS_MMC_cq_write() function. This 157 function supports up to 32 tasks. 158 159 To read a single block or multiple blocks of data stored within the eMMC 160 device using a command queue, a call is made to the MSS_MMC_cq_read() 161 function. This function supports up to 32 tasks. 162 163 *//*=========================================================================*/ 164 #ifndef __MSS_MMC_H 165 #define __MSS_MMC_H 166 167 #include <stddef.h> 168 #include <stdint.h> 169 170 #ifdef __cplusplus 171 extern "C" 172 #endif 173 174 /*----------------------------------------------------------------------------*/ 175 /* Clock rate*/ 176 #define MSS_MMC_CLOCK_400KHZ 400u 177 #define MSS_MMC_CLOCK_12_5MHZ 12500u 178 #define MSS_MMC_CLOCK_25MHZ 25000u 179 #define MSS_MMC_CLOCK_26MHZ 26000u 180 #define MSS_MMC_CLOCK_50MHZ 50000u 181 #define MSS_MMC_CLOCK_100MHZ 100000u 182 #define MSS_MMC_CLOCK_200MHZ 200000u 183 /* card type */ 184 #define MSS_MMC_CARD_TYPE_NONE 0u 185 #define MSS_MMC_CARD_TYPE_MMC 1u 186 #define MSS_MMC_CARD_TYPE_SD 2u 187 #define MSS_MMC_CARD_TYPE_SDIO 3u 188 #define MSS_MMC_CARD_TYPE_COMBO 4u 189 190 /* Host controller eMMC mode select */ 191 192 /* High-speed single data rate supports clock frequency up to 52 MHz and data 193 * bus width of 1 bit, 4 bits, and 8 bits. 194 */ 195 #define MSS_MMC_MODE_SDR 0x2u 196 197 /* High speed double data rate supports clock frequency up to 52 MHz and data 198 * bus width of 4 bits and 8 bits. 199 */ 200 #define MSS_MMC_MODE_DDR 0x3u 201 202 /* SDR data sampling supports clock frequency up to 200 MHz and data bus width 203 * of 4 bits and 8 bits. 204 */ 205 #define MSS_MMC_MODE_HS200 0x4u 206 207 /* DDR data sampling supports clock frequency up to 200 MHz and data bus width 208 * of 8 bits. 209 */ 210 #define MSS_MMC_MODE_HS400 0x5u 211 212 /* HS400 mode with Enhanced Strobe. */ 213 #define MSS_MMC_MODE_HS400_ES 0x6u 214 215 /* Backwards compatibility with legacy MMC card supports clock frequency up to 216 * 26MHz and data bus width of 1 bit, 4 bits, and 8 bits. 217 */ 218 #define MSS_MMC_MODE_LEGACY 0x7u 219 220 #define MSS_MMC_MODE_MASK 0x00000007u 221 #define MSS_MMC_MODE_SDCARD 0x0u 222 223 /* Host controller SD/SDIO card mode select */ 224 225 /* Default speed supports clock frequency up to 25 MHz and data bus width of 226 * 4 bits. 227 */ 228 #define MSS_SDCARD_MODE_DEFAULT_SPEED 0x8u 229 230 /* High-speed supports clock frequency up to 50 MHz and data bus width of 231 * 4 bits. 232 */ 233 #define MSS_SDCARD_MODE_HIGH_SPEED 0x9u 234 235 /* Ultra-High speed-I (UHS-I) single data rate supports clock frequency up to 236 * 25 MHz and data bus width of 4 bits. 237 */ 238 #define MSS_SDCARD_MODE_SDR12 0xAu 239 240 /* Ultra-High speed-I (UHS-I) single data rate supports clock frequency up to 241 * 50 MHz and data bus width of 4 bits. 242 */ 243 #define MSS_SDCARD_MODE_SDR25 0xBu 244 245 /* Ultra-High speed-I (UHS-I) single data rate supports clock frequency up to 246 * 100 MHz and data bus width of 4 bits. 247 */ 248 #define MSS_SDCARD_MODE_SDR50 0xCu 249 250 /* Ultra-High speed-I (UHS-I) single data rate supports clock frequency up to 251 * 208 MHz and data bus width of 4 bits. 252 */ 253 #define MSS_SDCARD_MODE_SDR104 0xDu 254 255 /* Ultra-High speed-I (UHS-I) double data rate supports clock frequency up to 256 * 50 MHz and data bus width of 4 bits. 257 */ 258 #define MSS_SDCARD_MODE_DDR50 0xEu 259 260 /* Host controller data width */ 261 #define MSS_MMC_DATA_WIDTH_1BIT 0x00u 262 #define MSS_MMC_DATA_WIDTH_4BIT 0x01u 263 #define MSS_MMC_DATA_WIDTH_8BIT 0x02u 264 265 /* eMMC bus voltage */ 266 /* 1.8v */ 267 #define MSS_MMC_1_8V_BUS_VOLTAGE 18u 268 /* 3.3v */ 269 #define MSS_MMC_3_3V_BUS_VOLTAGE 33u 270 271 #define MSS_SDIO_FUNCTION_NUMBER_0 0u 272 #define MSS_SDIO_FUNCTION_NUMBER_1 1u 273 #define MSS_SDIO_FUNCTION_NUMBER_2 2u 274 #define MSS_SDIO_FUNCTION_NUMBER_3 3u 275 #define MSS_SDIO_FUNCTION_NUMBER_4 4u 276 #define MSS_SDIO_FUNCTION_NUMBER_5 5u 277 #define MSS_SDIO_FUNCTION_NUMBER_6 6u 278 #define MSS_SDIO_FUNCTION_NUMBER_7 7u 279 280 /*-------------------------------------------------------------------------*//** 281 The mss_mmc_status_t type is used to indicate the return status of the eMMC/SD 282 data transfer. A variable of this type is returned by the MSS_MMC_init(), 283 MSS_MMC_single_block_write(), MSS_MMC_single_block_read(), MSS_MMC_sdma_write(), 284 MSS_MMC_sdma_read(), MSS_MMC_adma2_write(), MSS_MMC_adma2_read(), 285 MSS_MMC_cq_init(), MSS_MMC_cq_write(), MSS_MMC_cq_read(), 286 MSS_MMC_sdio_single_block_read(), MSS_MMC_sdio_single_block_write() functions. 287 */ 288 typedef enum 289 { 290 MSS_MMC_INIT_SUCCESS = 0u, 291 MSS_MMC_INIT_FAILURE, 292 MSS_MMC_NOT_INITIALISED, 293 MSS_MMC_TRANSFER_IN_PROGRESS, 294 MSS_MMC_TRANSFER_FAIL, 295 MSS_MMC_TRANSFER_SUCCESS, 296 MSS_MMC_DWIDTH_ERR, 297 MSS_MMC_RCA_ERROR, 298 MSS_MMC_CID_RESP_ERR, 299 MSS_MMC_OP_COND_ERR, 300 MSS_MMC_RESET_ERR, 301 MSS_MMC_CRC_ERR, 302 MSS_MMC_UNSUPPORTED_HW_REVISION, 303 MSS_MMC_INVALID_PARAMETER, 304 MSS_MMC_NO_ERROR, 305 MSS_MMC_BASE_CLK_IS_ZERO_ERR, 306 MSS_MMC_CARD_STATE_STABLE_ERR, 307 MSS_MMC_CARD_INSERTED_ERR, 308 MSS_MMC_MODE_NOT_SUPPORT_DATAWIDTH, 309 MSS_MMC_CLK_DIV_ERR, 310 MSS_MMC_RESPONSE_ERROR, 311 MSS_MMC_ERR_INTERRUPT, 312 MSS_MMC_ERR_SWITCH_VOLTAGE_FAILED, 313 MSS_MMC_CARD_SELECT_ERROR, 314 MSS_MMC_CARD_SELECT_SUCCESS, 315 MSS_MMC_DEVICE_NOT_SUPPORT_HS400, 316 MSS_MMC_DEVICE_NOT_SUPPORT_HS200, 317 MSS_MMC_DEVICE_NOT_SUPPORT_DDR, 318 MSS_MMC_DEVICE_NOT_SUPPORT_SDR, 319 MSS_MMC_DEVICE_NOT_SUPPORT_LOW_POWER, 320 MSS_MMC_HS400_MODE_SETUP_FAILURE, 321 MSS_MMC_DEVICE_NOT_SUPPORT_CQ, 322 MSS_MMC_CQ_INIT_FAILURE, 323 MSS_MMC_CQ_NOT_INITIALISED, 324 MSS_MMC_SDCARD_NOT_SUPPORT_SPEED, 325 MSS_MMC_SDCARD_NOT_SUPPORT_VOLTAGE, 326 MSS_MMC_SDCARD_NOT_SUPPORT_BUS_MODE, 327 MSS_MMC_SDCARD_CMD6_SWITCH_ERROR, 328 MSS_MMC_SDCARD_TUNING_FAILED, 329 MSS_MMC_SDIO_ERR_BUS_SPEED_UNSUPP, 330 MSS_MMC_DEVICE_NOT_SUPPORT_HPI, 331 MSS_MMC_DEVICE_IS_NOT_IN_HPI_MODE, 332 MSS_MMC_DEVICE_HPI_NOT_DISABLED, 333 MSS_MMC_DATA_SIZE_IS_NOT_MULTI_BLOCK, 334 MSS_MMC_DEVICE_ERROR 335 } mss_mmc_status_t; 336 337 /*-------------------------------------------------------------------------*//** 338 The mss_mmc_cfg_t type provides the prototype for the configuration values of 339 the MSS eMMC SD driver. The application need to create a record of this type 340 to hold the configuration of the eMMC/SD/SDIO. The MSS_MMC_init() function 341 initializes the MSS eMMC SD using this structure. A pointer to an initialized 342 of this structure should be passed as the first parameter to the 343 MSS_MMC_init() function. 344 */ 345 typedef struct 346 { 347 /* Specifies the clock frequency of the eMMC/SD/SDIO devices */ 348 uint32_t clk_rate; 349 /* Specifies the card type is the eMMC/SD/SDIO */ 350 uint8_t card_type; 351 /* Specifies the data bus width of the eMMC/SD/SDIO */ 352 uint8_t data_bus_width; 353 /* Specifies the bus speed mode of the eMMC/SD/SDIO */ 354 uint8_t bus_speed_mode; 355 /* Specifies the bus voltage for eMMC only */ 356 uint8_t bus_voltage; 357 } mss_mmc_cfg_t; 358 359 /*-------------------------------------------------------------------------*//** 360 This type definition specifies the prototype of a function that can be 361 registered with this driver as a eMMC/SD transfer completion handler function 362 through a call to MSS_MMC_set_handler(). The eMMC/SD transfer completion 363 handler will be called by the driver when an eMMC/SD transfer completes. The 364 PolarFire SoC MSS eMMC SD driver passes the outcome of the transfer to the 365 completion handler in the form of a status parameter indicating if the 366 transfer is successful or the type of error that occurred during the transfer. 367 */ 368 typedef void (*mss_mmc_handler_t)(uint32_t status); 369 370 /*-----------------------------Public APIs------------------------------------*/ 371 372 /*-------------------------------------------------------------------------*//** 373 The MSS_MMC_init() function initializes the MSS eMMC SD host controller and 374 the eMMC/SD/SDIO device. The MSS_MMC_init()function takes a pointer to a 375 configuration data structure of type mss_mmc_cfg_t as parameter. This 376 configuration data structure contains all the information required to 377 configure the MSS eMMC SD. 378 The configuration passed to the MSS_MMC_init() function specifies the type 379 of interface used to connect the MSS eMMC SD host controller and the 380 eMMC/SD/SDIO device. It also specifies the allowed clock frequency, data bus 381 width and bus speed mode. The MSS_MMC_init() function must be called prior 382 to any MSS eMMC SD data transfer functions being called. 383 384 @param cfg 385 This parameter is a pointer to a data structure of type mss_mmc_cfg_t 386 containing the MSS eMMC SD desired configuration. The application must fill 387 the configuration data structure parameters before passing it as parameter to 388 the call to the MSS_MMC_init() function. 389 390 @return 391 This function returns the initialization status of the eMMC/SD/SDIO device as 392 a value of type mss_mmc_status_t. 393 394 Example: 395 The following example shows how to initialize the eMMC device and configure 396 the data rate 25Mhz. 397 @code 398 399 mss_mmc_cfg_t g_mmc0; 400 mss_mmc_status_t ret_status; 401 402 g_mmc0.clk_rate = MSS_MMC_CLOCK_25MHZ; 403 g_mmc0.card_type = MSS_MMC_CARD_TYPE_MMC; 404 g_mmc0.data_bus_width = MSS_MMC_DATA_WIDTH_4BIT; 405 g_mmc0.bus_speed_mode = MSS_MMC_MODE_LEGACY; 406 g_mmc0.bus_voltage = MSS_MMC_3_3V_BUS_VOLTAGE; 407 408 ret_status = MSS_MMC_init(&g_mmc0); 409 if (MSS_MMC_INIT_SUCCESS == ret_status) 410 { 411 //... 412 } 413 @endcode 414 */ 415 mss_mmc_status_t 416 MSS_MMC_init 417 ( 418 const mss_mmc_cfg_t * cfg 419 ); 420 421 /*-------------------------------------------------------------------------*//** 422 The MSS_MMC_single_block_write() function is used to transmit a single block 423 of data from the host controller to the eMMC/SD device. The size of the block 424 of data transferred by this function is always 512 bytes, which is the 425 standard sector size for all eMMC/SD devices with a capacity of greater than 426 2 GB. 427 428 Note: This function is a blocking function and will not return until the 429 write operation is successful or an error occurs. 430 431 @param src_addr 432 This parameter is a pointer to a buffer containing the data to be stored in 433 the eMMC/SD device. The buffer to which this parameter points should be 434 declared with a minimum size of 512 bytes. 435 436 @param dst_addr 437 Specifies the sector address in the eMMC/SD device where the data is to be 438 stored. 439 Note: For eMMC/SD devices of greater than 2 GB in size, this address refers 440 to a 512-byte sector. 441 442 @return 443 This function returns a value of type mss_mmc_status_t which specifies the 444 transfer status of the operation. 445 446 Example: 447 The following example shows how to initialize the device, perform a single 448 block transfer. 449 @code 450 451 #define SECT_1 0x01u 452 #define BUFFER_SIZE 512u 453 454 mss_mmc_cfg_t g_mmc0; 455 mss_mmc_status_t ret_status; 456 uint8_t tx_data_buffer[BUFFER_SIZE] = {0u}; 457 458 g_mmc0.clk_rate = MSS_MMC_CLOCK_25MHZ; 459 g_mmc0.card_type = MSS_MMC_CARD_TYPE_MMC; 460 g_mmc0.data_bus_width = MSS_MMC_DATA_WIDTH_4BIT; 461 g_mmc0.bus_speed_mode = MSS_MMC_MODE_LEGACY; 462 g_mmc0.bus_voltage = MSS_MMC_3_3V_BUS_VOLTAGE; 463 464 for (loop_count = 0; loop_count < (BUFFER_SIZE); loop_count++) 465 { 466 tx_data_buffer[loop_count] = 0x45 + loop_count; 467 } 468 469 ret_status = MSS_MMC_init(&g_mmc0); 470 if (MSS_MMC_INIT_SUCCESS == ret_status) 471 { 472 ret_status = MSS_MMC_single_block_write(tx_data_buffer, SECT_1); 473 if (MSS_MMC_TRANSFER_SUCCESS == ret_status) 474 { 475 //.. 476 } 477 } 478 @endcode 479 */ 480 mss_mmc_status_t 481 MSS_MMC_single_block_write 482 ( 483 const uint32_t * src_addr, 484 uint32_t dst_addr 485 ); 486 487 /*-------------------------------------------------------------------------*//** 488 The MSS_MMC_single_block_read() function is used to read a single block of 489 data from the eMMC/SD device to the host controller. The size of the block 490 of data read by this function is always 512 bytes, which is the standard 491 sector size for all eMMC/SD devices with a capacity of greater than 2 GB. 492 493 Note: This function is a blocking function and will not return until the 494 read operation is successful or an error occurs. 495 496 @param src_addr 497 Specifies the sector address in the eMMC/SD device from where the data is 498 to be read. 499 Note: For eMMC/SD devices of greater than 2 GB in size, this address refers 500 to a 512-byte sector. 501 502 @param dst_addr 503 This parameter is a pointer to a buffer where the data to read from the 504 eMMC/SD device will be stored. The buffer to which this parameter points 505 should be declared with a minimum size of 512 bytes. 506 507 @return 508 This function returns a value of type mss_mmc_status_t which specifies the 509 transfer status of the operation. 510 511 Example: 512 The following example shows how to initialize the device, perform a single 513 block transfer and read back the data from the sector written to within 514 the eMMC device. 515 @code 516 517 #define SECT_1 0x01u 518 #define BUFFER_SIZE 512u 519 520 mss_mmc_cfg_t g_mmc0; 521 mss_mmc_status_t ret_status; 522 uint8_t tx_data_buffer[BUFFER_SIZE] = {0u}; 523 uint8_t rx_data_buffer[BUFFER_SIZE] = {0u}; 524 525 g_mmc0.clk_rate = MSS_MMC_CLOCK_25MHZ; 526 g_mmc0.card_type = MSS_MMC_CARD_TYPE_MMC; 527 g_mmc0.data_bus_width = MSS_MMC_DATA_WIDTH_4BIT; 528 g_mmc0.bus_speed_mode = MSS_MMC_MODE_LEGACY; 529 g_mmc0.bus_voltage = MSS_MMC_3_3V_BUS_VOLTAGE; 530 531 for (loop_count = 0; loop_count < (BUFFER_SIZE); loop_count++) 532 { 533 tx_data_buffer[loop_count] = 0x45 + loop_count; 534 } 535 536 ret_status = MSS_MMC_init(&g_mmc0); 537 if (MSS_MMC_INIT_SUCCESS == ret_status) 538 { 539 ret_status = MSS_MMC_single_block_write(tx_data_buffer, SECT_1); 540 if (MSS_MMC_TRANSFER_SUCCESS == ret_status) 541 { 542 ret_status = MSS_MMC_single_block_read(SECT_1, rx_data_buffer); 543 if (MSS_MMC_TRANSFER_SUCCESS == ret_status) 544 { 545 //.. 546 } 547 } 548 } 549 @endcode 550 */ 551 mss_mmc_status_t 552 MSS_MMC_single_block_read 553 ( 554 uint32_t src_addr, 555 uint32_t * dst_addr 556 ); 557 558 /*-------------------------------------------------------------------------*//** 559 The MSS_MMC_sdma_write() function is used to transfer a single block or multi 560 blocks of data from the host controller to the eMMC/SD device using SDMA. 561 The size of the block of data transferred by this function must be set to 512 562 bytes or a multiple of 512 bytes. The 512 bytes is the standard sector 563 size for all eMMC/SD devices with a capacity of greater than 2 GB. 564 565 Note: A call to MSS_MMC_sdma_write() while a transfer is in progress will not 566 initiate a new transfer. Use the MSS_MMC_get_transfer_status() function 567 or a completion handler registered by the MSS_MMC_set_handler() function 568 to check the status of the current transfer before calling the 569 MSS_MMC_sdma_write() function again. 570 571 Note: This function is a non-blocking function and returns immediately after 572 initiating the write transfer. 573 574 @param src 575 This parameter is a pointer to a buffer containing the data to be stored in 576 the eMMC/SD device. The buffer to which this parameter points must be 577 declared with a minimum size of 512 bytes. 578 579 @param dest 580 Specifies the sector address in the eMMC/SD device where the data is to be 581 stored. 582 Note: For eMMC/SD devices of greater than 2 GB in size, this address refers 583 to a 512-byte sector. 584 585 @param size 586 Specifies the size in bytes of the requested transfer. The value of size must 587 be a multiple of 512 but not greater than (32MB - 512). 588 589 @return 590 This function returns a value of type mss_mmc_status_t which specifies the 591 transfer status of the operation. 592 593 Example: 594 The following example shows how to initialize the device, perform a multi 595 block write transfer using SDMA. 596 @code 597 598 #define SECT_1 0x01u 599 #define BUFFER_SIZE 4096u 600 601 mss_mmc_cfg_t g_mmc0; 602 mss_mmc_status_t ret_status; 603 uint8_t data_buffer[BUFFER_SIZE]; 604 uint32_t loop_count; 605 606 g_mmc0.clk_rate = MSS_MMC_CLOCK_25MHZ; 607 g_mmc0.card_type = MSS_MMC_CARD_TYPE_MMC; 608 g_mmc0.data_bus_width = MSS_MMC_DATA_WIDTH_4BIT; 609 g_mmc0.bus_speed_mode = MSS_MMC_MODE_LEGACY; 610 g_mmc0.bus_voltage = MSS_MMC_3_3V_BUS_VOLTAGE; 611 612 for (loop_count = 0; loop_count < (BUFFER_SIZE); loop_count++) 613 { 614 data_buffer[loop_count] = 0x45 + loop_count; 615 } 616 617 ret_status = MSS_MMC_init(&g_mmc0); 618 if (MSS_MMC_INIT_SUCCESS == ret_status) 619 { 620 ret_status = MSS_MMC_sdma_write(data_buffer, SECT_1, BUFFER_SIZE); 621 do 622 { 623 ret_status = MSS_MMC_get_transfer_status(); 624 }while (ret_status == MSS_MMC_TRANSFER_IN_PROGRESS) 625 } 626 @endcode 627 */ 628 mss_mmc_status_t 629 MSS_MMC_sdma_write 630 ( 631 const uint8_t *src, 632 uint32_t dest, 633 uint32_t size 634 ); 635 /*-------------------------------------------------------------------------*//** 636 The MSS_MMC_sdma_read() function is used to read a single block or multiple 637 blocks of data from the eMMC/SD device to the host controller using SDMA. The 638 size of the block of data read by this function must be set to 512 bytes or 639 a multiple of 512 bytes. The 512 bytes is the standard sector size for all 640 eMMC/SD devices with a capacity of greater than 2 GB. 641 642 Note: A call to MSS_MMC_sdma_read() while a transfer is in progress will not 643 initiate a new transfer. Use the MSS_MMC_get_transfer_status() function 644 or a completion handler registered by the MSS_MMC_set_handler() function 645 to check the status of the current transfer before calling the 646 MSS_MMC_sdma_read() function again. 647 648 Note: This function is a non-blocking function and will return immediately 649 after initiating the read transfer. 650 651 @param src 652 Specifies the sector address in the eMMC/SD device from where the data is 653 to be read. 654 Note: For eMMC/SD devices of greater than 2 GB in size, this address refers 655 to a 512-byte sector. 656 657 @param dest 658 This parameter is a pointer to a buffer where the data to read from the 659 eMMC/SD device will be stored. The buffer to which this parameter points 660 must be declared with a minimum size of 512 bytes. 661 662 @param size 663 Specifies the size in bytes of the requested transfer. The value of size 664 must be a multiple of 512 but not greater than (32MB - 512). 665 666 @return 667 This function returns a value of type mss_mmc_status_t which specifies the 668 transfer status of the operation. 669 670 Example: 671 The following example shows how to initialize the device, perform a multi 672 block read transfer using SDMA. 673 @code 674 675 #define SECT_1 0x01u 676 #define BUFFER_SIZE 4096u 677 678 mss_mmc_cfg_t g_mmc0; 679 mss_mmc_status_t ret_status; 680 uint8_t data_buffer[BUFFER_SIZE]; 681 uint32_t loop_count; 682 683 g_mmc0.clk_rate = MSS_MMC_CLOCK_25MHZ; 684 g_mmc0.card_type = MSS_MMC_CARD_TYPE_MMC; 685 g_mmc0.data_bus_width = MSS_MMC_DATA_WIDTH_4BIT; 686 g_mmc0.bus_speed_mode = MSS_MMC_MODE_LEGACY; 687 g_mmc0.bus_voltage = MSS_MMC_3_3V_BUS_VOLTAGE; 688 689 for (loop_count = 0; loop_count < (BUFFER_SIZE); loop_count++) 690 { 691 data_buffer[loop_count] = 0x45 + loop_count; 692 } 693 ret_status = MSS_MMC_init(&g_mmc0); 694 if (MSS_MMC_INIT_SUCCESS == ret_status) 695 { 696 ret_status = MSS_MMC_sdma_read(SECT_1, data_buffer, BUFFER_SIZE); 697 do 698 { 699 ret_status = MSS_MMC_get_transfer_status(); 700 }while (ret_status == MSS_MMC_TRANSFER_IN_PROGRESS) 701 } 702 @endcode 703 */ 704 mss_mmc_status_t 705 MSS_MMC_sdma_read 706 ( 707 uint32_t src, 708 uint8_t *dest, 709 uint32_t size 710 ); 711 712 /*-------------------------------------------------------------------------*//** 713 The MSS_MMC_adma2_write() function is used to transfer a single block or 714 multiple blocks of data from the host controller to the eMMC/SD device using 715 ADMA2. The size of the block of data transferred by this function must be set 716 to 512 bytes or a multiple of 512 bytes. The 512 bytes is the standard sector 717 size for all eMMC/SD devices with a capacity of greater than 2 GB. 718 719 Note: A call to MSS_MMC_adma2_write() while a transfer is in progress will not 720 initiate a new transfer. Use the MSS_MMC_get_transfer_status() function 721 or a completion handler registered by the MSS_MMC_set_handler() function 722 to check the status of the current transfer before calling the 723 MSS_MMC_adma2_write() function again. 724 725 Note: This function is a non-blocking function and returns immediately after 726 initiating the write transfer. 727 728 @param src 729 This parameter is a pointer to a buffer containing the data to be stored in 730 the eMMC/SD device. The buffer to which this parameter points must be 731 declared with a minimum size of 512 bytes. 732 733 @param dest 734 Specifies the sector address in the eMMC/SD device where the data is 735 to be stored. 736 Note: For eMMC/SD devices of greater than 2 GB in size, this address refers 737 to a 512-byte sector. 738 739 @param size 740 Specifies the size in bytes of the requested transfer. The value of size must 741 be a multiple of 512 but not greater than (32MB - 512). 742 743 @return 744 This function returns a value of type mss_mmc_status_t which specifies the 745 transfer status of the operation. 746 747 Example: 748 The following example shows how to initialize the device, perform a multi 749 block transfer using ADMA2. 750 751 @code 752 753 #define SECT_1 0x01u 754 #define BUFFER_SIZE 4096u 755 756 mss_mmc_cfg_t g_mmc0; 757 mss_mmc_status_t ret_status; 758 uint8_t data_buffer[BUFFER_SIZE]; 759 uint32_t loop_count; 760 761 g_mmc0.clk_rate = MSS_MMC_CLOCK_25MHZ; 762 g_mmc0.card_type = MSS_MMC_CARD_TYPE_MMC; 763 g_mmc0.data_bus_width = MSS_MMC_DATA_WIDTH_4BIT; 764 g_mmc0.bus_speed_mode = MSS_MMC_MODE_LEGACY; 765 g_mmc0.bus_voltage = MSS_MMC_3_3V_BUS_VOLTAGE; 766 767 for (loop_count = 0; loop_count < (BUFFER_SIZE); loop_count++) 768 { 769 data_buffer[loop_count] = 0x45 + loop_count; 770 } 771 772 ret_status = MSS_MMC_init(&g_mmc0); 773 if (MSS_MMC_INIT_SUCCESS == ret_status) 774 { 775 ret_status = MSS_MMC_adma2_write(data_buffer, SECT_1, BUFFER_SIZE); 776 do 777 { 778 ret_status = MSS_MMC_get_transfer_status(); 779 }while (ret_status == MSS_MMC_TRANSFER_IN_PROGRESS) 780 } 781 @endcode 782 */ 783 mss_mmc_status_t 784 MSS_MMC_adma2_write 785 ( 786 const uint8_t *src, 787 uint32_t dest, 788 uint32_t size 789 ); 790 /*-------------------------------------------------------------------------*//** 791 The MSS_MMC_adma2_read() function is used to read a single or multiple blocks 792 of data from the eMMC/SD device to the host controller using ADMA2. The size 793 of the block of data read by this function must be set to 512 bytes or a 794 multiple of 512 bytes. The 512 bytes is the standard sector size for all 795 eMMC/SD devices with a capacity of greater than 2 GB. 796 797 Note: A call to MSS_MMC_adma2_read() while a transfer is in progress will not 798 initiate a new transfer. Use the MSS_MMC_get_transfer_status() function 799 or a completion handler registered by the MSS_MMC_set_handler() function 800 to check the status of the current transfer before calling the 801 MSS_MMC_adma2_read() function again. 802 803 Note: This function is a non-blocking function and returns immediately after 804 initiating the read transfer. 805 806 @param src 807 Specifies the sector address in the eMMC/SD device from where the data is 808 to be read. 809 Note: For eMMC/SD devices of greater than 2 GB in size, this address refers 810 to a 512-byte sector. 811 812 @param dest 813 This parameter is a pointer to a buffer where the data to read from the 814 eMMC/SD device will be stored. The buffer to which this parameter points 815 must be declared with a minimum size of 512 bytes. 816 817 @param size 818 Specifies the size in bytes of the requested transfer. The value of size must 819 be a multiple of 512 but not greater than (32MB -512). 820 821 @return 822 This function returns a value of type mss_mmc_status_t which specifies the 823 transfer status of the operation. 824 825 Example: 826 The following example shows how to initialize the device, perform a multi 827 block read transfer using ADMA2. 828 @code 829 830 #define SECT_1 0x01u 831 #define BUFFER_SIZE 4096u 832 833 mss_mmc_cfg_t g_mmc0; 834 mss_mmc_status_t ret_status; 835 uint8_t data_buffer[BUFFER_SIZE]; 836 uint32_t loop_count; 837 838 g_mmc0.clk_rate = MSS_MMC_CLOCK_25MHZ; 839 g_mmc0.card_type = MSS_MMC_CARD_TYPE_MMC; 840 g_mmc0.data_bus_width = MSS_MMC_DATA_WIDTH_4BIT; 841 g_mmc0.bus_speed_mode = MSS_MMC_MODE_LEGACY; 842 g_mmc0.bus_voltage = MSS_MMC_3_3V_BUS_VOLTAGE; 843 844 for (loop_count = 0; loop_count < (BUFFER_SIZE); loop_count++) 845 { 846 data_buffer[loop_count] = 0x45 + loop_count; 847 } 848 849 ret_status = MSS_MMC_init(&g_mmc0); 850 if (MSS_MMC_INIT_SUCCESS == ret_status) 851 { 852 ret_status = MSS_MMC_adma2_read(SECT_1, data_buffer, BUFFER_SIZE); 853 do 854 { 855 ret_status = MSS_MMC_get_transfer_status(); 856 }while (ret_status == MSS_MMC_TRANSFER_IN_PROGRESS) 857 } 858 @endcode 859 */ 860 mss_mmc_status_t 861 MSS_MMC_adma2_read 862 ( 863 uint32_t src, 864 uint8_t *dest, 865 uint32_t size 866 ); 867 /*-------------------------------------------------------------------------*//** 868 The MSS_MMC_sdio_single_block_write() function is used to transfer a single 869 block of data from the host controller to the SDIO device function 1 870 code storage area(CSA). The size of the block of data transferred by this 871 function is 1 to 512 bytes. 872 873 Note: This function is a blocking function and will not return until the 874 write operation is successful or an error occurs. 875 876 @param src_addr 877 This parameter is a pointer to a buffer containing the data to be stored in 878 the SDIO device. The buffer to which this parameter points must be declared 879 with a minimum size in the range of 1 to 512 bytes. 880 881 @param dst_addr 882 Specifies the function 1 code storage area(CSA) address in the SDIO device 883 where the data is to be stored. 884 885 @param data_size 886 Specifies the dat_size in bytes of the requested transfer. The value of size must 887 be in the range of 1 to 512 bytes but not greater than 512. 888 889 @return 890 This function returns a value of type mss_mmc_status_t which specifies the 891 transfer status of the operation. 892 893 Example: 894 The following example shows how to initialize the SDIO device and perform 895 single block transfer. 896 897 @code 898 899 #define BUFFER_SIZE 4 900 #define REG_NUM 0x1118u 901 902 mss_mmc_cfg_t g_mmc0; 903 mss_mmc_status_t ret_status; 904 905 uint8_t data_buffer[BUFFER_SIZE]; 906 uint32_t loop_count; 907 908 g_mmc0.clk_rate = MSS_MMC_CLOCK_25MHZ; 909 g_mmc0.card_type = MSS_MMC_CARD_TYPE_SDIO; 910 g_mmc0.data_bus_width = MSS_MMC_DATA_WIDTH_4BIT; 911 g_mmc0.bus_speed_mode = MSS_SDCARD_MODE_HIGH_SPEED; 912 913 for (loop_count = 0; loop_count < (BUFFER_SIZE); loop_count++) 914 { 915 data_buffer[loop_count] = 0x45 + loop_count; 916 } 917 918 ret_status = MSS_MMC_init(&g_mmc0); 919 if (MSS_MMC_INIT_SUCCESS == ret_status) 920 { 921 ret_status = MSS_MMC_sdio_single_block_write(data_buffer, 922 REG_NUM, 923 BUFFER_SIZE); 924 if (MSS_MMC_TRANSFER_SUCCESS == ret_status) 925 { 926 //... 927 } 928 } 929 @endcode 930 */ 931 mss_mmc_status_t 932 MSS_MMC_sdio_single_block_write 933 ( 934 const uint32_t * src_addr, 935 uint32_t dst_addr, 936 uint16_t data_size 937 ); 938 939 /*-------------------------------------------------------------------------*//** 940 The MSS_MMC_sdio_single_block_read() function is used to read a single block 941 of data from the the SDIO device function 1 code storage area(CSA) to host 942 controller. The size of the block of data transferred by this function 943 is set to in the range of 1 to 512 bytes. 944 945 Note: This function is a blocking function and will not return until the 946 write operation is successful or an error occurs. 947 948 @param src_addr 949 Specifies the function 1 code storage area(CSA) address in the SDIO device 950 from where the 1 to 512 bytes of data will be read. 951 952 @param dst_addr 953 This parameter is a pointer to a buffer where the data read from the SDIO 954 device will be stored. The buffer to which this parameter points must be 955 declared with a minimum size in the range of 1 to 512 bytes. 956 957 @param data_size 958 Specifies the dat_size in bytes of the requested transfer. The value of size must 959 be in the range of 1 to 512 bytes but not greater than 512. 960 961 @return 962 This function returns a value of type mss_mmc_status_t which specifies the 963 transfer status of the operation. 964 965 Example: 966 The following example shows how to initialize the SDIO device and perform 967 single block transfer. 968 969 @code 970 971 #define BUFFER_SIZE 512u 972 #define REG_NUM 0x000C0000u 973 974 mss_mmc_cfg_t g_mmc0; 975 mss_mmc_status_t ret_status; 976 uint8_t data_buffer[BUFFER_SIZE]; 977 978 g_mmc0.clk_rate = MSS_MMC_CLOCK_25MHZ; 979 g_mmc0.card_type = MSS_MMC_CARD_TYPE_SDIO; 980 g_mmc0.data_bus_width = MSS_MMC_DATA_WIDTH_4BIT; 981 g_mmc0.bus_speed_mode = MSS_SDCARD_MODE_HIGH_SPEED; 982 983 ret_status = MSS_MMC_init(&g_mmc0); 984 if (MSS_MMC_INIT_SUCCESS == ret_status) 985 { 986 ret_status = MSS_MMC_sdio_single_block_read(REG_NUM, 987 data_buffer 988 BUFFER_SIZE); 989 if (MSS_MMC_TRANSFER_SUCCESS == ret_status) 990 { 991 //... 992 } 993 } 994 @endcode 995 */ 996 mss_mmc_status_t 997 MSS_MMC_sdio_single_block_read 998 ( 999 uint32_t src_addr, 1000 uint32_t *dst_addr, 1001 uint16_t data_size 1002 ); 1003 1004 /*-------------------------------------------------------------------------*//** 1005 The MSS_MMC_get_transfer_status() function returns the status of the MMC 1006 transfer initiated by a call to MSS_MMC_sdma_write(), MSS_MMC_sdma_read(), 1007 MSS_MMC_adma2_write(), MSS_MMC_adma2_read(), MSS_MMC_cq_write(), 1008 MSS_MMC_cq_read() functions. 1009 1010 @param 1011 This function has no parameters. 1012 1013 @return 1014 This function returns a value of type mss_mmc_status_t. The possible return 1015 values are: 1016 - MSS_MMC_TRANSFER_IN_PROGRESS 1017 - MSS_MMC_TRANSFER_SUCCESS 1018 - MSS_MMC_TRANSFER_FAIL 1019 - MSS_MMC_RESPONSE_ERROR 1020 1021 Example: 1022 The following example shows the use of MSS_MMC_get_transfer_status() function. 1023 1024 @code 1025 1026 mss_mmc_status_t ret_status; 1027 ret_status = MSS_MMC_write(data_buffer, SECT_1, BUFFER_SIZE); 1028 do 1029 { 1030 ret_status = MSS_MMC_get_transfer_status(); 1031 }while(ret_status == MSS_MMC_TRANSFER_IN_PROGRESS) 1032 1033 @endcode 1034 */ 1035 mss_mmc_status_t MSS_MMC_get_transfer_status(void); 1036 1037 /*-------------------------------------------------------------------------*//** 1038 The MSS_MMC_set_handler() function registers a handler function that will be 1039 called by the driver when a read o write transfer completes. The application 1040 must create and register a transfer completion handler function. The MSS 1041 eMMC SD driver passes the outcome of the transfer to the completion handler 1042 in the form of a status (SRS12 register) parameter indicating if the transfer 1043 is successful or the type of error that occurred during the transfer if the 1044 transfer failed. 1045 1046 @param handler 1047 The handler parameter is a pointer to a handler function provided by the 1048 application. This handler is of type mss_mmc_handler_t. The handler function 1049 must take one parameter of type uint32_t and must not return a value. 1050 1051 @return 1052 This function does not return a value. 1053 1054 Example: 1055 The following example shows the use of MSS_MMC_set_handler() function. 1056 1057 @code 1058 1059 #define BLOCK_1 0x00000001u 1060 #define BUFFER_SIZE 1024 1061 #define ERROR_INTERRUPT 0x8000 1062 #define TRANSFER_COMPLETE 0x1 1063 1064 void transfer_complete_handler(uint32_t srs12_status); 1065 volatile uint32_t g_xfer_in_progress = 0; 1066 1067 mss_mmc_cfg_t g_mmc0; 1068 mss_mmc_status_t ret_status; 1069 uint8_t data_buffer[BUFFER_SIZE]; 1070 uint32_t loop_count; 1071 1072 g_mmc0.clk_rate = MSS_MMC_CLOCK_25MHZ; 1073 g_mmc0.card_type = MSS_MMC_CARD_TYPE_MMC; 1074 g_mmc0.data_bus_width = MSS_MMC_DATA_WIDTH_4BIT; 1075 g_mmc0.bus_speed_mode = MSS_MMC_MODE_LEGACY; 1076 g_mmc0.bus_voltage = MSS_MMC_3_3V_BUS_VOLTAGE; 1077 1078 for (loop_count = 0; loop_count < (BUFFER_SIZE); loop_count++) 1079 { 1080 data_buffer[loop_count] = 0x45 + loop_count; 1081 } 1082 1083 ret_status = MMC_init(&g_mmc0); 1084 if (MSS_MMC_INIT_SUCCESS == ret_status) 1085 { 1086 MSS_MMC_set_handler(transfer_complete_handler); 1087 ret_status = MSS_MMC_adma2_write(data_buffer, BLOCK_1, BUFFER_SIZE); 1088 if (ret_status == MSS_MMC_TRANSFER_IN_PROGRESS) 1089 { 1090 while(g_xfer_in_progress) 1091 { 1092 ; 1093 } 1094 } 1095 } 1096 1097 void transfer_complete_handler(uint32_t srs12_status) 1098 { 1099 g_xfer_in_progress = 0; 1100 uint32_t isr_err; 1101 if(ERROR_INTERRUPT & srs12_status) 1102 { 1103 isr_err = srs12_status >> 16; 1104 } 1105 else if(TRANSFER_COMPLETE & srs12_status) 1106 { 1107 isr_err = 0; 1108 } 1109 else 1110 { 1111 } 1112 } 1113 @endcode 1114 */ 1115 void MSS_MMC_set_handler(mss_mmc_handler_t handler); 1116 1117 /*-------------------------------------------------------------------------*//** 1118 The MSS_MMC_cq_init() function enables command queue in the eMMC device and 1119 in the host controller. The command queue allows the application to queue 1120 multiple read or write tasks. 1121 1122 Note: The MSS_MMC_init() must be configured for eMMC mode before using the 1123 MSS_MMC_cq_init() function. 1124 1125 @param 1126 This function has no parameters. 1127 1128 @return 1129 This function returns a value of type mss_mmc_status_t which specifies the 1130 transfer status of the operation. 1131 */ 1132 mss_mmc_status_t MSS_MMC_cq_init(void); 1133 1134 /*-------------------------------------------------------------------------*//** 1135 The MSS_MMC_cq_write() function is used to transmit a single block or multiple 1136 blocks of data from the host controller to the eMMC device using command queue 1137 with single or multiple tasks based on the data size. The size of the block of 1138 data transferred by this function must be set to 512 bytes or a multiple of 1139 512 bytes. The 512 bytes is the standard sector size for all eMMC 1140 devices with a capacity of greater than 2 GB. 1141 1142 Note: A call to MSS_MMC_cq_write() while a transfer is in progress will not 1143 initiate a new transfer. Use the MSS_MMC_get_transfer_status() function 1144 or a completion handler registered by the MSS_MMC_set_handler() function 1145 to check the status of the current transfer before calling the 1146 MSS_MMC_cq_write() function again. 1147 1148 Note: This function is a non-blocking function and returns immediately after 1149 initiating the write transfer. 1150 1151 @param src 1152 This parameter is a pointer to a buffer containing the data to be stored 1153 in the eMMC device. The buffer to which this parameter points must be 1154 declared with a minimum size of 512 bytes. 1155 1156 @param dest 1157 Specifies the sector address in the eMMC device where the data is 1158 to be stored. 1159 Note: For eMMC devices of greater than 2 GB in size, this address refers to a 1160 512 byte sector. 1161 1162 @param size 1163 Specifies the size in bytes of the requested transfer. The value of size must 1164 be a multiple of 512 but not greater than (1GB - 16KB). 1165 1166 @return 1167 This function returns a value of type mss_mmc_status_t which specifies the 1168 transfer status of the operation. 1169 1170 Example: 1171 The following example shows how to initialize the device and perform a multi 1172 block transfer.. 1173 @code 1174 1175 #define SECT_1 0x01u 1176 #define BUFFER_SIZE 4096u 1177 1178 mss_mmc_cfg_t g_mmc0; 1179 mss_mmc_status_t ret_status; 1180 uint8_t data_buffer[BUFFER_SIZE]; 1181 uint32_t loop_count; 1182 1183 g_mmc0.clk_rate = MSS_MMC_CLOCK_25MHZ; 1184 g_mmc0.card_type = MSS_MMC_CARD_TYPE_MMC; 1185 g_mmc0.data_bus_width = MSS_MMC_DATA_WIDTH_4BIT; 1186 g_mmc0.bus_speed_mode = MSS_MMC_MODE_LEGACY; 1187 g_mmc0.bus_voltage = MSS_MMC_3_3V_BUS_VOLTAGE; 1188 1189 for (loop_count = 0; loop_count < (BUFFER_SIZE); loop_count++) 1190 { 1191 data_buffer[loop_count] = 0x45 + loop_count; 1192 } 1193 1194 ret_status = MSS_MMC_init(&g_mmc0); 1195 if (MSS_MMC_INIT_SUCCESS == ret_status) 1196 { 1197 ret_status = MSS_MMC_cq_init(); 1198 if ( MSS_MMC_INIT_SUCCESS == ret_status) 1199 { 1200 ret_status = MSS_MMC_cq_write(data_buffer, SECT_1, BUFFER_SIZE); 1201 do 1202 { 1203 ret_status = MSS_MMC_get_transfer_status(); 1204 }while (ret_status == MSS_MMC_TRANSFER_IN_PROGRESS) 1205 } 1206 } 1207 @endcode 1208 */ 1209 mss_mmc_status_t 1210 MSS_MMC_cq_write 1211 ( 1212 const uint8_t *src, 1213 uint32_t dest, 1214 uint32_t size 1215 ); 1216 /*-------------------------------------------------------------------------*//** 1217 The MSS_MMC_cq_read() function is used to read a single block or multiple 1218 blocks of data from the eMMC device to the host controller using command queue 1219 with single or multiple tasks based on the data size. The size of the block of 1220 data read by this function must be set to 512 bytes or a multiple of 512 bytes. 1221 The 512 bytes is the standard sector size for all eMMC devices with a capacity 1222 of greater than 2 GB. 1223 1224 Note: A call to MSS_MMC_cq_read() while a transfer is in progress will not 1225 initiate a new transfer. Use the MSS_MMC_get_transfer_status() function 1226 or a completion handler registered by the MSS_MMC_set_handler() function 1227 to check the status of the current transfer before calling the 1228 MSS_MMC_cq_read() function again. 1229 1230 Note: This function is a non-blocking function and returns immediately after 1231 initiating the write transfer. 1232 1233 @param src_addr 1234 Specifies the sector address in the eMMC device from where the datato is 1235 to be read. 1236 1237 Note: For eMMC devices of greater than 2 GB in size, this address refers 1238 to a 512-byte sector. 1239 1240 @param dst_addr 1241 This parameter is a pointer to a buffer where the data to read from the eMMC 1242 device will be stored. The buffer to which this parameter points must be 1243 declared with a minimum size of 512 bytes. 1244 1245 @param size 1246 Specifies the size in bytes of the requested transfer. The value of size must 1247 be a multiple of 512 but not greater than (1GB - 16KB). 1248 1249 @return 1250 This function returns a value of type mss_mmc_status_t which specifies the 1251 transfer status of the operation. 1252 1253 Example: 1254 The following example shows how to initialize the device and perform a multi 1255 block transfer. 1256 1257 @code 1258 1259 #define SECT_1 0x01u 1260 #define BUFFER_SIZE 4096u 1261 1262 mss_mmc_cfg_t g_mmc0; 1263 mss_mmc_status_t ret_status; 1264 uint8_t data_buffer[BUFFER_SIZE]; 1265 uint32_t loop_count; 1266 1267 g_mmc0.clk_rate = MSS_MMC_CLOCK_25MHZ; 1268 g_mmc0.card_type = MSS_MMC_CARD_TYPE_MMC; 1269 g_mmc0.data_bus_width = MSS_MMC_DATA_WIDTH_4BIT; 1270 g_mmc0.bus_speed_mode = MSS_MMC_MODE_LEGACY; 1271 g_mmc0.bus_voltage = MSS_MMC_3_3V_BUS_VOLTAGE; 1272 1273 for (loop_count = 0; loop_count < (BUFFER_SIZE); loop_count++) 1274 { 1275 data_buffer[loop_count] = 0x45 + loop_count; 1276 } 1277 1278 ret_status = MSS_MMC_init(&g_mmc0); 1279 if (MSS_MMC_INIT_SUCCESS == ret_status) 1280 { 1281 ret_status = MSS_MMC_cq_init(); 1282 if (MSS_MMC_INIT_SUCCESS == ret_status) 1283 { 1284 ret_status = MSS_MMC_cq_read(SECT_1, data_buffer, BUFFER_SIZE); 1285 do 1286 { 1287 ret_status = MSS_MMC_get_transfer_status(); 1288 }while (ret_status == MSS_MMC_TRANSFER_IN_PROGRESS) 1289 } 1290 } 1291 @endcode 1292 */ 1293 mss_mmc_status_t 1294 MSS_MMC_cq_read 1295 ( 1296 uint32_t src, 1297 uint8_t *dest, 1298 uint32_t size 1299 ); 1300 1301 #ifdef __cplusplus 1302 } 1303 #endif 1304 1305 #endif /* __MSS_MMC_H */ 1306