亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? semtest.c

?? 最新版FreeRTOS, 包擴多種開發平臺的移植
?? C
字號:
/*
	FreeRTOS.org V4.1.1 - Copyright (C) 2003-2006 Richard Barry.

	This file is part of the FreeRTOS.org distribution.

	FreeRTOS.org is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	FreeRTOS.org is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with FreeRTOS.org; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

	A special exception to the GPL can be applied should you wish to distribute
	a combined work that includes FreeRTOS.org, without being obliged to provide
	the source code for any proprietary components.  See the licensing section 
	of http://www.FreeRTOS.org for full details of how and when the exception
	can be applied.

	***************************************************************************
	See http://www.FreeRTOS.org for documentation, latest information, license 
	and contact details.  Please ensure to read the configuration and relevant 
	port sections of the online documentation.
	***************************************************************************
*/

/**
 * Creates two sets of two tasks.  The tasks within a set share a variable, access 
 * to which is guarded by a semaphore.
 * 
 * Each task starts by attempting to obtain the semaphore.  On obtaining a 
 * semaphore a task checks to ensure that the guarded variable has an expected 
 * value.  It then clears the variable to zero before counting it back up to the 
 * expected value in increments of 1.  After each increment the variable is checked 
 * to ensure it contains the value to which it was just set. When the starting 
 * value is again reached the task releases the semaphore giving the other task in 
 * the set a chance to do exactly the same thing.  The starting value is high 
 * enough to ensure that a tick is likely to occur during the incrementing loop.
 *
 * An error is flagged if at any time during the process a shared variable is 
 * found to have a value other than that expected.  Such an occurrence would 
 * suggest an error in the mutual exclusion mechanism by which access to the 
 * variable is restricted.
 *
 * The first set of two tasks poll their semaphore.  The second set use blocking 
 * calls.
 *
 * \page SemTestC semtest.c
 * \ingroup DemoFiles
 * <HR>
 */

/*
Changes from V1.2.0:

	+ The tasks that operate at the idle priority now use a lower expected
	  count than those running at a higher priority.  This prevents the low
	  priority tasks from signaling an error because they have not been 
	  scheduled enough time for each of them to count the shared variable to
	  the high value.

Changes from V2.0.0

	+ Delay periods are now specified using variables and constants of
	  portTickType rather than unsigned portLONG.

Changes from V2.1.1

	+ The stack size now uses configMINIMAL_STACK_SIZE.
	+ String constants made file scope to decrease stack depth on 8051 port.
*/

#include <stdlib.h>

/* Scheduler include files. */
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"

/* Demo app include files. */
#include "semtest.h"
#include "print.h"

/* The value to which the shared variables are counted. */
#define semtstBLOCKING_EXPECTED_VALUE		( ( unsigned portLONG ) 0xfff )
#define semtstNON_BLOCKING_EXPECTED_VALUE	( ( unsigned portLONG ) 0xff  )

#define semtstSTACK_SIZE			configMINIMAL_STACK_SIZE

#define semtstNUM_TASKS				( 4 )

#define semtstDELAY_FACTOR			( ( portTickType ) 10 )

/* The task function as described at the top of the file. */
static void prvSemaphoreTest( void *pvParameters );

/* Structure used to pass parameters to each task. */
typedef struct SEMAPHORE_PARAMETERS
{
	xSemaphoreHandle xSemaphore;
	volatile unsigned portLONG *pulSharedVariable;
	portTickType xBlockTime;
} xSemaphoreParameters;

/* Variables used to check that all the tasks are still running without errors. */
static volatile portSHORT sCheckVariables[ semtstNUM_TASKS ] = { 0 };
static volatile portSHORT sNextCheckVariable = 0;

/* Strings to print if USE_STDIO is defined. */
const portCHAR * const pcPollingSemaphoreTaskError = "Guarded shared variable in unexpected state.\r\n";
const portCHAR * const pcSemaphoreTaskStart = "Guarded shared variable task started.\r\n";

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

