Paparazzi UAS  v6.3_unstable
Paparazzi is a free software Unmanned Aircraft System.
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Bart Slinger <>
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
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  */
27 #ifndef SDCARD_H_
28 #define SDCARD_H_
30 #include "std.h"
31 #include "mcu_periph/spi.h"
36 typedef void (*SDCardCallback)(void);
38 #define SD_BLOCK_SIZE 512
45 };
47 enum SDCardType {
53 };
88 };
107 };
109 struct SDCard {
110  struct spi_periph *spi_p;
111  struct spi_transaction spi_t;
112  volatile enum SDCardStatus status;
117  enum SDCardType card_type;
120 };
122 extern struct SDCard sdcard1;
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);
133 #endif // SDCARD_H_
SPI peripheral structure.
Definition: spi.h:174
SPI transaction structure.
Definition: spi.h:148
Definition: sdcard_spi.h:55
@ SDCard_ReadingCMD16Resp
Reading R1 response to CMD16 byte by byte.
Definition: sdcard_spi.h:73
@ SDCard_SendingCMD16
Busy sending CMD16.
Definition: sdcard_spi.h:72
@ SDCard_Error
An error has occured, sending debug message.
Definition: sdcard_spi.h:57
@ SDCard_ReadingCMD58Parameter
Reading the 32-bit parameter after receiving 0x00 from CMD58.
Definition: sdcard_spi.h:71
@ SDCard_ReadingCMD24Resp
Reading R1 response to CMD24 byte by byte.
Definition: sdcard_spi.h:75
@ SDCard_WaitingForDataToken
Reading a byte each period until there is a data token or error.
Definition: sdcard_spi.h:80
@ SDCard_UnInit
SDCard is not initialized.
Definition: sdcard_spi.h:56
@ SDCard_BeforeDummyClock
About to send dummy clock cycles to initialize spi mode.
Definition: sdcard_spi.h:60
@ SDCard_ReadingCMD58Resp
Reading R3 response to CMD58 byte by byte.
Definition: sdcard_spi.h:70
@ SDCard_ReadingDataBlock
Busy reading data block.
Definition: sdcard_spi.h:81
@ SDCard_SendingDummyClock
Busy sending dummy clock cycles.
Definition: sdcard_spi.h:61
@ SDCard_MultiWriteIdle
CMD25 complete, ready to sent blocks.
Definition: sdcard_spi.h:84
@ SDCard_SendingCMD17
Busy sending CMD17 (block read request)
Definition: sdcard_spi.h:78
@ SDCard_ReadingACMD41v2Resp
Reading R1 response to ACMD41 byte by byte.
Definition: sdcard_spi.h:68
@ SDCard_SendingCMD24
Busy sending CMD24.
Definition: sdcard_spi.h:74
@ SDCard_ReadingCMD8Resp
Reading R7 response to CMD8 byte by byte.
Definition: sdcard_spi.h:65
@ SDCard_MultiWriteStopping
Busy sending the stop token.
Definition: sdcard_spi.h:87
@ SDCard_SendingCMD0
Busy sending CMD0.
Definition: sdcard_spi.h:62
@ SDCard_Idle
Initialization sequence succesful.
Definition: sdcard_spi.h:58
@ SDCard_MultiWriteBusy
Busy flag after sending data block in multiwrite.
Definition: sdcard_spi.h:86
@ SDCard_SendingDataBlock
Busy sending data block.
Definition: sdcard_spi.h:77
@ SDCard_ReadingCMD8Parameter
Reading the 32-bit parameter after receiving 0x01.
Definition: sdcard_spi.h:66
@ SDCard_SendingCMD8
Busy sending CMD8.
Definition: sdcard_spi.h:64
@ SDCard_SendingCMD58
Busy sending CMD58.
Definition: sdcard_spi.h:69
@ SDCard_MultiWriteWriting
Busy with the SPI transfer in multiwrite.
Definition: sdcard_spi.h:85
@ SDCard_SendingCMD25
Busy sending CMD25 (multiwrite start command)
Definition: sdcard_spi.h:82
@ SDCard_SendingACMD41v2
Busy sending ACMD41.
Definition: sdcard_spi.h:67
@ SDCard_Busy
SDCard is busy with internal process.
Definition: sdcard_spi.h:59
@ SDCard_ReadingCMD25Resp
Reading R1 response to CMD25 byte by byte.
Definition: sdcard_spi.h:83
@ SDCard_BeforeSendingDataBlock
Start data block transfer.
Definition: sdcard_spi.h:76
@ SDCard_ReadingCMD17Resp
Reading R1 response to CMD17 byte by byte.
Definition: sdcard_spi.h:79
@ SDCard_ReadingCMD0Resp
Reading R1 response to CMD0 byte by byte.
Definition: sdcard_spi.h:63
enum SDCardStatus status
The status of the SD card.
Definition: sdcard_spi.h:112
uint8_t response_counter
Response counter used at various locations.
Definition: sdcard_spi.h:115
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
struct spi_periph * spi_p
The SPI peripheral for the connection.
Definition: sdcard_spi.h:110
Definition: sdcard_spi.h:38
uint8_t output_buf[SD_BLOCK_SIZE+10]
The output buffer for the SPI transaction.
Definition: sdcard_spi.h:114
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
enum SDCardType card_type
Type of SDCard.
Definition: sdcard_spi.h:117
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
Definition: sdcard_spi.h:90
@ SDCardError_ACMD41NoResponse
Definition: sdcard_spi.h:96
@ SDCardError_WriteBlockNoResponse
Definition: sdcard_spi.h:100
@ SDCardError_InitializationNoResponse
Definition: sdcard_spi.h:92
@ SDCardError_ReadBlockTimeout
Definition: sdcard_spi.h:104
@ SDCardError_SetBlockSizeNoResponse
Definition: sdcard_spi.h:99
@ SDCardError_SpiDriverError
Definition: sdcard_spi.h:101
@ SDCardError_BlockWriteError
Definition: sdcard_spi.h:102
@ SDCardError_MultiWriteNoResponse
Definition: sdcard_spi.h:105
@ SDCardError_CardInfoNoResponse
Definition: sdcard_spi.h:93
@ SDCardError_ACMD41Timeout
Definition: sdcard_spi.h:95
@ SDCardError_CMD58NoResponse
Definition: sdcard_spi.h:97
@ SDCardError_InvalidCardInfo
Definition: sdcard_spi.h:94
@ SDCardError_CCSBitInvalid
Definition: sdcard_spi.h:98
@ SDCardError_None
Definition: sdcard_spi.h:91
@ SDCardError_ReadBlockNoResponse
Definition: sdcard_spi.h:103
@ SDCardError_MultiWriteError
Definition: sdcard_spi.h:106
uint8_t input_buf[SD_BLOCK_SIZE+10]
The input buffer for the SPI transaction.
Definition: sdcard_spi.h:113
enum SDCardErrorStatus error_status
Contains information on where the error has occured.
Definition: sdcard_spi.h:118
struct spi_transaction spi_t
The SPI transaction used for the writing and reading of registers.
Definition: sdcard_spi.h:111
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
void sdcard_spi_periodic(struct SDCard *sdcard)
Periodic function of the SDCard.
Definition: sdcard_spi.c:99
uint32_t timeout_counter
Timeout counter used for initialization checks with ACMD41.
Definition: sdcard_spi.h:116
Definition: sdcard_spi.h:40
@ SdResponseR1
Definition: sdcard_spi.h:42
@ SdResponseR7
Definition: sdcard_spi.h:44
@ SdResponseNone
Definition: sdcard_spi.h:41
@ SdResponseR3
Definition: sdcard_spi.h:43
struct SDCard sdcard1
This is the definition of the SD card.
Definition: sdcard_spi.c:56
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
void(* SDCardCallback)(void)
SDCard Callback function.
Definition: sdcard_spi.h:36
SDCardCallback external_callback
Callback to call when external operation finishes.
Definition: sdcard_spi.h:119
Definition: sdcard_spi.h:47
@ SDCardType_SdV2byte
Definition: sdcard_spi.h:51
@ SDCardType_SdV2block
Definition: sdcard_spi.h:52
@ SDCardType_SdV1
Definition: sdcard_spi.h:50
@ SDCardType_Unknown
Definition: sdcard_spi.h:48
@ SDCardType_MmcV3
Definition: sdcard_spi.h:49
void sdcard_spi_multiwrite_stop(struct SDCard *sdcard)
Stop with multiwrite procedure.
Definition: sdcard_spi.c:666
Architecture independent SPI (Serial Peripheral Interface) API.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98