Shohei Yasutake / Mbed 2 deprecated koibumi2000

Dependencies:   fll mbed-rtos mbed

Revision:
26:08387521c994
Parent:
17:69536d02cb3c
Child:
33:cc84b10e6c67
diff -r f7ffeb4d99bc -r 08387521c994 fll.cpp
--- a/fll.cpp	Mon Feb 16 17:56:58 2015 +0000
+++ b/fll.cpp	Mon Feb 16 18:06:40 2015 +0000
@@ -35,6 +35,21 @@
     }
 }
 
+void Sink::reset()
+{
+    mutex->lock();
+    osEvent e;
+    do {
+        e = mail_box->get(0);
+        if(e.status == osEventMail) {
+            mail_box->free((button_t*)e.value.p);
+        }
+    } while (e.status == osEventMail);
+    // reset source
+    source->reset();
+    mutex->unlock();
+}
+
 void Sink::reset(Producer* src)
 {
     mutex->lock();
@@ -149,19 +164,14 @@
     Mutex* mutex = new Mutex();
 
     Sink* sink = new Sink(producer, mail_box, mutex);
+    InterruptIn reset_pin(p20);
+    reset_pin.fall(sink, &Sink::reset);
 
     Ticker ticker;
     Output* output = new Output(mail_box);
 
     Thread th(invoke_sinkrun, (void *)sink);
-    DigitalIn pin20(p20);
-    wait(1);
-    while (1) {
-        // pc.printf("pin20: %d\r\n", pin20.read());
-        if (pin20.read() == 1) {
-            break;
-        }
-    }
+
     ticker.attach(output, &Output::run, FRAME);
 
     Thread::wait(osWaitForever);