
First
Fork of TEN_mbedos_threads by
Diff: main.cpp
- Revision:
- 1:d1d5c33000fb
- Parent:
- 0:95bee34b8805
- Child:
- 2:967778096fa0
--- a/main.cpp Sun Jan 29 20:42:49 2017 +0000 +++ b/main.cpp Thu Mar 02 07:57:50 2017 +0000 @@ -4,63 +4,52 @@ #include "mbed.h" #include "rtos.h" -/* declares threads for this demo: */ -const size_t a_stk_size = 1024; -uint8_t a_stk[a_stk_size]; -Thread a_thread(osPriorityNormal, a_stk_size, &a_stk[0]); - -const size_t b_stk_size = 1024; -uint8_t b_stk[b_stk_size]; -Thread b_thread(osPriorityNormal, b_stk_size, &b_stk[0]); +#define THREAD_A "thread_a" +#define THREAD_B "thread_b" +#define THREAD_C "thread_c" /* reserve the debbuger uart to shell interface */ Serial pc_serial(USBTX,USBRX); +/* declares threads for this demo: */ +const size_t a_stk_size = 512; +uint8_t a_stk[a_stk_size]; +Thread a_thread(osPriorityNormal, a_stk_size, &a_stk[0]); + +const size_t b_stk_size = 512; +uint8_t b_stk[b_stk_size]; +Thread b_thread(osPriorityNormal, b_stk_size, &b_stk[0]); + +const size_t c_stk_size = 512; +uint8_t c_stk[c_stk_size]; +Thread c_thread(osPriorityNormal, c_stk_size, &c_stk[0]); /** * @brief thread a function */ -static void thread_a(void) +static void thread(void const *buf) { uint32_t execs = 0; - pc_serial.printf("## started thread_a execution! ##\n\r"); + pc_serial.printf("## started %s execution! ##\n\r", (char *)buf); for(;;) { execs++; /* adds dummy processing */ for(int i = 0 ; i < 0xFFFFFF; i++); - pc_serial.printf("## thread_a executed %d times! ##\n\r", execs); - a_thread.yield(); + pc_serial.printf("## %s executed %d times! ##\n\r", (char *)buf, execs); + Thread::yield(); } } /** - * @brief thread a function - */ -static void thread_b(void) -{ - uint32_t execs = 0; - pc_serial.printf("## started thread_b execution! ##\n\r"); - - for(;;) { - execs++; - /* adds dummy processing */ - for(int i = 0 ; i < 0xFFFFFF; i++); - pc_serial.printf("## thread_b executed %d times! ##\n\r", execs); - b_thread.yield(); - } -} - - - -/** * @brief main application loop */ int main(void) -{ +{ pc_serial.baud(115200); - a_thread.start(thread_a); - b_thread.start(thread_b); + a_thread.start(callback(thread, (void *)THREAD_A)); + b_thread.start(callback(thread, (void *)THREAD_B)); + c_thread.start(callback(thread, (void *)THREAD_C)); return 0; } \ No newline at end of file