由于自己最近开发记步算法有些问题一直记步十分不准确,先发一个如何使用mbed来使用rtos的帖子。先给一个线程打印实现程序:2 w! b) Z) d s4 ^) S1 i$ n) a' b
#include "rtos.h"#include "mbed.h" Serial pc(SERIAL_TX, SERIAL_RX); uint8_t theadindex[2]; //线程打印的数字 long count[2]; void printstr(void const *args) { while (true) { count[*(uint8_t *)args-1]++; Thread::wait(500); } * G# E. l! @7 L" y } int main() ) x, F4 S1 I4 g9 i2 P9 e. t, X . L: }( x) F! x# ?1 n6 F/ ~" J {* Q, Y: @4 d$ W# Q1 b. T+ x# n1 k3 h theadindex[0]=1; 4 \# j+ P9 S9 V! @$ h+ u theadindex[1]=2; 1 j" d& R0 K* S" a Thread thread1(printstr,(void *)theadindex,osPriorityNormal); * P5 Z6 t# e7 m2 z! W Thread thread2(printstr,(void *)(theadindex+1),osPriorityHigh); while (1) {2 {2 W E$ l5 P e$ Q 2 s6 f) Q. n9 i8 | pc.printf("Thread1 count is %ld,Thread2 count is %ld. \n",count[0],count[1]);3 B$ u4 u( I3 Q! Z0 m- N- p $ \" h9 L% D, g& [! J* R) w Thread::wait(1000);# S+ B% d; ^- B2 m) D 9 z7 o' F3 ^% `* F0 o. k) i% t }0 @3 \+ M) p: @7 E( I( h1 V) h6 R : K$ Q: i, C. t/ D6 Z }! O$ f J$ z9 _
运行结果如下
|
多谢分享 |
| 感谢分享!顶一个! |
| 感谢分享 |
| 这个问题很好! |
| 学习一下。 |
| 不错 |
| MBED现在很火啊。 |
| 貌似很高端的样子 |
| 不错,谢谢分享@ |
| 楼主可以把怎么导入RTOS写一下嘛 |
微信公众号
手机版