no-OS
sd.h
Go to the documentation of this file.
1 /***************************************************************************/
51 #ifndef __SD_H__
52 #define __SD_H__
53 
54 /******************************************************************************/
55 /***************************** Include Files **********************************/
56 /******************************************************************************/
57 
58 #include <string.h>
59 #include <stdbool.h>
60 #include <stdlib.h>
61 #include "no_os_spi.h"
62 
63 /******************************************************************************/
64 /********************** Macros and Constants Definitions **********************/
65 /******************************************************************************/
66 
67 #define DATA_BLOCK_LEN (512u)
68 #define MAX_RESPONSE_LEN (18u)
69 
70 #ifdef SD_DEBUG
71 #include <stdio.h>
72 #define DEBUG_MSG(X) printf((X))
73 #else
74 #define DEBUG_MSG(X)
75 #endif //SD_DEBUG
76 
77 /******************************************************************************/
78 /*************************** Types Declarations *******************************/
79 /******************************************************************************/
80 
85 struct sd_init_param {
88 };
89 
94 struct sd_desc {
98  uint64_t memory_size;
100  uint8_t high_capacity;
102  uint8_t buff[18];
103 };
104 
109 struct cmd_desc {
111  uint8_t cmd;
113  uint32_t arg;
117  uint32_t response_len;
118 };
119 
120 /******************************************************************************/
121 /************************ Functions Declarations ******************************/
122 /******************************************************************************/
123 
124 int32_t sd_init(struct sd_desc **sd_desc,
125  const struct sd_init_param *init_param);
126 int32_t sd_remove(struct sd_desc *desc);
127 int32_t sd_read(struct sd_desc *desc,
128  uint8_t *data,
129  uint64_t address,
130  uint64_t len);
131 int32_t sd_write(struct sd_desc *desc,
132  uint8_t *data,
133  uint64_t address,
134  uint64_t len);
135 
136 #endif /* __SD_H__ */
137 
BIT_CCS
#define BIT_CCS
Definition: sd.c:54
sd_init_param::spi_desc
struct no_os_spi_desc * spi_desc
Definition: sd.h:87
DEBUG_MSG
#define DEBUG_MSG(X)
Definition: sd.h:74
no_os_spi_write_and_read
int32_t no_os_spi_write_and_read(struct no_os_spi_desc *desc, uint8_t *data, uint16_t bytes_number)
Write and read data to/from SPI.
Definition: no_os_spi.c:83
BIT_APPLICATION_CMD
#define BIT_APPLICATION_CMD
Definition: sd.c:55
CSD_LEN
#define CSD_LEN
Definition: sd.c:71
no_os_spi.h
Header file of SPI Interface.
MASK_ADDR_IN_BLOCK
#define MASK_ADDR_IN_BLOCK
Definition: sd.c:80
cmd_desc::cmd
uint8_t cmd
Definition: sd.h:111
sd_desc::spi_desc
struct no_os_spi_desc * spi_desc
Definition: sd.h:96
no_os_delay.h
Header file of Delay functions.
sd_write
int32_t sd_write(struct sd_desc *desc, uint8_t *data, uint64_t address, uint64_t len)
Definition: sd.c:468
cmd_desc::response
uint8_t response[MAX_RESPONSE_LEN]
Definition: sd.h:115
START_1_BLOCK_TOKEN
#define START_1_BLOCK_TOKEN
Definition: sd.c:83
MASK_RESPONSE_TOKEN
#define MASK_RESPONSE_TOKEN
Definition: sd.c:86
STOP_TRANSMISSION_TOKEN
#define STOP_TRANSMISSION_TOKEN
Definition: sd.c:85
no_os_mdelay
void no_os_mdelay(uint32_t msecs)
Wait until msecs milliseconds passed.
Definition: aducm3029_delay.c:132
no_os_error.h
Error codes definition.
START_N_BLOCK_TOKEN
#define START_N_BLOCK_TOKEN
Definition: sd.c:84
sd_desc::buff
uint8_t buff[18]
Definition: sd.h:102
MASK_BLOCK_NUMBER
#define MASK_BLOCK_NUMBER
Definition: sd.c:81
R1_IDLE_STATE
#define R1_IDLE_STATE
Definition: sd.c:64
WAIT_RESP_TIMEOUT
#define WAIT_RESP_TIMEOUT
Definition: sd.c:61
cmd_desc
Contains the elements needed to build a command.
Definition: sd.h:109
ACMD
#define ACMD(x)
Definition: sd.c:58
sd_desc::memory_size
uint64_t memory_size
Definition: sd.h:98
DATA_BLOCK_BITS
#define DATA_BLOCK_BITS
Definition: sd.c:79
sd_init
int32_t sd_init(struct sd_desc **sd_desc, const struct sd_init_param *param)
Definition: sd.c:528
sd_remove
int32_t sd_remove(struct sd_desc *desc)
Definition: sd.c:639
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:143
CMD
#define CMD(x)
Definition: sd.c:57
sd_read
int32_t sd_read(struct sd_desc *desc, uint8_t *data, uint64_t address, uint64_t len)
Definition: sd.c:417
CMD8_ARG
#define CMD8_ARG
Definition: sd.c:76
sd_desc::high_capacity
uint8_t high_capacity
Definition: sd.h:100
R1_LEN
#define R1_LEN
Definition: sd.c:67
STUFF_ARG
#define STUFF_ARG
Definition: sd.c:75
ACMD41_ARG
#define ACMD41_ARG
Definition: sd.c:77
sd_read
int32_t sd_read(struct sd_desc *sd_desc, uint8_t *data, uint64_t address, uint64_t len)
Definition: sd.c:417
sd_desc
Structure that stores data about the SD card configurations.
Definition: sd.h:94
sd.h
Header file for SD card interface over SPI.
sd_init_param
Configuration structure sent in the function sd_init.
Definition: sd.h:85
NULL
#define NULL
Definition: wrapper.h:64
R3_LEN
#define R3_LEN
Definition: sd.c:69
cmd_desc::response_len
uint32_t response_len
Definition: sd.h:117
CMD0_RETRY_NUMBER
#define CMD0_RETRY_NUMBER
Definition: sd.c:60
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:96
sd_remove
int32_t sd_remove(struct sd_desc *desc)
Definition: sd.c:639
MAX_RESPONSE_LEN
#define MAX_RESPONSE_LEN
Definition: sd.h:68
R1_READY_STATE
#define R1_READY_STATE
Definition: sd.c:63
cmd_desc::arg
uint32_t arg
Definition: sd.h:113
CMD_LEN
#define CMD_LEN
Definition: sd.c:73
sd_init
int32_t sd_init(struct sd_desc **sd_desc, const struct sd_init_param *init_param)
Definition: sd.c:528
sd_write
int32_t sd_write(struct sd_desc *sd_desc, uint8_t *data, uint64_t address, uint64_t len)
Definition: sd.c:468
CRC_LEN
#define CRC_LEN
Definition: sd.c:72
DATA_BLOCK_LEN
#define DATA_BLOCK_LEN
Definition: sd.h:67
MASK_ERROR_TOKEN
#define MASK_ERROR_TOKEN
Definition: sd.c:87