Example to show how priority can be used to ensure timing critical task can be run

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
simon
Date:
Tue Aug 17 10:14:44 2010 +0000
Commit message:

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 2b952ccae54d main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Aug 17 10:14:44 2010 +0000
@@ -0,0 +1,46 @@
+// Example running the mbed Tickers at a lower priority
+
+#include "mbed.h"
+
+volatile int counter = 0;
+void timing_critical() {
+    counter++;
+}
+
+void long_event() {
+    wait_ms(50);
+}
+
+PwmOut out(p25);
+InterruptIn in(p26);
+Ticker tick;
+
+int main() {
+    out.period_ms(10);
+    out.pulsewidth_ms(5);
+    in.rise(&timing_critical);
+
+    printf("1) InterruptIn only...\n");    
+    for(int i=0; i<5; i++) {
+        counter = 0;
+        wait(1);
+        printf("counts/sec = %d\n", counter);
+    }
+
+    tick.attach(&long_event, 0.1);    
+    
+    printf("2) InterruptIn plus long running occasional ticker event...\n");    
+    for(int i=0; i<5; i++) {
+        counter = 0;
+        wait(1);
+        printf("count/sec = %d\n", counter);
+    }
+    
+    printf("3) InterruptIn plus long running occasional ticker event at lower priority...\n");    
+    NVIC_SetPriority(TIMER3_IRQn, 255); // set mbed tickers to lower priority than other things
+    for(int i=0; i<5; i++) {
+        counter = 0;
+        wait(1);
+        printf("counter = %d\n", counter);
+    }
+}
diff -r 000000000000 -r 2b952ccae54d mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Aug 17 10:14:44 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9114680c05da