4、信号量(semaphore)
2022-11-30 14:43:31 1 举报
AI智能生成
v
作者其他创作
大纲/内容
特性
信号 --> 通知作用 量 --> 表示资源的数量
Counting Semaphores(计数型信号量) give +1, take -1
Binary Semaphores(二进制信号量) 最大为1
函数
创建
动态创建
SemaphoreHandle_t <b><font color="#64b5f6">xSemaphoreCreateBinary</font></b>( void );
SemaphoreHandle_t <b><font color="#64b5f6">xSemaphoreCreateCounting</font></b>(UBaseType_t <b>uxMaxCount</b>, UBaseType_t <b>uxInitialCount</b>);<br>
静态创建
SemaphoreHandle_t <b><font color="#64b5f6">xSemaphoreCreateBinaryStatic</font></b>( StaticSemaphore_t *<b>pxSemaphoreBuffer </b>);<br>
SemaphoreHandle_t <b><font color="#64b5f6">xSemaphoreCreateCountingStatic</font></b>( UBaseType_t <b>uxMaxCount</b>,<br> UBaseType_t <b>uxInitialCount</b>,<br> StaticSemaphore_t *<b>pxSemaphoreBuffer </b> );
参数 <b><font color="#7b1fa2">uxMaxCount </font></b> 最大计数值 <b><font color="#7b1fa2">uxInitialCount </font></b>初始计数值 <b><font color="#7b1fa2">pxSemaphoreBuffer</font></b> StaticSemaphore_t结构体指针<br>
删除
void <b><font color="#64b5f6">vSemaphoreDelete</font></b>( SemaphoreHandle_t <b>xSemaphore </b>);
give/take
在任务中使用
BaseType_t <b><font color="#64b5f6">xSemaphoreGive</font></b>( SemaphoreHandle_t <b>xSemaphore </b>);<br>
BaseType_t <b><font color="#64b5f6">xSemaphoreTake</font></b>(<br> SemaphoreHandle_t <b>xSemaphore</b>,<br> TickType_t <b>xTicksToWait</b><br> );<br>
ISR中使用
BaseType_t <b><font color="#64b5f6">xSemaphoreGiveFromISR</font></b>(<br> SemaphoreHandle_t <b>xSemaphore</b>,<br> BaseType_t *<b>pxHigherPriorityTaskWoken</b><br> );<br>
BaseType_t <b><font color="#64b5f6">xSemaphoreTakeFromISR</font></b>(<br> SemaphoreHandle_t <b>xSemaphore</b>,<br> BaseType_t *<b>pxHigherPriorityTaskWoken</b><br> );<br><br>
参数 <b><font color="#7b1fa2">pxHigherPriorityTaskWoken </font></b>如果释放信号量导致更高优先级的任务变为了就绪态,则<b><font color="#000000">*pxHigherPriorityTaskWoken = pdTRUE 返回值 </font></b>pdTRUE --> 成功 如果二进制信号量的计数值已经是1,再次调用此函数则返回失败; 如果计数型信号量的计数值已经是最大值,再次调用此函数则返回失败<br>
0 条评论
下一页