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