test
Dependencies: mbed-STM32F103C8T6 mbed-rtos mbed-dev
main.cpp@2:f48b0967b6cc, 2020-04-16 (annotated)
- Committer:
- hankzhang
- Date:
- Thu Apr 16 07:15:00 2020 +0000
- Revision:
- 2:f48b0967b6cc
- Parent:
- 1:0fe432e5dfc4
- Child:
- 3:30d61fa10b98
test mul-ti thread;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
techneo | 0:217105958c2d | 1 | #include "mbed.h" |
bbw | 1:0fe432e5dfc4 | 2 | #include "stm32f103c8t6.h" |
bbw | 1:0fe432e5dfc4 | 3 | |
hankzhang | 2:f48b0967b6cc | 4 | DigitalOut led1(PC_13); |
techneo | 0:217105958c2d | 5 | |
hankzhang | 2:f48b0967b6cc | 6 | Serial pc(PA_9,PA_10); |
bbw | 1:0fe432e5dfc4 | 7 | |
hankzhang | 2:f48b0967b6cc | 8 | |
hankzhang | 2:f48b0967b6cc | 9 | void led2_thread() { |
hankzhang | 2:f48b0967b6cc | 10 | while (true) { |
hankzhang | 2:f48b0967b6cc | 11 | pc.printf("led2_thread\r\n"); |
hankzhang | 2:f48b0967b6cc | 12 | thread_sleep_for(4000); |
techneo | 0:217105958c2d | 13 | } |
techneo | 0:217105958c2d | 14 | } |
techneo | 0:217105958c2d | 15 | |
hankzhang | 2:f48b0967b6cc | 16 | void led1_thread() { |
hankzhang | 2:f48b0967b6cc | 17 | while (true) { |
hankzhang | 2:f48b0967b6cc | 18 | pc.printf("led1_thread\r\n"); |
hankzhang | 2:f48b0967b6cc | 19 | thread_sleep_for(3000); |
hankzhang | 2:f48b0967b6cc | 20 | } |
hankzhang | 2:f48b0967b6cc | 21 | } |
bbw | 1:0fe432e5dfc4 | 22 | |
hankzhang | 2:f48b0967b6cc | 23 | void led0_thread() { |
hankzhang | 2:f48b0967b6cc | 24 | while (true) { |
hankzhang | 2:f48b0967b6cc | 25 | pc.printf("led0_thread\r\n"); |
hankzhang | 2:f48b0967b6cc | 26 | thread_sleep_for(2000); |
bbw | 1:0fe432e5dfc4 | 27 | } |
bbw | 1:0fe432e5dfc4 | 28 | } |
hankzhang | 2:f48b0967b6cc | 29 | int main() { |
hankzhang | 2:f48b0967b6cc | 30 | pc.baud(115200); |
hankzhang | 2:f48b0967b6cc | 31 | pc.printf("hello world\r\n"); |
hankzhang | 2:f48b0967b6cc | 32 | |
hankzhang | 2:f48b0967b6cc | 33 | Thread thread0(osPriorityNormal, 512, nullptr, nullptr); |
hankzhang | 2:f48b0967b6cc | 34 | Thread thread1(osPriorityNormal, 512, nullptr, nullptr); |
hankzhang | 2:f48b0967b6cc | 35 | Thread thread2(osPriorityNormal, 512, nullptr, nullptr); |
hankzhang | 2:f48b0967b6cc | 36 | |
hankzhang | 2:f48b0967b6cc | 37 | thread0.start(led0_thread); |
hankzhang | 2:f48b0967b6cc | 38 | thread1.start(led1_thread); |
hankzhang | 2:f48b0967b6cc | 39 | thread2.start(led2_thread); |
hankzhang | 2:f48b0967b6cc | 40 | |
hankzhang | 2:f48b0967b6cc | 41 | while (true) { |
hankzhang | 2:f48b0967b6cc | 42 | //led1 = !led1; |
hankzhang | 2:f48b0967b6cc | 43 | thread_sleep_for(5000); |
hankzhang | 2:f48b0967b6cc | 44 | pc.printf("+++++main task++++++\r\n"); |
bbw | 1:0fe432e5dfc4 | 45 | } |
hankzhang | 2:f48b0967b6cc | 46 | } |