由于自己最近开发记步算法有些问题一直记步十分不准确,先发一个如何使用mbed来使用rtos的帖子。先给一个线程打印实现程序:, H" ~; e* k% S0 n, o* H
#include "rtos.h"#include "mbed.h" u2 {+ c: W, K5 H8 i( B$ F0 y b Serial pc(SERIAL_TX, SERIAL_RX); uint8_t theadindex[2];6 O9 v. j4 D: K( S9 h/ i //线程打印的数字 long count[2];8 s0 Q5 r% q9 c void printstr(void const *args) E9 c4 j" E6 r1 u) k0 }2 B% v3 R { 1 D# g. m2 m" T1 m while (true) { _9 i2 ]$ _8 ^; d4 Y count[*(uint8_t *)args-1]++;* k( n1 y$ c/ c' S Thread::wait(500);$ G1 J3 `, ]5 T/ H' S7 V K8 _ ! G% a& |0 A6 P. p5 y2 e } ' t7 S! c; p/ A/ W, h }7 e4 a% t2 A/ {; q9 T ! n6 A5 s( J2 w! f: m6 ?& E int main() ) L9 F$ S9 w2 }! P0 }! h {$ I2 A5 ?7 c& A& d5 n( B 6 |* f3 o. W0 g9 I1 c8 U! D+ m theadindex[0]=1; theadindex[1]=2;, O) E/ k+ }3 m" F7 K' C# O3 l6 @ Thread thread1(printstr,(void *)theadindex,osPriorityNormal); Thread thread2(printstr,(void *)(theadindex+1),osPriorityHigh);- O/ M7 z- `$ L9 f+ s4 w while (1) {% I8 t+ `+ W0 L0 I( P i4 ~" z# v pc.printf("Thread1 count is %ld,Thread2 count is %ld. \n",count[0],count[1]); 1 q/ j# g& Z# c# S0 ~! v% ` Thread::wait(1000); / p$ L7 A$ s: I, y+ S. ^ }" @8 v% @& r; j8 L3 T2 B }2 L. x" _5 s, _% L ; Y; K1 S# Z9 Y% k/ b5 V+ c% G3 r& c' W ' G$ V, z9 {/ r% h) R' `4 D6 j
运行结果如下- g( ~( p% E# K- g9 L
|
多谢分享 |
| 感谢分享!顶一个! |
| 感谢分享 |
| 这个问题很好! |
| 学习一下。 |
| 不错 |
| MBED现在很火啊。 |
| 貌似很高端的样子 |
| 不错,谢谢分享@ |
| 楼主可以把怎么导入RTOS写一下嘛 |
微信公众号
手机版