Guest User

Untitled

a guest
Nov 22nd, 2011
98
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. uint8_t FlashInit(void)
  2. {
  3. uint8_t buff[5]; // buff for CMD_READ_ID response
  4.  
  5. MLCRefreshRow = 0xffffffff;
  6. TotalPhySec = 0;
  7. FlashPendCmd.Valid = 0;
  8. FlashReadStatusCmd = CMD_READ_STATUS;
  9.  
  10. FMWAIT = 0x1081;
  11. FLCTL = FL_RST;
  12.  
  13. for (i=0; i< MAX_FLASH_NUM i++)
  14. {
  15. FlashSpec[i].Cmd = 0x180E8200 + (i<<9);
  16. FlashSpec[i].Addr = 0x180E204 + (i<<9);
  17. FlashSpec[i].Data = 0x180E208 + (i<<9);
  18.  
  19. FlashCs(i);
  20. *FlashSpec[i].Cmd = CMD_RESET; //write cmd to flash chip
  21. Delay100cyc(2):
  22. FlashWaitBusy(0);
  23. *FlashSpec[i].Cmd = CMD_READ_ID; //write cmd to flash chip
  24. *FlashSpec[i].Addr = 0x00;
  25.  
  26. // read 5 bytes of CMD_READ_ID response
  27. for (j=0; j<5; j++)
  28. buff[j] = *FlashSpec[i].Data;
  29.  
  30. FlashDeCs();
  31.  
  32. for (j=0; j<sizeof(ManufactureIDTbl); j++)
  33. {
  34. // store Manufacturer index
  35. if (ManufactureIDTbl[j] == buff[0])
  36. FlashSpec[i].Vendor = j;
  37. }
  38.  
  39. for (j=0; j<sizeof(DeviceCode); j++)
  40. {
  41. // look for matching device code
  42. // and store total phys sectors
  43. if (DeviceCode[j] == buff[1])
  44. {
  45. FlashSpec[i].TotPhySec = DeviceInfo[j];
  46. break;
  47. }
  48. }
  49.  
  50. FlashSpec[i].MLC = 0;
  51. //FlashSpec[i].Large = 0;
  52. if (j > 2)
  53. FlashSpec[i].Large = 1;
  54. else
  55. FlashSpec[i].Large = 0;
  56.  
  57. FlashSpec[i].Five = 1;
  58. FlashSpec[i].MulPlane = 1;
  59. FlashSpec[i].Interleave = 0;
  60.  
  61. FlashSpec[i].CacheProg = buff[2] & 0x80;
  62.  
  63. // store flash access time (ns)
  64. switch (buff[3] & 0x88)
  65. case 0:
  66. FlashSpec[i].AccessTime = 50;
  67. break;
  68. case 0x80:
  69. FlashSpec[i].AccessTime = 25;
  70. break;
  71. case 0x08:
  72. FlashSpec[i].AccessTime = 20;
  73. break;
  74. default:
  75. FlashSpec[i].AccessTime = 60;
  76.  
  77. // how many bits holds single flash cell
  78. FlashSpec[i].MLC = (buff[3] >> 2) &0x03;
  79.  
  80. FlashSpec[i].SecPerPageRaw=2; // 1KB~8KB
  81. for (j=0; j<(buff[3] & 0x03); j++) // page size
  82. {
  83. FlashSpec[i].SecPerPageRaw <<= 1;
  84. }
  85.  
  86. FlashSpec[i].SecPerBlockRaw = 128; //64KB~512KB
  87. for (j=0; j<((buff[3]>>4) & 0x03); j++) // block size
  88. {
  89. FlashSpec[i].SecPerBlockRaw<<=1;
  90. }
  91.  
  92. // number of simultanously programmed pages
  93. FlashSpec[i].MulPlane = 1<<((buff[2]>>4)&0x03 - 1);
  94.  
  95. FlashSpec[i].Interleave = (buff[2]>>6)&0x01;
  96.  
  97. FlashSpec[i].PagePerBlockRaw = FlashSpec[i].SectorPerBlockRaw/FlashSpec[i].SectorPerPageRaw;
  98. FlashSpec[i].PagePerBlock = FlashSpec[i].PagePerBlockRaw * FlashSpec[i].MulPlane;
  99. FlashSpec[i].SectorPerBlock = FlashSpec[i].SectorPerBlockRaw * FlashSpec[i].MulPlane;
  100. FlashSpec[i].SectorPerPage = FlashSpec[i].SectorPerPageRaw * FlashSpec[i].MulPlane;
  101. FlashSpec[i].TotBlks = FlashSpec[i].TotPhySec / FlashSpec[i].SectorPerBlock;
  102. }
  103.  
  104. // read ID block and propagate SysDiskCapacity and SysResBlocks
  105. }
  106.  
  107.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×