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