no-OS
Classes | Macros | Functions
sd.h File Reference

Header file for SD card interface over SPI. More...

#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include "no_os_spi.h"
Include dependency graph for sd.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  sd_init_param
 Configuration structure sent in the function sd_init. More...
 
struct  sd_desc
 Structure that stores data about the SD card configurations. More...
 
struct  cmd_desc
 Contains the elements needed to build a command. More...
 

Macros

#define DATA_BLOCK_LEN   (512u)
 
#define MAX_RESPONSE_LEN   (18u)
 
#define DEBUG_MSG(X)
 

Functions

int32_t sd_init (struct sd_desc **sd_desc, const struct sd_init_param *init_param)
 
int32_t sd_remove (struct sd_desc *desc)
 
int32_t sd_read (struct sd_desc *desc, uint8_t *data, uint64_t address, uint64_t len)
 
int32_t sd_write (struct sd_desc *desc, uint8_t *data, uint64_t address, uint64_t len)
 

Detailed Description

Header file for SD card interface over SPI.

Author
Mihail Chindris (mihai.nosp@m.l.ch.nosp@m.indri.nosp@m.s@an.nosp@m.alog..nosp@m.com)

Copyright 2019(c) Analog Devices, Inc.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of Analog Devices, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Library description

This interface supports byte read and write operations for SD cards that that meet the following conditions:

Macro Definition Documentation

◆ DATA_BLOCK_LEN

#define DATA_BLOCK_LEN   (512u)

◆ DEBUG_MSG

#define DEBUG_MSG (   X)

◆ MAX_RESPONSE_LEN

#define MAX_RESPONSE_LEN   (18u)

Function Documentation

◆ sd_init()

int32_t sd_init ( struct sd_desc **  sd_desc,
const struct sd_init_param param 
)

Initialize an instance of SD card and stores it to the parameter desc

Parameters
sd_desc- Pointer where to store the instance of the SD
param- Contains an initialized SPI descriptor
Returns
0 in case of success, -1 otherwise.

◆ sd_read()

int32_t sd_read ( struct sd_desc sd_desc,
uint8_t *  data,
uint64_t  address,
uint64_t  len 
)

Read data of size len from the specified address and store it in data. This operation returns only when the read is complete

Parameters
sd_desc- Instance of the SD card
data- Where data will be read
address- Address in memory from where data will be read
len- Length in bytes of data to be read
Returns
0 in case of success, -1 otherwise.
Here is the caller graph for this function:

◆ sd_remove()

int32_t sd_remove ( struct sd_desc desc)

Remove the initialize instance of SD card.

Parameters
desc- Instance of the SD card
Returns
0 in case of success, -1 otherwise.

◆ sd_write()

int32_t sd_write ( struct sd_desc sd_desc,
uint8_t *  data,
uint64_t  address,
uint64_t  len 
)

Write data of size len to the specified address This operation returns only when the write is complete

Parameters
sd_desc- Instance of the SD card
data- Data to write
address- Address in memory where data will be written
len- Length of data in bytes
Returns
0 in case of success, -1 otherwise.