AM243x MCU+ SDK  10.01.00
mmcsd_lld.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2024 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
54 #ifndef MMCSD_LLD_H_
55 #define MMCSD_LLD_H_
56 
57 /* ========================================================================== */
58 /* Include Files */
59 /* ========================================================================== */
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 #include <stdint.h>
66 #include <stdbool.h>
67 #include <stdlib.h>
68 #include <stddef.h>
69 #include <string.h>
70 #include <drivers/hw_include/cslr.h>
71 #include <drivers/hw_include/cslr64.h>
72 #include <drivers/hw_include/hw_types.h>
73 #include <drivers/hw_include/cslr_mmcsd.h>
74 #include <drivers/mmcsd/v0/cslr_mmcsd.h>
75 
76 /* ========================================================================== */
77 /* Macros & Typedefs */
78 /* ========================================================================== */
79 
87 #define MMCSD_STS_SUCCESS ((int32_t) 0)
88 
90 #define MMCSD_STS_ERR ((int32_t)-1)
91 
93 #define MMCSD_STS_ERR_TIMEOUT ((int32_t)-2)
94 
95 #define MMCSD_STS_ERR_INVALID_PARAM ((int32_t)-3)
96 
97 #define MMCSD_STS_ERR_BUSY ((int32_t)-4)
98 
99 #define MMCSD_STS_ERR_CARD_NOT_FOUND ((int32_t)-5)
100 
101 #define MMCSD_STS_ERR_CARD_UNUSEABLE ((int32_t)-6)
102 
103 #define MMCSD_STS_ERR_CARD_UNLOCK_FAIL ((int32_t)-7)
104 
115 #define MMCSD_NO_WAIT ((uint32_t)0)
116 
118 #define MMCSD_WAIT_FOREVER ((uint32_t)-1)
119 
130 #define MMCSD_STATE_RESET ((uint8_t) 0U)
131 
133 #define MMCSD_STATE_IDLE ((uint8_t) 1U)
134 
136 #define MMCSD_STATE_BUSY ((uint8_t) 2U)
137 
139 #define MMCSD_STATE_ERROR ((uint8_t) 3U)
140 
150 #define MMCSD_XFER_IDLE_STATE ((uint8_t) 0U)
151 
152 #define MMCSD_XFER_CMD_STATE ((uint8_t) 1U)
153 
154 #define MMCSD_XFER_WRITE_STATE ((uint8_t) 2U)
155 
156 #define MMCSD_XFER_READ_STATE ((uint8_t) 3U)
157 
166 #define MMCSD_SLOT_TYPE_VAL_REMOVABLE ((uint8_t) 0x0U)
167 #define MMCSD_SLOT_TYPE_VAL_EMBEDDED ((uint8_t) 0x1U)
168 #define MMCSD_SLOT_TYPE_VAL_SHARED ((uint8_t) 0x2U)
169 
178 #define MMCSD_CARD_TYPE_SD ((uint32_t) 0U)
179 #define MMCSD_CARD_TYPE_EMMC ((uint32_t) 2U)
180 #define MMCSD_CARD_TYPE_NO_DEVICE ((uint32_t) 3U)
181 
190 #define MMCSD_PHY_TYPE_HW_PHY ((uint32_t) 0U)
191 #define MMCSD_PHY_TYPE_SW_PHY ((uint32_t) 1U)
192 #define MMCSD_PHY_TYPE_NO_PHY ((uint32_t) 2U)
193 
202 #define MMCSD_BUS_WIDTH_4BIT ((uint32_t) 0x4U)
203 #define MMCSD_BUS_WIDTH_8BIT ((uint32_t) 0x8U)
204 #define MMCSD_BUS_WIDTH_1BIT ((uint32_t) 0x1U)
205 
214 #define MMCSD_PHY_TUNING_TYPE_AUTO ((uint32_t) 0U)
215 #define MMCSD_PHY_TUNING_TYPE_MANUAL ((uint32_t) 1U)
216 
225 #define MMCSD_SD_MODE_HS ((uint32_t) 10U)
226 #define MMCSD_SD_MODE_DS ((uint32_t) 11U)
227 #define MMCSD_SD_MODE_SDR12 ((uint32_t) 12U)
228 #define MMCSD_SD_MODE_SDR25 ((uint32_t) 13U)
229 #define MMCSD_SD_MODE_SDR50 ((uint32_t) 14U)
230 #define MMCSD_SD_MODE_DDR50 ((uint32_t) 15U)
231 #define MMCSD_SD_MODE_SDR104 ((uint32_t) 16U)
232 
241 #define MMCSD_MMC_MODE_SDR25 ((uint32_t) 20U)
242 #define MMCSD_MMC_MODE_SDR50 ((uint32_t) 21U)
243 #define MMCSD_MMC_MODE_HS200 ((uint32_t) 23U)
244 
247 /* ========================================================================== */
248 /* Function Pointers Declarations */
249 /* ========================================================================== */
250 
258 typedef uint32_t (*MMCSD_Clock_getTicks) (void);
259 
269 typedef uint32_t (*MMCSD_Clock_usecToTicks) (uint64_t usecs);
270 
278 typedef void (*MMCSD_Clock_uSleep) (uint32_t usec);
279 
287 typedef void (*MMCSD_lld_transferCompleteCallback) (void *args,
288  int32_t xferStatus);
289 
290 /* ========================================================================== */
291 /* Structure Declarations */
292 /* ========================================================================== */
293 
297 typedef struct {
298 
300  uint32_t ocr;
302  uint32_t rca;
304  uint16_t maxReadBlockLen;
308  char manuDate[9];
310  uint8_t manuID;
312  char productName[7];
314  uint8_t specVersion;
316  uint32_t blockCount;
318  uint8_t transferSpeed;
320  uint8_t supportedModes;
322  uint8_t eStrobeSupport;
324  uint8_t driveStrength;
326  bool isHC;
327 
329 
333 typedef struct {
334 
336  uint32_t ocr;
338  uint32_t rca;
340  uint16_t maxReadBlockLen;
344  char manuDate[9];
346  uint8_t manuID;
348  char productName[6];
350  uint8_t specVersion;
352  uint32_t blockCount;
354  uint8_t transferSpeed;
356  uint32_t isCmd23;
360  bool isHC;
361 
363 
371 typedef struct {
372 
374  uint32_t cmd;
376  uint32_t dir;
378  uint32_t arg;
380  uint8_t *dataBuf;
382  uint32_t blockSize;
384  uint32_t blockCount;
386  uint32_t autoCmdEn;
388  uint32_t enableDma;
390  uint32_t isTuning;
392  uint32_t response[4];
393 
395 
399 typedef struct {
400 
402  uint32_t ctrlBaseAddr;
404  uint32_t ssBaseAddr;
406  uint32_t inputClkFreq;
408  uint32_t cardType;
412  uint32_t uaBusSpeed;
415  uint32_t tuningType;
417  uint32_t intrNum;
419  uint32_t slotType;
421  uint32_t busWidth;
423  bool enableDma;
425  uint32_t phyType;
429  void *deviceData;
433  uint8_t *dataBuf;
438 
440 
441 
445 typedef struct {
446 
448  uint16_t cmdErrorStat;
450  uint16_t xferErrorStat;
452  uint8_t *dataBufIdx;
454  uint32_t dataBlockCount;
456  uint32_t dataBlockSize;
465  uint32_t setBusSpeed;
467  uint32_t setBusWidth;
469  uint8_t xferState;
471  uint8_t state;
475  void *args;
478 
480 
481 /* ========================================================================== */
482 /* API Function Declarations */
483 /* ========================================================================== */
484 
493 
502 
516 
527 int32_t MMCSD_lld_write_SD_Poll(MMCSDLLD_Handle handle, uint8_t *buf,
528  uint32_t startBlk, uint32_t numBlks);
529 
540 int32_t MMCSD_lld_read_SD_Poll(MMCSDLLD_Handle handle, uint8_t *buf,
541  uint32_t startBlk, uint32_t numBlks);
542 
553 int32_t MMCSD_lld_write_MMC_Poll(MMCSDLLD_Handle handle, uint8_t *buf,
554  uint32_t startBlk, uint32_t numBlks);
555 
566 int32_t MMCSD_lld_read_MMC_Poll(MMCSDLLD_Handle handle, uint8_t *buf,
567  uint32_t startBlk, uint32_t numBlks);
568 
579 int32_t MMCSD_lld_write_SD_Intr(MMCSDLLD_Handle handle, uint8_t *buf,
580  uint32_t startBlk, uint32_t numBlks);
581 
592 int32_t MMCSD_lld_read_SD_Intr(MMCSDLLD_Handle handle, uint8_t *buf,
593  uint32_t startBlk, uint32_t numBlks);
594 
605 int32_t MMCSD_lld_write_MMC_Intr(MMCSDLLD_Handle handle, uint8_t *buf,
606  uint32_t startBlk, uint32_t numBlks);
607 
618 int32_t MMCSD_lld_read_MMC_Intr(MMCSDLLD_Handle handle, uint8_t *buf,
619  uint32_t startBlk, uint32_t numBlks);
620 
631  uint32_t busSpeed, uint32_t busWidth);
632 
642  uint32_t busSpeed);
643 
653  uint32_t tuningType);
654 
668  uint32_t partitionNum);
669 
682 
683 /* ========================================================================== */
684 /* ISR Function Declarations */
685 /* ========================================================================== */
686 
693 void MMCSD_lld_Isr(void *args);
694 
695 #ifdef __cplusplus
696 }
697 #endif
698 
699 #endif /* MMCSD_LLD_H_ */
700 
MMCSDLLD_Object::setBusSpeed
uint32_t setBusSpeed
Definition: mmcsd_lld.h:465
MMCSDLLD_Object::dataBufIdx
uint8_t * dataBufIdx
Definition: mmcsd_lld.h:452
MMCSDLLD_InitObject::slotType
uint32_t slotType
Definition: mmcsd_lld.h:419
MMCSD_lld_read_SD_Poll
int32_t MMCSD_lld_read_SD_Poll(MMCSDLLD_Handle handle, uint8_t *buf, uint32_t startBlk, uint32_t numBlks)
Function to perform block reads from the SD media in Polling Mode.
MMCSDLLD_InitObject::intrNum
uint32_t intrNum
Definition: mmcsd_lld.h:417
MMCSD_SdDeviceData::ocr
uint32_t ocr
Definition: mmcsd_lld.h:336
MMCSDLLD_InitObject::autoAssignMaxSpeed
bool autoAssignMaxSpeed
Definition: mmcsd_lld.h:410
MMCSD_SdDeviceData::manuID
uint8_t manuID
Definition: mmcsd_lld.h:346
MMCSDLLD_Object::transferCompleteCallback
MMCSD_lld_transferCompleteCallback transferCompleteCallback
Definition: mmcsd_lld.h:477
MMCSD_SdDeviceData::transferSpeed
uint8_t transferSpeed
Definition: mmcsd_lld.h:354
MMCSDLLD_InitObject::dataBuf
uint8_t * dataBuf
Definition: mmcsd_lld.h:433
MMCSD_EmmcDeviceData::blockCount
uint32_t blockCount
Definition: mmcsd_lld.h:316
MMCSDLLD_InitObject::enableDma
bool enableDma
Definition: mmcsd_lld.h:423
MMCSD_SdDeviceData
SD device properties.
Definition: mmcsd_lld.h:333
MMCSD_Clock_usecToTicks
uint32_t(* MMCSD_Clock_usecToTicks)(uint64_t usecs)
The definition of a micro seconds to ticks function used by the MMCSD driver to get ticks from micros...
Definition: mmcsd_lld.h:269
MMCSD_EmmcDeviceData::rca
uint32_t rca
Definition: mmcsd_lld.h:302
MMCSDLLD_Object::state
uint8_t state
Definition: mmcsd_lld.h:471
MMCSD_lld_enableBootPartition
int32_t MMCSD_lld_enableBootPartition(MMCSDLLD_Handle handle, uint32_t partitionNum)
Function to enable the boot partition given the media is eMMC.
MMCSD_lld_Isr
void MMCSD_lld_Isr(void *args)
This is the MMCSD Controller ISR and can be used as IRQ handler.
MMCSD_SdDeviceData::specVersion
uint8_t specVersion
Definition: mmcsd_lld.h:350
MMCSD_lld_read_MMC_Intr
int32_t MMCSD_lld_read_MMC_Intr(MMCSDLLD_Handle handle, uint8_t *buf, uint32_t startBlk, uint32_t numBlks)
Function to perform block reads from the MMC media in Interrupt Mode.
MMCSDLLD_Object::setBusWidth
uint32_t setBusWidth
Definition: mmcsd_lld.h:467
MMCSDLLD_Transaction
MMCSDLLD Transaction.
Definition: mmcsd_lld.h:371
MMCSDLLD_InitObject::pllEnableSD
bool pllEnableSD
Definition: mmcsd_lld.h:427
MMCSDLLD_InitObject::tuningType
uint32_t tuningType
Definition: mmcsd_lld.h:415
MMCSDLLD_Transaction::arg
uint32_t arg
Definition: mmcsd_lld.h:378
MMCSDLLD_Object::xferErrorStat
uint16_t xferErrorStat
Definition: mmcsd_lld.h:450
MMCSD_SdDeviceData::maxReadBlockLen
uint16_t maxReadBlockLen
Definition: mmcsd_lld.h:340
MMCSDLLD_InitObject::ctrlBaseAddr
uint32_t ctrlBaseAddr
Definition: mmcsd_lld.h:402
MMCSD_lld_write_MMC_Intr
int32_t MMCSD_lld_write_MMC_Intr(MMCSDLLD_Handle handle, uint8_t *buf, uint32_t startBlk, uint32_t numBlks)
Function to perform block writes to the MMC media in Interrupt Mode.
MMCSD_SdDeviceData::isHC
bool isHC
Definition: mmcsd_lld.h:360
MMCSD_lld_deInit
int32_t MMCSD_lld_deInit(MMCSDLLD_Handle handle)
This API De-Initializes the MMCSD instance.
MMCSDLLD_Transaction::autoCmdEn
uint32_t autoCmdEn
Definition: mmcsd_lld.h:386
MMCSD_Clock_getTicks
uint32_t(* MMCSD_Clock_getTicks)(void)
The definition of a get System Tick function used by the MMCSD driver to keep track of time.
Definition: mmcsd_lld.h:258
MMCSD_lld_write_SD_Intr
int32_t MMCSD_lld_write_SD_Intr(MMCSDLLD_Handle handle, uint8_t *buf, uint32_t startBlk, uint32_t numBlks)
Function to perform block writes to the SD media in Interrupt Mode.
MMCSDLLD_Object::currentTxn
MMCSDLLD_Transaction * currentTxn
Definition: mmcsd_lld.h:460
MMCSDLLD_InitObject
MMCSD Driver Initialization Object.
Definition: mmcsd_lld.h:399
MMCSD_EmmcDeviceData::eStrobeSupport
uint8_t eStrobeSupport
Definition: mmcsd_lld.h:322
MMCSD_EmmcDeviceData::manuID
uint8_t manuID
Definition: mmcsd_lld.h:310
MMCSD_SdDeviceData::isCmd23
uint32_t isCmd23
Definition: mmcsd_lld.h:356
MMCSD_EmmcDeviceData::specVersion
uint8_t specVersion
Definition: mmcsd_lld.h:314
MMCSD_EmmcDeviceData::ocr
uint32_t ocr
Definition: mmcsd_lld.h:300
MMCSDLLD_InitObject::cardType
uint32_t cardType
Definition: mmcsd_lld.h:408
MMCSDLLD_InitObject::ssBaseAddr
uint32_t ssBaseAddr
Definition: mmcsd_lld.h:404
MMCSD_lld_change_Bus_Config_MMC
int32_t MMCSD_lld_change_Bus_Config_MMC(MMCSDLLD_Handle handle, uint32_t busSpeed, uint32_t busWidth)
Function to reconfigure the bus Speed and Bus width of the bus for MMC.
MMCSDLLD_Object
MMCSD Driver Object.
Definition: mmcsd_lld.h:445
MMCSDLLD_Transaction::blockCount
uint32_t blockCount
Definition: mmcsd_lld.h:384
MMCSDLLD_InitHandle
struct MMCSDLLD_InitObject * MMCSDLLD_InitHandle
MMCSDLLD_InitObject::Clock_getTicks
MMCSD_Clock_getTicks Clock_getTicks
Definition: mmcsd_lld.h:435
MMCSDLLD_Transaction::dataBuf
uint8_t * dataBuf
Definition: mmcsd_lld.h:380
MMCSD_lld_read_SD_Intr
int32_t MMCSD_lld_read_SD_Intr(MMCSDLLD_Handle handle, uint8_t *buf, uint32_t startBlk, uint32_t numBlks)
Function to perform block reads from the SD media in Interrupt Mode.
MMCSD_SdDeviceData::rca
uint32_t rca
Definition: mmcsd_lld.h:338
MMCSD_lld_disableBootPartition
int32_t MMCSD_lld_disableBootPartition(MMCSDLLD_Handle handle)
This function disables the boot partition if the media is eMMC.
MMCSDLLD_Object::remainingBlockCount
uint32_t remainingBlockCount
Definition: mmcsd_lld.h:458
MMCSD_EmmcDeviceData::supportedModes
uint8_t supportedModes
Definition: mmcsd_lld.h:320
MMCSDLLD_Transaction::blockSize
uint32_t blockSize
Definition: mmcsd_lld.h:382
MMCSD_lld_write_SD_Poll
int32_t MMCSD_lld_write_SD_Poll(MMCSDLLD_Handle handle, uint8_t *buf, uint32_t startBlk, uint32_t numBlks)
Function to perform block writes to the SD media in Polling Mode.
MMCSDLLD_Object::dataBlockCount
uint32_t dataBlockCount
Definition: mmcsd_lld.h:454
MMCSD_lld_read_MMC_Poll
int32_t MMCSD_lld_read_MMC_Poll(MMCSDLLD_Handle handle, uint8_t *buf, uint32_t startBlk, uint32_t numBlks)
Function to perform block reads from the MMC media in Polling Mode.
MMCSD_lld_init
int32_t MMCSD_lld_init(MMCSDLLD_Handle handle)
This API Initializes the MMCSD instance.
MMCSD_EmmcDeviceData
eMMC device properties
Definition: mmcsd_lld.h:297
MMCSD_EmmcDeviceData::maxReadBlockLen
uint16_t maxReadBlockLen
Definition: mmcsd_lld.h:304
MMCSDLLD_InitObject::busWidth
uint32_t busWidth
Definition: mmcsd_lld.h:421
MMCSDLLD_Handle
struct MMCSDLLD_Object * MMCSDLLD_Handle
MMCSD_EmmcDeviceData::transferSpeed
uint8_t transferSpeed
Definition: mmcsd_lld.h:318
MMCSD_SdDeviceData::supportedDataWidths
uint32_t supportedDataWidths
Definition: mmcsd_lld.h:358
MMCSDLLD_Object::mmcsdTxn
MMCSDLLD_Transaction mmcsdTxn
Definition: mmcsd_lld.h:462
MMCSD_EmmcDeviceData::maxWriteBlockLen
uint16_t maxWriteBlockLen
Definition: mmcsd_lld.h:306
MMCSDLLD_Transaction::isTuning
uint32_t isTuning
Definition: mmcsd_lld.h:390
MMCSD_lld_change_Bus_Config_SD
int32_t MMCSD_lld_change_Bus_Config_SD(MMCSDLLD_Handle handle, uint32_t busSpeed)
Function to reconfigure the bus Speed and Bus width of the bus for MMC.
MMCSD_lld_getBlockSize
uint32_t MMCSD_lld_getBlockSize(MMCSDLLD_Handle handle)
This function returns the block size of the MMC/SD media connected to the MMCSD controller.
MMCSDLLD_InitObject::deviceData
void * deviceData
Definition: mmcsd_lld.h:429
MMCSDLLD_Transaction::dir
uint32_t dir
Definition: mmcsd_lld.h:376
MMCSD_lld_write_MMC_Poll
int32_t MMCSD_lld_write_MMC_Poll(MMCSDLLD_Handle handle, uint8_t *buf, uint32_t startBlk, uint32_t numBlks)
Function to perform block writes to the MMC media in Polling Mode.
MMCSD_EmmcDeviceData::isHC
bool isHC
Definition: mmcsd_lld.h:326
MMCSDLLD_InitObject::phyType
uint32_t phyType
Definition: mmcsd_lld.h:425
MMCSDLLD_Object::dataBlockSize
uint32_t dataBlockSize
Definition: mmcsd_lld.h:456
MMCSD_SdDeviceData::blockCount
uint32_t blockCount
Definition: mmcsd_lld.h:352
MMCSDLLD_Object::initHandle
MMCSDLLD_InitHandle initHandle
Definition: mmcsd_lld.h:473
MMCSDLLD_Transaction::cmd
uint32_t cmd
Definition: mmcsd_lld.h:374
MMCSDLLD_Transaction::enableDma
uint32_t enableDma
Definition: mmcsd_lld.h:388
MMCSD_lld_transferCompleteCallback
void(* MMCSD_lld_transferCompleteCallback)(void *args, int32_t xferStatus)
The definition of a transfer completion callback function used by the MMCSD driver when used in Callb...
Definition: mmcsd_lld.h:287
MMCSDLLD_InitObject::inputClkFreq
uint32_t inputClkFreq
Definition: mmcsd_lld.h:406
MMCSDLLD_Object::args
void * args
Definition: mmcsd_lld.h:475
MMCSDLLD_Object::xferState
uint8_t xferState
Definition: mmcsd_lld.h:469
MMCSDLLD_InitObject::Clock_uSleep
MMCSD_Clock_uSleep Clock_uSleep
Definition: mmcsd_lld.h:437
MMCSDLLD_Object::cmdErrorStat
uint16_t cmdErrorStat
Definition: mmcsd_lld.h:448
MMCSD_EmmcDeviceData::driveStrength
uint8_t driveStrength
Definition: mmcsd_lld.h:324
MMCSD_Clock_uSleep
void(* MMCSD_Clock_uSleep)(uint32_t usec)
The definition of a sleep function used by the MMCSD driver for delay.
Definition: mmcsd_lld.h:278
MMCSDLLD_InitObject::uaBusSpeed
uint32_t uaBusSpeed
Definition: mmcsd_lld.h:412
MMCSD_lld_change_Tuning_Type
int32_t MMCSD_lld_change_Tuning_Type(MMCSDLLD_Handle handle, uint32_t tuningType)
Function to reconfigure the bus Speed and Bus width of the bus for MMC.
MMCSD_SdDeviceData::maxWriteBlockLen
uint16_t maxWriteBlockLen
Definition: mmcsd_lld.h:342