Rev Author Line No. Line
1110 kaklik 1  
2 /*
3 * Copyright (c) 2006-2007 by Roland Riegel <feedback@roland-riegel.de>
4 *
5 * This file is free software; you can redistribute it and/or modify
6 * it under the terms of either the GNU General Public License version 2
7 * or the GNU Lesser General Public License version 2.1, both as
8 * published by the Free Software Foundation.
9 */
10  
11 #ifndef SD_RAW_H
12 #define SD_RAW_H
13  
14 #include <stdint.h>
15 #include "sd_raw_config.h"
16  
17 /**
18 * \addtogroup sd_raw
19 *
20 * @{
21 */
22 /**
23 * \file
24 * MMC/SD raw access header (license: GPLv2 or LGPLv2.1)
25 *
26 * \author Roland Riegel
27 */
28  
29 /**
30 * The card's layout is harddisk-like, which means it contains
31 * a master boot record with a partition table.
32 */
33 #define SD_RAW_FORMAT_HARDDISK 0
34 /**
35 * The card contains a single filesystem and no partition table.
36 */
37 #define SD_RAW_FORMAT_SUPERFLOPPY 1
38 /**
39 * The card's layout follows the Universal File Format.
40 */
41 #define SD_RAW_FORMAT_UNIVERSAL 2
42 /**
43 * The card's layout is unknown.
44 */
45 #define SD_RAW_FORMAT_UNKNOWN 3
46  
47 /**
48 * This struct is used by sd_raw_get_info() to return
49 * manufacturing and status information of the card.
50 */
51 struct sd_raw_info
52 {
53 /**
54 * A manufacturer code globally assigned by the SD card organization.
55 */
56 uint8_t manufacturer;
57 /**
58 * A string describing the card's OEM or content, globally assigned by the SD card organization.
59 */
60 uint8_t oem[3];
61 /**
62 * A product name.
63 */
64 uint8_t product[6];
65 /**
66 * The card's revision, coded in packed BCD.
67 *
68 * For example, the revision value \c 0x32 means "3.2".
69 */
70 uint8_t revision;
71 /**
72 * A serial number assigned by the manufacturer.
73 */
74 uint32_t serial;
75 /**
76 * The year of manufacturing.
77 *
78 * A value of zero means year 2000.
79 */
80 uint8_t manufacturing_year;
81 /**
82 * The month of manufacturing.
83 */
84 uint8_t manufacturing_month;
85 /**
86 * The card's total capacity in bytes.
87 */
88 uint32_t capacity;
89 /**
90 * Defines wether the card's content is original or copied.
91 *
92 * A value of \c 0 means original, \c 1 means copied.
93 */
94 uint8_t flag_copy;
95 /**
96 * Defines wether the card's content is write-protected.
97 *
98 * \note This is an internal flag and does not represent the
99 * state of the card's mechanical write-protect switch.
100 */
101 uint8_t flag_write_protect;
102 /**
103 * Defines wether the card's content is temporarily write-protected.
104 *
105 * \note This is an internal flag and does not represent the
106 * state of the card's mechanical write-protect switch.
107 */
108 uint8_t flag_write_protect_temp;
109 /**
110 * The card's data layout.
111 *
112 * See the \c SD_RAW_FORMAT_* constants for details.
113 *
114 * \note This value is not guaranteed to match reality.
115 */
116 uint8_t format;
117 };
118  
119 typedef uint8_t (*sd_raw_read_interval_handler_t)(uint8_t* buffer, uint32_t offset, void* p);
120 typedef uint16_t (*sd_raw_write_interval_handler_t)(uint8_t* buffer, uint32_t offset, void* p);
121  
122 uint8_t sd_raw_init();
123 uint8_t sd_raw_available();
124 uint8_t sd_raw_locked();
125  
126 uint8_t sd_raw_read(uint32_t offset, uint8_t* buffer, uint16_t length);
127 uint8_t sd_raw_read_interval(uint32_t offset, uint8_t* buffer, uint16_t interval, uint16_t length, sd_raw_read_interval_handler_t callback, void* p);
128 uint8_t sd_raw_write(uint32_t offset, const uint8_t* buffer, uint16_t length);
129 uint8_t sd_raw_write_interval(uint32_t offset, uint8_t* buffer, uint16_t length, sd_raw_write_interval_handler_t callback, void* p);
130 uint8_t sd_raw_sync();
131  
132 uint8_t sd_raw_get_info(struct sd_raw_info* info);
133  
134 /**
135 * @}
136 */
137  
138 #endif
139