8be9c501749cb1f243e284ce3a586acf5c8827d2
[bertos.git] / bertos / drv / sd.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos 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 of the License, or
9  * (at your option) any later version.
10  *
11  * This program 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 this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
30  * -->
31  *
32  * \brief Function library for secure digital memory.
33  *
34  * Right now, the interface for these function is the one defined in diskio.h from
35  * the FatFS module.
36  *
37  * \version $Id$
38  * \author Francesco Sacchi <batt@develer.com>
39  */
40
41
42 #ifndef DRV_SD_H
43 #define DRV_SD_H
44
45 #include <fs/fatfs/diskio.h>
46 #include <kern/kfile.h>
47 #include <cfg/cfg_fat.h>
48
49 bool sd_test(void);
50
51 /**
52  * Initializes the SD driver.
53  *
54  * \param _fd A pointer to a kfile where the SD will read/write to.
55  * \return true if initialization succeds, false otherwise.
56  */
57 bool sd_init(KFile *_fd);
58
59 #if CONFIG_FAT_DRIVES == 1
60
61         /**
62          * Same as sd_disk_status.
63          *
64          * Card initialization must be done with sd_init.
65          */
66         #define sd_disk_initialize disk_initialize
67
68         /**
69          * Return the status of the disk.
70          *
71          * \param drv The number of the drive to initialize. Currently only drive 0 is allowed.
72          * \return RES_OK if the sd card was correctly initialized by a previous call to sd_init(), STA_NOINIT otherwise.
73          */
74         #define sd_disk_status     disk_status
75         /**
76          * Read \a count sectors from SD card.
77          *
78          * \param drv The drive number to read from. Only 0 is supported.
79          * \param buf A buffer to store read data. You can get sector size using sd_disk_ioctl.
80          * \param sector Start sector number.
81          * \param count The number of sectors to read.
82          * \return RES_OK if the function succeded, RES_ERROR if any error occurred, RES_NOTRDY if the disk is not initialized.
83          *
84          * \sa diskio.h
85          */
86         #define sd_disk_read       disk_read
87
88         #if     CONFIG_FAT_FS_READONLY == 0
89
90                 /**
91                  * Write \a count sectors to SD card.
92                  *
93                  * \param drv The drive number to read from. Only 0 is supported.
94                  * \param buf The data to be written.
95                  * \param sector Start sector number.
96                  * \param count The number of sectors to write.
97                  * \return RES_OK if the function succeded, RES_ERROR if any error occurred, RES_NOTRDY if the disk is not initialized.
98                  *
99                  * \sa diskio.h
100                  */
101                 #define sd_disk_write      disk_write
102         #endif
103
104         /**
105          * Interface to send device independant commands to the device.
106          *
107          * \sa diskio.h and related documentation for further explanations.
108          */
109         #define sd_disk_ioctl      disk_ioctl
110
111 #endif /* CONFIG_FAT_DRIVES == 1 */
112
113 #endif /* DRV_SD_H */