Contiki 2.5
flash-microSD.h
Go to the documentation of this file.
1 /* Copyright (c) 2010, Ulf Kulau
2  *
3  * Permission is hereby granted, free of charge, to any person
4  * obtaining a copy of this software and associated documentation
5  * files (the "Software"), to deal in the Software without
6  * restriction, including without limitation the rights to use,
7  * copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following
10  * conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 /**
26  * \addtogroup Device Interfaces
27  * @{
28  *
29  * \defgroup microSD_interface MicroSD Card Interface
30  *
31  * \note This sd-card interface is based on the work of Ulrich Radig
32  * "Connect AVR to MMC/SD" and was a little bit modified plus
33  * adapted to the mspi-drv
34  *
35  * <p> Huge memory space is always nice to have, because you don't have to
36  * decide which data has to be stored, just store everything! Furthermore you
37  * can buffer your data, whenever wireless connection breaks down.
38  * An easy and modular way is a SD card. For smaller applications (like
39  * sensor nodes), the tiny version "microSD" would be the best choice. Both, the
40  * "big" SD-Cards and the microSD-Cards can be interfaced by SPI and use the same
41  * Instruction set, so this interface can be used for both SD-Card types.</p>
42  *
43  * @{
44  *
45  */
46 
47 /**
48  * \file
49  * MicroSD Card interface definitions
50  * \author
51  * Original Source Code:
52  * Ulrich Radig
53  * Modified by:
54  * Ulf Kulau <kulau@ibr.cs.tu-bs.de>
55  */
56 
57 #ifndef FLASH_MICROSD_H_
58 #define FLASH_MICROSD_H_
59 
60 #include "../drv/mspi-drv.h"
61 #include <stdio.h>
62 #include <util/delay.h>
63 
64 /*!
65  * SPI device order. The chip select number where the
66  * microSD-Card is connected to the BCD-decimal decoder
67  */
68 #define MICRO_SD_CS 5
69 
70 #define MICRO_SD_PWR_PORT PORTA
71 #define MICRO_SD_PWR_PORT_DDR DDRA
72 #define MICRO_SD_PWR_PIN PORTA4
73 
74 /**
75  * \brief Powers on and initialize the microSD / SD-Card
76  *
77  * \return <ul>
78  * <li> 0 : SD-Card was initialized without an error
79  * <li> 1 : CMD0 failure!
80  * <li> 2 : CMD1 failure!
81  * </ul>
82  */
83 uint8_t microSD_init(void);
84 
85 uint8_t microSD_deinit(void);
86 
87 /**
88  * \brief This function will read one block (512Byte) of the SD-Card.
89  *
90  * \param addr Block address
91  * \param *buffer Pointer to a block buffer
92  *
93  * \return <ul>
94  * <li> 0 : SD-Card block read was successful
95  * <li> 1 : CMD17 failure!
96  * </ul>
97  */
98 uint8_t microSD_read_block(uint32_t addr, uint8_t *buffer);
99 
100 /**
101  * \brief This function will write one block (512Byte) of the SD-Card.
102  *
103  * \param addr Block address
104  * \param *buffer Pointer to a block buffer
105  *
106  * \return <ul>
107  * <li> 0 : SD-Card block write was successful
108  * <li> 1 : CMD24 failure!
109  * </ul>
110  */
111 uint8_t microSD_write_block(uint32_t addr, uint8_t *buffer);
112 
113 /**
114  * \brief This function sends a command via SPI to the SD-Card. An SPI
115  * command consists off 6 bytes
116  *
117  * \param *cmd Pointer to the command array
118  *
119  * \return <ul>
120  * <li> 1 : Acknowledge
121  * <li> other failure code
122  * </ul>
123  */
124 uint8_t microSD_write_cmd(uint8_t *cmd);
125 
126 
127 
128 
129 
130 #endif /* FLASH_MICROSD_H_ */