Ejemplo n.º 1
0
static void prvBlockingTask( void *pvParameters )
{
TaskHandle_t xControllingTask;
uint32_t ulNotificationValue;
const uint32_t ulMax = 0xffffffffUL;

	/* Just to remove compiler warnings. */
	( void ) pvParameters;

	xControllingTask = xTaskGetHandle( pcControllingTaskName );
	configASSERT( xControllingTask );

	for( ;; )
	{
		/* Wait to be notified of the test that is to be performed next. */
		xTaskNotifyWait( 0, ulMax, &ulNotificationValue, portMAX_DELAY );

		switch( ulNotificationValue )
		{
			case abtNOTIFY_WAIT_ABORTS:
				prvTestAbortingTaskNotifyWait();
				break;

			case abtNOTIFY_TAKE_ABORTS:
				prvTestAbortingTaskNotifyTake();
				break;

			case abtDELAY_ABORTS:
				prvTestAbortingTaskDelay();
				break;

			case abtDELAY_UNTIL_ABORTS:
				prvTestAbortingTaskDelayUntil();
				break;

			case abtSEMAPHORE_TAKE_ABORTS:
				prvTestAbortingSemaphoreTake();
				break;

			case abtEVENT_GROUP_ABORTS:
				prvTestAbortingEventGroupWait();
				break;

			case abtQUEUE_SEND_ABORTS:
				prvTestAbortingQueueSend();
				break;

			default:
				/* Should not get here. */
				break;
		}

		/* Let the primary task know the test is complete. */
		xTaskNotifyGive( xControllingTask );

		/* To indicate this task is still executing. */
		xBlockingCycles++;
	}
}
Ejemplo n.º 2
0
static void prvControllingTask( void *pvParameters )
{
TaskHandle_t xBlockingTask;
uint32_t ulTestToPerform = abtNOTIFY_WAIT_ABORTS;
TickType_t xTimeAtStart;
const TickType_t xStartMargin = 2UL;

	/* Just to remove compiler warnings. */
	( void ) pvParameters;

	xBlockingTask = xTaskGetHandle( pcBlockingTaskName );
	configASSERT( xBlockingTask );

	for( ;; )
	{
		/* Tell the secondary task to perform the next test. */
		xTimeAtStart = xTaskGetTickCount();
		xTaskNotify( xBlockingTask, ulTestToPerform, eSetValueWithOverwrite );

		/* The secondary task has a higher priority, so will now be in the
		Blocked state to wait for a maximum of xMaxBlockTime.  It expects that
		period to complete with a timeout.  It will then block for
		xMaxBlockTimeAgain, but this time it expects to the block time to abort
		half way through.  Block until it is time to send the abort to the
		secondary task.  xStartMargin is used because this task takes timing
		from the beginning of the test, whereas the blocking task takes timing
		from the entry into the Blocked state - and as the tasks run at
		different priorities, there may be some discrepancy.  Also, temporarily
		raise the priority of the controlling task to that of the blocking
		task to minimise discrepancies. */
		vTaskPrioritySet( NULL, abtBLOCKING_PRIORITY );
		vTaskDelay( xMaxBlockTime + xHalfMaxBlockTime + xStartMargin );
		xTaskAbortDelay( xBlockingTask );

		/* Reset the priority to the normal controlling priority. */
		vTaskPrioritySet( NULL, abtCONTROLLING_PRIORITY );

		/* Now wait to be notified that the secondary task has completed its
		test. */
		ulTaskNotifyTake( pdTRUE, portMAX_DELAY );

		/* Did the entire test run for the expected time, which is two full
		block times plus the half block time caused by calling
		xTaskAbortDelay()? */
		prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, ( xMaxBlockTime + xMaxBlockTime + xHalfMaxBlockTime ) );

		/* Move onto the next test. */
		ulTestToPerform++;

		if( ulTestToPerform >= abtMAX_TESTS )
		{
			ulTestToPerform = 0;
		}

		/* To indicate this task is still executing. */
		xControllingCycles++;
	}
}
Ejemplo n.º 3
0
	TaskHandle_t MPU_xTaskGetHandle( const char *pcNameToQuery )
	{
	TaskHandle_t xReturn;
	BaseType_t xRunningPrivileged = xPortRaisePrivilege();

		xReturn = xTaskGetHandle( pcNameToQuery );
		vPortResetPrivilege( xRunningPrivileged );
		return xReturn;
	}
