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