zoukankan      html  css  js  c++  java
  • FreeRTOS二值信号量

    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
    ", data);
            }
    
            vTaskDelay(10);
        }
    }

    实验现象
    1

  • 相关阅读:
    animate动画回调函数
    triggerHandler不执行事件默认值
    trigger自动执行事件
    js与jquery对象的互转
    让低版本浏览器支持html5的标签
    闭包的好处罗列
    AJAX跨域
    php能干什么?
    concat() 方法用于连接两个或多个数组。
    使用 v-cloak 防止页面加载时出现 vuejs 的变量名
  • 原文地址:https://www.cnblogs.com/zhangxuechao/p/11709476.html
Copyright © 2011-2022 走看看