SD.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2017, 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 
88 #ifndef ti_drivers_SD__include
89 #define ti_drivers_SD__include
90 
91 #ifdef __cplusplus
92 extern "C" {
93 #endif
94 
95 #include <stdint.h>
96 
113 #define SD_CMD_RESERVED (32)
114 
127 #define SD_STATUS_RESERVED (-32)
128 
142 #define SD_STATUS_SUCCESS (0)
143 
150 #define SD_STATUS_ERROR (-1)
151 
159 #define SD_STATUS_UNDEFINEDCMD (-2)
160 
170 /* Add SD_CMD_<commands> here */
171 
179 typedef enum SD_CardType_ {
180  SD_NOCARD = 0,
181  SD_MMC = 1,
182  SD_SDSC = 2,
183  SD_SDHC = 3
184 } SD_CardType;
185 
189 typedef struct SD_Config_ *SD_Handle;
190 
200 /* SD Parameters */
201 typedef struct SD_Params_ {
202  void *custom;
203 } SD_Params;
204 
209 typedef void (*SD_CloseFxn) (SD_Handle handle);
210 
215 typedef int_fast16_t (*SD_ControlFxn) (SD_Handle handle,
216  uint_fast16_t cmd, void *arg);
217 
222 typedef uint_fast32_t (*SD_getNumSectorsFxn) (SD_Handle handle);
223 
228 typedef uint_fast32_t (*SD_getSectorSizeFxn) (SD_Handle handle);
229 
234 typedef void (*SD_InitFxn) (SD_Handle handle);
235 
240 typedef int_fast16_t (*SD_InitializeFxn) (SD_Handle handle);
241 
246 typedef SD_Handle (*SD_OpenFxn) (SD_Handle handle, SD_Params *params);
247 
252 typedef int_fast16_t (*SD_ReadFxn) (SD_Handle handle, void *buf,
253  int_fast32_t sector, uint_fast32_t secCount);
254 
259 typedef int_fast16_t (*SD_WriteFxn) (SD_Handle handle, const void *buf,
260  int_fast32_t sector, uint_fast32_t secCount);
261 
267 typedef struct SD_FxnTable_ {
286 } SD_FxnTable;
287 
299 typedef struct SD_Config_ {
302 
304  void *object;
305 
307  void const *hwAttrs;
308 } SD_Config;
309 
319 extern void SD_close(SD_Handle handle);
320 
359 extern int_fast16_t SD_control(SD_Handle handle, uint_fast16_t cmd, void *arg);
360 
375 extern uint_fast32_t SD_getNumSectors(SD_Handle handle);
376 
388 extern uint_fast32_t SD_getSectorSize(SD_Handle handle);
389 
398 extern void SD_init(void);
399 
405 extern void SD_Params_init(SD_Params *params);
406 
418 extern int_fast16_t SD_initialize(SD_Handle handle);
419 
439 extern SD_Handle SD_open(uint_least8_t index, SD_Params *params);
440 
461 extern int_fast16_t SD_read(SD_Handle handle, void *buf,
462  int_fast32_t sector, uint_fast32_t secCount);
463 
484 extern int_fast16_t SD_write(SD_Handle handle, const void *buf,
485  int_fast32_t sector, uint_fast32_t secCount);
486 
487 #ifdef __cplusplus
488 }
489 #endif
490 
491 #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.
SD_ControlFxn controlFxn
Definition: SD.h:271
struct SD_Config_ * SD_Handle
A handle that is returned from a SD_open() call.
Definition: SD.h:189
int_fast16_t(* SD_InitializeFxn)(SD_Handle handle)
A function pointer to a driver specific implementation of SD_initializeFxn().
Definition: SD.h:240
SD Global configuration.
Definition: SD.h:299
uint_fast32_t SD_getSectorSize(SD_Handle handle)
Function to obtain the sector size used to access the SD card.
SD_Handle(* SD_OpenFxn)(SD_Handle handle, SD_Params *params)
A function pointer to a driver specific implementation of SD_OpenFxn().
Definition: SD.h:246
uint_fast32_t SD_getNumSectors(SD_Handle handle)
A function pointer to a driver specific implementation of SD_getNumSectors(). Note: Total Card capaci...
Definition: SD.h:180
SD_CloseFxn closeFxn
Definition: SD.h:269
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:259
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:228
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:215
SD_WriteFxn writeFxn
Definition: SD.h:285
SD_InitFxn initFxn
Definition: SD.h:277
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_getSectorSizeFxn getSectorSizeFxn
Definition: SD.h:275
struct SD_Config_ SD_Config
SD Global configuration.
Definition: SD.h:181
SD_ReadFxn readFxn
Definition: SD.h:283
void(* SD_InitFxn)(SD_Handle handle)
A function pointer to a driver specific implementation of SD_InitFxn().
Definition: SD.h:234
SD_CardType_
SD Card type inserted.
Definition: SD.h:179
void * custom
Definition: SD.h:202
Definition: SD.h:183
SD_InitializeFxn initializeFxn
Definition: SD.h:279
struct SD_Params_ SD_Params
SD Parameters.
uint_fast32_t(* SD_getNumSectorsFxn)(SD_Handle handle)
A function pointer to a driver specific implementation of SD_getNumSectorsFxn().
Definition: SD.h:222
Definition: SD.h:182
SD_getNumSectorsFxn getNumSectorsFxn
Definition: SD.h:273
The definition of a SD function table that contains the required set of functions to control a specif...
Definition: SD.h:267
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:252
struct SD_FxnTable_ SD_FxnTable
The definition of a SD function table that contains the required set of functions to control a specif...
void const * hwAttrs
Definition: SD.h:307
enum SD_CardType_ SD_CardType
SD Card type inserted.
SD_FxnTable const * fxnTablePtr
Definition: SD.h:301
void SD_Params_init(SD_Params *params)
Function to initialize the SD_Params struct to its defaults.
SD_OpenFxn openFxn
Definition: SD.h:281
SD_Handle SD_open(uint_least8_t index, SD_Params *params)
A function pointer to a driver specific implementation of SD_open().
SD Parameters.
Definition: SD.h:201
void(* SD_CloseFxn)(SD_Handle handle)
A function pointer to a driver specific implementation of SD_CloseFxn().
Definition: SD.h:209
void * object
Definition: SD.h:304
int_fast16_t SD_initialize(SD_Handle handle)
A function pointer to a driver specific implementation of SD_initialize().
© Copyright 1995-2018, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale