概述
以下在CMSIS V2代码下实现,不区分是否中断安全。
1、信号量 semaphores
/* Definitions for adcFinishedBinSem */
osSemaphoreId_t adcFinishedBinSemHandle;
const osSemaphoreAttr_t adcFinishedBinSem_attributes = {
.name = "adcFinishedBinSem"
};
/* Create the semaphores(s) */
/* creation of adcFinishedBinSem */
adcFinishedBinSemHandle = osSemaphoreNew(1, 1, &adcFinishedBinSem_attributes);
/* How to use */
osSemaphoreRelease(adcFinishedBinSemHandle);
osSemaphoreAcquire(adcFinishedBinSemHandle,osWaitForever);
2、事件标志 EventFlag
/* Definitions for pcADCCmdEvent */
osEventFlagsId_t pcADCCmdEventHandle;
const osEventFlagsAttr_t pcADCCmdEvent_attributes = {
.name = "pcADCCmdEvent"
};
/* creation of pcADCCmdEvent */
pcADCCmdEventHandle = osEventFlagsNew(&pcADCCmdEvent_attributes);
/* how to use: osFlagsNoClear,osFlagsWaitAny,osFlagsWaitAll*/
#define ADC_CTRL ( 1 << 0 )
osEventFlagsSet(pcADCReadEventHandle, ADC_CTRL);
osEventFlagsClear(pcADCReadEventHandle, ADC_CTRL);
pcADCReadEvenFlag = osEventFlagsWait(pcADCReadEventHandle, ADC_CTRL, osFlagsNoClear, osWaitForever);
if((pcADCReadEvenFlag&0x01) == 0x01){
}
3、互斥 Mutex
/* Definitions for algorithmResutMutex */
osMutexId_t algorithmResutMutexHandle;
const osMutexAttr_t algorithmResutMutex_attributes = {
.name = "algorithmResutMutex"
};
/* creation of algorithmResutMutex */
algorithmResutMutexHandle = osMutexNew(&algorithmResutMutex_attributes);
/* how to use */
osMutexWait(algorithmResutMutexHandle,osWaitForever);
osMutexRelease(algorithmResutMutexHandle);
3、消息队列 Queue
/* Definitions for usartRxMsgQueue */
osMessageQueueId_t usartRxMsgQueueHandle;
const osMessageQueueAttr_t usartRxMsgQueue_attributes = {
.name = "usartRxMsgQueue"
};
/* Create the queue(s) */
/* creation of usartRxMsgQueue */
usartRxMsgQueueHandle = osMessageQueueNew(2, sizeof(USART_RECEIVETYPE), &usartRxMsgQueue_attributes);
/* how to use */
osMessageQueuePut(usartRxMsgQueueHandle,&Uart1Rx,1,0);
osMessageQueueGet(usartRxMsgQueueHandle,(void*)&pUARTRx,NULL,osWaitForever);
最后
以上就是无奈芒果为你收集整理的FreeRTOS 任务间同步和通信方法的全部内容,希望文章能够帮你解决FreeRTOS 任务间同步和通信方法所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复