sample K64F program using the RTOS (fully updated + Mbed sdk updated) with EthernetInterface added

Dependencies:   EthernetInterface mbed-rtos mbed

Committer:
ansond
Date:
Sat Dec 13 23:37:15 2014 +0000
Revision:
0:12187df41036
updated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:12187df41036 1 #include "mbed.h"
ansond 0:12187df41036 2 #include "rtos.h"
ansond 0:12187df41036 3
ansond 0:12187df41036 4 DigitalOut led1(LED1);
ansond 0:12187df41036 5 InterruptIn sw2(SW2);
ansond 0:12187df41036 6 uint32_t button_pressed;
ansond 0:12187df41036 7 Thread *thread2;
ansond 0:12187df41036 8
ansond 0:12187df41036 9 void sw2_press(void)
ansond 0:12187df41036 10 {
ansond 0:12187df41036 11 thread2->signal_set(0x1);
ansond 0:12187df41036 12 }
ansond 0:12187df41036 13
ansond 0:12187df41036 14 void led_thread(void const *argument)
ansond 0:12187df41036 15 {
ansond 0:12187df41036 16 while (true) {
ansond 0:12187df41036 17 led1 = !led1;
ansond 0:12187df41036 18 Thread::wait(1000);
ansond 0:12187df41036 19 }
ansond 0:12187df41036 20 }
ansond 0:12187df41036 21
ansond 0:12187df41036 22 void button_thread(void const *argument)
ansond 0:12187df41036 23 {
ansond 0:12187df41036 24 while (true) {
ansond 0:12187df41036 25 Thread::signal_wait(0x1);
ansond 0:12187df41036 26 button_pressed++;
ansond 0:12187df41036 27 }
ansond 0:12187df41036 28 }
ansond 0:12187df41036 29
ansond 0:12187df41036 30 int main()
ansond 0:12187df41036 31 {
ansond 0:12187df41036 32 Thread thread(led_thread);
ansond 0:12187df41036 33 thread2 = new Thread(button_thread);
ansond 0:12187df41036 34
ansond 0:12187df41036 35 button_pressed = 0;
ansond 0:12187df41036 36 sw2.fall(&sw2_press);
ansond 0:12187df41036 37 while (true) {
ansond 0:12187df41036 38 Thread::wait(5000);
ansond 0:12187df41036 39 printf("SW2 was pressed (last 5 seconds): %d \n", button_pressed);
ansond 0:12187df41036 40 fflush(stdout);
ansond 0:12187df41036 41 button_pressed = 0;
ansond 0:12187df41036 42 }
ansond 0:12187df41036 43 }