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:
- 26:9f0b9833cac6
- Parent:
- 25:aac250164497
- Child:
- 27:934ab7455115
--- a/src/d7a_fs.cpp	Fri Mar 25 16:48:02 2016 +0000
+++ b/src/d7a_fs.cpp	Thu Mar 31 14:48:50 2016 +0000
@@ -33,7 +33,7 @@
 
 typedef struct {
     Thread* thread;
-    Semaphore*  fs_done;
+    Queue<void, 8> fs_done;
     WriteFileFunction write_file;
     ReadFileFunction read_file;
     Queue<d7a_com_rx_msg_t, 16> pkt_queue;
@@ -53,11 +53,11 @@
     memset(&g_fs_ctx.com, 0, sizeof(g_fs_ctx.com));
     g_fs_ctx.write_file = write_file;
     g_fs_ctx.read_file = read_file;
-    g_fs_ctx.fs_done = new Semaphore(1);
+    //g_fs_ctx.fs_done = new Semaphore(1);
     g_fs_ctx.thread = new Thread(d7a_fs_thread, NULL, osPriorityBelowNormal, DEFAULT_STACK_SIZE*2);
     
     // Wait to consume Semaphore
-    g_fs_ctx.fs_done->wait();
+    //g_fs_ctx.fs_done->wait();
 }
 
 static void d7a_fs_msg(uint8_t* buf, uint8_t len, uint8_t id)
@@ -71,10 +71,21 @@
     d7a_com_send_msg(&msg);
 }
 
-void d7a_fs_wait_done( uint32_t millisec )
+void* d7a_fs_wait_done( uint32_t millisec )
 {
     FPRINT("\r\n");
-    g_fs_ctx.fs_done->wait(millisec);
+    void* ret;
+    osEvent evt = g_fs_ctx.fs_done.get(millisec);
+    if (evt.status == osEventMessage)
+    {
+        ret = (void*)evt.value.p;
+    }
+    else
+    {
+        ret = (void*)0xFFFFFFFF;
+        EPRINT("FS Wait Timeout!\r\n");
+    }
+    return ret;
 }
 
 void d7a_fs_new_pkt(d7a_com_rx_msg_t* pkt)
@@ -137,6 +148,22 @@
     return ret;
 }
 
+void d7a_fs_distant_stat(uint8_t fid, int* length)
+{
+    FPRINT("\r\n");
+    // "Distant" Files
+    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_STAT,fid,0,0};
+    g_fs_ctx.com.data = length;
+    d7a_fs_msg((uint8_t*)&g_fs_ctx.com.req,sizeof(d7a_fs_com_req_t), KAL_COM_FLOW_FS_CMD);
+    // We do a "normal" STAT but we don't want to update our local(true) file-size
+    // with the response of the STAT as:
+    // - the distant is likely a "Host-file" with hazardous size/alloc
+    // - we may not even have the corresponding local file (-> assert when getting props)
+    // So flag the cmd to differentiate response treatment
+    g_fs_ctx.com.req.cmd = FS_OP_DSTAT; // XXX
+}
+
 int d7a_fs_distant_create(uint8_t fid, d7a_fs_properties_t* props)
 {
     FPRINT("\r\n");
@@ -168,23 +195,6 @@
     return 0;
 }
 
-void d7a_fs_post_distant_stat(uint8_t fid, int* length)
-{
-    FPRINT("\r\n");
-    // "Distant" Files
-    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_STAT,fid,0,0};
-    g_fs_ctx.com.data = length;
-    d7a_fs_msg((uint8_t*)&g_fs_ctx.com.req,sizeof(d7a_fs_com_req_t), KAL_COM_FLOW_FS_CMD);
-    // We do a "normal" STAT but we don't want to update our local(true) file-size
-    // with the response of the STAT as:
-    // - the distant is likely a "Host-file" with hazardous size/alloc
-    // - we may not even have the corresponding local file (-> assert when getting props)
-    // So flag the cmd to differentiate response treatment
-    g_fs_ctx.com.req.cmd = FS_OP_DSTAT; // XXX
-}
-
-
 
 #define OP_SIZE_RD      10
 #define OP_SIZE_WR      10
@@ -214,7 +224,7 @@
 {
     FPRINT("\r\n");
     d7a_com_rx_msg_t* pkt;
-    int8_t status;
+    int8_t status = FS_STAT_OK;
     
     while (true)
     {
@@ -275,7 +285,7 @@
                     b->length = props->length;
                     b->cmd    = FS_OP_RETSTAT;
                     b->status = FS_STAT_OK;
-                    d7a_fs_msg((uint8_t*)b,OP_SIZE_RETSTAT + sizeof(d7a_fs_properties_t), KAL_COM_FLOW_FS_RESP);
+                    d7a_fs_msg((uint8_t*)b, OP_SIZE_RETSTAT + sizeof(d7a_fs_properties_t), KAL_COM_FLOW_FS_RESP);
                     FREE(b);
                 }
                 else if (req->cmd == FS_OP_FLUSH)
@@ -288,20 +298,24 @@
                     //d7a_fs_create(req->fid,(d7a_fs_properties_t*)&pkt->buffer[OP_SIZE_CREATE]);
                     //d7a_fs_msg((uint8_t*)&buf, OP_SIZE_RETSTAT, KAL_COM_FLOW_FS_RESP);
                 }
+                else
+                {
+                    ASSERT(false, "FS: Unknown cmd %d\r\n", req->cmd);
+                }
                 break;
             // ---------------------------------------------------------------------------
             // Response to our commands
             // ---------------------------------------------------------------------------
             case KAL_COM_FLOW_FS_RESP:
                 d7a_fs_com_resp_t* resp = (d7a_fs_com_resp_t*)pkt->buffer;
-                DPRINT("Rfs resp - status:%d bytes:%d\n",resp->status,resp->length);
-                ASSERT(g_fs_ctx.com.req.cmd !=FS_OP_NULL,"FS: Unexpected FS_RESP\n");
+                DPRINT("Rfs resp - cmd:%d status:%d bytes:%d\n", resp->cmd, resp->status, resp->length);
+                ASSERT(g_fs_ctx.com.req.cmd != FS_OP_NULL, "FS: Unexpected FS_RESP\n");
                 if (g_fs_ctx.com.req.cmd != FS_OP_STAT &&
                     g_fs_ctx.com.req.cmd != FS_OP_DSTAT )
                 {
                     // No pity for errors here, handled-ones should be avoided at
                     // upper level, the others diserve to assert anyway.
-                    ASSERT(resp->status==FS_STAT_OK,"FS: Peer error:%d\n",resp->status);
+                    ASSERT(resp->status == FS_STAT_OK, "FS: Peer error:%d\n", resp->status);
     
                     // Fill read buffer
                     if (resp->cmd == FS_OP_RETDATA)
@@ -342,13 +356,16 @@
                         }
                     }
                     // TODO: for now only keep length info for upper layer. (normal for a STAT)
-                    if (g_fs_ctx.com.data!=NULL) *(uint32_t*)g_fs_ctx.com.data = resp->length;
+                    if (g_fs_ctx.com.data != NULL)
+                    {
+                         *(uint32_t*)g_fs_ctx.com.data = resp->length;
+                    }
                     status = resp->status;
                 }
                 // Free to serve a new request
                 g_fs_ctx.com.req.cmd = FS_OP_NULL;
                 // Inform requester
-                g_fs_ctx.fs_done->release();
+                g_fs_ctx.fs_done.put((void*)status);
                 break;
             default:
                 EPRINT("FS Unknown Flow ID 0x%02X\r\n", pkt->id);
    