Trond Enger / d7a_1x

Fork of d7a_1x by WizziLab

Revision:
38:c1e7f97ab396
Parent:
34:1311cc53201a
Child:
41:a924aa709b6f
Child:
43:28202405094d
--- a/src/d7a_fs.cpp	Wed Aug 24 17:31:51 2016 +0000
+++ b/src/d7a_fs.cpp	Thu Aug 25 09:38:40 2016 +0000
@@ -196,13 +196,14 @@
     int status = 0;
     FPRINT("\r\n");
     //DPRINT("CrD[%d] type 0x%x\n",fid,props->type);
-
-    switch (props->type)
+    
+    
+    
+    switch (FS_PHY_TYPE(props->type))
     {
         case EEPROM:
         case RAM:
         case PFLASH:
-        case HOST:
             id = d7a_fs_get_req_id();
             DPRINT("CrD[%d](%d)\r\n", fid, id);
             // Build WR command
@@ -219,7 +220,7 @@
             break;
         // Wrong type
         default:
-            ASSERT(false, "FS:post_distant_create wrong file type %x\n",props->type);
+            ASSERT(false, "FS:post_distant_create wrong file type %x\n", FS_PHY_TYPE(props->type));
             break;
     }
     
@@ -236,34 +237,25 @@
     if (!d7a_fs_hdr(fid, &hdr))
     {
         // If file is not found locally, it is a distant file
-        hdr.bf.type = HOST;
+        hdr.bf.type |= FS_TYPE_DISTANT;
     }
     
-    switch (hdr.bf.type)
+    if(hdr.bf.type & FS_TYPE_DISTANT) // XXX: HOST only
     {
-        // "Local" files are also supported through "posted" API
-        case EEPROM:
-        case RAM:
-        case PFLASH:
-            // "Local" file, respond right away
-            DPRINT("RdP[%d](-) @:%d %d bytes\r\n", fid, offset, length);
-            status = (g_fs_ctx.callback->read_file(fid, offset, length, (uint8_t*)data) == length)?
-                FS_STAT_OK : FS_STAT_ERR_UNKNOWN;
-            break;
-        // "Distant" Files
-        case HOST:
-            id = d7a_fs_get_req_id();
-            DPRINT("RdP[%d](%d) @:%d %d bytes\r\n", fid, id, offset, length);
-            g_fs_ctx.com[id].req = (d7a_fs_com_req_t){id,FS_OP_RD,fid,offset,length};
-            g_fs_ctx.com[id].data = data;
-            d7a_fs_msg((uint8_t*)&g_fs_ctx.com[id].req, sizeof(d7a_fs_com_req_t), KAL_COM_FLOW_FS_CMD);
-            status = (int)d7a_fs_wait_done(id, TO_FS);
-            break;
-        // Wrong type
-        default:
-            ASSERT(false, "FS:post_read wrong file type %x\n", hdr.bf.type);
+        id = d7a_fs_get_req_id();
+        DPRINT("RdP[%d](%d) @:%d %d bytes\r\n", fid, id, offset, length);
+        g_fs_ctx.com[id].req = (d7a_fs_com_req_t){id,FS_OP_RD,fid,offset,length};
+        g_fs_ctx.com[id].data = data;
+        d7a_fs_msg((uint8_t*)&g_fs_ctx.com[id].req, sizeof(d7a_fs_com_req_t), KAL_COM_FLOW_FS_CMD);
+        status = (int)d7a_fs_wait_done(id, TO_FS);
     }
-    
+    else
+    {
+        DPRINT("RdP[%d](-) @:%d %d bytes\r\n", fid, offset, length);
+        status = (g_fs_ctx.callback->read_file(fid, offset, length, (uint8_t*)data) == length)?
+            FS_STAT_OK : FS_STAT_ERR_UNKNOWN;
+    }
+
     return status;
 }
 
@@ -436,11 +428,12 @@
                         d7a_fs_hdr(g_fs_ctx.com[id].req.fid, &hdr);
                         // Try to keep HOST-files coherency as much as we can:
                         // STAT returns the full header so we can update all fields.
-                        if (hdr.byte.type == HOST)
+                        if (FS_COM_TYPE(hdr.byte.type) == HOST)
                         {
                             d7a_fs_properties_t* props = (d7a_fs_properties_t*)&resp->data[0];
                             // XXX d7a_fs_set_properties_p is for now keeping our file remote,
                             // as it doesn't change addr,type,mirror etc.
+                            props->type += HOST; // HOST, but keep physical type as well
                             //d7a_fs_set_properties(hdr, (uint32_t)props);
                         }
                     }