FreeRTOS学习笔记之信号量
一、創(chuàng)建信號量:
1. 動態(tài)創(chuàng)建信號量(自動分配內(nèi)存):
xSemaphoreCreateMutex:具有優(yōu)先級繼承關(guān)系,創(chuàng)建互斥信號量(一般用于保護(hù)全局變量,防止被意外修改);
xSemaphoreCreateBinary:新版本創(chuàng)建二進(jìn)制信號量(一般用于實(shí)現(xiàn)同步消息);創(chuàng)建的初始值為空,可以直接使用;
vSemaphoreCreateBinary:老版本創(chuàng)建二進(jìn)制信號量,創(chuàng)建的初始值為滿,使用之前可以先‘Take’下,使其變成空;
xSemaphoreCreateCounting:創(chuàng)建計數(shù)型信號量;
xSemaphoreCreateRecursiveMutex:創(chuàng)建遞歸信號量;
2. 靜態(tài)創(chuàng)建信號量(自己分配內(nèi)存):
xSemaphoreCreateMutexStatic:靜態(tài)互斥信號量;
xSemaphoreCreateBinaryStatic:靜態(tài)二進(jìn)制信號量;
xSemaphoreCreateCountingStatic:創(chuàng)建靜態(tài)計數(shù)型信號量;
xSemaphoreCreateRecursiveMutexStatic:靜態(tài)創(chuàng)建遞歸信號量;
二、獲取等待信號量:
xSemaphoreTake:正常模式下等待信號量,信號量可以由xSemaphoreCreateMutex,xSemaphoreCreateBinary、? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? xSemaphoreCreateCounting創(chuàng)建;
xSemaphoreTakeFromISR:處理器(中斷)模式下等待信號量,信號量可以有xSemaphoreCreateBinary、? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? xSemaphoreCreateCounting創(chuàng)建,禁止由xSemaphoreCreateMutex創(chuàng)建的信號量;
xSemaphoreTakeRecursive:正常模式下等待信號量,信號量只能是xSemaphoreCreateRecursiveMutex或? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? xSemaphoreCreateRecursiveMutexStatic創(chuàng)建;
三、釋放信號量:
xSemaphoreGive:正常模式下釋放釋放信號量,信號量可以由xSemaphoreCreateMutex,xSemaphoreCreateBinary、? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?xSemaphoreCreateCounting創(chuàng)建;
xSemaphoreGiveFromISR:處理器(中斷)模式下釋放信號量,信號量可以有xSemaphoreCreateBinary、? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? xSemaphoreCreateCounting創(chuàng)建,禁止由xSemaphoreCreateMutex創(chuàng)建的信號量;
xSemaphoreGiveRecursive:正常模式下釋放信號量,信號量只能是xSemaphoreCreateRecursiveMutex或? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?xSemaphoreCreateRecursiveMutexStatic創(chuàng)建;
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的FreeRTOS学习笔记之信号量的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于Python的编码注释# -*- c
- 下一篇: C++之指向对象成员函数的指针