AM263Px MCU+ SDK  11.00.00
mmcsd_lld.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2024-2025 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 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 #include <stdint.h>
65 #include <stdbool.h>
66 #include <stdlib.h>
67 #include <stddef.h>
68 #include <drivers/edma/v0/edma.h>
69 #include <drivers/mmcsd/v1/cslr_mmcsd.h>
70 
71 /* ========================================================================== */
72 /* Macros & Typedefs */
73 /* ========================================================================== */
74 
82 
83 typedef struct MMCSD_EdmaChConfig_s *MMCSD_DmaChConfig;
84 
86 #define MMCSD_STS_SUCCESS ((int32_t) 0)
87 
89 #define MMCSD_STS_ERR ((int32_t)-1)
90 
92 #define MMCSD_STS_ERR_TIMEOUT ((int32_t)-2)
93 
94 #define MMCSD_STS_ERR_INVALID_PARAM ((int32_t)-3)
95 
96 #define MMCSD_STS_ERR_BUSY ((int32_t)-4)
97 
98 #define MMCSD_STS_ERR_CARD_NOT_FOUND ((int32_t)-5)
99 
100 #define MMCSD_STS_ERR_CARD_UNUSEABLE ((int32_t)-6)
101 
102 #define MMCSD_STS_ERR_CARD_UNLOCK_FAIL ((int32_t)-7)
103 
114 #define MMCSD_NO_WAIT ((uint32_t)0)
115 
117 #define MMCSD_WAIT_FOREVER ((uint32_t)-1)
118 
129 #define MMCSD_STATE_RESET ((uint8_t) 0U)
130 
132 #define MMCSD_STATE_IDLE ((uint8_t) 1U)
133 
135 #define MMCSD_STATE_BUSY ((uint8_t) 2U)
136 
138 #define MMCSD_STATE_ERROR ((uint8_t) 3U)
139 
149 #define MMCSD_XFER_IDLE_STATE ((uint8_t) 0U)
150 
151 #define MMCSD_XFER_CMD_STATE ((uint8_t) 1U)
152 
153 #define MMCSD_XFER_WRITE_STATE ((uint8_t) 2U)
154 
155 #define MMCSD_XFER_READ_STATE ((uint8_t) 3U)
156 
166 #define MMCSD_CARD_TYPE_SD ((uint32_t) 0U)
167 
168 #define MMCSD_CARD_TYPE_EMMC ((uint32_t) 2U)
169 
170 #define MMCSD_CARD_TYPE_NO_DEVICE ((uint32_t) 3U)
171 
181 #define MMCSD_BUS_WIDTH_1BIT ((uint32_t) 1U)
182 
183 #define MMCSD_BUS_WIDTH_4BIT ((uint32_t) 4U)
184 
185 #define MMCSD_BUS_WIDTH_8BIT ((uint32_t) 8U)
186 
197 #define MMCSD_ECSD_BUS_WIDTH_INDEX (183U)
198 
199 #define MMCSD_ECSD_BUS_WIDTH_1BIT (0U)
200 
201 #define MMCSD_ECSD_BUS_WIDTH_4BIT (1U)
202 
203 #define MMCSD_ECSD_BUS_WIDTH_8BIT (2U)
204 
205 #define MMCSD_ECSD_BUS_WIDTH_4BIT_DDR (5U)
206 
207 #define MMCSD_ECSD_BUS_WIDTH_8BIT_DDR (6U)
208 
210 #define MMCSD_ECSD_BUS_WIDTH_BUSWIDTH_MASK (0x0FU)
211 
212 #define MMCSD_ECSD_BUS_WIDTH_BUSWIDTH_SHIFT (0U)
213 
215 #define MMCSD_ECSD_BUS_WIDTH_ES_ENABLE (0x80U)
216 
217 #define MMCSD_ECSD_BUS_WIDTH_ES_MASK (0x80U)
218 
219 #define MMCSD_ECSD_BUS_WIDTH_ES_SHIFT (7U)
220 
230 #define MMCSD_SD_MODE_DS ((uint32_t) 10U)
231 
232 #define MMCSD_SD_MODE_HS ((uint32_t) 11U)
233 
236 /* ========================================================================== */
237 /* Function Pointers Declarations */
238 /* ========================================================================== */
239 
248  int32_t xferStatus);
249 
250 /* ========================================================================== */
251 /* Structure Declarations */
252 /* ========================================================================== */
253 
257 typedef struct {
258 
260  uint32_t ocr;
262  uint32_t rca;
264  uint16_t maxReadBlockLen;
268  char manuDate[9];
270  uint8_t manuID;
272  char productName[7];
274  uint8_t specVersion;
276  uint32_t blockCount;
278  uint8_t transferSpeed;
280  uint8_t supportedModes;
282  uint8_t eStrobeSupport;
284  uint8_t driveStrength;
286  uint8_t extCsd[512];
288  bool isHC;
289 
291 
295 typedef struct {
296 
298  uint32_t ocr;
300  uint32_t rca;
302  uint16_t maxReadBlockLen;
306  char manuDate[9];
308  uint8_t manuID;
310  char productName[6];
312  uint8_t specVersion;
314  uint32_t blockCount;
316  uint8_t transferSpeed;
318  uint32_t isCmd23;
322  bool isHC;
323 
325 
333 typedef struct {
334 
336  uint32_t cmd;
338  uint32_t flags;
340  uint32_t arg;
342  uint8_t *dataBuf;
344  uint32_t blockSize;
346  uint32_t blockCount;
348  uint32_t response[4];
349 
351 
355 typedef struct {
356 
358  uint32_t baseAddr;
360  uint32_t inputClkFreq;
362  uint32_t intrNum;
364  uint32_t cardType;
368  uint32_t uaBusSpeed;
370  uint32_t busWidth;
372  bool enableDma;
374  void *deviceData;
382  uint8_t *dataBuf;
383 
385 
389 typedef struct {
390 
392  uint16_t cmdErrorStat;
394  uint16_t xferErrorStat;
396  uint8_t *dataBufIdx;
398  uint32_t dataBlockCount;
400  uint32_t dataBlockSize;
409  uint32_t setBusSpeed;
411  uint32_t setBusWidth;
413  uint8_t xferState;
415  uint8_t state;
419  void *args;
422 
424 
425 /* ========================================================================== */
426 /* API Function Declarations */
427 /* ========================================================================== */
428 
437 
446 
455 
464 
475 int32_t MMCSD_lld_write_SD_Poll(MMCSDLLD_Handle handle, uint8_t *buf,
476  uint32_t startBlk, uint32_t numBlks);
477 
488 int32_t MMCSD_lld_read_SD_Poll(MMCSDLLD_Handle handle, uint8_t *buf,
489  uint32_t startBlk, uint32_t numBlks);
490 
501 int32_t MMCSD_lld_write_SD_Intr(MMCSDLLD_Handle handle, uint8_t *buf,
502  uint32_t startBlk, uint32_t numBlks);
503 
514 int32_t MMCSD_lld_read_SD_Intr(MMCSDLLD_Handle handle, uint8_t *buf,
515  uint32_t startBlk, uint32_t numBlks);
516 
527 int32_t MMCSD_lld_write_SD_Dma(MMCSDLLD_Handle handle, uint8_t *buf,
528  uint32_t startBlk, uint32_t numBlks);
529 
540 int32_t MMCSD_lld_read_SD_Dma(MMCSDLLD_Handle handle, uint8_t *buf,
541  uint32_t startBlk, uint32_t numBlks);
542 
543 
557 int32_t MMCSD_lld_write_MMC_Poll(MMCSDLLD_Handle handle, uint8_t *buf,
558  uint32_t startBlk, uint32_t numBlks);
559 
573 int32_t MMCSD_lld_read_MMC_Poll(MMCSDLLD_Handle handle, uint8_t *buf,
574  uint32_t startBlk, uint32_t numBlks);
575 
589 int32_t MMCSD_lld_write_MMC_Intr(MMCSDLLD_Handle handle, uint8_t *buf,
590  uint32_t startBlk, uint32_t numBlks);
591 
605 int32_t MMCSD_lld_read_MMC_Intr(MMCSDLLD_Handle handle, uint8_t *buf,
606  uint32_t startBlk, uint32_t numBlks);
607 
618 int32_t MMCSD_lld_write_MMC_Dma(MMCSDLLD_Handle handle, uint8_t *buf,
619  uint32_t startBlk, uint32_t numBlks);
620 
631 int32_t MMCSD_lld_read_MMC_Dma(MMCSDLLD_Handle handle, uint8_t *buf,
632  uint32_t startBlk, uint32_t numBlks);
633 
647 
648 
662 void MMCSD_lld_completeCurrTransfer(MMCSDLLD_Handle handle,int32_t xferStatus);
663 
664 /* ========================================================================== */
665 /* ISR Function Declarations */
666 /* ========================================================================== */
667 
674 void MMCSD_lld_Isr(void *args);
675 
676 #ifdef __cplusplus
677 }
678 #endif
679 
680 #endif /* MMCSD_LLD_H_ */
681 
MMCSDLLD_Object::setBusSpeed
uint32_t setBusSpeed
Definition: mmcsd_lld.h:409
MMCSDLLD_InitObject::mmcsdDmaChConfig
MMCSD_DmaChConfig mmcsdDmaChConfig
Definition: mmcsd_lld.h:378
MMCSDLLD_Object::dataBufIdx
uint8_t * dataBufIdx
Definition: mmcsd_lld.h:396
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:362
args
void * args
Definition: hsmclient_msg.h:4
MMCSD_SdDeviceData::ocr
uint32_t ocr
Definition: mmcsd_lld.h:298
MMCSDLLD_InitObject::autoAssignMaxSpeed
bool autoAssignMaxSpeed
Definition: mmcsd_lld.h:366
MMCSD_SdDeviceData::manuID
uint8_t manuID
Definition: mmcsd_lld.h:308
MMCSDLLD_Object::transferCompleteCallback
MMCSD_lld_transferCompleteCallback transferCompleteCallback
Definition: mmcsd_lld.h:421
MMCSD_SdDeviceData::transferSpeed
uint8_t transferSpeed
Definition: mmcsd_lld.h:316
MMCSDLLD_InitObject::dataBuf
uint8_t * dataBuf
Definition: mmcsd_lld.h:382
MMCSD_DmaChConfig
struct MMCSD_EdmaChConfig_s * MMCSD_DmaChConfig
Definition: mmcsd_lld.h:83
MMCSD_EmmcDeviceData::blockCount
uint32_t blockCount
Definition: mmcsd_lld.h:276
MMCSDLLD_InitObject::enableDma
bool enableDma
Definition: mmcsd_lld.h:372
MMCSD_SdDeviceData
SD device properties.
Definition: mmcsd_lld.h:295
MMCSDLLD_InitObject::baseAddr
uint32_t baseAddr
Definition: mmcsd_lld.h:358
MMCSD_EmmcDeviceData::rca
uint32_t rca
Definition: mmcsd_lld.h:262
MMCSDLLD_Object::state
uint8_t state
Definition: mmcsd_lld.h:415
MMCSD_lld_read_SD_Dma
int32_t MMCSD_lld_read_SD_Dma(MMCSDLLD_Handle handle, uint8_t *buf, uint32_t startBlk, uint32_t numBlks)
Function to perform block reads from the SD media in DMA Mode.
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:312
MMCSDLLD_InitObject::mmcsdDmaHandle
MMCSD_DmaHandle mmcsdDmaHandle
Definition: mmcsd_lld.h:376
MMCSD_lld_read_MMC_Intr
int32_t MMCSD_lld_read_MMC_Intr(MMCSDLLD_Handle handle, uint8_t *buf, uint32_t startBlk, uint32_t numBlks)
Reads data from the MMC card using interrupt method.
MMCSDLLD_Object::setBusWidth
uint32_t setBusWidth
Definition: mmcsd_lld.h:411
MMCSDLLD_Transaction
MMCSD LLD Transaction.
Definition: mmcsd_lld.h:333
MMCSDLLD_Transaction::arg
uint32_t arg
Definition: mmcsd_lld.h:340
MMCSDLLD_Object::xferErrorStat
uint16_t xferErrorStat
Definition: mmcsd_lld.h:394
MMCSD_SdDeviceData::maxReadBlockLen
uint16_t maxReadBlockLen
Definition: mmcsd_lld.h:302
MMCSD_lld_write_MMC_Intr
int32_t MMCSD_lld_write_MMC_Intr(MMCSDLLD_Handle handle, uint8_t *buf, uint32_t startBlk, uint32_t numBlks)
Writes data to the MMC card using interrupt method.
MMCSD_SdDeviceData::isHC
bool isHC
Definition: mmcsd_lld.h:322
MMCSD_lld_deInit
int32_t MMCSD_lld_deInit(MMCSDLLD_Handle handle)
This API De-Initializes the MMCSD instance.
MMCSD_lld_write_MMC_Dma
int32_t MMCSD_lld_write_MMC_Dma(MMCSDLLD_Handle handle, uint8_t *buf, uint32_t startBlk, uint32_t numBlks)
Function to perform block writes to the MMC media in DMA Mode.
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:404
MMCSDLLD_InitObject
MMCSD Driver Initialization Object.
Definition: mmcsd_lld.h:355
MMCSD_lld_write_SD_Dma
int32_t MMCSD_lld_write_SD_Dma(MMCSDLLD_Handle handle, uint8_t *buf, uint32_t startBlk, uint32_t numBlks)
Function to perform block writes to the SD media in DMA Mode.
MMCSD_EmmcDeviceData::eStrobeSupport
uint8_t eStrobeSupport
Definition: mmcsd_lld.h:282
MMCSD_EmmcDeviceData::manuID
uint8_t manuID
Definition: mmcsd_lld.h:270
MMCSD_SdDeviceData::isCmd23
uint32_t isCmd23
Definition: mmcsd_lld.h:318
MMCSD_EmmcDeviceData::specVersion
uint8_t specVersion
Definition: mmcsd_lld.h:274
MMCSD_EmmcDeviceData::ocr
uint32_t ocr
Definition: mmcsd_lld.h:260
MMCSDLLD_InitObject::cardType
uint32_t cardType
Definition: mmcsd_lld.h:364
MMCSD_lld_read_MMC_Dma
int32_t MMCSD_lld_read_MMC_Dma(MMCSDLLD_Handle handle, uint8_t *buf, uint32_t startBlk, uint32_t numBlks)
Function to perform block reads from the MMC media in DMA Mode.
MMCSDLLD_Object
MMCSD Driver Object.
Definition: mmcsd_lld.h:389
MMCSDLLD_Transaction::blockCount
uint32_t blockCount
Definition: mmcsd_lld.h:346
MMCSDLLD_InitHandle
struct MMCSDLLD_InitObject * MMCSDLLD_InitHandle
MMCSDLLD_Transaction::dataBuf
uint8_t * dataBuf
Definition: mmcsd_lld.h:342
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:300
MMCSD_lld_completeCurrTransfer
void MMCSD_lld_completeCurrTransfer(MMCSDLLD_Handle handle, int32_t xferStatus)
Completes the current MMC/SD data transfer operation.
MMCSDLLD_Object::remainingBlockCount
uint32_t remainingBlockCount
Definition: mmcsd_lld.h:402
MMCSD_EmmcDeviceData::supportedModes
uint8_t supportedModes
Definition: mmcsd_lld.h:280
MMCSD_DmaHandle
EDMA_Handle MMCSD_DmaHandle
Definition: mmcsd_lld.h:81
MMCSDLLD_Transaction::blockSize
uint32_t blockSize
Definition: mmcsd_lld.h:344
edma.h
This file contains the prototype of EDMA driver APIs.
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:398
MMCSD_lld_read_MMC_Poll
int32_t MMCSD_lld_read_MMC_Poll(MMCSDLLD_Handle handle, uint8_t *buf, uint32_t startBlk, uint32_t numBlks)
Reads data from the MMC card using polling method.
MMCSD_lld_deInitDma
int32_t MMCSD_lld_deInitDma(MMCSDLLD_Handle handle)
This API De-Initializes the MMCSD instance with DMA transfers.
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:257
MMCSD_EmmcDeviceData::maxReadBlockLen
uint16_t maxReadBlockLen
Definition: mmcsd_lld.h:264
MMCSDLLD_InitObject::busWidth
uint32_t busWidth
Definition: mmcsd_lld.h:370
MMCSDLLD_Handle
struct MMCSDLLD_Object * MMCSDLLD_Handle
MMCSD_EmmcDeviceData::transferSpeed
uint8_t transferSpeed
Definition: mmcsd_lld.h:278
MMCSD_SdDeviceData::supportedDataWidths
uint32_t supportedDataWidths
Definition: mmcsd_lld.h:320
MMCSDLLD_Object::mmcsdTxn
MMCSDLLD_Transaction mmcsdTxn
Definition: mmcsd_lld.h:406
MMCSD_EmmcDeviceData::maxWriteBlockLen
uint16_t maxWriteBlockLen
Definition: mmcsd_lld.h:266
EDMA_Handle
void * EDMA_Handle
A handle that is returned from a EDMA_open() call.
Definition: edma/v0/edma.h:596
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:374
MMCSD_lld_write_MMC_Poll
int32_t MMCSD_lld_write_MMC_Poll(MMCSDLLD_Handle handle, uint8_t *buf, uint32_t startBlk, uint32_t numBlks)
Writes data to the MMC card using polling method.
MMCSD_EmmcDeviceData::isHC
bool isHC
Definition: mmcsd_lld.h:288
MMCSDLLD_Object::dataBlockSize
uint32_t dataBlockSize
Definition: mmcsd_lld.h:400
MMCSD_SdDeviceData::blockCount
uint32_t blockCount
Definition: mmcsd_lld.h:314
MMCSDLLD_Object::initHandle
MMCSDLLD_InitHandle initHandle
Definition: mmcsd_lld.h:417
MMCSDLLD_Transaction::cmd
uint32_t cmd
Definition: mmcsd_lld.h:336
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:247
MMCSDLLD_InitObject::inputClkFreq
uint32_t inputClkFreq
Definition: mmcsd_lld.h:360
MMCSDLLD_Object::args
void * args
Definition: mmcsd_lld.h:419
MMCSDLLD_Object::xferState
uint8_t xferState
Definition: mmcsd_lld.h:413
MMCSDLLD_Object::cmdErrorStat
uint16_t cmdErrorStat
Definition: mmcsd_lld.h:392
MMCSD_EmmcDeviceData::driveStrength
uint8_t driveStrength
Definition: mmcsd_lld.h:284
MMCSD_lld_InitDma
int32_t MMCSD_lld_InitDma(MMCSDLLD_Handle handle)
This API Initializes the MMCSD instance for DMA transfers.
MMCSDLLD_Transaction::flags
uint32_t flags
Definition: mmcsd_lld.h:338
MMCSDLLD_InitObject::uaBusSpeed
uint32_t uaBusSpeed
Definition: mmcsd_lld.h:368
MMCSD_SdDeviceData::maxWriteBlockLen
uint16_t maxWriteBlockLen
Definition: mmcsd_lld.h:304