Program to update the D7A modem's firmware.

Dependencies:   modem_ref_helper DebouncedInterrupt

Revision:
9:bd53ca2aece5
Parent:
7:5b8648784381
Child:
12:beabd59e0c35
--- a/cup.cpp	Thu Nov 10 17:18:42 2016 +0000
+++ b/cup.cpp	Thu Nov 10 17:55:05 2016 +0000
@@ -5,12 +5,10 @@
 #include "d7a.h"
 #include "dbg.h"
 
-#define MODEM_FLASH_PAGE_SIZE   (256)
-#define TU_LOCAL                (220)
 
 const uint8_t const cup_data[CUP_DATA_SIZE] = CUP_DATA;
 
-void cup_start_update(uint32_t src_offset, uint32_t max_size)
+void cup_start_update(uint32_t offset)
 {
     cup_cfg_t cfg = {
         .cmd = 0x10AD,
@@ -23,38 +21,18 @@
     uint8_t percent_old = 255;
     Timer tim;
     
-    // get archive address
-    uint32_t addr = *((uint32_t*)&cup_data[4]);
-    // End address
-    uint32_t eaddr = addr + CUP_CODE_SIZE;
-    
-    uint32_t offset = 0;
-    
-    if (eaddr > src_offset)
-    {
-        // Calculate offset if needed
-        PRINT("/!\\ CUP process will overwrite Archive: 0x%08X + %d > 0x%08X /!\\\r\n", addr, CUP_CODE_SIZE, src_offset);
-        eaddr = ((eaddr / MODEM_FLASH_PAGE_SIZE) + 1) * MODEM_FLASH_PAGE_SIZE;
-        offset = eaddr - src_offset;
-        PRINT("/!\\ CUP Shifting archive storage to 0x%08X (Offset 0x%X) /!\\\r\n", eaddr, offset);
-    }
-    
-    max_size -= offset;
-    int32_t slack = max_size - CUP_DATA_SIZE;
-    ASSERT(slack >= 0, "Not enough space to store archive! (%d bytes short)\r\n", -slack);
-    
     D7A_WRITE((uint8_t*)&cfg, CUP_CFG_FID, 0, 4, root_key);
     
     // Upload file
-    PRINT("Uploading %d bytes at address 0x%08X (%d bytes slack)\r\n", CUP_DATA_SIZE, src_offset + offset, slack);
+    PRINT("Uploading %d bytes to CUP file. (offset %d)\r\n", CUP_DATA_SIZE, offset);
     
     tim.start();
     
     while (rem > 0)
     {
-        D7A_WRITE(&(cup_data[fof]), CUP_CODE_FID, fof + offset, TU_LOCAL, NULL);
-        rem -= TU_LOCAL;
-        fof += TU_LOCAL;
+        D7A_WRITE(&(cup_data[fof]), CUP_CODE_FID, fof + offset, CUP_LOCAL_MTU, NULL);
+        rem -= CUP_LOCAL_MTU;
+        fof += CUP_LOCAL_MTU;
         
         percent = (100*fof)/CUP_DATA_SIZE;
         if (percent != percent_old)