123

Dependencies:   mbed

Fork of LG by igor Apu

Revision:
156:e68ee0bcdcda
Parent:
149:abbf7663d27d
Child:
167:bedc0a9d559a
--- a/DeviceFlash.c	Fri May 06 14:08:54 2016 +0000
+++ b/DeviceFlash.c	Mon May 09 20:03:26 2016 +0000
@@ -3,7 +3,6 @@
 
 extern Device device;
 extern HashParam hashParamTable[HASH_PARAM_COUNT];
-char tmp[256];
 
 //Flash memory sectors
 #define FLASH_SECTOR0_SIZE   0x1000
@@ -127,11 +126,11 @@
 #define FLASH_SECTOR29_END   0x0007FFFF
 
 void InitFlashWithDefaults(void){
-  device.flash.settings.hashSector = 22;
-  //device.flash.settings.hashPageLength = 256;
+  device.controller.flash.settings.hashSector = 22;
+  //device.controller.flash.settings.hashPageLength = 256;
   
-  device.flash.settings.dataSector = 23;
-  //device.flash.settings.dataPageLength = 256;
+  device.controller.flash.settings.dataSector = 23;
+  //device.controller.flash.settings.dataPageLength = 256;
 }
 
 void InitFlash(void){
@@ -244,9 +243,9 @@
 */
 
 DeviceFlashHash * FlashFindByHash(uint32_t hash){
-  uint16_t sectorLength = LengthFromSector(device.flash.settings.hashSector);
+  uint16_t sectorLength = LengthFromSector(device.controller.flash.settings.hashSector);
   uint16_t hashCapacity = sectorLength / sizeof(DeviceFlashHash);
-  uint32_t sectorAddress = AddressFromSector(device.flash.settings.hashSector);
+  uint32_t sectorAddress = AddressFromSector(device.controller.flash.settings.hashSector);
   DeviceFlashHash * item = (DeviceFlashHash *)sectorAddress;
   for (uint16_t i = 0; i < hashCapacity; i++){
     if (item->hash == 0) break;
@@ -256,11 +255,11 @@
   return 0;
 }
 
-void FlashReadAll(void){
+void DeviceFlashReadAll(void){
   uint16_t count = 0;
-  uint16_t sectorLength = LengthFromSector(device.flash.settings.hashSector);
+  uint16_t sectorLength = LengthFromSector(device.controller.flash.settings.hashSector);
   uint16_t hashCapacity = sectorLength / sizeof(DeviceFlashHash);
-  uint32_t sectorAddress = AddressFromSector(device.flash.settings.hashSector);
+  uint32_t sectorAddress = AddressFromSector(device.controller.flash.settings.hashSector);
   DeviceFlashHash * item = (DeviceFlashHash *)sectorAddress;
   for (uint16_t i = 0; i < hashCapacity; i++){
     if (item->hash == 0) break; //Cleared
@@ -279,7 +278,7 @@
     item++;
     count++;
   }
-  sprintf(tmp,"FlashReadAll(): %d\r\n",count); WriteCon(tmp);
+  sprintf(device.service.buffer,"FlashReadAll(): %d\r\n",count); WriteConcole();
 }
 
 void FlashOperationWritePage(DeviceFlashWriteOperation * op){
@@ -287,18 +286,18 @@
   if (op->sectorPosition == 0){
     //Prepare new sector for write operation
     res = u32IAP_PrepareSectors(op->sector, op->sector);
-    sprintf(tmp,"PrepareSectors(): %02d %08x\r\n",op->sector, res); WriteCon(tmp);
+    sprintf(device.service.buffer,"PrepareSectors(): %02d %08x\r\n",op->sector, res); WriteConcole();
     //Erase new sector
     res = u32IAP_EraseSectors(op->sector, op->sector);
-    sprintf(tmp,"EraseSectors(): %02d %08x\r\n",op->sector, res); WriteCon(tmp);
+    sprintf(device.service.buffer,"EraseSectors(): %02d %08x\r\n",op->sector, res); WriteConcole();
   }
   if (op->bytes < op->maxBytes){
     //Prepare sector for write operation
     res = u32IAP_PrepareSectors(op->sector, op->sector);
-    sprintf(tmp,"PrepareSectors(): %02d %08x\r\n",op->sector, res); WriteCon(tmp);
+    sprintf(device.service.buffer,"PrepareSectors(): %02d %08x\r\n",op->sector, res); WriteConcole();
     //Copy page buffer to flash
     res = u32IAP_CopyRAMToFlash(op->sectorAddress + op->sectorPosition, (uint32_t)&op->pageBuffer[0], FLASH_PAGE_SIZE);
-    sprintf(tmp,"CopyRAMToFlash(): %8x %08x\r\n", op->sectorAddress + op->sectorPosition, res); WriteCon(tmp);
+    sprintf(device.service.buffer,"CopyRAMToFlash(): %8x %08x\r\n", op->sectorAddress + op->sectorPosition, res); WriteConcole();
     //Update bytes count
     op->bytes += FLASH_PAGE_SIZE;
     //Update sector position
@@ -337,12 +336,12 @@
   FlashOperationWritePage(op);
 }
 
-void FlashWriteAll(void){
+void DeviceFlashWriteAll(void){
   //#pragma pack(push)  /* push current alignment to stack */
   //#pragma pack(4)     /* set alignment to 4 byte boundary */
   DeviceFlashWriteOperation hash;
   //#pragma pack(pop)   /* restore original alignment from stack */
-  hash.sector = device.flash.settings.hashSector;
+  hash.sector = device.controller.flash.settings.hashSector;
   hash.sectorAddress = AddressFromSector(hash.sector);
   hash.sectorLength = LengthFromSector(hash.sector);
   hash.sectorPosition = 0;
@@ -352,7 +351,7 @@
   hash.maxBytes = hash.sectorLength;
   
   DeviceFlashWriteOperation data;
-  data.sector = device.flash.settings.dataSector;
+  data.sector = device.controller.flash.settings.dataSector;
   data.sectorAddress = AddressFromSector(data.sector);
   data.sectorLength = LengthFromSector(data.sector);
   data.sectorPosition = 0;