AM263Px 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 #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/mmcsd/v1/cslr_mmcsd.h>
69 
70 /* ========================================================================== */
71 /* Macros & Typedefs */
72 /* ========================================================================== */
73 
81 #define MMCSD_STS_SUCCESS ((int32_t) 0)
82 
84 #define MMCSD_STS_ERR ((int32_t)-1)
85 
87 #define MMCSD_STS_ERR_TIMEOUT ((int32_t)-2)
88 
89 #define MMCSD_STS_ERR_INVALID_PARAM ((int32_t)-3)
90 
91 #define MMCSD_STS_ERR_BUSY ((int32_t)-4)
92 
93 #define MMCSD_STS_ERR_CARD_NOT_FOUND ((int32_t)-5)
94 
95 #define MMCSD_STS_ERR_CARD_UNUSEABLE ((int32_t)-6)
96 
97 #define MMCSD_STS_ERR_CARD_UNLOCK_FAIL ((int32_t)-7)
98 
109 #define MMCSD_NO_WAIT ((uint32_t)0)
110 
112 #define MMCSD_WAIT_FOREVER ((uint32_t)-1)
113 
124 #define MMCSD_STATE_RESET ((uint8_t) 0U)
125 
127 #define MMCSD_STATE_IDLE ((uint8_t) 1U)
128 
130 #define MMCSD_STATE_BUSY ((uint8_t) 2U)
131 
133 #define MMCSD_STATE_ERROR ((uint8_t) 3U)
134 
144 #define MMCSD_XFER_IDLE_STATE ((uint8_t) 0U)
145 
146 #define MMCSD_XFER_CMD_STATE ((uint8_t) 1U)
147 
148 #define MMCSD_XFER_WRITE_STATE ((uint8_t) 2U)
149 
150 #define MMCSD_XFER_READ_STATE ((uint8_t) 3U)
151 
161 #define MMCSD_CARD_TYPE_SD ((uint32_t) 0U)
162 
163 #define MMCSD_CARD_TYPE_EMMC ((uint32_t) 2U)
164 
165 #define MMCSD_CARD_TYPE_NO_DEVICE ((uint32_t) 3U)
166 
176 #define MMCSD_BUS_WIDTH_1BIT ((uint32_t) 1U)
177 
178 #define MMCSD_BUS_WIDTH_4BIT ((uint32_t) 4U)
179 
180 #define MMCSD_BUS_WIDTH_8BIT ((uint32_t) 8U)
181 
191 #define MMCSD_SD_MODE_DS ((uint32_t) 10U)
192 
193 #define MMCSD_SD_MODE_HS ((uint32_t) 11U)
194 
197 /* ========================================================================== */
198 /* Function Pointers Declarations */
199 /* ========================================================================== */
200 
208 typedef void (*MMCSD_Clock_uSleep) (uint32_t usec);
209 
218  int32_t xferStatus);
219 
220 /* ========================================================================== */
221 /* Structure Declarations */
222 /* ========================================================================== */
223 
227 typedef struct {
228 
230  uint32_t ocr;
232  uint32_t rca;
234  uint16_t maxReadBlockLen;
238  char manuDate[9];
240  uint8_t manuID;
242  char productName[7];
244  uint8_t specVersion;
246  uint32_t blockCount;
248  uint8_t transferSpeed;
250  uint8_t supportedModes;
252  uint8_t eStrobeSupport;
254  uint8_t driveStrength;
256  bool isHC;
257 
259 
263 typedef struct {
264 
266  uint32_t ocr;
268  uint32_t rca;
270  uint16_t maxReadBlockLen;
274  char manuDate[9];
276  uint8_t manuID;
278  char productName[6];
280  uint8_t specVersion;
282  uint32_t blockCount;
284  uint8_t transferSpeed;
286  uint32_t isCmd23;
290  bool isHC;
291 
293 
301 typedef struct {
302 
304  uint32_t cmd;
306  uint32_t flags;
308  uint32_t arg;
310  uint8_t *dataBuf;
312  uint32_t blockSize;
314  uint32_t blockCount;
316  uint32_t response[4];
317 
319 
323 typedef struct {
324 
326  uint32_t baseAddr;
328  uint32_t inputClkFreq;
330  uint32_t intrNum;
332  uint32_t cardType;
336  uint32_t uaBusSpeed;
338  uint32_t busWidth;
340  bool enableDma;
342  void *deviceData;
346  uint8_t *dataBuf;
347 
350 
352 
356 typedef struct {
357 
359  uint16_t cmdErrorStat;
361  uint16_t xferErrorStat;
363  uint8_t *dataBufIdx;
365  uint32_t dataBlockCount;
367  uint32_t dataBlockSize;
376  uint32_t setBusSpeed;
378  uint32_t setBusWidth;
380  uint8_t xferState;
382  uint8_t state;
386  void *args;
389 
391 
392 /* ========================================================================== */
393 /* API Function Declarations */
394 /* ========================================================================== */
395 
404 
413 
424 int32_t MMCSD_lld_write_SD_Poll(MMCSDLLD_Handle handle, uint8_t *buf,
425  uint32_t startBlk, uint32_t numBlks);
426 
437 int32_t MMCSD_lld_read_SD_Poll(MMCSDLLD_Handle handle, uint8_t *buf,
438  uint32_t startBlk, uint32_t numBlks);
439 
450 int32_t MMCSD_lld_write_SD_Intr(MMCSDLLD_Handle handle, uint8_t *buf,
451  uint32_t startBlk, uint32_t numBlks);
452 
463 int32_t MMCSD_lld_read_SD_Intr(MMCSDLLD_Handle handle, uint8_t *buf,
464  uint32_t startBlk, uint32_t numBlks);
465 
479 
480 
481 /* ========================================================================== */
482 /* ISR Function Declarations */
483 /* ========================================================================== */
484 
491 void MMCSD_lld_Isr(void *args);
492 
493 #ifdef __cplusplus
494 }
495 #endif
496 
497 #endif /* MMCSD_LLD_H_ */
498 
MMCSDLLD_Object::setBusSpeed
uint32_t setBusSpeed
Definition: mmcsd_lld.h:376
MMCSDLLD_Object::dataBufIdx
uint8_t * dataBufIdx
Definition: mmcsd_lld.h:363
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:330
args
void * args
Definition: hsmclient_msg.h:4
MMCSD_SdDeviceData::ocr
uint32_t ocr
Definition: mmcsd_lld.h:266
MMCSDLLD_InitObject::autoAssignMaxSpeed
bool autoAssignMaxSpeed
Definition: mmcsd_lld.h:334
MMCSD_SdDeviceData::manuID
uint8_t manuID
Definition: mmcsd_lld.h:276
MMCSDLLD_Object::transferCompleteCallback
MMCSD_lld_transferCompleteCallback transferCompleteCallback
Definition: mmcsd_lld.h:388
MMCSD_SdDeviceData::transferSpeed
uint8_t transferSpeed
Definition: mmcsd_lld.h:284
MMCSDLLD_InitObject::dataBuf
uint8_t * dataBuf
Definition: mmcsd_lld.h:346
MMCSD_EmmcDeviceData::blockCount
uint32_t blockCount
Definition: mmcsd_lld.h:246
MMCSDLLD_InitObject::enableDma
bool enableDma
Definition: mmcsd_lld.h:340
MMCSD_SdDeviceData
SD device properties.
Definition: mmcsd_lld.h:263
MMCSDLLD_InitObject::baseAddr
uint32_t baseAddr
Definition: mmcsd_lld.h:326
MMCSD_EmmcDeviceData::rca
uint32_t rca
Definition: mmcsd_lld.h:232
MMCSDLLD_Object::state
uint8_t state
Definition: mmcsd_lld.h:382
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:280
MMCSDLLD_Object::setBusWidth
uint32_t setBusWidth
Definition: mmcsd_lld.h:378
MMCSDLLD_Transaction
MMCSD LLD Transaction.
Definition: mmcsd_lld.h:301
MMCSDLLD_Transaction::arg
uint32_t arg
Definition: mmcsd_lld.h:308
MMCSDLLD_Object::xferErrorStat
uint16_t xferErrorStat
Definition: mmcsd_lld.h:361
MMCSD_SdDeviceData::maxReadBlockLen
uint16_t maxReadBlockLen
Definition: mmcsd_lld.h:270
MMCSD_SdDeviceData::isHC
bool isHC
Definition: mmcsd_lld.h:290
MMCSD_lld_deInit
int32_t MMCSD_lld_deInit(MMCSDLLD_Handle handle)
This API De-Initializes the MMCSD instance.
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:371
MMCSDLLD_InitObject
MMCSD Driver Initialization Object.
Definition: mmcsd_lld.h:323
MMCSD_EmmcDeviceData::eStrobeSupport
uint8_t eStrobeSupport
Definition: mmcsd_lld.h:252
MMCSD_EmmcDeviceData::manuID
uint8_t manuID
Definition: mmcsd_lld.h:240
MMCSD_SdDeviceData::isCmd23
uint32_t isCmd23
Definition: mmcsd_lld.h:286
MMCSD_EmmcDeviceData::specVersion
uint8_t specVersion
Definition: mmcsd_lld.h:244
MMCSD_EmmcDeviceData::ocr
uint32_t ocr
Definition: mmcsd_lld.h:230
MMCSDLLD_InitObject::cardType
uint32_t cardType
Definition: mmcsd_lld.h:332
MMCSDLLD_Object
MMCSD Driver Object.
Definition: mmcsd_lld.h:356
MMCSDLLD_Transaction::blockCount
uint32_t blockCount
Definition: mmcsd_lld.h:314
MMCSDLLD_InitHandle
struct MMCSDLLD_InitObject * MMCSDLLD_InitHandle
MMCSDLLD_Transaction::dataBuf
uint8_t * dataBuf
Definition: mmcsd_lld.h:310
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:268
MMCSDLLD_Object::remainingBlockCount
uint32_t remainingBlockCount
Definition: mmcsd_lld.h:369
MMCSD_EmmcDeviceData::supportedModes
uint8_t supportedModes
Definition: mmcsd_lld.h:250
MMCSDLLD_Transaction::blockSize
uint32_t blockSize
Definition: mmcsd_lld.h:312
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:365
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:227
MMCSD_EmmcDeviceData::maxReadBlockLen
uint16_t maxReadBlockLen
Definition: mmcsd_lld.h:234
MMCSDLLD_InitObject::busWidth
uint32_t busWidth
Definition: mmcsd_lld.h:338
MMCSDLLD_Handle
struct MMCSDLLD_Object * MMCSDLLD_Handle
MMCSD_EmmcDeviceData::transferSpeed
uint8_t transferSpeed
Definition: mmcsd_lld.h:248
MMCSD_SdDeviceData::supportedDataWidths
uint32_t supportedDataWidths
Definition: mmcsd_lld.h:288
MMCSDLLD_Object::mmcsdTxn
MMCSDLLD_Transaction mmcsdTxn
Definition: mmcsd_lld.h:373
MMCSD_EmmcDeviceData::maxWriteBlockLen
uint16_t maxWriteBlockLen
Definition: mmcsd_lld.h:236
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:342
MMCSD_EmmcDeviceData::isHC
bool isHC
Definition: mmcsd_lld.h:256
MMCSDLLD_Object::dataBlockSize
uint32_t dataBlockSize
Definition: mmcsd_lld.h:367
MMCSD_SdDeviceData::blockCount
uint32_t blockCount
Definition: mmcsd_lld.h:282
MMCSDLLD_Object::initHandle
MMCSDLLD_InitHandle initHandle
Definition: mmcsd_lld.h:384
MMCSDLLD_Transaction::cmd
uint32_t cmd
Definition: mmcsd_lld.h:304
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:217
MMCSDLLD_InitObject::inputClkFreq
uint32_t inputClkFreq
Definition: mmcsd_lld.h:328
MMCSDLLD_Object::args
void * args
Definition: mmcsd_lld.h:386
MMCSDLLD_Object::xferState
uint8_t xferState
Definition: mmcsd_lld.h:380
MMCSDLLD_InitObject::Clock_uSleep
MMCSD_Clock_uSleep Clock_uSleep
Definition: mmcsd_lld.h:349
MMCSDLLD_Object::cmdErrorStat
uint16_t cmdErrorStat
Definition: mmcsd_lld.h:359
MMCSD_EmmcDeviceData::driveStrength
uint8_t driveStrength
Definition: mmcsd_lld.h:254
MMCSDLLD_Transaction::flags
uint32_t flags
Definition: mmcsd_lld.h:306
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:208
MMCSDLLD_InitObject::uaBusSpeed
uint32_t uaBusSpeed
Definition: mmcsd_lld.h:336
MMCSD_SdDeviceData::maxWriteBlockLen
uint16_t maxWriteBlockLen
Definition: mmcsd_lld.h:272