void vStartSemaphoreTasks( unsigned portBASE_TYPE uxPriority )
{
xSemaphoreParameters *pxFirstSemaphoreParameters, *pxSecondSemaphoreParameters;
const portTickType xBlockTime = ( portTickType ) 100;

	/* Create the structure used to pass parameters to the first two tasks. */
	pxFirstSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );

	if( pxFirstSemaphoreParameters != NULL )
	{
		/* Create the semaphore used by the first two tasks. */
		vSemaphoreCreateBinary( pxFirstSemaphoreParameters->xSemaphore );

		if( pxFirstSemaphoreParameters->xSemaphore != NULL )
		{
			/* Create the variable which is to be shared by the first two tasks. */
			pxFirstSemaphoreParameters->pulSharedVariable = ( unsigned portLONG * ) pvPortMalloc( sizeof( unsigned portLONG ) );

			/* Initialise the share variable to the value the tasks expect. */
			*( pxFirstSemaphoreParameters->pulSharedVariable ) = semtstNON_BLOCKING_EXPECTED_VALUE;

			/* The first two tasks do not block on semaphore calls. */
			pxFirstSemaphoreParameters->xBlockTime = ( portTickType ) 0;

			/* Spawn the first two tasks.  As they poll they operate at the idle priority. */
			xTaskCreate( prvSemaphoreTest, "PolSEM1", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( xTaskHandle * ) NULL );
			xTaskCreate( prvSemaphoreTest, "PolSEM2", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( xTaskHandle * ) NULL );
		}
	}

	/* Do exactly the same to create the second set of tasks, only this time 
	provide a block time for the semaphore calls. */
	pxSecondSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
	if( pxSecondSemaphoreParameters != NULL )
	{
		vSemaphoreCreateBinary( pxSecondSemaphoreParameters->xSemaphore );

		if( pxSecondSemaphoreParameters->xSemaphore != NULL )
		{
			pxSecondSemaphoreParameters->pulSharedVariable = ( unsigned portLONG * ) pvPortMalloc( sizeof( unsigned portLONG ) );
			*( pxSecondSemaphoreParameters->pulSharedVariable ) = semtstBLOCKING_EXPECTED_VALUE;
			pxSecondSemaphoreParameters->xBlockTime = xBlockTime / portTICK_RATE_MS;

			xTaskCreate( prvSemaphoreTest, "BlkSEM1", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( xTaskHandle * ) NULL );
			xTaskCreate( prvSemaphoreTest, "BlkSEM2", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( xTaskHandle * ) NULL );
		}
	}
}
/*-----------------------------------------------------------*/

static void prvSemaphoreTest( void *pvParameters )
{
xSemaphoreParameters *pxParameters;
volatile unsigned portLONG *pulSharedVariable, ulExpectedValue;
unsigned portLONG ulCounter;
portSHORT sError = pdFALSE, sCheckVariableToUse;

	/* See which check variable to use.  sNextCheckVariable is not semaphore 
	protected! */
	portENTER_CRITICAL();
		sCheckVariableToUse = sNextCheckVariable;
		sNextCheckVariable++;
	portEXIT_CRITICAL();

	/* Queue a message for printing to say the task has started. */
	vPrintDisplayMessage( &pcSemaphoreTaskStart );

	/* A structure is passed in as the parameter.  This contains the shared 
	variable being guarded. */
	pxParameters = ( xSemaphoreParameters * ) pvParameters;
	pulSharedVariable = pxParameters->pulSharedVariable;

	/* If we are blocking we use a much higher count to ensure loads of context
	switches occur during the count. */
	if( pxParameters->xBlockTime > ( portTickType ) 0 )
	{
		ulExpectedValue = semtstBLOCKING_EXPECTED_VALUE;
	}
	else
	{
		ulExpectedValue = semtstNON_BLOCKING_EXPECTED_VALUE;
	}

	for( ;; )
	{
		/* Try to obtain the semaphore. */
		if( xSemaphoreTake( pxParameters->xSemaphore, pxParameters->xBlockTime ) == pdPASS )
		{
			/* We have the semaphore and so expect any other tasks using the
			shared variable to have left it in the state we expect to find
			it. */
			if( *pulSharedVariable != ulExpectedValue )
			{
				vPrintDisplayMessage( &pcPollingSemaphoreTaskError );
				sError = pdTRUE;
			}
			
			/* Clear the variable, then count it back up to the expected value
			before releasing the semaphore.  Would expect a context switch or
			two during this time. */
			for( ulCounter = ( unsigned portLONG ) 0; ulCounter <= ulExpectedValue; ulCounter++ )
			{
				*pulSharedVariable = ulCounter;
				if( *pulSharedVariable != ulCounter )
				{
					if( sError == pdFALSE )
					{
						vPrintDisplayMessage( &pcPollingSemaphoreTaskError );
					}
					sError = pdTRUE;
				}
			}

			/* Release the semaphore, and if no errors have occurred increment the check
			variable. */
			if(	xSemaphoreGive( pxParameters->xSemaphore ) == pdFALSE )
			{
				vPrintDisplayMessage( &pcPollingSemaphoreTaskError );
				sError = pdTRUE;
			}

			if( sError == pdFALSE )
			{
				if( sCheckVariableToUse < semtstNUM_TASKS )
				{
					( sCheckVariables[ sCheckVariableToUse ] )++;
				}
			}

			/* If we have a block time then we are running at a priority higher
			than the idle priority.  This task takes a long time to complete
			a cycle	(deliberately so to test the guarding) so will be starving
			out lower priority tasks.  Block for some time to allow give lower
			priority tasks some processor time. */
			vTaskDelay( pxParameters->xBlockTime * semtstDELAY_FACTOR );
		}
		else
		{
			if( pxParameters->xBlockTime == ( portTickType ) 0 )
			{
				/* We have not got the semaphore yet, so no point using the
				processor.  We are not blocking when attempting to obtain the
				semaphore. */
				taskYIELD();
			}
		}
	}
}
/*-----------------------------------------------------------*/

