SD.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2019, 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 /*!***************************************************************************
34  * @file SD.h
35  * @brief Secure Digital (SD) Driver
36  *
37  * @anchor ti_drivers_SD_Overview
38  * # Overview
39  *
40  * The SD driver is designed to serve as an interface to perform basic
41  * transfers directly to the SD card.
42  *
43  * <hr>
44  * @anchor ti_drivers_SD_Usage
45  * # Usage
46  * This section will cover driver usage.
47  *
48  * @anchor ti_drivers_SD_Synopsis
49  * ## Synopsis
50  * @anchor ti_drivers_SD_Synopsis_Code
51  * @code
52  * SD_Handle handle;
53  * uint16_t status;
54  *
55  * SD_init();
56  *
57  * // Open SD and initialize card
58  * handle = SD_open(CONFIG_SD0, NULL);
59  * status = SD_initialize(handle);
60  * if (handle == NULL || status != SD_STATUS_SUCCESS) {
61  * //Error opening SD driver
62  * while (1);
63  * }
64  *
65  * // Write and read back the first sector
66  * status = SD_write(handle, sendBuffer, 0, 1);
67  * if (status == SD_STATUS_SUCCESS) {
68  * status = SD_read(handle, readBuffer, 0 , 1);
69  * }
70  *
71  * SD_close(handle);
72  * @endcode
73  *
74  * @anchor ti_drivers_SD_Examples
75  * # Examples
76  * - @ref ti_drivers_SD_Synopsis "Overview"
77  * - @ref ti_drivers_SD_Example_getCardSpace "Get SD card size"
78  *
79  * Get total capacity of an SD card:
80  * @anchor ti_drivers_SD_Example_getCardSpace
81  * @code
82  * SD_Handle handle;
83  * Display_Handle display;
84  * uint_fast32_t sectorSize, sectorCount;
85  *
86  * // Init, open, etc
87  * ...
88  *
89  * sectorSize = SD_getSectorSize(handle);
90  * sectorCount = SD_getNumSectors(handle);
91  *
92  * Display_printf(display, 0, 0,"SD card total capacity is %lu bytes.",
93  * sectorSize * sectorCount);
94  * @endcode
95  *
96  * <hr>
97  * @anchor ti_drivers_SD_Configuration
98  * # Configuration
99  * Refer to the @ref driver_configuration "Driver's Configuration"
100  * section for driver configuration information.
101  *
102  * <hr>
103  ******************************************************************************
104  */
105 
106 #ifndef ti_drivers_SD__include
107 #define ti_drivers_SD__include
108 
109 #include <stdint.h>
110 
111 #ifdef __cplusplus
112 extern "C" {
113 #endif
114 
131 #define SD_CMD_RESERVED (32)
132 
145 #define SD_STATUS_RESERVED (-32)
146 
160 #define SD_STATUS_SUCCESS (0)
161 
168 #define SD_STATUS_ERROR (-1)
169 
177 #define SD_STATUS_UNDEFINEDCMD (-2)
178 
188 /* Add SD_CMD_<commands> here */
189 
197 typedef enum {
198  SD_NOCARD = 0,
199  SD_MMC = 1,
200  SD_SDSC = 2,
201  SD_SDHC = 3
202 } SD_CardType;
203 
207 typedef struct SD_Config_ *SD_Handle;
208 
218 /* SD Parameters */
219 typedef struct {
220  void *custom;
221 } SD_Params;
222 
227 typedef void (*SD_CloseFxn) (SD_Handle handle);
228 
233 typedef int_fast16_t (*SD_ControlFxn) (SD_Handle handle,
234  uint_fast16_t cmd, void *arg);
235 
240 typedef uint_fast32_t (*SD_getNumSectorsFxn) (SD_Handle handle);
241 
246 typedef uint_fast32_t (*SD_getSectorSizeFxn) (SD_Handle handle);
247 
252 typedef void (*SD_InitFxn) (SD_Handle handle);
253 
258 typedef int_fast16_t (*SD_InitializeFxn) (SD_Handle handle);
259 
264 typedef SD_Handle (*SD_OpenFxn) (SD_Handle handle, SD_Params *params);
265 
270 typedef int_fast16_t (*SD_ReadFxn) (SD_Handle handle, void *buf,
271  int_fast32_t sector, uint_fast32_t secCount);
272 
277 typedef int_fast16_t (*SD_WriteFxn) (SD_Handle handle, const void *buf,
278  int_fast32_t sector, uint_fast32_t secCount);
279 
285 typedef struct {
304 } SD_FxnTable;
305 
317 typedef struct SD_Config_ {
320 
322  void *object;
323 
325  void const *hwAttrs;
326 } SD_Config;
327 
337 extern void SD_close(SD_Handle handle);
338 
377 extern int_fast16_t SD_control(SD_Handle handle, uint_fast16_t cmd, void *arg);
378 
393 extern uint_fast32_t SD_getNumSectors(SD_Handle handle);
394 
406 extern uint_fast32_t SD_getSectorSize(SD_Handle handle);
407 
416 extern void SD_init(void);
417 
423 extern void SD_Params_init(SD_Params *params);
424 
436 extern int_fast16_t SD_initialize(SD_Handle handle);
437 
457 extern SD_Handle SD_open(uint_least8_t index, SD_Params *params);
458 
479 extern int_fast16_t SD_read(SD_Handle handle, void *buf,
480  int_fast32_t sector, uint_fast32_t secCount);
481 
502 extern int_fast16_t SD_write(SD_Handle handle, const void *buf,
503  int_fast32_t sector, uint_fast32_t secCount);
504 
505 #ifdef __cplusplus
506 }
507 #endif
508 
509 #endif /* ti_drivers_SD__include */
int_fast16_t SD_control(SD_Handle handle, uint_fast16_t cmd, void *arg)
Function performs implementation specific features on a given SD_Handle.
struct SD_Config_ * SD_Handle
A handle that is returned from a SD_open() call.
Definition: SD.h:207
int_fast16_t(* SD_InitializeFxn)(SD_Handle handle)
A function pointer to a driver specific implementation of SD_initializeFxn().
Definition: SD.h:258
void * custom
Definition: SD.h:220
Definition: SD.h:201
SD_getSectorSizeFxn getSectorSizeFxn
Definition: SD.h:293
SD Global configuration.
Definition: SD.h:317
uint_fast32_t SD_getSectorSize(SD_Handle handle)
Function to obtain the sector size used to access the SD card.
SD_InitFxn initFxn
Definition: SD.h:295
Definition: SD.h:199
SD_InitializeFxn initializeFxn
Definition: SD.h:297
SD Parameters.
Definition: SD.h:219
SD_Handle(* SD_OpenFxn)(SD_Handle handle, SD_Params *params)
A function pointer to a driver specific implementation of SD_OpenFxn().
Definition: SD.h:264
uint_fast32_t SD_getNumSectors(SD_Handle handle)
A function pointer to a driver specific implementation of SD_getNumSectors(). Note: Total Card capaci...
int_fast16_t(* SD_WriteFxn)(SD_Handle handle, const void *buf, int_fast32_t sector, uint_fast32_t secCount)
A function pointer to a driver specific implementation of SD_writeFxn().
Definition: SD.h:277
void SD_init(void)
This function initializes the SD driver.
uint_fast32_t(* SD_getSectorSizeFxn)(SD_Handle handle)
A function pointer to a driver specific implementation of SD_getSectorSizeFxn().
Definition: SD.h:246
int_fast16_t(* SD_ControlFxn)(SD_Handle handle, uint_fast16_t cmd, void *arg)
A function pointer to a driver specific implementation of SD_controlFxn().
Definition: SD.h:233
SD_OpenFxn openFxn
Definition: SD.h:299
The definition of a SD function table that contains the required set of functions to control a specif...
Definition: SD.h:285
int_fast16_t SD_write(SD_Handle handle, const void *buf, int_fast32_t sector, uint_fast32_t secCount)
A function pointer to a driver specific implementation of SD_write().
int_fast16_t SD_read(SD_Handle handle, void *buf, int_fast32_t sector, uint_fast32_t secCount)
A function pointer to a driver specific implementation of SD_read().
void SD_close(SD_Handle handle)
Function to close a SD peripheral specified by the SD handle.
SD_ReadFxn readFxn
Definition: SD.h:301
SD_ControlFxn controlFxn
Definition: SD.h:289
struct SD_Config_ SD_Config
SD Global configuration.
void(* SD_InitFxn)(SD_Handle handle)
A function pointer to a driver specific implementation of SD_InitFxn().
Definition: SD.h:252
SD_WriteFxn writeFxn
Definition: SD.h:303
SD_getNumSectorsFxn getNumSectorsFxn
Definition: SD.h:291
Definition: SD.h:198
Definition: SD.h:200
uint_fast32_t(* SD_getNumSectorsFxn)(SD_Handle handle)
A function pointer to a driver specific implementation of SD_getNumSectorsFxn().
Definition: SD.h:240
SD_CardType
SD Card type inserted.
Definition: SD.h:197
int_fast16_t(* SD_ReadFxn)(SD_Handle handle, void *buf, int_fast32_t sector, uint_fast32_t secCount)
A function pointer to a driver specific implementation of SD_readFxn().
Definition: SD.h:270
SD_CloseFxn closeFxn
Definition: SD.h:287
void const * hwAttrs
Definition: SD.h:325
SD_FxnTable const * fxnTablePtr
Definition: SD.h:319
void SD_Params_init(SD_Params *params)
Function to initialize the SD_Params struct to its defaults.
SD_Handle SD_open(uint_least8_t index, SD_Params *params)
A function pointer to a driver specific implementation of SD_open().
void(* SD_CloseFxn)(SD_Handle handle)
A function pointer to a driver specific implementation of SD_CloseFxn().
Definition: SD.h:227
void * object
Definition: SD.h:322
int_fast16_t SD_initialize(SD_Handle handle)
A function pointer to a driver specific implementation of SD_initialize().
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale