示例#1
0
文件: flop.c 项目: nks5295/Composite
static void vCompetingMathTask1( void *pvParameters )
{
portDOUBLE d1, d2, d3, d4;
volatile unsigned short *pusTaskCheckVariable;
const portDOUBLE dAnswer = ( 123.4567 + 2345.6789 ) * -918.222;
const char * const pcTaskStartMsg = "Math task 1 started.\r\n";
const char * const pcTaskFailMsg = "Math task 1 failed.\r\n";
short sError = pdFALSE;
	/* Queue a message for printing to say the task has started. */
	vPrintDisplayMessage( &pcTaskStartMsg );
	//freertos_print("vCompetingMathTask1\n");
	freertos_print(pcTaskStartMsg);

	/* The variable this task increments to show it is still running is passed in 
	as the parameter. */
	pusTaskCheckVariable = ( unsigned short * ) pvParameters;

	/* Keep performing a calculation and checking the result against a constant. */
	for(;;)
	{
		d1 = 123.4567;
		d2 = 2345.6789;
		d3 = -918.222;

		d4 = ( d1 + d2 ) * d3;

		taskYIELD();

		/* If the calculation does not match the expected constant, stop the
		increment of the check variable. */
		if( fabs( d4 - dAnswer ) > 0.001 )
		{
			vPrintDisplayMessage( &pcTaskFailMsg );
			freertos_print(pcTaskFailMsg);
			sError = pdTRUE;
		} else {
			freertos_print("Math task 1 calculation successful\n");
		}

		if( sError == pdFALSE )
		{
			/* If the calculation has always been correct, increment the check
			variable so we know this task is still running okay. */
			( *pusTaskCheckVariable )++;
		}
		
		taskYIELD();
		
	}
}
示例#2
0
void *pvPortMalloc( size_t xWantedSize )
{
void *pvReturn = NULL;
 freertos_print("Called pvPortMalloc in heap_1.\n");
	/* Ensure that blocks are always aligned to the required number of bytes. */
	#if portBYTE_ALIGNMENT != 1
		if( xWantedSize & portBYTE_ALIGNMENT_MASK )
		{
			/* Byte alignment required. */
			xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
		}
	#endif

		//		freertos_print("Suspending in pvPortMalloc()\n");
	vTaskSuspendAll();
	{
		/* Check there is enough room left for the allocation. */
		if( ( ( xNextFreeByte + xWantedSize ) < configTOTAL_HEAP_SIZE ) &&
			( ( xNextFreeByte + xWantedSize ) > xNextFreeByte )	)/* Check for overflow. */
		{
			/* Return the next free byte then increment the index past this
			block. */
			pvReturn = &( xHeap.ucHeap[ xNextFreeByte ] );
			xNextFreeByte += xWantedSize;
		} else {
			freertos_print("Not enough memory to allocate requested size, %u, only have %u\n", xWantedSize, configTOTAL_HEAP_SIZE - xNextFreeByte);
			freertos_print("Heap size: %u\n", configTOTAL_HEAP_SIZE);
			freertos_print("Current bump pointer %u\n", xNextFreeByte);
		}
	}
	//	freertos_print("Resuming in pvPortMalloc()\n");
	xTaskResumeAll();

	#if( configUSE_MALLOC_FAILED_HOOK == 1 )
	{
		if( pvReturn == NULL )
		{
			extern void vApplicationMallocFailedHook( void );
			vApplicationMallocFailedHook();
		}
	}
	#endif
	
	//	freertos_print("Returning from pvPortMalloc()\n");
	return pvReturn;
}
示例#3
0
文件: flop.c 项目: nks5295/Composite
void vStartMathTasks( unsigned portBASE_TYPE uxPriority )
{
	xTaskCreate( vCompetingMathTask1, "Math1", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
	xTaskCreate( vCompetingMathTask2, "Math2", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
	xTaskCreate( vCompetingMathTask3, "Math3", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
	xTaskCreate( vCompetingMathTask4, "Math4", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
	xTaskCreate( vCompetingMathTask1, "Math5", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 4 ] ), uxPriority, NULL );
	xTaskCreate( vCompetingMathTask2, "Math6", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 5 ] ), uxPriority, NULL );
	xTaskCreate( vCompetingMathTask3, "Math7", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 6 ] ), uxPriority, NULL );
	xTaskCreate( vCompetingMathTask4, "Math8", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 7 ] ), uxPriority, NULL );
	freertos_print("Created all tasks...\n");
}
static void vCheckpointTask( void *pvParameters )
{
	const char * const pcTaskStartMsg = "Checkpoint task 1 started.\r\n";
	volatile u64_t x = 0;
	u64_t tsc;

	freertos_print(pcTaskStartMsg);

	for(;;)
	{
		x++;
		if (x % 1000000 == 0) {
			freertos_print("x: %llu (u64_t)\n", x);
		}
		rdtscll(tsc);

		if (tsc % 12345555 == 0 && (!have_restored)) {
			freertos_print("About to page fault? TSC was accepted value\n");
			x = (int)(*((char *)0));
			/* freertos_print("what?\n"); */
		}
	}
}
int freeRTOS_entry( void )
{
	freertos_checkpoint();
	/* CREATE ALL THE DEMO APPLICATION TASKS. */
	/* vStartMathTasks( tskIDLE_PRIORITY ); */
	/* vStartCheckpointTask(); */
	vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
/* 	vCreateBlockTimeTasks(); */
/* 	vStartSemaphoreTasks( mainSEMAPHORE_TASK_PRIORITY ); */
/* 	vStartMultiEventTasks(); */
/* 	vStartQueuePeekTasks(); */
/* 	vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY ); */
/* #if mainCPU_INTENSIVE_TASKS == 1 */
/* 	vStartRecursiveMutexTasks(); */
/* 	vStartDynamicPriorityTasks(); */
/* 	vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY ); */
/* 	vStartCountingSemaphoreTasks(); */
/* #endif */

	/* Create the co-routines that communicate with the tick hook. */
	/* vStartHookCoRoutines(); */

	/* Create the "Print" task as described at the top of the file. */
	/* xTaskCreate( vErrorChecks, "Print", configMINIMAL_STACK_SIZE, NULL, mainPRINT_TASK_PRIORITY, NULL ); */

	/* This task has to be created last as it keeps account of the number of tasks
	it expects to see running. */
/* #if mainUSE_SUICIDAL_TASKS_DEMO == 1 */
/* 	vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY ); */
/* #endif */

	/* Create a Task which waits to receive messages and sends its own when it times out. */
	/* xTaskCreate( prvUDPTask, "UDPRxTx", configMINIMAL_STACK_SIZE, xUDPReceiveQueue, tskIDLE_PRIORITY + 1, &hUDPTask ); */

	/* Create a Task which waits to receive messages and sends its own when it times out. */
	/* xTaskCreate( prvMessageQueueTask, "MQ RxTx", configMINIMAL_STACK_SIZE, xIPCQueue, tskIDLE_PRIORITY + 1, &hMQTask ); */

	/* Create a Task which waits to receive bytes. */
	/* xTaskCreate( prvSerialConsoleEchoTask, "SerialRx", configMINIMAL_STACK_SIZE, xSerialRxQueue, tskIDLE_PRIORITY + 4, &hSerialTask ); */

	/* Set the scheduler running.  This function will not return unless a task calls vTaskEndScheduler(). */
	vTaskStartScheduler();
	freertos_print("END OF FREERTOS EXECUTION\n");
	return 1;
}
示例#6
0
void *pvPortMalloc( size_t xWantedSize )
{
	void *pvReturn;
	//	freertos_print("WRONG MALLOC, IDIOT\n");
	vTaskSuspendAll();
	{
		pvReturn = malloc( xWantedSize );
	}
	xTaskResumeAll();

	#if( configUSE_MALLOC_FAILED_HOOK == 1 )
	{
		if( pvReturn == NULL )
		{
			freertos_print("Malloc failed from heap_3\n");
			extern void vApplicationMallocFailedHook( void );
			vApplicationMallocFailedHook();
		}
	}
	#endif
	
	return pvReturn;
}
示例#7
0
文件: flop.c 项目: nks5295/Composite
static void vCompetingMathTask4( void *pvParameters )
{
portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;
volatile unsigned short *pusTaskCheckVariable;
const unsigned short usArraySize = 250;
unsigned short usPosition;
const char * const pcTaskStartMsg = "Math task 4 started.\r\n";
const char * const pcTaskFailMsg = "Math task 4 failed.\r\n";
short sError = pdFALSE;

	/* Queue a message for printing to say the task has started. */
	vPrintDisplayMessage( &pcTaskStartMsg );
	freertos_print("Started math task 4\n");
	freertos_print(pcTaskStartMsg);
	/* The variable this task increments to show it is still running is passed in 
	as the parameter. */
	pusTaskCheckVariable = ( unsigned short * ) pvParameters;

	pdArray = ( portDOUBLE * ) pvPortMalloc( ( size_t ) 250 * sizeof( portDOUBLE ) );

	/* Keep filling an array, keeping a running total of the values placed in the 
	array.  Then run through the array adding up all the values.  If the two totals 
	do not match, stop the check variable from incrementing. */
	for( ;; )
	{
		dTotal1 = 0.0;
		dTotal2 = 0.0;

		for( usPosition = 0; usPosition < usArraySize; usPosition++ )
		{
			pdArray[ usPosition ] = ( portDOUBLE ) usPosition * 12.123;
			dTotal1 += ( portDOUBLE ) usPosition * 12.123;	
		}

		//		freertos_print("yielding from task 4\n");
		taskYIELD();

		for( usPosition = 0; usPosition < usArraySize; usPosition++ )
		{
			dTotal2 += pdArray[ usPosition ];
		}

		dDifference = dTotal1 - dTotal2;
		if( fabs( dDifference ) > 0.001 )
		{
			vPrintDisplayMessage( &pcTaskFailMsg );
			sError = pdTRUE;
		} else {
			//		freertos_print("Math task 4 successful\n");
		}

		taskYIELD();

		if( sError == pdFALSE )
		{
			/* If the calculation has always been correct, increment the check 
			variable so we know	this task is still running okay. */
			( *pusTaskCheckVariable )++;
		}
	}
}