1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
diff --git a/firmware/target/arm/as3525/dbop-as3525.c b/firmware/target/arm/as3525/dbop-as3525.c
index 5e7b7bd..9e2cfe5 100644
--- a/firmware/target/arm/as3525/dbop-as3525.c
+++ b/firmware/target/arm/as3525/dbop-as3525.c
@@ -32,7 +32,10 @@
 #endif

 static struct wakeup dbop_wakeup;
+static struct wakeup dbop_wakeup2;
 static struct semaphore dbop_sem;
+static struct mutex dbop_mutex;
+static struct queue_sender_list dbop_qsl;
 static struct event_queue dbop_ev;

 static char dbop_thread_name[] = "dbop";
@@ -54,16 +57,19 @@ static void dbop_thread(void)
         c = *(struct dbop_ctx*)ev.data;
         dbop_write_data_ex(c.ptr, c.count);
         semaphore_release(&dbop_sem);
+        wakeup_signal(&dbop_wakeup2);
     }
 }

 void dbop_init(void)
 {
     wakeup_init(&dbop_wakeup);
+    wakeup_init(&dbop_wakeup2);
+    mutex_init(&dbop_mutex);
     semaphore_init(&dbop_sem, 1, 0);
     queue_init(&dbop_ev, true);

-    create_thread(dbop_thread, dbop_thread_stack, sizeof(dbop_thread_stack),
+    int id = create_thread(dbop_thread, dbop_thread_stack, sizeof(dbop_thread_stack),
                        0, dbop_thread_name IF_PRIO(, PRIORITY_REALTIME)
                        IF_COP(, CPU));
 }
@@ -224,7 +230,7 @@ static void dbop_write_data_ex(const int16_t* p_bytes, int count)
     /* due to the 32bit alignment requirement or uneven count,
      * we possibly need to do a 16bit transfer at the end also */
     if (count > 0)
-        dbop_write_data((int16_t*)data, 1);
+        dbop_write_data_ex((int16_t*)data, 1);
 }

 void dbop_write_data(const int16_t* p_bytes, int count)
@@ -243,4 +249,5 @@ void dbop_write_data(const int16_t* p_bytes, int count)
     c.count = count;
     /* async transfer from here */
     queue_post(&dbop_ev, 0, (intptr_t)(&c));
+    wakeup_wait(&dbop_wakeup2, TIMEOUT_BLOCK);
 }