/* This is called to check that all the created tasks are still running. */
portBASE_TYPE xAreSemaphoreTasksStillRunning( void )
{
static portSHORT sLastCheckVariables[ semtstNUM_TASKS ] = { 0 };
portBASE_TYPE xTask, xReturn = pdTRUE;

	for( xTask = 0; xTask < semtstNUM_TASKS; xTask++ )
	{
		if( sLastCheckVariables[ xTask ] == sCheckVariables[ xTask ] )
		{
			xReturn = pdFALSE;
		}

		sLastCheckVariables[ xTask ] = sCheckVariables[ xTask ];
	}

	return xReturn;
}


?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
夜夜嗨av一区二区三区四季av| 欧美一区二区三区四区五区| 亚洲国产精品久久一线不卡| 欧美伊人久久大香线蕉综合69| 国产综合久久久久久久久久久久| 亚洲一区在线电影| 国产亚洲精久久久久久| 欧美高清dvd| 欧美日韩专区在线| 99re这里只有精品视频首页| 国产精品综合视频| 韩国精品主播一区二区在线观看| 男女性色大片免费观看一区二区| 亚洲欧美另类综合偷拍| 国产精品久久久久影院老司| 日韩视频不卡中文| 91麻豆精品国产91久久久使用方法 | 成人性色生活片| 国产乱子伦一区二区三区国色天香| 日韩av一区二| 一区二区三区在线播| 国产精品久久久久精k8| 中文字幕+乱码+中文字幕一区| 中文av一区二区| 久久久久97国产精华液好用吗| 久久免费看少妇高潮| 精品福利av导航| 欧美日韩免费一区二区三区视频| 欧美艳星brazzers| 久久综合99re88久久爱| 波多野结衣亚洲| 在线免费观看一区| 在线视频你懂得一区| 欧美视频在线不卡| 欧美裸体一区二区三区| 精品视频1区2区| 日韩亚洲欧美高清| 国产三级欧美三级| 亚洲精品一卡二卡| 日韩高清一级片| av在线播放一区二区三区| 成人黄色在线视频| 色综合久久久久综合99| 99精品视频在线观看免费| 欧美日韩国产一二三| 日韩欧美激情一区| 国产欧美一区二区精品忘忧草| 国产精品久久久久久福利一牛影视 | 亚洲人成网站影音先锋播放| 亚洲在线中文字幕| 一区二区三区在线影院| 捆绑紧缚一区二区三区视频| www.欧美日韩国产在线| 99re这里只有精品首页| 色偷偷久久人人79超碰人人澡 | 国产亚洲短视频| 亚洲激情av在线| 美国毛片一区二区| 91麻豆免费看片| 日韩精品一区二区三区老鸭窝| 中文字幕精品一区二区精品绿巨人 | 亚洲成人福利片| 美女视频黄频大全不卡视频在线播放 | 日韩视频一区二区三区在线播放| 国产欧美日韩在线看| 亚洲18色成人| 91蜜桃免费观看视频| 精品国产91久久久久久久妲己| 亚洲精品成人悠悠色影视| 国产精品一二三四五| 欧美三级一区二区| 亚洲色图20p| 国产美女精品人人做人人爽| 欧美日韩国产综合一区二区| 国产欧美日韩精品a在线观看| 日韩av电影免费观看高清完整版| 色婷婷综合久久久久中文| 亚洲免费在线看| 欧美日韩国产一二三| 免费在线看一区| 久久久三级国产网站| 国产69精品一区二区亚洲孕妇 | 亚洲人成亚洲人成在线观看图片 | 三级成人在线视频| 5月丁香婷婷综合| 秋霞国产午夜精品免费视频| 91麻豆精品国产91久久久使用方法| 奇米888四色在线精品| 精品少妇一区二区三区日产乱码| 麻豆免费看一区二区三区| 久久无码av三级| 9i看片成人免费高清| 亚洲一区二区欧美| 国产一区二区三区蝌蚪| 国产精品你懂的在线| 91久久线看在观草草青青| 肉肉av福利一精品导航| 久久五月婷婷丁香社区| 一本到不卡免费一区二区| 婷婷久久综合九色综合绿巨人 | 国产麻豆欧美日韩一区| 中文字幕一区视频| 337p亚洲精品色噜噜| 国产99久久久久| 亚洲国产aⅴ天堂久久| 久久久综合网站| 91色porny蝌蚪| 美女看a上一区| 18成人在线观看| 欧美主播一区二区三区| 欧美肥妇free| 国产在线一区二区综合免费视频| 国产午夜精品一区二区| 91九色最新地址| 久久99热这里只有精品| 亚洲精品成人少妇| 久久久综合精品| 日韩欧美一级精品久久| 99久久久久免费精品国产| 免费成人av在线播放| 一区二区三区成人在线视频| 久久亚洲免费视频| 欧美唯美清纯偷拍| 99久久精品免费看| 久久99国产精品久久99| 亚洲成a人片综合在线| 国产精品久久久久久久久晋中| 日韩女优av电影在线观看| 色婷婷亚洲综合| 成人国产精品视频| 国产酒店精品激情| 麻豆免费看一区二区三区| 亚洲成av人片在www色猫咪| 国产精品午夜电影| 精品国产精品网麻豆系列| 91精品国产综合久久精品app| 色88888久久久久久影院野外| 国产a视频精品免费观看| 国产乱码精品1区2区3区| 欧美aaaaa成人免费观看视频| 亚洲精选视频免费看| 国产精品国产三级国产aⅴ原创 | 日韩女优av电影| 精品视频一区二区三区免费| 色综合久久88色综合天天 | 国产精品久久久一区麻豆最新章节| 欧美va在线播放| 欧美成人福利视频| 欧美大胆一级视频| 91麻豆精品久久久久蜜臀| 91精品国产aⅴ一区二区| 7777精品伊人久久久大香线蕉完整版 | 亚洲综合在线五月| 一区二区三区色| 亚洲一区二区美女| 香蕉影视欧美成人| 日本v片在线高清不卡在线观看| 日韩中文字幕区一区有砖一区| 91久久奴性调教| 色综合中文字幕国产| 91理论电影在线观看| 色综合咪咪久久| 色国产综合视频| 在线看一区二区| 日韩免费电影网站| 久久一区二区三区国产精品| 久久这里只有精品首页| 国产亚洲一本大道中文在线| 国产精品免费看片| 亚洲日本护士毛茸茸| 亚洲一区二区三区在线播放| 午夜电影久久久| 国内精品免费**视频| 福利一区二区在线| 色婷婷av久久久久久久| 欧美酷刑日本凌虐凌虐| 精品日韩在线观看| 国产日韩欧美激情| 亚洲三级电影网站| 日韩成人一区二区| 国产精品123区| 91小视频免费观看| 欧美一区国产二区| 久久精品亚洲麻豆av一区二区| 亚洲精品亚洲人成人网在线播放| 午夜精品一区在线观看| 国内成人精品2018免费看| 91香蕉视频mp4| 精品少妇一区二区三区免费观看| 国产精品午夜春色av| 日韩一区欧美二区| av亚洲产国偷v产偷v自拍| 欧美亚洲综合另类| 国产欧美日韩精品在线| 午夜精品久久久久久久| av激情亚洲男人天堂| 91精品国产综合久久小美女| 国产精品高清亚洲| 高清免费成人av| 午夜精品一区二区三区免费视频|