SDWFF3.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2025, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the 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 "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*
33  * @file SDWFF3.h
34  * @brief SDWFF3 driver implementation for a Wi-Fi F3 device.
35  * SDWFF3 controller using the DMA controller or Core.
36  *
37  * # Driver include #
38  * The SDWFF3 header file should be included in an application as follows:
39  * @code
40  * #include <ti/drivers/SD.h>
41  * #include <ti/drivers/sd/SDWFF3.h>
42  * #include <ti/drivers/dma/DMAWFF3.h>
43  * @endcode
44  *
45  * Refer to @ref SD.h for a complete description of APIs.
46  *
47  * Note that the user also needs to include the DMAWFF3.h driver since the SDWFF3
48  * uses DMA in order to improve throughput.
49  *
50  * # Overview #
51  * The general SD API should be used in application code, i.e. #SD_open()
52  * should be used instead of #SDWFF3_open(). The board file will define the
53  * device specific config, and casting in the general API will ensure that the
54  * correct device specific functions are called.
55  *
56  * # General Behavior #
57  * Before using SDWFF3 on Wi-Fi F3 devices:
58  * - The SDWFF3 driver is initialized by calling #SD_init().
59  * - The SDWFF3 HW is configured and flags system dependencies (e.g. IOs, power,
60  * etc.) by calling #SD_open().
61  * - The SDWFF3 driver makes use of DMA in order to optimize throughput. This is
62  * handled directly by the SDWFF3 driver, so the application should never make
63  * any calls directly to the DMAWFF3.h driver.
64  * - After SDWFF3 HW IP initialized, card must be initialized too.
65  * The application must make sure that the card is connected.
66  * It is recommended to check with #SD_control() with command SDWFF3_CMD_IS_CARD_CONNECTED
67  * before using #SD_initialize().
68  * note: The driver will indicate to the application if the card is connected or not,
69  * using call-back function that define in the Parameters of #SD_open().
70  * - #SD_read() and #SD_write() can be called only after the HW IP and the card are initiated.
71  *
72  * After SDWFF3 operation has ended:
73  * - Release system dependencies for SD by calling #SD_close().
74  *
75  * The SDWFF3.h driver is setting a power constraint during transfers to
76  * keep the device out of sleep. When the transfer has finished, the power
77  * constraint is released.
78  *
79  * ## Power voltage #
80  * This driver supports a card voltage of 3.3V only.
81  * In case the pins of the SD card are defined as 1.8V, the user must use external
82  * level-shifter and supply 3.3V to the card.
83  *
84  * ## Data Frames #
85  * SDWFF3 data frames is fixed on 32-bits (4-bytes)
86  *
87  * ## Bit Rate ##
88  * When the connected card is UHS-1 then the maximum bit rate is 40MHz.
89  * Else the maximum bit rate is 20MHz.
90  *
91  * ### Transfer Size Limit #
92  * The DMA controller only supports data transfers of up to 16383 bytes.
93  * A transfer with more than 16383 bytes will be transmitted/received in
94  * multiple 16383 sized portions until all data has been transmitted/received.
95  *
96  * ## Polling SDWFF3 transfers #
97  * When using #SD_read() or #SD_write() with small number of sectors the transmit can be done by polling
98  * the peripheral & sending data sector-by-sector. A controller device can
99  * perform the transfer immediately and return, but a peripheral will block
100  * until it receives the number of sectors specified in the #SD_read() or #SD_write() call.
101  * The minDmaTransferSize field in the hardware attributes is the threshold; if
102  * the transaction count is below the threshold a polling transfer is
103  * performed; otherwise a DMA transfer is done. This is intended to reduce the
104  * overhead of setting up a DMA transfer to only send a few data sectors.
105  *
106  * # Supported Functions #
107  * Generic API function | WFF3 API function | Description
108  * -----------------------|----------------------- -|------------------------------------------------------------
109  * #SD_init() | #SDWFF3_init() | Initializes the SD driver
110  * #SD_open() | #SDWFF3_open() | Open the SD peripheral with the parameters specified
111  * #SD_close() | #SDWFF3_close() | Close a SD peripheral
112  * #SD_initialize() | #SDWFF3_initialize() | Initialize the SD card
113  * #SD_control() | #SDWFF3_control() | Performs implementation specific features
114  * #SD_write() | #SDWFF3_write() | Writes data to the specified sectors of the SD card
115  * #SD_read() | #SDWFF3_read() | Reads the specified sectors from the SD card
116  * #SD_getNumSectors() | #SDWFF3_getNumSectors() | Obtain the total number of sectors on the SD card
117  * #SD_getSectorSize() | #SDWFF3_getSectorSize() | Obtain the sector size used to access the SD card
118  *
119  * @note All calls should go through the generic API
120  *
121  * # SysConfig #
122  * The output of SysConfig will supply #SD_Config, #SDWFF3_Object and #SDWFF3_HwAttrs
123  * for the driver usage.
124  * A sample #SDWFF3_HwAttrs structure is shown below:
125  *
126  * SDWFF3_HwAttrs SDWFF3_hwAttrs[CONFIG_SD_COUNT] = {
127  * {
128  * .baseAddr = SDMMC_BASE,
129  * .intNum = INT_EVT_SDMMC_PUB_REQ,
130  * .intPriority = (~0),
131  * .powerID = PowerWFF3_PERIPH_SDMMC,
132  * .DmaChannel = 5,
133  * .clkPin = 14,
134  * .clkPinMux = 3,
135  * .cmdPin = 15,
136  * .cmdPinMux = 3,
137  * .data0Pin = 13,
138  * .data0PinMux = 3,
139  * .data1Pin = 12,
140  * .data1PinMux = 3,
141  * .data2Pin = 11,
142  * .data2PinMux = 3,
143  * .data3Pin = 10,
144  * .data3PinMux = 3,
145  * .cdPin = GPIO_INVALID_INDEX,
146  * .cdPinMux = GPIO_MUX_GPIO_INTERNAL,
147  * .wpPin = GPIO_INVALID_INDEX,
148  * .wpPinMux = GPIO_MUX_GPIO_INTERNAL,
149  * .powPin = GPIO_INVALID_INDEX,
150  * .powPinMux = GPIO_MUX_GPIO_INTERNAL,
151  * .numData = 4,
152  * .divClk = 0,
153  * .cdEnable = false,
154  * .cdPolHigh = false,
155  * .wpEnable = false,
156  * .wpPolHigh = false,
157  * .powEnable = false,
158  * .powerOffInSleep = false
159  * },
160  * };
161  *---------------------------------------------------------------------*
162  * An example for using SDWFF3 driver correctly on Wi-Fi F3 devices
163  *---------------------------------------------------------------------*
164  *
165  * @code
166  * Customer should provide a callback function by #SDWFF3_Param that is sent to #SD_open().
167  * SDWFF3 will indicate the application for any event in Event_Type enum
168  * //function scratch
169  * void SDWFF3_callBack(uint8_t event){
170  * if (event == SD_CARD_INSERTED){
171  * // do something
172  * }
173  * .
174  * .
175  * .
176  * }
177  *
178  * //Variable declaration for driver usage - can be declare with any name
179  * SDWFF3_Param SDWFF3_param;
180  *
181  * //Initiate #SDWFF3_Param - for more details about the params, please review #SDWFF3_open description
182  * SDWFF3_param.SDWFF3CallbackFxn = SDWFF3_callBack;
183  * SDWFF3_param.minDmaTransferSize = (uint32_t)num;
184  *
185  * //To start using SD driver, the driver must be initialized
186  * SD_init();
187  *
188  * //Then the SD host controller peripheral must be open using #SDWFF3_param
189  * SD_handle = SD_open(0, (SD_Params *)&SDWFF3_param);
190  *
191  * //The last initialization is for the card - IF CONNECTED!!
192  * SD_initialize(SD_handle);
193  *
194  * if the return from #SD_initialize() is SD_STATUS_SUCCESS, read and write to the card is allowed
195  *
196  *
197  */
198 
199 #ifndef ti_drivers_sd_SDWFF3__include
200 #define ti_drivers_sd_SDWFF3__include
201 
202 #include <stdint.h>
203 #include <string.h>
204 #include <stdbool.h>
205 
206 #include <ti/devices/DeviceFamily.h>
207 #include DeviceFamily_constructPath(inc/hw_types.h)
208 #include DeviceFamily_constructPath(driverlib/dma.h)
209 #include DeviceFamily_constructPath(inc/hw_memmap.h)
210 #include DeviceFamily_constructPath(inc/hw_iomux.h)
211 #include DeviceFamily_constructPath(inc/hw_sdmmc.h)
212 #include DeviceFamily_constructPath(inc/hw_ints.h)
213 
214 #include <ti/drivers/SD.h>
215 #include <ti/drivers/dpl/HwiP.h>
216 #include <ti/drivers/dpl/ClockP.h>
218 #include <ti/drivers/Power.h>
219 
220 #ifdef __cplusplus
221 extern "C" {
222 #endif
223 
224 //------------------------------------------------------------------//
225 
229 typedef void (*SDWFF3_EventCB)(uint8_t event);
230 
236 #define SDWFF3_CMD_IS_CARD_CONNECTED (SD_CMD_RESERVED + 0)
237 #define SDWFF3_CMD_IS_CARD_WRITE_PROTECTED (SD_CMD_RESERVED + 1)
238 
242 typedef struct
243 {
245  bool isOpen;
246 
249 
252 
255 
258 
260  uint32_t cid[4];
261 
263  uint32_t rca;
264 
266  uint32_t csd[4];
267 
269  uint32_t scr[2];
270 
272  uint8_t tranSpeed;
273 
275  uint32_t curBlockSize;
276 
278  uint32_t maxBlockSize;
279 
281  uint32_t numSectors;
282 
284  uint32_t dataBlockCount;
285 
288 
290  uint32_t maxBusWidth;
291 
293  uint32_t clockDiv;
294 
297 
300 
303 
306 
307 } SDWFF3_Object;
308 
309 typedef struct
310 {
312  uint32_t baseAddr;
313 
315  uint32_t intNum;
316 
318  uint32_t intPriority;
319 
321  PowerWFF3_Resource powerID;
322 
324  uint32_t DmaChannel;
325 
327  uint8_t clkPin;
328 
330  uint8_t clkPinMux;
331 
333  uint8_t cmdPin;
334 
336  uint8_t cmdPinMux;
337 
339  uint8_t data0Pin;
340 
342  uint8_t data0PinMux;
343 
345  uint8_t data1Pin;
346 
348  uint8_t data1PinMux;
349 
351  uint8_t data2Pin;
352 
354  uint8_t data2PinMux;
355 
357  uint8_t data3Pin;
358 
360  uint8_t data3PinMux;
361 
363  uint8_t cdPin;
364 
366  uint8_t cdPinMux;
367 
369  uint8_t wpPin;
370 
372  uint8_t wpPinMux;
373 
375  uint8_t powPin;
376 
378  uint8_t powPinMux;
379 
381  uint32_t numData;
382 
384  uint32_t divClk;
385 
387  bool cdEnable;
388 
390  bool cdPolHigh;
391 
393  bool wpEnable;
394 
396  bool wpPolHigh;
397 
399  bool powEnable;
400 
403 
405 
406 typedef struct
407 {
410 
413 
414 } SDWFF3_Param;
415 
416 typedef enum
417 {
423 } Event_Type;
424 
425 /* ========================================================================== */
426 /* Function Declarations */
427 /* ========================================================================== */
428 
447 void SDWFF3_close(SD_Handle handle);
448 
470 int_fast16_t SDWFF3_control(SD_Handle handle, uint_fast16_t cmd, void *arg);
471 
485 uint_fast32_t SDWFF3_getNumSectors(SD_Handle handle);
486 
490 uint_fast32_t SDWFF3_getSectorSize(SD_Handle handle);
491 
502 void SDWFF3_init(SD_Handle handle);
503 
514 int_fast16_t SDWFF3_initialize(SD_Handle handle);
515 
538 
561 int_fast16_t SDWFF3_read(SD_Handle handle, void *buf, int_fast32_t sector, uint_fast32_t secCount);
562 
585 int_fast16_t SDWFF3_write(SD_Handle handle, const void *buf, int_fast32_t sector, uint_fast32_t secCount);
586 
587 /* SDWFF3 function table */
588 extern const SD_FxnTable SDWFF3_fxnTable;
589 
590 #ifdef __cplusplus
591 }
592 #endif
593 
594 #endif /* ti_drivers_sd_SDWFF3__include */
Event_Type
Definition: SDWFF3.h:416
uint8_t cmdPinMux
Definition: SDWFF3.h:336
bool wpPolHigh
Definition: SDWFF3.h:396
ADC_Params params
Definition: Driver_Init.h:11
uint8_t data2PinMux
Definition: SDWFF3.h:354
const SD_FxnTable SDWFF3_fxnTable
SD_CardType cardType
Definition: SDWFF3.h:251
int_fast16_t SDWFF3_read(SD_Handle handle, void *buf, int_fast32_t sector, uint_fast32_t secCount)
Function that reads the specified sectors from the SD card. The destination is specified by buf...
SD Global configuration.
Definition: SD.h:317
bool wpEnable
Definition: SDWFF3.h:393
uint32_t intNum
Definition: SDWFF3.h:315
uint8_t powPinMux
Definition: SDWFF3.h:378
uint32_t rca
Definition: SDWFF3.h:263
HwiP structure.
Definition: HwiP.h:166
HwiP_Struct SDhwiStruct
Definition: SDWFF3.h:305
uint8_t powPin
Definition: SDWFF3.h:375
uint32_t intPriority
Definition: SDWFF3.h:318
SD Parameters.
Definition: SD.h:220
uint8_t cmdPin
Definition: SDWFF3.h:333
int_fast16_t SDWFF3_write(SD_Handle handle, const void *buf, int_fast32_t sector, uint_fast32_t secCount)
Function that writes data to the specified sectors of the SD card. The source is specified by buf...
Clock interface for the RTOS Porting Interface.
uint32_t DmaChannel
Definition: SDWFF3.h:324
Power Manager.
uint8_t data1PinMux
Definition: SDWFF3.h:348
void * SDWFF3CallbackFxn
Definition: SDWFF3.h:409
uint8_t data0PinMux
Definition: SDWFF3.h:342
uint8_t data2Pin
Definition: SDWFF3.h:351
Definition: SDWFF3.h:422
uint_fast32_t SDWFF3_getNumSectors(SD_Handle handle)
Function to obtain the total number of sectors on the SD card. Note: Total Card capacity is the (Numb...
int_fast16_t SDWFF3_initialize(SD_Handle handle)
Function to initialize the SD card.
SD_Handle SDWFF3_open(SD_Handle handle, SD_Params *params)
Function to open the SD peripheral with the index and parameters specified.
Definition: SDWFF3.h:421
uint32_t clockDiv
Definition: SDWFF3.h:293
The definition of a SD function table that contains the required set of functions to control a specif...
Definition: SD.h:284
uint32_t dataBlockCount
Definition: SDWFF3.h:284
Semaphore module for the RTOS Porting Interface.
uint32_t SDminDmaTransferSize
Definition: SDWFF3.h:296
uint32_t numSectors
Definition: SDWFF3.h:281
Definition: SDWFF3.h:419
uint32_t curBlockSize
Definition: SDWFF3.h:275
HwiP_Params SDhwiPrms
Definition: SDWFF3.h:302
uint32_t baseAddr
Definition: SDWFF3.h:312
void SDWFF3_init(SD_Handle handle)
This function initializes the SD driver.
Secure Digital (SD) Driver.
uint32_t divClk
Definition: SDWFF3.h:384
uint8_t cdPinMux
Definition: SDWFF3.h:366
bool cdPolHigh
Definition: SDWFF3.h:390
SDWFF3 driver object.
Definition: SDWFF3.h:242
uint8_t clkPin
Definition: SDWFF3.h:327
bool powEnable
Definition: SDWFF3.h:399
bool cardInitiated
Definition: SDWFF3.h:248
uint8_t data3PinMux
Definition: SDWFF3.h:360
Definition: SDWFF3.h:309
bool isOpen
Definition: SDWFF3.h:245
uint32_t numData
Definition: SDWFF3.h:381
uint32_t minDmaTransferSize
Definition: SDWFF3.h:412
Definition: SDWFF3.h:420
uint_fast32_t SDWFF3_getSectorSize(SD_Handle handle)
SD_CardType
SD Card type inserted.
Definition: SD.h:197
PowerWFF3_Resource powerID
Definition: SDWFF3.h:321
Definition: SDWFF3.h:418
uint8_t cdPin
Definition: SDWFF3.h:363
Definition: SDWFF3.h:406
uint8_t wpPinMux
Definition: SDWFF3.h:372
bool write_protected
Definition: SDWFF3.h:257
int_fast16_t SDWFF3_control(SD_Handle handle, uint_fast16_t cmd, void *arg)
Function for setting control parameters of the SDWFF3 driver after it has been opened.
void SDWFF3_close(SD_Handle handle)
Function to close a SD peripheral specified by the SD handle.
void(* SDWFF3_EventCB)(uint8_t event)
Callback function supplied by the application.
Definition: SDWFF3.h:229
bool powerOffInSleep
Definition: SDWFF3.h:402
bool card_inserted
Definition: SDWFF3.h:254
uint32_t maxBusWidth
Definition: SDWFF3.h:290
uint8_t data1Pin
Definition: SDWFF3.h:345
bool partialBlock
Definition: SDWFF3.h:287
uint8_t data3Pin
Definition: SDWFF3.h:357
Basic HwiP Parameters.
Definition: HwiP.h:205
Hardware Interrupt module for the RTOS Porting Interface.
uint8_t tranSpeed
Definition: SDWFF3.h:272
uint32_t maxBlockSize
Definition: SDWFF3.h:278
bool cdEnable
Definition: SDWFF3.h:387
uint8_t wpPin
Definition: SDWFF3.h:369
uint8_t clkPinMux
Definition: SDWFF3.h:330
uint8_t data0Pin
Definition: SDWFF3.h:339
SDWFF3_EventCB SDWFF3_CB_function
Definition: SDWFF3.h:299
© Copyright 1995-2026, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale