看Freertos头文件Semphr.h的注释。 % R9 [0 e3 C8 l! e, n7 r2) Resource management.- S/ S/ h: C# Y% ^" K' b$ v4 e
* In this usage scenario the count value indicates the number of resources) C- @( D& {( g/ ?
* available. To obtain control of a resource a task must first obtain a$ L% Q2 c) C B
* semaphore - decrementing the semaphore count value. When the count value " r5 P& E* V* ?+ j$ f3 e9 X3 } * reaches zero there are no free resources. When a task finishes with the 1 N% S' ?2 t4 H0 S2 I3 r * resource it 'gives' the semaphore back - incrementing the semaphore count : Y8 u) X! j+ n, ?4 j+ o * value. In this case it is desirable for the initial count value to be5 { E1 P: v0 |1 Y4 e
* equal to the maximum count value, indicating that all resources are free.
刚刚贴的代码怎么不见了?再贴一遍头文件中的注释,很明了:6 l' f+ i2 e1 k8 u6 l M
* Counting semaphores are typically used for two things: 0 T0 h. {+ I# B *" f: f7 H+ l2 [' U5 n, B; i
* 1) Counting events. ' l4 ~/ t2 R' L& R * ) s6 f# X7 p0 N! A * In this usage scenario an event handler will 'give' a semaphore each time, l! V+ ]+ J; D: D$ h1 ]! K
* an event occurs (incrementing the semaphore count value), and a handler ( l1 o/ I0 G2 g( C" d/ @- q5 Q6 t * task will 'take' a semaphore each time it processes an event - {( M* J9 G7 e4 h * (decrementing the semaphore count value). The count value is therefore & l4 y1 M; q; H. ?9 ~- ^: ` * the difference between the number of events that have occurred and the + Q5 R, m$ X! E * number that have been processed. In this case it is desirable for the - H- _/ A T3 h6 V l% |- b4 y * initial count value to be zero.2 ~! I, ^4 x3 }4 c3 A! o* a
*9 r# c% d( R! K; ^
* 2) Resource management. 7 U( W+ Y: ^5 |( |6 S * J5 `2 @( e$ p
* In this usage scenario the count value indicates the number of resources / \; o* u' Q% {& s4 Z; S2 t * available. To obtain control of a resource a task must first obtain a2 A- z F: X. f s# H, g9 N
* semaphore - decrementing the semaphore count value. When the count value2 D0 s6 H% x1 I! L
* reaches zero there are no free resources. When a task finishes with the3 f0 z0 T" v7 A
* resource it 'gives' the semaphore back - incrementing the semaphore count. I) N# B2 i$ f
* value. In this case it is desirable for the initial count value to be , i6 @4 t$ j2 \& X * equal to the maximum count value, indicating that all resources are free.
看帖 应该 就知道很好用了 基本上 点几下鼠标就创建一个可以直接使用的 工程
那只是可用,效率怎么样呢
本人建议 库只用于 比较复杂的 外设初始化 比如 串口 ,SPI SDIO等等4 U" i |9 E; \( J; J0 L/ Q- U! \
8 k. w7 H+ w' D
初始化完成之后的操作 建议使用寄存器
2) Resource management.- S/ S/ h: C# Y% ^" K' b$ v4 e
* In this usage scenario the count value indicates the number of resources) C- @( D& {( g/ ?
* available. To obtain control of a resource a task must first obtain a$ L% Q2 c) C B
* semaphore - decrementing the semaphore count value. When the count value
* reaches zero there are no free resources. When a task finishes with the
* resource it 'gives' the semaphore back - incrementing the semaphore count
* value. In this case it is desirable for the initial count value to be5 { E1 P: v0 |1 Y4 e
* equal to the maximum count value, indicating that all resources are free.
* Counting semaphores are typically used for two things:
*" f: f7 H+ l2 [' U5 n, B; i
* 1) Counting events.
*
* In this usage scenario an event handler will 'give' a semaphore each time, l! V+ ]+ J; D: D$ h1 ]! K
* an event occurs (incrementing the semaphore count value), and a handler
* task will 'take' a semaphore each time it processes an event
* (decrementing the semaphore count value). The count value is therefore
* the difference between the number of events that have occurred and the
* number that have been processed. In this case it is desirable for the
* initial count value to be zero.2 ~! I, ^4 x3 }4 c3 A! o* a
*9 r# c% d( R! K; ^
* 2) Resource management.
* J5 `2 @( e$ p
* In this usage scenario the count value indicates the number of resources
* available. To obtain control of a resource a task must first obtain a2 A- z F: X. f s# H, g9 N
* semaphore - decrementing the semaphore count value. When the count value2 D0 s6 H% x1 I! L
* reaches zero there are no free resources. When a task finishes with the3 f0 z0 T" v7 A
* resource it 'gives' the semaphore back - incrementing the semaphore count. I) N# B2 i$ f
* value. In this case it is desirable for the initial count value to be
* equal to the maximum count value, indicating that all resources are free.
是的 因为我的 资源一开始是不可用的 1 b- I5 |( F" c
这是典型的 生产消费问题; l" q% c! b2 c) R8 C% d
! c( b+ E8 J# E0 d5 X& C3 O* }
串口接收数据(生产)
$ d3 j4 h6 J/ {" U7 f" w
线程消费数据
9 j5 X% x2 r! [7 F1 e& y
一开始是没有现成的数据的
而这个 函数接口 只能以另一种方式使用那就是一开始就存在资源,这在实际使用中是不合理的!!
哈哈 你来晚了钱都被他们拿完了~~