ms_protocol.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. #ifndef _H_MS_PROTOCOL
  2. #define _H_MS_PROTOCOL
  3. #pragma pack(1)
  4. typedef struct _MS_Registers { //Register Name //Addr R/W
  5. unsigned char Reserved00; //0x00 ---
  6. unsigned char INT_Reg; //0x01 R
  7. unsigned char Status_Reg0; //0x02 R
  8. unsigned char Status_Reg1; //0x03 R
  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 Block_Address_Reg2; //0x11 W
  23. unsigned char Block_Address_Reg1; //0x12 W
  24. unsigned char Block_Address_Reg0; //0x13 W
  25. unsigned char CMD_Parameter_Reg; //0x14 W
  26. unsigned char Page_Address_Reg; //0x15 R/W
  27. unsigned char Overwrite_Flag_Reg; //0x16 R/W
  28. unsigned char Management_Flag_Reg; //0x17 R/W
  29. unsigned char Logical_Address_Reg1; //0x18 R/W
  30. unsigned char Logical_Address_Reg0; //0x19 R/W
  31. unsigned char Reserved1A; //0x1A R/W
  32. unsigned char Reserved1B; //0x1B R/W
  33. unsigned char Reserved1C; //0x1C R/W
  34. unsigned char Reserved1D; //0x1D R/W
  35. unsigned char Reserved1E; //0x1E R/W
  36. //unsigned char Reserved1F~ReservedFF //0x1F~0xFF
  37. } MS_Registers_t;
  38. typedef struct _MS_Status_Register0 {
  39. unsigned WP:1; //D0: Write Protect
  40. unsigned SL:1; //D1: Sleep
  41. unsigned Reserved1:1; //D2
  42. unsigned Reserved2:1; //D3
  43. unsigned BF:1; //D4: Buffer Full
  44. unsigned BE:1; //D5: Buffer Empty
  45. unsigned FB0:1; //D6: Flash Busy 0
  46. unsigned MB:1; //D7: Media Busy
  47. } MS_Status_Register0_t;
  48. typedef struct _MS_Status_Register1 {
  49. unsigned UCFG:1; //D0: Unable to Correct Flag
  50. unsigned FGER:1; //D1: Flag Error
  51. unsigned UCEX:1; //D2: Unable to Correct Extra Data
  52. unsigned EXER:1; //D3: Extra Data Error
  53. unsigned UCDT:1; //D4: Unable to Correct Data
  54. unsigned DTER:1; //D5: Data Error
  55. unsigned FB1:1; //D6: Flash Busy 1
  56. unsigned MB:1; //D7: Media Busy
  57. } MS_Status_Register1_t;
  58. typedef struct _MS_System_Parameter_Register {
  59. unsigned Reserved1:1; //D0
  60. unsigned Reserved2:1; //D1
  61. unsigned Reserved3:1; //D2
  62. unsigned PAM:1; //D3: Parallel Access Mode
  63. unsigned Reserved4:1; //D4
  64. unsigned Reserved5:1; //D5
  65. unsigned Reserved6:1; //D6
  66. unsigned Reserved7:1; //D7: 1
  67. } MS_System_Parameter_Register_t;
  68. typedef struct _MS_Overwrite_Flag_Register {
  69. unsigned Reserved1:1; //D0
  70. unsigned Reserved2:1; //D1
  71. unsigned Reserved3:1; //D2
  72. unsigned Reserved4:1; //D3
  73. unsigned UDST:1; //D4: Update Status
  74. unsigned PGST1:1; //D5: Page Status
  75. unsigned PGST0:1; //D6: Page Status
  76. unsigned BKST:1; //D7: Block Status
  77. } MS_Overwrite_Flag_Register_t;
  78. typedef struct _MS_Management_Flag_Register {
  79. unsigned Reserved1:1; //D0
  80. unsigned Reserved2:1; //D1
  81. unsigned SYSFLG:1; //D2: System bit
  82. unsigned ATFLG:1; //D3: Conversion table bit
  83. unsigned SCMS1:1; //D4: Digital Read Protectd bit
  84. unsigned SCMS0:1; //D5: Digital Read Protectd bit
  85. unsigned Reserved3:1; //D6
  86. unsigned Reserved4:1; //D7
  87. } MS_Management_Flag_Register_t;
  88. typedef struct MS_Boot_Header //big_endian
  89. {
  90. unsigned short Block_ID; //0x0001: Boot Block ID
  91. unsigned char Data_Entry; //2: Number of effective blocks in a Boot Block (Disabled Block Data and CIS/IDI)
  92. } MS_Boot_Header_t;
  93. typedef struct MS_Boot_System_Entry //big_endian
  94. {
  95. unsigned long Disabled_Block_Start_Address; //0x00000000: Disabled Block Data start location
  96. unsigned long Disabled_Block_Data_Size; //(Disabled number of blocks * 2)Bytes
  97. unsigned char Disabled_Block_Data_Type_ID; //0x01: Disabled Block Data
  98. unsigned char Reserved0[3]; //All 0x00
  99. unsigned long CIS_IDI_Start_Address; //0x00000200: CIS/IDI data start location
  100. unsigned long CIS_IDI_Data_Size; //0x00000200: Data Size (512[Bytes], 1page)
  101. unsigned char CIS_IDI_Data_Type_ID; //0x0a
  102. unsigned char Reserved1[27]; //All 0x00
  103. } MS_Boot_System_Entry_t;
  104. typedef struct MS_Boot_Attribute_Information //big_endian
  105. {
  106. unsigned char Memory_Stick_Class; //1: ver1.xx, other: reserved
  107. unsigned char Format_Unique_Value1; //Set to 2
  108. unsigned short Block_Size; //16[kb]:0x10, 8[kb]:0x08, other: reserved
  109. unsigned short Block_Numbers; //4MB:0x0200, 8MB:0x0400, 16MB:0x0400, 32MB:0x0800, 64MB:0x1000, 128MB:0x2000
  110. unsigned short Effective_Block_Numbers; //4MB:0x01f0, 8MB:0x03e0, 16MB:0x03e0, 32MB:0x07c0, 64MB:0x0f80, 128MB:0x1f00
  111. unsigned short Page_Size; //0x0200(512) fixed
  112. unsigned char Extra_Data_Area_Size; //0x10(16) fixed
  113. unsigned char Format_Unique_Value2; //Set to 1
  114. struct {
  115. unsigned char TD; //Can be set in unite of 15mins from 12 to -12 hours, negative numbers are expressed in complement. 0x80: No setting
  116. unsigned short AD; //Binary description 0xffff: No setting
  117. unsigned char Month; //Binary description 0xff: No setting
  118. unsigned char Day; //Binary description 0xff: No setting
  119. unsigned char Hour; //Binary description 0xff: No setting
  120. unsigned char Minute; //Binary description 0xff: No setting
  121. unsigned char Second; //Binary description 0xff: No setting
  122. } Assembly_Date_Time;
  123. unsigned char Format_Unique_Value3; //Set to 0
  124. unsigned char Serial_Number2; //The number shall not be
  125. unsigned char Serial_Number1; //set duplicated for Memory Sticks
  126. unsigned char Serial_Number0; //manufactured on the same day
  127. unsigned char Assembly_Manufacturer_Code; //Setting values shall be obtained from the licensor
  128. unsigned char Assembly_Model_Code2; //4MB: 0x00, 8MB: 0x00, 16MB: 0x00, 32MB: 0x00, 64MB: 0x00, 128MB: 0x01
  129. unsigned char Assembly_Model_Code1; //4MB: 0x04, 8MB: 0x08, 16MB: 0x16, 32MB: 0x32, 64MB: 0x64, 128MB: 0x28
  130. unsigned char Assembly_Model_Code0; //4MB: 0x00, 8MB: 0x00, 16MB: 0x02, 32MB: 0x00, 64MB: 0x00, 128MB: 0x00
  131. unsigned short Memory_Manufacturer_Code; //0: Unknown, other: reserved
  132. unsigned short Memory_Device_Code; //0: Unknown, other: reserved
  133. unsigned short Implemented_Capacity; //describe total MB
  134. unsigned char Format_Unique_Value4; //Set to 1
  135. unsigned char Format_Unique_Value5; //Set to 1
  136. unsigned char VCC; //Expressed in 0.1V(VCC unit)ex3.3V 0x21
  137. unsigned char VPP; //Expressed in 0.1V(VPP unit)ex3.3V 0x21
  138. unsigned short Controller_Number; //Controller chip number
  139. unsigned short Controller_Function; //0x1001: MG, other: reserved
  140. unsigned char Reserved0[9]; //
  141. unsigned char Parallel_Transfer_Supporting; //0: serial, 1: Serial&Parallel, ohter: reserved
  142. unsigned short Format_Unique_Value6; //Set to 0
  143. unsigned char Format_Type; //1: FAT, ohter: reserved
  144. unsigned char Memory_Stick_Application; //0: General purpose, ohter: reserved
  145. unsigned char Device_Type; //0: Memory Stick, 1: ROM, 2: ROM2, 3: ROM3, other: reserved
  146. unsigned char Reserved1[22]; //
  147. unsigned char Format_Unique_Value7; //Set to 0x0a(10)
  148. unsigned char Format_Unique_Value8; //Set to 1
  149. unsigned char Reserved2[15]; //
  150. } MS_Boot_Attribute_Information_t;
  151. typedef struct MS_Boot_CIS //big_endian
  152. {
  153. unsigned char CISTPL_DEVICE[6];
  154. unsigned char CISTPL_DEVICEOC[6];
  155. unsigned char CISTPL_JEDEC_C[6];
  156. unsigned char CISTPL_MANFID[6];
  157. unsigned char CISTPL_VERS_1[32];
  158. unsigned char CISTPL_FUNID[4];
  159. unsigned char CISTPL_FUNCE1[4];
  160. unsigned char CISTPL_FUNCE2[5];
  161. unsigned char CISTPL_CONFIG[7];
  162. unsigned char CISTPL_CFTABL_ENTRY1[10];
  163. unsigned char CISTPL_CFTABL_ENTRY2[8];
  164. unsigned char CISTPL_CFTABL_ENTRY3[12];
  165. unsigned char CISTPL_CFTABL_ENTRY4[8];
  166. unsigned char CISTPL_CFTABL_ENTRY5[17];
  167. unsigned char CISTPL_CFTABL_ENTRY6[8];
  168. unsigned char CISTPL_CFTABL_ENTRY7[17];
  169. unsigned char CISTPL_CFTABL_ENTRY8[8];
  170. unsigned char CISTPL_NO_LINK[2];
  171. unsigned char CISTPL_END[1];
  172. unsigned char Reserved[90];
  173. } MS_Boot_CIS_t;
  174. typedef struct MS_Boot_IDI //little_endian
  175. {
  176. unsigned short General_Configuration;
  177. unsigned short Logical_Cylinder_Numbers;
  178. unsigned short Reserved0;
  179. unsigned short Logical_Head_Numbers;
  180. unsigned short Logical_Bytes_PerTrack;
  181. unsigned short Logical_Bytes_PerSector;
  182. unsigned short Logical_Sectors_PerTrack;
  183. unsigned short Logical_Sector_Numbers_MSW;
  184. unsigned short Logical_Sector_Numbers_LSW;
  185. unsigned short Reserved1;;
  186. unsigned char Serial_Number[20];
  187. unsigned short Buffer_Type;
  188. unsigned short Buffer_Size_By512Bytes;
  189. unsigned short Long_Command_ECC;
  190. unsigned char Firmware_Version[8];
  191. unsigned char Model_Name[40];
  192. unsigned short Reserved2;
  193. unsigned short Dual_Word_Supported;
  194. unsigned short DMA_Transfer_Support;
  195. unsigned short Reserved3;
  196. unsigned short PIO_Mode_Number;
  197. unsigned short DMA_Mode_Number;
  198. unsigned short Field_Validity;
  199. unsigned short Current_Logical_Cylinders;
  200. unsigned short Current_Logical_Heads;
  201. unsigned short Current_Logical_Sectors_PerTrack;
  202. unsigned long Current_Sectors_Capacity;
  203. unsigned short Multi_Sector_Setting;
  204. unsigned long User_Addressable_Sectors;
  205. unsigned short Single_Word_DMA_Transfer;
  206. unsigned short Multi_Word_DMA_Transfer;
  207. unsigned char Reserved4[128];
  208. } MS_Boot_IDI_t;
  209. #pragma pack()
  210. #define MS_PAGE_SIZE 512
  211. #define MS_MAX_DISABLED_BLOCKS MS_PAGE_SIZE/2
  212. typedef struct _MS_Disabled_Block_Data {
  213. unsigned short disabled_block_nums;
  214. unsigned short disabled_block_table[MS_MAX_DISABLED_BLOCKS];
  215. } MS_Disabled_Block_Data_t;
  216. #define MS_BOOT_HEADER_SIZE 368
  217. #define MS_BOOT_SYSTEM_ENTRY_SIZE 48
  218. #define MS_BOOT_ATTRIBUTE_INFORMATION_SIZE 96
  219. #define MS_BOOT_CIS_SIZE 256
  220. #define MS_BOOT_IDI_SIZE 256
  221. #define MS_BLOCKS_PER_SEGMENT 512
  222. #define MS_LOGICAL_SIZE_PER_SEGMENT 496
  223. #define MS_MAX_FREE_BLOCKS_PER_SEGMENT 16
  224. #define MS_MAX_SEGMENT_NUMBERS 16
  225. //Acceptable Command List for Memory Stick
  226. #define CMD_MS_BLOCK_READ 0xAA
  227. #define CMD_MS_BLOCK_WRITE 0x55
  228. #define CMD_MS_BLOCK_END 0x33
  229. #define CMD_MS_BLOCK_ERASE 0x99
  230. #define CMD_MS_FLASH_STOP 0xCC
  231. #define CMD_MS_SLEEP 0x5A
  232. #define CMD_MS_CLEAR_BUFFER 0xC3
  233. #define CMD_MS_RESET 0x3C
  234. //definitions for INT timeout
  235. #define MS_INT_TIMEOUT_BLOCK_READ (5*TIMER_1MS)
  236. #define MS_INT_TIMEOUT_BLOCK_WRITE (10*TIMER_1MS)
  237. #define MS_INT_TIMEOUT_BLOCK_END (5*TIMER_1MS)
  238. #define MS_INT_TIMEOUT_ERASE (100*TIMER_1MS)
  239. #define MS_INT_TIMEOUT_FLASH_STOP (5*TIMER_1MS)
  240. #define MS_INT_TIMEOUT_SLEEP (1*TIMER_1MS)
  241. #define MS_INT_TIMEOUT_CLEAR_BUF (1*TIMER_1MS)
  242. //#define MS_WRITE_PATTERN_1
  243. #define MS_WRITE_PATTERN_2
  244. #endif //_H_MS_PROTOCOL