mspro_protocol.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. #ifndef _H_MSPRO_PROTOCOL
  2. #define _H_MSPRO_PROTOCOL
  3. #pragma pack(1)
  4. typedef struct _MSPRO_Registers { //Register Name //Addr R/W
  5. unsigned char Reserved00; //0x00 ---
  6. unsigned char INT_Reg; //0x01 R
  7. unsigned char Status_Reg; //0x02 R
  8. unsigned char Reserved03; //0x03 ---
  9. unsigned char Type_Reg; //0x04 R
  10. unsigned char Reserved05; //0x05 ---
  11. unsigned char Category_Reg; //0x06 R
  12. unsigned char Class_Reg; //0x07 R
  13. unsigned char Reserved08; //0x08 ---
  14. unsigned char Reserved09; //0x09 ---
  15. unsigned char Reserved0A; //0x0A ---
  16. unsigned char Reserved0B; //0x0B ---
  17. unsigned char Reserved0C; //0x0C ---
  18. unsigned char Reserved0D; //0x0D ---
  19. unsigned char Reserved0E; //0x0E ---
  20. unsigned char Reserved0F; //0x0F ---
  21. unsigned char System_Parameter_Reg; //0x10 W
  22. unsigned char Data_Count_Reg1; //0x11 W
  23. unsigned char Data_Count_Reg0; //0x12 W
  24. union {
  25. struct //for data access
  26. {
  27. unsigned char Data_Address_Reg3; //0x13 W
  28. unsigned char Data_Address_Reg2; //0x14 W
  29. unsigned char Data_Address_Reg1; //0x15 W
  30. unsigned char Data_Address_Reg0; //0x16 W
  31. unsigned char TPC_Pamameter_Reg; //0x17 W
  32. unsigned char CMD_Parameter_Reg; //0x18 W
  33. } data;
  34. struct //for security access
  35. {
  36. unsigned char Security_Parameter_Reg5; //0x13 W
  37. unsigned char Security_Parameter_Reg4; //0x14 W
  38. unsigned char Security_Parameter_Reg3; //0x15 W
  39. unsigned char Security_Parameter_Reg2; //0x16 W
  40. unsigned char Security_Parameter_Reg1; //0x17 W
  41. unsigned char Security_Parameter_Reg0; //0x18 W
  42. } security;
  43. } parameters;
  44. unsigned char Reserved19; //0x19 ---
  45. unsigned char Reserved1A; //0x1A ---
  46. unsigned char Reserved1B; //0x1B ---
  47. unsigned char Reserved1C; //0x1C ---
  48. unsigned char Reserved1D; //0x1D ---
  49. unsigned char Reserved1E; //0x1E ---
  50. //unsigned char Reserved1F~ReservedFF //0x1F~0xFF
  51. } MSPRO_Registers_t;
  52. typedef struct _MSPRO_Status_Register {
  53. unsigned WP:1; //D0: Write Protect
  54. unsigned SL:1; //D1: Sleep
  55. unsigned Reserved1:1; //D2
  56. unsigned Reserved2:1; //D3
  57. unsigned Reserved3:1; //D4
  58. unsigned Reserved4:1; //D5
  59. unsigned Reserved5:1; //D6
  60. unsigned ES:1; //D7: Erase Status
  61. } MSPRO_Status_Register_t;
  62. typedef struct _MSPRO_System_Parameter_Register {
  63. unsigned Reserved1:1; //D0
  64. unsigned Reserved2:1; //D1
  65. unsigned Reserved3:1; //D2
  66. unsigned Reserved4:1; //D3
  67. unsigned Reserved5:1; //D4
  68. unsigned Reserved6:1; //D5
  69. unsigned Reserved7:1; //D6
  70. unsigned SRAC:1; //D7: Serial Access
  71. } MSPRO_System_Parameter_Register_t;
  72. typedef struct _MSPRO_Attribute_Information_Area {
  73. unsigned short Signature_Code; //Setting: A5C3h
  74. unsigned short Version_Information; //Setting: 01xxh
  75. unsigned char Device_Information_Entry_Count; //1~12
  76. unsigned char Reserved[11];
  77. } MSPRO_Attribute_Information_Area_t;
  78. typedef struct _MSPRO_Device_Information_Entry {
  79. unsigned long Address; //Starting Location
  80. unsigned long Size; //Size(by bytes)
  81. unsigned char Device_Information_ID; //
  82. unsigned char Reserved[3];
  83. } MSPRO_Device_Information_Entry_t;
  84. typedef struct _MSPRO_System_Information //big_endian
  85. {
  86. unsigned char Memory_Stick_Class; //2: Memory Stick Pro, other: reserved
  87. unsigned char Reserved0; //Undefined value
  88. unsigned short Block_Size; //Erase size(number of units)
  89. unsigned short Total_Blocks; //Number of the whole block
  90. unsigned short User_Area_Blocks; //Number of User Area blocks
  91. unsigned short Page_Size; //Writing and reading size(number of units)
  92. unsigned short Reserved1; //Undefined value
  93. struct {
  94. unsigned char GMT_Difference; //Time difference from GMT
  95. unsigned short Year; //Binary description 0xffff: No setting
  96. unsigned char Month; //Binary description 0xff: No setting
  97. unsigned char Day; //Binary description 0xff: No setting
  98. unsigned char Hour; //Binary description 0xff: No setting
  99. unsigned char Minute; //Binary description 0xff: No setting
  100. unsigned char Second; //Binary description 0xff: No setting
  101. } Assembly_Date;
  102. unsigned long Serial_Number; //Product serial number
  103. unsigned char Assembly_Maker_Code; //Assembly maker code
  104. unsigned char Assembly_Model_Code2; //Assembly model code
  105. unsigned char Assembly_Model_Code1; //Assembly model code
  106. unsigned char Assembly_Model_Code0; //Assembly model code
  107. unsigned short Memory_Maker_Code; //Memory maker code
  108. unsigned short Memory_Model_Code; //Memory model code
  109. unsigned long Reserved2; //Undefined value
  110. unsigned char VCC; //Expressed in 0.1V(VCC unit)ex3.3V 0x21
  111. unsigned char VPP; //Expressed in 0.1V(VPP unit)ex3.3V 0x21
  112. unsigned short Controller_Number; //Internal controller number
  113. unsigned short Controller_Function; //Internal controller function
  114. unsigned short Start_Sector; //Starting sector number of the block boundary
  115. unsigned short Unit_Size; //unit size(Number of bytes)
  116. unsigned char Memory_Stick_Sub_Class; //Memory Stick sub class
  117. unsigned long Reserved3; //Undefined value
  118. unsigned char Interface_Type; //0: serial, 1: Serial&Parallel, ohter: reserved
  119. unsigned short Controller_Code; //Internal controller code
  120. unsigned char Format_Type; //1: FAT, ohter: reserved
  121. unsigned char Reserved4; //Undefined value
  122. unsigned char Device_Type; //0: R/W, 1: ROM, 2: ROM2, 3: ROM3, other: reserved
  123. unsigned char Reserved5[7]; //Undefined value
  124. unsigned char Memory_Stick_Pro_ID[16]; //Different ID is set on every Media
  125. unsigned char Reserved6[16]; //Undefined value
  126. } MSPRO_System_Information_t;
  127. typedef struct _MSPRO_Modal_Name //big_endian
  128. {
  129. char CardName[0x10]; //0x00~0x0F, "Memory Stick PRO"
  130. char MediaType[0x09]; //0x10~0x18, "-ROM Duo "
  131. char Capacity[0x08]; //0x18~0x20, "( 512MB)"
  132. char VendorStr[0x0F]; //0x21~0x2F
  133. } MSPRO_Modal_Name_t;
  134. typedef struct _MSPRO_MBR_Values //little_endian
  135. {
  136. unsigned char Default_boot_partition;
  137. unsigned char Start_head_No;
  138. unsigned char Start_sector_No;
  139. unsigned char Start_cylinder_No;
  140. unsigned char Partition_type;
  141. unsigned char End_head_No;
  142. unsigned char End_sector_No;
  143. unsigned char End_cylinder_No;
  144. unsigned long PBR_start_sectors;
  145. unsigned long Sectors_per_partition;
  146. } MSPRO_MBR_Values_t;
  147. typedef struct _MSPRO_PBR_FAT16_Values //little_endian
  148. {
  149. unsigned char Jmp_Code[3];
  150. char OEM_Name_Version[8];
  151. unsigned short Bytes_PerSector;
  152. unsigned char Sectors_PerCluster;
  153. unsigned short Reserved_Sectors;
  154. unsigned char FAT_Numbers;
  155. unsigned short Root_Directory_Entrys;
  156. unsigned short Total_Sectors;
  157. unsigned char Media_ID_Bytes;
  158. unsigned short FAT_Sectors;
  159. unsigned short Sectors_PerTrack;
  160. unsigned short Head_Numbers;
  161. unsigned long Hidden_Sectors;
  162. unsigned char Drive_Number;
  163. unsigned char PBR_Reserved;
  164. unsigned char EXT_Boot_Signature;
  165. unsigned long Volume_ID;
  166. char Volume_Label[11];
  167. char File_System_Type[8];
  168. unsigned char Reserved[2];
  169. } MSPRO_PBR_FAT16_Values_t;
  170. typedef struct _MSPRO_PBR_FAT32_Values //little_endian
  171. {
  172. unsigned char Jmp_Code[3];
  173. char OEM_Name_Version[8];
  174. unsigned short Bytes_PerSector;
  175. unsigned char Sectors_PerCluster;
  176. unsigned short Reserved_Sectors;
  177. unsigned char FAT_Numbers;
  178. unsigned short Root_Directory_Entrys;
  179. unsigned short Total_Sectors;
  180. unsigned char Media_ID_Bytes;
  181. unsigned short FAT_Sectors;
  182. unsigned short Sectors_PerTrack;
  183. unsigned short Head_Numbers;
  184. unsigned long Hidden_Sectors;
  185. unsigned long Huge_Sectors;
  186. unsigned long FAT_Numbers_Big;
  187. unsigned short Extended_Flag;
  188. unsigned short File_System_Version;
  189. unsigned long Root_Start_Cluster;
  190. unsigned short FSINFO_Start_Sector;
  191. unsigned short Boot_Copy_Start_Sector;
  192. unsigned char PBR_Reserved1[12];
  193. unsigned char Drive_Number;
  194. unsigned char PBR_Reserved2;
  195. unsigned char EXT_Boot_Signature;
  196. unsigned long Volume_ID;
  197. char Volume_Label[11];
  198. char File_System_Type[8];
  199. unsigned char Reserved[6];
  200. } MSPRO_PBR_FAT32_Values_t;
  201. typedef struct _MSPRO_Special_File_Values //little_endian
  202. {
  203. char File_Name[8];
  204. char Extention[3];
  205. unsigned char Attribute;
  206. unsigned char Reserved[10];
  207. unsigned short Modified_Time;
  208. unsigned short Modified_Date;
  209. unsigned short Starting_Cluster_Number;
  210. unsigned long File_Size;
  211. } MSPRO_Special_File_Values_t;
  212. typedef struct _MSPRO_Identify_Device_Information //big_endian
  213. {
  214. unsigned short Cylinder_Numbers;
  215. unsigned short Head_Numbers;
  216. unsigned short Unformatted_Bytes_PerTrack;
  217. unsigned short Unformatted_Bytes_PerSector;
  218. unsigned short Sectors_PerTrack;
  219. unsigned char Reserved[6];
  220. } MSPRO_Identify_Device_Information_t;
  221. #pragma pack()
  222. #define MSPRO_SECTOR_SIZE 512
  223. #define MSPRO_DEVID_SYSTEM_INFORMATION 0x10
  224. #define MSPRO_DEVID_MODEL_NAME 0x15
  225. #define MSPRO_DEVID_MBR_VALUES 0x20
  226. #define MSPRO_DEVID_PBR_FAT16_VALUES 0x21
  227. #define MSPRO_DEVID_PBR_FAT32_VALUES 0x22
  228. #define MSPRO_DEVID_SPECIAL_VALUES1 0x25
  229. #define MSPRO_DEVID_SPECIAL_VALUES2 0x26
  230. #define MSPRO_DEVID_IDENTIFY_DEVICE_INFORMATION 0x30
  231. #define MSPRO_DEVID_VENDOR_SPECIFICATION1 0x11
  232. #define MSPRO_DEVID_VENDOR_SPECIFICATION2 0x12
  233. #define MSRPO_ATTRIBUTE_INFOMATION_SIZE 16
  234. #define MSRPO_DEVICE_INFORMATION_ENTRY_SIZE 12
  235. #define MSRPO_MAX_DEVICE_INFORMATION_ENTRY 12
  236. #define MSPRO_SYSTEM_INFORMATION_SIZE 96
  237. #define MSPRO_MODAL_NAME_SIZE 48
  238. #define MSPRO_MBR_VALUES_SIZE 16
  239. #define MSPRO_PBR_FAT16_VALUES_SIZE 64
  240. #define MSPRO_PBR_FAT32_VALUES_SIZE 96
  241. #define MSPRO_SPECIAL_FILE_VALUES_SIZE 32
  242. #define MSPRO_IDENTIFY_DEVICE_INFORMATION_SIZE 16
  243. //Acceptable Command List for Memory Stick Pro
  244. #define CMD_MSPRO_READ_DATA 0x20
  245. #define CMD_MSPRO_WRITE_DATA 0x21
  246. #define CMD_MSPRO_READ_ATRB 0x24
  247. #define CMD_MSPRO_STOP 0x25
  248. #define CMD_MSPRO_ERASE 0x26
  249. #define CMD_MSPRO_SET_IBD 0x46
  250. #define CMD_MSPRO_GET_IBD 0x47
  251. #define CMD_MSPRO_FORMAT 0x10
  252. #define CMD_MSPRO_SLEEP 0x11
  253. //definitions for progress report
  254. #define MSPRO_REPORT_32BYTES 0x00
  255. #define MSPRO_REPORT_64BYTES 0x01
  256. #define MSPRO_REPORT_128BYTES 0x02
  257. #define MSPRO_REPORT_256BYTES 0x03
  258. #define MSPRO_REPORT_TYPE MSPRO_REPORT_32BYTES
  259. #if (MSPRO_REPORT_TYPE==MSPRO_REPORT_32BYTES)
  260. #define MSPRO_REPORT_SIZE 32
  261. #elif (MSPRO_REPORT_TYPE==MSPRO_REPORT_64BYTES)
  262. #define MSPRO_REPORT_SIZE 64
  263. #elif (MSPRO_REPORT_TYPE==MSPRO_REPORT_128BYTES)
  264. #define MSPRO_REPORT_SIZE 128
  265. #else /* */
  266. #define MSPRO_REPORT_SIZE 256
  267. #endif /* */
  268. //definitions for INT timeout
  269. #define MSPRO_INT_TIMEOUT_READ_DATA (1000*TIMER_1MS)
  270. #define MSPRO_INT_TIMEOUT_WRITE_DATA (1000*TIMER_1MS)
  271. #define MSPRO_INT_TIMEOUT_READ_ATRB (1000*TIMER_1MS)
  272. #define MSPRO_INT_TIMEOUT_STOP (1000*TIMER_1MS)
  273. #define MSPRO_INT_TIMEOUT_ERASE (1000*TIMER_1MS)
  274. #define MSPRO_INT_TIMEOUT_FORMAT (3000*TIMER_1MS)
  275. #define MSPRO_INT_TIMEOUT_SLEEP (1000*TIMER_1MS)
  276. #define MSPRO_INT_TIMEOUT_SET_IBD (1000*TIMER_1MS)
  277. #define MSPRO_INT_TIMEOUT_GET_IBD (1000*TIMER_1MS)
  278. #define MSPRO_SLEEP_TIMEOUT_PLUS (500*TIMER_1MS)
  279. //#define MSPRO_STARTUP_TIMEOUT (1000*TIMER_1MS)
  280. #define MSPRO_STARTUP_TIMEOUT 300
  281. #endif //_H_MSPRO_PROTOCOL