no-OS
sd.h
Go to the documentation of this file.
1 /***************************************************************************/
45 #ifndef __SD_H__
46 #define __SD_H__
47 
48 /******************************************************************************/
49 /***************************** Include Files **********************************/
50 /******************************************************************************/
51 
52 #include <string.h>
53 #include <stdbool.h>
54 #include <stdlib.h>
55 #include "no_os_spi.h"
56 
57 /******************************************************************************/
58 /********************** Macros and Constants Definitions **********************/
59 /******************************************************************************/
60 
61 #define DATA_BLOCK_LEN (512u)
62 #define MAX_RESPONSE_LEN (18u)
63 
64 #ifdef SD_DEBUG
65 #include <stdio.h>
66 #define DEBUG_MSG(X) printf((X))
67 #else
68 #define DEBUG_MSG(X)
69 #endif //SD_DEBUG
70 
71 /******************************************************************************/
72 /*************************** Types Declarations *******************************/
73 /******************************************************************************/
74 
79 struct sd_init_param {
82 };
83 
88 struct sd_desc {
92  uint64_t memory_size;
94  uint8_t high_capacity;
96  uint8_t buff[18];
97 };
98 
103 struct cmd_desc {
105  uint8_t cmd;
107  uint32_t arg;
111  uint32_t response_len;
112 };
113 
114 /******************************************************************************/
115 /************************ Functions Declarations ******************************/
116 /******************************************************************************/
117 
118 int32_t sd_init(struct sd_desc **sd_desc,
119  const struct sd_init_param *init_param);
120 int32_t sd_remove(struct sd_desc *desc);
121 int32_t sd_read(struct sd_desc *desc,
122  uint8_t *data,
123  uint64_t address,
124  uint64_t len);
125 int32_t sd_write(struct sd_desc *desc,
126  uint8_t *data,
127  uint64_t address,
128  uint64_t len);
129 
130 #endif /* __SD_H__ */
131 
no_os_alloc.h
BIT_CCS
#define BIT_CCS
Definition: sd.c:49
sd_init_param::spi_desc
struct no_os_spi_desc * spi_desc
Definition: sd.h:81
DEBUG_MSG
#define DEBUG_MSG(X)
Definition: sd.h:68
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:159
BIT_APPLICATION_CMD
#define BIT_APPLICATION_CMD
Definition: sd.c:50
CSD_LEN
#define CSD_LEN
Definition: sd.c:66
no_os_spi.h
Header file of SPI Interface.
MASK_ADDR_IN_BLOCK
#define MASK_ADDR_IN_BLOCK
Definition: sd.c:75
cmd_desc::cmd
uint8_t cmd
Definition: sd.h:105
sd_desc::spi_desc
struct no_os_spi_desc * spi_desc
Definition: sd.h:90
no_os_delay.h
Header file of Delay functions.
no_os_calloc
void * no_os_calloc(size_t nitems, size_t size)
Allocate memory and return a pointer to it, set memory to 0.
Definition: chibios_alloc.c:54
sd_write
int32_t sd_write(struct sd_desc *desc, uint8_t *data, uint64_t address, uint64_t len)
Definition: sd.c:463
cmd_desc::response
uint8_t response[MAX_RESPONSE_LEN]
Definition: sd.h:109
START_1_BLOCK_TOKEN
#define START_1_BLOCK_TOKEN
Definition: sd.c:78
MASK_RESPONSE_TOKEN
#define MASK_RESPONSE_TOKEN
Definition: sd.c:81
STOP_TRANSMISSION_TOKEN
#define STOP_TRANSMISSION_TOKEN
Definition: sd.c:80
no_os_mdelay
void no_os_mdelay(uint32_t msecs)
Wait until msecs milliseconds passed.
Definition: aducm3029_delay.c:126
no_os_error.h
Error codes definition.
START_N_BLOCK_TOKEN
#define START_N_BLOCK_TOKEN
Definition: sd.c:79
sd_desc::buff
uint8_t buff[18]
Definition: sd.h:96
MASK_BLOCK_NUMBER
#define MASK_BLOCK_NUMBER
Definition: sd.c:76
R1_IDLE_STATE
#define R1_IDLE_STATE
Definition: sd.c:59
WAIT_RESP_TIMEOUT
#define WAIT_RESP_TIMEOUT
Definition: sd.c:56
cmd_desc
Contains the elements needed to build a command.
Definition: sd.h:103
ACMD
#define ACMD(x)
Definition: sd.c:53
sd_desc::memory_size
uint64_t memory_size
Definition: sd.h:92
DATA_BLOCK_BITS
#define DATA_BLOCK_BITS
Definition: sd.c:74
sd_init
int32_t sd_init(struct sd_desc **sd_desc, const struct sd_init_param *param)
Definition: sd.c:523
sd_remove
int32_t sd_remove(struct sd_desc *desc)
Definition: sd.c:634
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:192
CMD
#define CMD(x)
Definition: sd.c:52
sd_read
int32_t sd_read(struct sd_desc *desc, uint8_t *data, uint64_t address, uint64_t len)
Definition: sd.c:412
CMD8_ARG
#define CMD8_ARG
Definition: sd.c:71
sd_desc::high_capacity
uint8_t high_capacity
Definition: sd.h:94
R1_LEN
#define R1_LEN
Definition: sd.c:62
STUFF_ARG
#define STUFF_ARG
Definition: sd.c:70
ACMD41_ARG
#define ACMD41_ARG
Definition: sd.c:72
sd_read
int32_t sd_read(struct sd_desc *sd_desc, uint8_t *data, uint64_t address, uint64_t len)
Definition: sd.c:412
sd_desc
Structure that stores data about the SD card configurations.
Definition: sd.h:88
no_os_free
void no_os_free(void *ptr)
Deallocate memory previously allocated by a call to no_os_calloc or no_os_malloc.
Definition: chibios_alloc.c:69
sd.h
Header file for SD card interface over SPI.
sd_init_param
Configuration structure sent in the function sd_init.
Definition: sd.h:79
NULL
#define NULL
Definition: wrapper.h:64
R3_LEN
#define R3_LEN
Definition: sd.c:64
cmd_desc::response_len
uint32_t response_len
Definition: sd.h:111
CMD0_RETRY_NUMBER
#define CMD0_RETRY_NUMBER
Definition: sd.c:55
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:113
sd_remove
int32_t sd_remove(struct sd_desc *desc)
Definition: sd.c:634
MAX_RESPONSE_LEN
#define MAX_RESPONSE_LEN
Definition: sd.h:62
R1_READY_STATE
#define R1_READY_STATE
Definition: sd.c:58
cmd_desc::arg
uint32_t arg
Definition: sd.h:107
CMD_LEN
#define CMD_LEN
Definition: sd.c:68
sd_init
int32_t sd_init(struct sd_desc **sd_desc, const struct sd_init_param *init_param)
Definition: sd.c:523
sd_write
int32_t sd_write(struct sd_desc *sd_desc, uint8_t *data, uint64_t address, uint64_t len)
Definition: sd.c:463
CRC_LEN
#define CRC_LEN
Definition: sd.c:67
DATA_BLOCK_LEN
#define DATA_BLOCK_LEN
Definition: sd.h:61
MASK_ERROR_TOKEN
#define MASK_ERROR_TOKEN
Definition: sd.c:82