Trond Enger / d7a_1x

Fork of d7a_1x by WizziLab

Revision:
49:81d5bddb02f0
Parent:
46:665391110051
Child:
51:644de6fe1ee7
--- a/src/d7a_fs.cpp	Fri Sep 02 10:07:12 2016 +0000
+++ b/src/d7a_fs.cpp	Fri Sep 02 16:08:09 2016 +0000
@@ -38,7 +38,8 @@
 typedef struct {
     Thread* thread;
     Queue<void, 8> fs_done;
-    const d7a_fs_callbacks_t* callback;
+    WriteFileFunction write_file;
+    ReadFileFunction read_file;
     Queue<d7a_com_rx_msg_t, 16> pkt_queue;
     uint8_t  hdr_map[FS_MAX_FILE_QTY];
     uint8_t  nb_files;
@@ -49,12 +50,15 @@
 
 void d7a_fs_thread(const void *p);
 
-void d7a_fs_open(const d7a_fs_callbacks_t* config)
+d7a_errors_t d7a_fs_open(WriteFileFunction wf, ReadFileFunction rf)
 {
     FPRINT("\r\n");
     
-    g_fs_ctx.callback = config;
+    g_fs_ctx.write_file = wf;
+    g_fs_ctx.read_file = rf;
     g_fs_ctx.thread = new Thread(d7a_fs_thread, NULL, osPriorityHigh, DEFAULT_STACK_SIZE);
+    
+    return D7A_ERR_NONE;
 }
 
 static void d7a_fs_msg(uint8_t* buf, uint8_t len, uint8_t id)
@@ -81,11 +85,6 @@
     return (evt.status == osEventMessage)? (d7a_com_rx_msg_t*)evt.value.p : NULL;
 }
 
-void d7a_fs_notif_done(const uint8_t file_id, const uint8_t error)
-{
-    g_fs_ctx.callback->notif_done(file_id, error);
-}
-
 
 #define OP_SIZE_RD      11
 #define OP_SIZE_WR      11
@@ -158,7 +157,7 @@
                 else if (req->cmd == FS_OP_RD)
                 {
                     d7a_fs_com_resp_t* b = (d7a_fs_com_resp_t*)MALLOC(OP_SIZE_RETDATA + req->length);
-                    uint32_t len = g_fs_ctx.callback->read_file(req->fid, req->offset, req->length, &b->data[0]);
+                    uint32_t len = g_fs_ctx.read_file(req->fid, req->offset, req->length, &b->data[0]);
                     b->id     = req->id;
                     b->length = len;
                     b->cmd    = FS_OP_RETDATA;
@@ -168,7 +167,7 @@
                 }
                 else if (req->cmd == FS_OP_WR)
                 {
-                    buf.length = g_fs_ctx.callback->write_file(req->fid, req->offset, req->length, &pkt->buffer[OP_SIZE_WR]);
+                    buf.length = g_fs_ctx.write_file(req->fid, req->offset, req->length, &pkt->buffer[OP_SIZE_WR]);
                     d7a_fs_msg((uint8_t*)&buf, OP_SIZE_RETSTAT, KAL_COM_FLOW_FS_RESP);
                 }
                 else if (req->cmd == FS_OP_TOUCH)