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.
Dependencies: fll mbed-rtos mbed
Diff: fll.cpp
- Revision:
- 34:422d4d6ae5ea
- Parent:
- 33:cc84b10e6c67
diff -r cc84b10e6c67 -r 422d4d6ae5ea fll.cpp
--- a/fll.cpp Tue Feb 17 03:22:36 2015 +0000
+++ b/fll.cpp Tue Feb 17 06:28:32 2015 +0000
@@ -20,12 +20,18 @@
source = src;
mail_box = box;
mutex = mut;
+ paused = true;
+ temporary_size = 0;
+
}
void Sink::run()
{
button_t *btn;
while(1) {
+ if (paused) {
+ continue;
+ }
mutex->lock();
btn = mail_box->alloc();
if(!btn) {
@@ -38,7 +44,43 @@
}
}
-void Sink::reset()
+void Sink::resume()
+{
+ if (!paused) {
+ return;
+ }
+ button_t *btn;
+ mutex->lock();
+ for (int i = 0; i < temporary_size; i++) {
+ btn = mail_box->alloc();
+ *btn = temporary[i];
+ mail_box->put(btn);
+ }
+ mutex->unlock();
+ paused = false;
+}
+
+void Sink::pause()
+{
+ if (paused) {
+ return;
+ }
+ paused = true;
+ mutex->lock();
+ osEvent e;
+ int i = 0;
+ do {
+ e = mail_box->get(0);
+ if(e.status == osEventMail) {
+ mail_box->free((button_t*)e.value.p);
+ temporary[i++] = *(button_t*)(e.value.p);
+ }
+ } while (e.status == osEventMail);
+ temporary_size = i;
+ mutex->unlock();
+}
+
+void Sink::restart()
{
mutex->lock();
osEvent e;
@@ -50,6 +92,7 @@
} while (e.status == osEventMail);
// reset source
source->reset();
+ temporary_size = 0;
mutex->unlock();
}
@@ -93,53 +136,56 @@
FLL::FLL(Producer* p)
{
producer = p;
-
+
// button_no -> pin (R1 to L1)
PinName ps[] = {
- p10, p5, p6, p7, p8, p9,
- p11, p12, p13, p18, p16, p17, p15,
- p19, p14,
+ p5, p6, p7, p8, p9,
+ p10, p11, p12, p13, p14, p15,
+ p16, p17, p18, p19,
};
-
+
for(int i = 0; i < BUTTON_NUM; i++) {
- off[i] = new int(1);
- pin[i] = new DigitalOut(ps[i], *off[i]);
+ off[i] = 1;
+ pin[i] = new DigitalOut(ps[i], off[i]);
}
}
FLL::~FLL()
{
for(int i = 0; i < BUTTON_NUM; i++) {
- delete off[i];
delete pin[i];
}
}
-// button-pin mapping table
void FLL::press(button_t btn)
{
for(int i = 0; i < BUTTON_NUM; i++) {
if ((btn >> i) & 0x1) {
- pin[i]->write(!(*off[i]));
+ pin[i]->write(!off[i]);
} else {
- pin[i]->write(*off[i]);
+ pin[i]->write(off[i]);
}
}
}
void FLL::run()
{
+
Mail<button_t, MAIL_BOX_SIZE>* mail_box = new Mail<button_t, MAIL_BOX_SIZE>();
Mutex* mutex = new Mutex();
+ Sink* sink = new Sink(producer, mail_box, mutex);
+ Output* output = new Output(mail_box, this);
- Sink* sink = new Sink(producer, mail_box, mutex);
- InterruptIn reset_pin(p20);
- reset_pin.fall(sink, &Sink::reset);
+ InterruptIn reset_pin(p21);
+ InterruptIn resume_pin(p22);
+ InterruptIn pause_pin(p23);
+ reset_pin.rise(sink, &Sink::restart);
+ resume_pin.rise(sink, &Sink::resume);
+ pause_pin.rise(sink, &Sink::pause);
+
+ Thread th(invoke_sinkrun, (void *)sink);
Ticker ticker;
- Output* output = new Output(mail_box, this);
-
- Thread th(invoke_sinkrun, (void *)sink);
ticker.attach(output, &Output::run, FRAME);
Thread::wait(osWaitForever);
