FreeRTOS二值信号量
2018-02-07 11:00
357 查看
API函数
使用举例
实验现象
#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) #define xSemaphoreCreateBinary() xQueueGenericCreate( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE ) QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, const uint8_t ucQueueType ) #endif #define xSemaphoreGive( xSemaphore ) xQueueGenericSend( ( QueueHandle_t ) ( xSemaphore ), NULL, semGIVE_BLOCK_TIME, queueSEND_TO_BACK ) BaseType_t xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, const BaseType_t xCopyPosition ) #define xSemaphoreGiveFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueGiveFromISR( ( QueueHandle_t ) ( xSemaphore ), ( pxHigherPriorityTaskWoken ) ) BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue, BaseType_t * const pxHigherPriorityTaskWoken ) #define xSemaphoreTake( xSemaphore, xBlockTime ) xQueueGenericReceive( ( QueueHandle_t ) ( xSemaphore ), NULL, ( xBlockTime ), pdFALSE ) BaseType_t xQueueGenericReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait, const BaseType_t xJustPeeking ) #define xSemaphoreTakeFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueReceiveFromISR( ( QueueHandle_t ) ( xSemaphore ), NULL, ( pxHigherPriorityTaskWoken ) ) BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, void * const pvBuffer, BaseType_t * const pxHigherPriorityTaskWoken )
使用举例
u8 data; void start_task(void *pvParameters) { //创建二值信号量 BinarySemaphore = xSemaphoreCreateBinary(); } void USART1_IRQHandler(void) { if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) { data = USART_ReceiveData(USART1); xSemaphoreGiveFromISR(BinarySemaphore, &xHigherPriorityTaskWoken); //释放二值信号量 portYIELD_FROM_ISR(xHigherPriorityTaskWoken); } } void data_task(void *pvParameters) { BaseType_t ret; while(1) { ret = xSemaphoreTake(BinarySemaphore,portMAX_DELAY); if(ret == pdTRUE) { printf("data %c\r\n", data); } vTaskDelay(10); } }
实验现象
相关文章推荐
- Linux 同步机制:信号量
- VxWorks -- 信号量
- 【C#】【Thread】Semaphore/SemaphoreSlim信号量
- 用信号量实现进程互斥.c
- 60-System V 信号量(操作)
- window信号量、互斥、自旋锁
- 自旋锁、内核信号量、原子变量
- Linux信号量的SEM_UNDO标志
- 信号量释放和等待函数sem_post()和sem_wait()
- 多线程之线程等待与信号量
- Java Note: 多线程的同步(互斥锁)的方法对比,信号量锁,读写锁的实现,生产者-消费者模式的实现
- 信号量的创建/打开,访问
- 信号量
- linux下进程的信号量
- 【Linux】进程间通信(IPC)之信号量详解与测试用例
- 信号量
- Android 价值千万java多线程同步 <五>CountDownLatch(计数器)和Semaphore(信号量)
- 用邮箱作二值信号量
- QSystemSemaphore 系统级信号量
- 经典线程同步总结 关键段 事件 互斥量 信号量