Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of d7a_1x by
Diff: src/d7a_fs.cpp
- Revision:
- 27:934ab7455115
- Parent:
- 26:9f0b9833cac6
- Child:
- 28:0376b97b4b55
--- a/src/d7a_fs.cpp	Thu Mar 31 14:48:50 2016 +0000
+++ b/src/d7a_fs.cpp	Fri Apr 01 10:55:30 2016 +0000
@@ -101,10 +101,10 @@
     return (evt.status == osEventMessage)? (d7a_com_rx_msg_t*)evt.value.p : NULL;
 }
 
-static void d7a_fs_hdr(uint8_t fid, d7a_fs_header_t* hdr)
+static uint32_t d7a_fs_hdr(uint8_t fid, d7a_fs_header_t* hdr)
 {
     FPRINT("\r\n");
-    g_fs_ctx.read_file(fid, 0, sizeof(d7a_fs_header_t), (uint8_t*)hdr);
+    return g_fs_ctx.read_file(fid, 0, sizeof(d7a_fs_header_t), (uint8_t*)hdr);
 }
 
 uint32_t d7a_fs_get_properties(uint8_t fid, d7a_fs_property_t prop, d7a_fs_properties_t* props)
@@ -195,6 +195,45 @@
     return 0;
 }
 
+int d7a_fs_read(uint8_t fid, void *data, uint32_t offset, uint32_t length)
+{
+    DPRINT("RdP[%d] @:%d %d bytes\n", fid, offset, length);
+    d7a_fs_header_t hdr;
+    uint8_t local = 0;
+
+    if (!d7a_fs_hdr(fid, &hdr))
+    {
+        hdr.bf.type = HOST;
+    }
+    
+    switch (hdr.bf.type)
+    {
+        // "Local" files are also supported through "posted" API
+        case EEPROM:
+        case RAM:
+        case PFLASH:
+            // "Local" file, respond right away
+            d7a_fs_read(fid,data,offset,length);
+            g_fs_ctx.read_file(fid, offset+sizeof(d7a_fs_header_t), length, (uint8_t*)data);
+            // Inform requester
+            g_fs_ctx.fs_done.put((void*)fid);
+            local = 1;
+            break;
+        // "Distant" Files
+        case HOST:
+            ASSERT(g_fs_ctx.com.req.cmd == FS_OP_NULL,"FS: Concurrent Distant File access\n");
+            g_fs_ctx.com.req = (d7a_fs_com_req_t){FS_OP_RD,fid,offset,length};
+            g_fs_ctx.com.data = data;
+            d7a_fs_msg((uint8_t*)&g_fs_ctx.com.req, sizeof(d7a_fs_com_req_t), KAL_COM_FLOW_FS_CMD);
+            break;
+        // Wrong type
+        default:
+            ASSERT(false, "FS:post_read wrong file type %x\n", hdr.bf.type);
+    }
+    return local;
+}
+
+
 
 #define OP_SIZE_RD      10
 #define OP_SIZE_WR      10
    