multi thread test(rtos)
Revision 0:76241820e391, committed 2013-03-18
- Comitter:
- ryought
- Date:
- Mon Mar 18 06:49:19 2013 +0000
- Commit message:
- First commit;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Mar 18 06:49:19 2013 +0000
@@ -0,0 +1,51 @@
+#include "mbed.h"
+#include "rtos.h"
+
+DigitalOut getcommand(LED1);
+Serial pc(USBTX, USBRX);
+DigitalOut leds[2] = {DigitalOut(LED2), DigitalOut(LED3)};
+DigitalOut threadled(LED4);
+
+char buf[2];
+char command[2];
+
+void led(void const *args) {
+ while(true) {
+ threadled = !threadled;
+ Thread::wait(100);
+ }
+}
+
+
+int main() {
+ Thread thread(led);
+
+ while(1) {
+ if (pc.readable()) {
+ pc.printf("something get\n");
+ buf[0] = pc.getc();
+ buf[1] = pc.getc();
+ if (buf[0] == 0xFF && buf[1] == 0xFF) {
+ getcommand = 1;
+ pc.printf("its a command!\n");
+
+ for(int i = 0; i < 2; i++) {
+ pc.printf("mgmg\n");
+ command[i] = pc.getc();
+ pc.printf("%x\n", command[i]);
+ }
+
+ switch (command[0]) {
+ case 0x01:
+ leds[0] = !leds[0];
+ pc.printf("led1 : on/off\n");
+ break;
+ case 0x02:
+ leds[1] = !leds[1];
+ pc.printf("led2 : on/off\n");
+ break;
+ }
+ }
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Mon Mar 18 06:49:19 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#53e6cccd8782
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Mar 18 06:49:19 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/5e5da4a5990b \ No newline at end of file
Ryo Nakabayashi