Ejemplo n.º 4
0
void vn4( void * pvParameters )
{  

   xHandle = xTaskGetHandle( "Noticer" );
   
   while(1)
   {
   	vTaskDelay(7000);
	UART0_SendStr("N4 sent a MSG\n");
	xTaskNotify(xHandle, 0x04, eSetBits);
	
	
	}
}
Ejemplo n.º 5
0
void vn2( void * pvParameters )
{  

   xHandle = xTaskGetHandle( "Noticer" );
   
   while(1)
   {
   	vTaskDelay(5000);
	UART0_SendStr("N2 sent a Message\n");
	xTaskNotify(xHandle, 0x02, eSetBits);
	
	
	}
}
Ejemplo n.º 6
0
static void prvExerciseSemaphoreAPI( void )
{
SemaphoreHandle_t xSemaphore;
const UBaseType_t uxMaxCount = 5, uxInitialCount = 0;

	/* Most of the semaphore API is common to the queue API and is already being
	used.  This function uses a few semaphore functions that are unique to the
	RTOS objects, rather than generic and used by queues also.

	First create and use a counting semaphore. */
	xSemaphore = xSemaphoreCreateCounting( uxMaxCount, uxInitialCount );
	configASSERT( xSemaphore );

	/* Give the semaphore a couple of times and ensure the count is returned
	correctly. */
	xSemaphoreGive( xSemaphore );
	xSemaphoreGive( xSemaphore );
	configASSERT( uxSemaphoreGetCount( xSemaphore ) == 2 );
	vSemaphoreDelete( xSemaphore );

	/* Create a recursive mutex, and ensure the mutex holder and count are
	returned returned correctly. */
	xSemaphore = xSemaphoreCreateRecursiveMutex();
	configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 );
	configASSERT( xSemaphore );
	xSemaphoreTakeRecursive( xSemaphore, mainDONT_BLOCK );
	xSemaphoreTakeRecursive( xSemaphore, mainDONT_BLOCK );
	configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetCurrentTaskHandle() );
	configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetHandle( mainTASK_TO_DELETE_NAME ) );
	xSemaphoreGiveRecursive( xSemaphore );
	configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 );
	xSemaphoreGiveRecursive( xSemaphore );
	configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 );
	configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == NULL );
	vSemaphoreDelete( xSemaphore );

	/* Create a normal mutex, and sure the mutex holder and count are returned
	returned correctly. */
	xSemaphore = xSemaphoreCreateMutex();
	configASSERT( xSemaphore );
	xSemaphoreTake( xSemaphore, mainDONT_BLOCK );
	xSemaphoreTake( xSemaphore, mainDONT_BLOCK );
	configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 ); /* Not recursive so can only be 1. */
	configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetCurrentTaskHandle() );
	xSemaphoreGive( xSemaphore );
	configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 );
	configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == NULL );
	vSemaphoreDelete( xSemaphore );
}
Ejemplo n.º 7
0
static void prvDemonstrateTaskStateAndHandleGetFunctions( void )
{
TaskHandle_t xIdleTaskHandle, xTimerTaskHandle;
char *pcTaskName;
static portBASE_TYPE xPerformedOneShotTests = pdFALSE;
TaskHandle_t xTestTask;
TaskStatus_t xTaskInfo;
extern StackType_t uxTimerTaskStack[];

	/* Demonstrate the use of the xTimerGetTimerDaemonTaskHandle() and
	xTaskGetIdleTaskHandle() functions.  Also try using the function that sets
	the task number. */
	xIdleTaskHandle = xTaskGetIdleTaskHandle();
	xTimerTaskHandle = xTimerGetTimerDaemonTaskHandle();

	/* This is the idle hook, so the current task handle should equal the
	returned idle task handle. */
	if( xTaskGetCurrentTaskHandle() != xIdleTaskHandle )
	{
		pcStatusMessage = "Error:  Returned idle task handle was incorrect";
	}

	/* Check the same handle is obtained using the idle task's name.  First try
	with the wrong name, then the right name. */
	if( xTaskGetHandle( "Idle" ) == xIdleTaskHandle )
	{
		pcStatusMessage = "Error:  Returned handle for name Idle was incorrect";
	}

	if( xTaskGetHandle( "IDLE" ) != xIdleTaskHandle )
	{
		pcStatusMessage = "Error:  Returned handle for name Idle was incorrect";
	}

	/* Check the timer task handle was returned correctly. */
	pcTaskName = pcTaskGetName( xTimerTaskHandle );
	if( strcmp( pcTaskName, "Tmr Svc" ) != 0 )
	{
		pcStatusMessage = "Error:  Returned timer task handle was incorrect";
	}

	if( xTaskGetHandle( "Tmr Svc" ) != xTimerTaskHandle )
	{
		pcStatusMessage = "Error:  Returned handle for name Tmr Svc was incorrect";
	}

	/* This task is running, make sure it's state is returned as running. */
	if( eTaskStateGet( xIdleTaskHandle ) != eRunning )
	{
		pcStatusMessage = "Error:  Returned idle task state was incorrect";
	}

	/* If this task is running, then the timer task must be blocked. */
	if( eTaskStateGet( xTimerTaskHandle ) != eBlocked )
	{
		pcStatusMessage = "Error:  Returned timer task state was incorrect";
	}

	/* Also with the vTaskGetInfo() function. */
	vTaskGetInfo( xTimerTaskHandle, /* The task being queried. */
					  &xTaskInfo,		/* The structure into which information on the task will be written. */
					  pdTRUE,			/* Include the task's high watermark in the structure. */
					  eInvalid );		/* Include the task state in the structure. */

	/* Check the information returned by vTaskGetInfo() is as expected. */
	if( ( xTaskInfo.eCurrentState != eBlocked )						 ||
		( strcmp( xTaskInfo.pcTaskName, "Tmr Svc" ) != 0 )			 ||
		( xTaskInfo.uxCurrentPriority != configTIMER_TASK_PRIORITY ) ||
		( xTaskInfo.pxStackBase != uxTimerTaskStack )				 ||
		( xTaskInfo.xHandle != xTimerTaskHandle ) )
	{
		pcStatusMessage = "Error:  vTaskGetInfo() returned incorrect information about the timer task";
	}

	/* Other tests that should only be performed once follow.  The test task
	is not created on each iteration because to do so would cause the death
	task to report an error (too many tasks running). */
	if( xPerformedOneShotTests == pdFALSE )
	{
		/* Don't run this part of the test again. */
		xPerformedOneShotTests = pdTRUE;

		/* Create a test task to use to test other eTaskStateGet() return values. */
		if( xTaskCreate( prvTestTask, "Test", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTestTask ) == pdPASS )
		{
			/* If this task is running, the test task must be in the ready state. */
			if( eTaskStateGet( xTestTask ) != eReady )
			{
				pcStatusMessage = "Error: Returned test task state was incorrect 1";
			}

			/* Now suspend the test task and check its state is reported correctly. */
			vTaskSuspend( xTestTask );
			if( eTaskStateGet( xTestTask ) != eSuspended )
			{
				pcStatusMessage = "Error: Returned test task state was incorrect 2";
			}

			/* Now delete the task and check its state is reported correctly. */
			vTaskDelete( xTestTask );
			if( eTaskStateGet( xTestTask ) != eDeleted )
			{
				pcStatusMessage = "Error: Returned test task state was incorrect 3";
			}
		}
	}
}