Пример #1
0
/**
 * Flashes an LED.
 * @param n - Unique ID of the LED to flash.
 * @param onTime - Time the LED is on (in ms)
 * @param offTime - Time the LED is off (in ms)
 * @return TRUE if parameters are valid and the flash task is running, otherwise false.
 */
bool d1k_LED_Flash ( d1k_LED_ID_t n, uint32 onTime, uint32 offTime )
{
	if ( offTime > 0 && onTime > 0 )
	{
		leds[n].offTime = offTime;
		leds[n].onTime = onTime;

		// If we have not yet created the task, create it.
		if ( flashHandles[n] == NULL )
		{
			xTaskCreate(d1k_LED_Flash_Task,"LEDFLSH",256,&(leds[n]),1,&(flashHandles[n]));
			return true;
		}

		// If a task is already created, resume it.
		if ( eTaskStateGet( flashHandles[n] ) == eSuspended )
		{
			xTaskResumeFromISR( flashHandles[n] );
			return true;
		}

		// Task is already running, just update it.
		return true;
	}
	else
	{
		// If a task is running, it will suspend itself.
		leds[n].onTime = 0;
		leds[n].offTime = 0;
		d1k_LED_Off(n);
	}

	return false;
}
Пример #2
0
static void prvDemonstrateTaskStateAndHandleGetFunctions( void )
{
TaskHandle_t xIdleTaskHandle, xTimerTaskHandle;
char *pcTaskName;
static portBASE_TYPE xPerformedOneShotTests = pdFALSE;
TaskHandle_t xTestTask;

	/* 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 timer task handle was returned correctly. */
	pcTaskName = pcTaskGetTaskName( xTimerTaskHandle );
	if( strcmp( pcTaskName, "Tmr Svc" ) != 0 )
	{
		pcStatusMessage = "Error:  Returned timer task handle 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";
	}

	/* 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";
			}
		}
	}
}
Пример #3
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";
			}
		}
	}
}