907-FreeRTOS202212‐ulTaskNotifyTake() 与 ulTaskNotifyTakeIndexed()

#define ulTaskNotifyTake( xClearCountOnExit, xTicksToWait ) \
	ulTaskGenericNotifyTake( ( tskDEFAULT_INDEX_TO_NOTIFY ), ( xClearCountOnExit ), ( xTicksToWait ) )

#define ulTaskNotifyTakeIndexed( uxIndexToWaitOn, xClearCountOnExit, xTicksToWait ) \
    	ulTaskGenericNotifyTake( ( uxIndexToWaitOn ), ( xClearCountOnExit ), ( xTicksToWait ) )

/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

#if ( configUSE_TASK_NOTIFICATIONS == 1 )

    	uint32_t ulTaskGenericNotifyTake( 	UBaseType_t 	uxIndexToWait,	/* 调用任务的数组中通知值的索引, 调用任务将在该通知值上等待通知 */
                                      	BaseType_t 	xClearCountOnExit,	/* pdTRUE:退出前清零任务通知值,类似二值信号量, pdFALSE:退出前任务通知值递减,类似递减计数信号量 */
                                      	TickType_t 	xTicksToWait )	/* 阻塞状态下等待接收通知的最长时间 */

    	{
        	uint32_t ulReturn;

        	configASSERT( uxIndexToWait < configTASK_NOTIFICATION_ARRAY_ENTRIES );

        	taskENTER_CRITICAL();
        	{
            		/* Only block if the notification count is not already non-zero. */
			/* 仅当通知值 为零时 阻塞任务 */
            		if( pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] == 0UL )
            		{
                		/* Mark this task as waiting for a notification. */
				/* 设置任务通知的状态为等待通知状态 */
                		pxCurrentTCB->ucNotifyState[ uxIndexToWait ] = taskWAITING_NOTIFICATION;

                		if( xTicksToWait > ( TickType_t ) 0 )
                		{
                    			prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE );
                    			traceTASK_NOTIFY_TAKE_BLOCK( uxIndexToWait );

                    			/* All ports are written to allow a yield in a critical section (some will yield immediately, others wait until the critical section exits) - but it is not something that application code should ever do. */
					/*所有端口都被编写为允许在临界段中进行屈服(有些端口将立即屈服,另一些端口则等待关键部分退出),但这不是应用程序代码应该做的事情*/
                    			portYIELD_WITHIN_API();
                		}
                		else
                		{
                    			mtCOVERAGE_TEST_MARKER();
                		}
            		}
            		else
            		{
                		mtCOVERAGE_TEST_MARKER();
            		}
        	}
        	taskEXIT_CRITICAL();

        	taskENTER_CRITICAL();
        	{
            		traceTASK_NOTIFY_TAKE( uxIndexToWait );
            		ulReturn = pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ];

            		if( ulReturn != 0UL )
            		{
                		if( xClearCountOnExit != pdFALSE )
                		{
                    			pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] = 0UL;
                		}
                		else
                		{
                    			pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] = ulReturn - ( uint32_t ) 1;
                		}
            		}
            		else
            		{
                		mtCOVERAGE_TEST_MARKER();
            		}

            		pxCurrentTCB->ucNotifyState[ uxIndexToWait ] = taskNOT_WAITING_NOTIFICATION;
        	}
        	taskEXIT_CRITICAL();

        	return ulReturn;
    	}

#endif /* configUSE_TASK_NOTIFICATIONS */
/*-----------------------------------------------------------*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值