-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmmc_if.h
163 lines (139 loc) · 3.82 KB
/
mmc_if.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* ***********************************************************************
**
** Copyright (C) 2006 Jesper Hansen <[email protected]>
**
**
** Interface functions for MMC/SD cards
**
** File mmc_if.h
**
** Hacked by Michael Spiceland at http://tinkerish.com to support
** writing as well.
**
*************************************************************************
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software Foundation,
** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
*************************************************************************/
/** \file mmc_if.h
Simple MMC/SD-card functionality
*/
#ifndef __MMC_IF_H__
#define __MMC_IF_H__
/** @name MMC/SD Card I/O ports
*/
//@{
#define SPI_PORT PORTB
#define SPI_DDR DDRB
#define SPI_PIN PINB
#define MMC_CS_PORT PORTB
#define MMC_CS_DIR DDRB
//@}
/** @name MMC/SD Card I/O lines in MMC mode
*/
//@{
#define SD_SCK 1 //!< Clock
#define SD_CMD 2
#define SD_DAT0 3
#define SD_DAT3 4
#define SD_DAT1 5
#define SD_DAT2 6
#define SD_CARD 7
//@}
/** @name MMC/SD Card I/O lines in SPI mode
*/
//@{
#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega48__) || defined(__AVR_ATmega88__) || \
defined(__AVR_ATmega16__) || defined(__AVR_ATmega32__) || defined(__AVR_ATmega162__) || defined(__AVR_ATmega168__)
#define MMC_SCK 5
#define MMC_MOSI 3
#define MMC_MISO 4
#define MMC_CS 2
#elif defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__)
#define MMC_SCK 1
#define MMC_MOSI 2
#define MMC_MISO 3
#define MMC_CS 0
#else
//
// unsupported type
//
#error "Processor type not supported in mmc_if.h !"
#endif
//@}
/** Helper structure.
This simplify conversion between bytes and words.
*/
struct u16bytes
{
uint8_t low; //!< byte member
uint8_t high; //!< byte member
};
/** Helper union.
This simplify conversion between bytes and words.
*/
union u16convert
{
uint16_t value; //!< for word access
struct u16bytes bytes; //!< for byte access
};
/** Helper structure.
This simplify conversion between bytes and longs.
*/
struct u32bytes
{
uint8_t byte1; //!< byte member
uint8_t byte2; //!< byte member
uint8_t byte3; //!< byte member
uint8_t byte4; //!< byte member
};
/** Helper structure.
This simplify conversion between words and longs.
*/
struct u32words
{
uint16_t low; //!< word member
uint16_t high; //!< word member
};
/** Helper union.
This simplify conversion between bytes, words and longs.
*/
union u32convert
{
uint32_t value; //!< for long access
struct u32words words; //!< for word access
struct u32bytes bytes; //!< for byte access
};
/** Write MMC/SD sector.
Write a single 512 byte sector from the MMC/SD card
\param lba Logical sectornumber to write
\param buffer Pointer to buffer to write from
\return 0 on success, -1 on error
*/
int mmc_writesector(uint32_t lba, uint8_t *buffer);
/** Read MMC/SD sector.
Read a single 512 byte sector from the MMC/SD card
\param lba Logical sectornumber to read
\param buffer Pointer to buffer for received data
\return 0 on success, -1 on error
*/
int mmc_readsector(uint32_t lba, uint8_t *buffer);
/** Init MMC/SD card.
Initialize I/O ports for the MMC/SD interface and
send init commands to the MMC/SD card
\return 0 on success, other values on error
*/
uint8_t mmc_init(void);
#endif