Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
sdcard_spi.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Bart Slinger <bartslinger@gmail.com>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
27 #ifndef SDCARD_H_
28 #define SDCARD_H_
29 
30 #include "std.h"
31 #include "mcu_periph/spi.h"
32 
36 typedef void (*SDCardCallback)(void);
37 
38 #define SD_BLOCK_SIZE 512
39 
45 };
46 
47 enum SDCardType {
53 };
54 
88 };
89 
107 };
108 
109 struct SDCard {
110  struct spi_periph *spi_p;
112  volatile enum SDCardStatus status;
120 };
121 
122 extern struct SDCard sdcard1;
123 
124 /* Public functions */
125 extern void sdcard_spi_init(struct SDCard *sdcard, struct spi_periph *spi_p, const uint8_t slave_idx);
126 extern void sdcard_spi_periodic(struct SDCard *sdcard);
127 extern void sdcard_spi_write_block(struct SDCard *sdcard, uint32_t addr);
128 extern void sdcard_spi_read_block(struct SDCard *sdcard, uint32_t addr, SDCardCallback callback);
129 extern void sdcard_spi_multiwrite_start(struct SDCard *sdcard, uint32_t addr);
130 extern void sdcard_spi_multiwrite_next(struct SDCard *sdcard, SDCardCallback callback);
131 extern void sdcard_spi_multiwrite_stop(struct SDCard *sdcard);
132 
133 #endif // SDCARD_H_
134 
Reading R1 response to CMD0 byte by byte.
Definition: sdcard_spi.h:63
Reading the 32-bit parameter after receiving 0x00 from CMD58.
Definition: sdcard_spi.h:71
Busy sending CMD24.
Definition: sdcard_spi.h:74
Initialization sequence succesful.
Definition: sdcard_spi.h:58
enum SDCardType card_type
Type of SDCard.
Definition: sdcard_spi.h:117
void sdcard_spi_init(struct SDCard *sdcard, struct spi_periph *spi_p, const uint8_t slave_idx)
Configure initial values for SDCard.
Definition: sdcard_spi.c:74
uint8_t input_buf[SD_BLOCK_SIZE+10]
The input buffer for the SPI transaction.
Definition: sdcard_spi.h:113
uint8_t response_counter
Response counter used at various locations.
Definition: sdcard_spi.h:115
Reading R1 response to CMD24 byte by byte.
Definition: sdcard_spi.h:75
About to send dummy clock cycles to initialize spi mode.
Definition: sdcard_spi.h:60
void sdcard_spi_multiwrite_stop(struct SDCard *sdcard)
Stop with multiwrite procedure.
Definition: sdcard_spi.c:666
struct spi_transaction spi_t
The SPI transaction used for the writing and reading of registers.
Definition: sdcard_spi.h:111
void sdcard_spi_multiwrite_next(struct SDCard *sdcard, SDCardCallback callback)
Write a(nother) data block (512 bytes) to the SDCard.
Definition: sdcard_spi.c:638
enum SDCardStatus status
The status of the SD card.
Definition: sdcard_spi.h:112
Reading R3 response to CMD58 byte by byte.
Definition: sdcard_spi.h:70
uint8_t output_buf[SD_BLOCK_SIZE+10]
The output buffer for the SPI transaction.
Definition: sdcard_spi.h:114
Reading R7 response to CMD8 byte by byte.
Definition: sdcard_spi.h:65
SPI transaction structure.
Definition: spi.h:148
void sdcard_spi_read_block(struct SDCard *sdcard, uint32_t addr, SDCardCallback callback)
Read a single block (512 bytes) from the SDCard at a given address.
Definition: sdcard_spi.c:587
Reading R1 response to CMD16 byte by byte.
Definition: sdcard_spi.h:73
SDCardCallback external_callback
Callback to call when external operation finishes.
Definition: sdcard_spi.h:119
Busy reading data block.
Definition: sdcard_spi.h:81
void sdcard_spi_write_block(struct SDCard *sdcard, uint32_t addr)
Write a single block (512 bytes) to the SDCard at a given address.
Definition: sdcard_spi.c:560
Reading the 32-bit parameter after receiving 0x01.
Definition: sdcard_spi.h:66
Architecture independent SPI (Serial Peripheral Interface) API.
void sdcard_spi_multiwrite_start(struct SDCard *sdcard, uint32_t addr)
Start writing multiple blocks of 512 bytes to the SDCard.
Definition: sdcard_spi.c:616
void sdcard_spi_periodic(struct SDCard *sdcard)
Periodic function of the SDCard.
Definition: sdcard_spi.c:99
SPI peripheral structure.
Definition: spi.h:174
#define SD_BLOCK_SIZE
Definition: sdcard_spi.h:38
void(* SDCardCallback)(void)
SDCard Callback function.
Definition: sdcard_spi.h:36
Busy sending CMD58.
Definition: sdcard_spi.h:69
Busy sending the stop token.
Definition: sdcard_spi.h:87
struct spi_periph * spi_p
The SPI peripheral for the connection.
Definition: sdcard_spi.h:110
Busy with the SPI transfer in multiwrite.
Definition: sdcard_spi.h:85
uint32_t timeout_counter
Timeout counter used for initialization checks with ACMD41.
Definition: sdcard_spi.h:116
SDCardStatus
Definition: sdcard_spi.h:55
unsigned long uint32_t
Definition: types.h:18
struct SDCard sdcard1
This is the definition of the SD card.
Definition: sdcard_spi.c:56
Busy sending CMD16.
Definition: sdcard_spi.h:72
SDCardType
Definition: sdcard_spi.h:47
An error has occured, sending debug message.
Definition: sdcard_spi.h:57
Busy sending data block.
Definition: sdcard_spi.h:77
Busy sending CMD0.
Definition: sdcard_spi.h:62
Busy sending CMD25 (multiwrite start command)
Definition: sdcard_spi.h:82
Reading R1 response to CMD17 byte by byte.
Definition: sdcard_spi.h:79
enum SDCardErrorStatus error_status
Contains information on where the error has occured.
Definition: sdcard_spi.h:118
unsigned char uint8_t
Definition: types.h:14
Busy sending ACMD41.
Definition: sdcard_spi.h:67
SdResponseType
Definition: sdcard_spi.h:40
Reading R1 response to CMD25 byte by byte.
Definition: sdcard_spi.h:83
SDCard is not initialized.
Definition: sdcard_spi.h:56
SDCard is busy with internal process.
Definition: sdcard_spi.h:59
Busy sending CMD17 (block read request)
Definition: sdcard_spi.h:78
Busy flag after sending data block in multiwrite.
Definition: sdcard_spi.h:86
Busy sending CMD8.
Definition: sdcard_spi.h:64
CMD25 complete, ready to sent blocks.
Definition: sdcard_spi.h:84
Busy sending dummy clock cycles.
Definition: sdcard_spi.h:61
SDCardErrorStatus
Definition: sdcard_spi.h:90
Reading a byte each period until there is a data token or error.
Definition: sdcard_spi.h:80
Start data block transfer.
Definition: sdcard_spi.h:76
Reading R1 response to ACMD41 byte by byte.
Definition: sdcard_spi.h:68