»
(008) CubeIDE Implementation of USB Peripherals*
(018) C99 pointer*
(019) C99 With only value assignment*
(022) POSIX pthread multi-threads mutex*
(023) POSIX pthread multi-threads programming*
(027) C99 time and wait*
(028) High-precision calculation with GMP*
(029) Web Service Lib*
(030) International Components for Unicode (ICU)*
(031) Performance of C is higher than C++, because...*
🕹️(024) FreeRTOS semaphore
FreeRTOS中的信号量:Semaphore
定义信号量:SemaphoreHandle_t sem;
创建二值信号量:sem = xSemaphoreCreateBinary();
创建计数信号量:sem = xSemaphoreCreateCounting(10, 0);//最大10,初始0
信号量加一:xSemaphoreGive(sem);
信号量减一:xSemaphoreTake(sem, portMAX_DELAY);//一直等待信号量
从ChatGPT得到的等待信号量失败的例子:
if (xSemaphoreTake(xSemaphore, pdMS_TO_TICKS(1000)) == pdFAIL) {
// 超过1秒没有获取到信号量
}
切记:别用mutex