Move kfile interface to the io/ directory.
[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  * \author Francesco Sacchi <batt@develer.com>
38  *
39  * $WIZ$ module_name = "sd"
40  * $WIZ$ module_depends = "kfile", "timer"
41  * $WIZ$ module_hw = "bertos/hw/hw_sd.h"
42  */
43
44
45 #ifndef DRV_SD_H
46 #define DRV_SD_H
47
48 #include "cfg/cfg_fat.h"
49
50 #include <io/kfile.h>
51
52 #include <fs/fatfs/diskio.h>
53
54 bool sd_test(void);
55
56 /**
57  * Initializes the SD driver.
58  *
59  * \param _fd A pointer to a kfile where the SD will read/write to.
60  * \return true if initialization succeds, false otherwise.
61  */
62 bool sd_init(KFile *_fd);
63
64 #if CONFIG_FAT_DRIVES == 1
65
66         /**
67          * Same as sd_disk_status.
68          *
69          * Card initialization must be done with sd_init.
70          */
71         #define sd_disk_initialize disk_initialize
72
73         /**
74          * Return the status of the disk.
75          *
76          * \param drv The number of the drive to initialize. Currently only drive 0 is allowed.
77          * \return RES_OK if the sd card was correctly initialized by a previous call to sd_init(), STA_NOINIT otherwise.
78          */
79         #define sd_disk_status     disk_status
80         /**
81          * Read \a count sectors from SD card.
82          *
83          * \param drv The drive number to read from. Only 0 is supported.
84          * \param buf A buffer to store read data. You can get sector size using sd_disk_ioctl.
85          * \param sector Start sector number.
86          * \param count The number of sectors to read.
87          * \return RES_OK if the function succeded, RES_ERROR if any error occurred, RES_NOTRDY if the disk is not initialized.
88          *
89          * \sa diskio.h
90          */
91         #define sd_disk_read       disk_read
92
93         #if     CONFIG_FAT_FS_READONLY == 0
94
95                 /**
96                  * Write \a count sectors to SD card.
97                  *
98                  * \param drv The drive number to read from. Only 0 is supported.
99                  * \param buf The data to be written.
100                  * \param sector Start sector number.
101                  * \param count The number of sectors to write.
102                  * \return RES_OK if the function succeded, RES_ERROR if any error occurred, RES_NOTRDY if the disk is not initialized.
103                  *
104                  * \sa diskio.h
105                  */
106                 #define sd_disk_write      disk_write
107         #endif
108
109         /**
110          * Interface to send device independant commands to the device.
111          *
112          * \sa diskio.h and related documentation for further explanations.
113          */
114         #define sd_disk_ioctl      disk_ioctl
115
116 #endif /* CONFIG_FAT_DRIVES == 1 */
117
118 #endif /* DRV_SD_H */