
First
Fork of TEN_mbedos_threads by
main.cpp@1:d1d5c33000fb, 2017-03-02 (annotated)
- Committer:
- narasimma23
- Date:
- Thu Mar 02 07:57:50 2017 +0000
- Revision:
- 1:d1d5c33000fb
- Parent:
- 0:95bee34b8805
- Child:
- 2:967778096fa0
Thread test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
uLipe | 0:95bee34b8805 | 1 | /** |
uLipe | 0:95bee34b8805 | 2 | * @brief first thread control program with MBED OS |
uLipe | 0:95bee34b8805 | 3 | */ |
uLipe | 0:95bee34b8805 | 4 | #include "mbed.h" |
uLipe | 0:95bee34b8805 | 5 | #include "rtos.h" |
uLipe | 0:95bee34b8805 | 6 | |
narasimma23 | 1:d1d5c33000fb | 7 | #define THREAD_A "thread_a" |
narasimma23 | 1:d1d5c33000fb | 8 | #define THREAD_B "thread_b" |
narasimma23 | 1:d1d5c33000fb | 9 | #define THREAD_C "thread_c" |
uLipe | 0:95bee34b8805 | 10 | |
uLipe | 0:95bee34b8805 | 11 | /* reserve the debbuger uart to shell interface */ |
uLipe | 0:95bee34b8805 | 12 | Serial pc_serial(USBTX,USBRX); |
uLipe | 0:95bee34b8805 | 13 | |
narasimma23 | 1:d1d5c33000fb | 14 | /* declares threads for this demo: */ |
narasimma23 | 1:d1d5c33000fb | 15 | const size_t a_stk_size = 512; |
narasimma23 | 1:d1d5c33000fb | 16 | uint8_t a_stk[a_stk_size]; |
narasimma23 | 1:d1d5c33000fb | 17 | Thread a_thread(osPriorityNormal, a_stk_size, &a_stk[0]); |
narasimma23 | 1:d1d5c33000fb | 18 | |
narasimma23 | 1:d1d5c33000fb | 19 | const size_t b_stk_size = 512; |
narasimma23 | 1:d1d5c33000fb | 20 | uint8_t b_stk[b_stk_size]; |
narasimma23 | 1:d1d5c33000fb | 21 | Thread b_thread(osPriorityNormal, b_stk_size, &b_stk[0]); |
narasimma23 | 1:d1d5c33000fb | 22 | |
narasimma23 | 1:d1d5c33000fb | 23 | const size_t c_stk_size = 512; |
narasimma23 | 1:d1d5c33000fb | 24 | uint8_t c_stk[c_stk_size]; |
narasimma23 | 1:d1d5c33000fb | 25 | Thread c_thread(osPriorityNormal, c_stk_size, &c_stk[0]); |
uLipe | 0:95bee34b8805 | 26 | |
uLipe | 0:95bee34b8805 | 27 | /** |
uLipe | 0:95bee34b8805 | 28 | * @brief thread a function |
uLipe | 0:95bee34b8805 | 29 | */ |
narasimma23 | 1:d1d5c33000fb | 30 | static void thread(void const *buf) |
uLipe | 0:95bee34b8805 | 31 | { |
uLipe | 0:95bee34b8805 | 32 | uint32_t execs = 0; |
narasimma23 | 1:d1d5c33000fb | 33 | pc_serial.printf("## started %s execution! ##\n\r", (char *)buf); |
uLipe | 0:95bee34b8805 | 34 | |
uLipe | 0:95bee34b8805 | 35 | for(;;) { |
uLipe | 0:95bee34b8805 | 36 | execs++; |
uLipe | 0:95bee34b8805 | 37 | /* adds dummy processing */ |
uLipe | 0:95bee34b8805 | 38 | for(int i = 0 ; i < 0xFFFFFF; i++); |
narasimma23 | 1:d1d5c33000fb | 39 | pc_serial.printf("## %s executed %d times! ##\n\r", (char *)buf, execs); |
narasimma23 | 1:d1d5c33000fb | 40 | Thread::yield(); |
uLipe | 0:95bee34b8805 | 41 | } |
uLipe | 0:95bee34b8805 | 42 | } |
uLipe | 0:95bee34b8805 | 43 | |
uLipe | 0:95bee34b8805 | 44 | |
uLipe | 0:95bee34b8805 | 45 | /** |
uLipe | 0:95bee34b8805 | 46 | * @brief main application loop |
uLipe | 0:95bee34b8805 | 47 | */ |
uLipe | 0:95bee34b8805 | 48 | int main(void) |
narasimma23 | 1:d1d5c33000fb | 49 | { |
uLipe | 0:95bee34b8805 | 50 | pc_serial.baud(115200); |
narasimma23 | 1:d1d5c33000fb | 51 | a_thread.start(callback(thread, (void *)THREAD_A)); |
narasimma23 | 1:d1d5c33000fb | 52 | b_thread.start(callback(thread, (void *)THREAD_B)); |
narasimma23 | 1:d1d5c33000fb | 53 | c_thread.start(callback(thread, (void *)THREAD_C)); |
uLipe | 0:95bee34b8805 | 54 | return 0; |
uLipe | 0:95bee34b8805 | 55 | } |