/* Standard includes. */ #include /* Kernel includes. */ #include #include "task.h" #include "queue.h" /* Standard demo includes. */ #include "BlockQ.h" #include "integer.h" #include "semtest.h" #include "PollQ.h" #include "GenQTest.h" #include "QPeek.h" #include "recmutex.h" #include "flop.h" /* Priorities at which the tasks are created. */ #define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 ) #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 ) #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 ) #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 ) #define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 ) #define mainuIP_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 ) #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY ) #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY ) #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY ) /* Task function prototypes. */ static void prvCheckTask( void *pvParameters ); static void vTask1( void *pvParameters ); static void vTask2( void *pvParameters ); static void vTask3( void *pvParameters ); static void vTask4( void *pvParameters ); xQueueHandle xQueue,xMutex; xTaskHandle xTask1Handle,xTask2Handle,xTask3Handle,xTask4Handle; int main( void ) { portBASE_TYPE xStatus; printf( "%s : %s\n","main","xTaskCreate(vTask1,Task1,configMINIMAL_STACK_SIZE,NULL,1,&xTask1Handle)" ); xTaskCreate(vTask1,"Task1",configMINIMAL_STACK_SIZE,NULL,1,&xTask1Handle); // starting scheduler printf( "%s : %s\n","main","vTaskStartScheduler()" ); vTaskStartScheduler(); /* Should never get here unless there was not enough heap space to create the idle and other system tasks. */ return 0; } /*-----------------------------------------------------------*/ static void vTask1( void *pvParameters ) { portBASE_TYPE xStatus1,xStatus2; long data; /* Just to remove compiler warning. */ ( void ) pvParameters; // creating a queue (xQueue) of size 2 printf( "%s : %s \n", "Task1","xQueue = xQueueCreate( 2,sizeof (long) )" ); xQueue = xQueueCreate( 2,sizeof (long) ); // creating mutex (xMutex) printf( "%s : %s \n", "Task1","xMutex = xQueueCreateMutex()" ); xMutex = xQueueCreateMutex(); printf( "%s : %s \n", "Task1","xStatus1 = xQueueTakeMutexRecursive( xMutex, portMAX_DELAY )" ); xStatus1 = xQueueTakeMutexRecursive( xMutex, portMAX_DELAY ); printf( "%s : %s\n", "Task1","xTaskCreate(vTask2,Task2,configMINIMAL_STACK_SIZE,NULL,2,&xTask2Handle)" ); xTaskCreate(vTask2,"Task2",configMINIMAL_STACK_SIZE,NULL,2,&xTask2Handle); printf( "%s : %s \n", "Task1","xStatus2 = xQueueReceive(xQueue,&data,portMAX_DELAY)" ); xStatus2 = xQueueReceive(xQueue,&data,portMAX_DELAY); printf( "%s : %s \n", "Task1","xStatus2 = xQueueGiveMutexRecursive( xMutex )" ); xStatus2 = xQueueGiveMutexRecursive( xMutex ); printf( "%s : %s \n", "Task1","vTaskDelete(xTask1Handle)" ); vTaskDelete(xTask1Handle); } /*-----------------------------------------------------------*/ static void vTask2( void *pvParameters ) { portBASE_TYPE xStatus; long data; /* Just to remove compiler warning. */ ( void ) pvParameters; printf( "%s : %s\n", "Task2","xTaskCreate(vTask3,Task3,configMINIMAL_STACK_SIZE,NULL,1,&xTask3Handle)" ); xTaskCreate(vTask3,"Task3",configMINIMAL_STACK_SIZE,NULL,1,&xTask3Handle); printf( "%s : %s \n", "Task2","xStatus = xQueueReceive(xQueue,&data,portMAX_DELAY)" ); xStatus = xQueueReceive(xQueue,&data,portMAX_DELAY); printf( "%s : %s \n", "Task2","vTaskDelete(xTask2Handle)" ); printf( "%s\n", "***PROPERTY VIOLATION***" ); vTaskDelete(xTask2Handle); } /*-----------------------------------------------------------*/ static void vTask3( void *pvParameters ) { portBASE_TYPE xStatus; long data = 10; /* Just to remove compiler warning. */ ( void ) pvParameters; printf( "%s : %s\n", "Task3","xTaskCreate(vTask4,Task4,configMINIMAL_STACK_SIZE,NULL,4,&xTask4Handle)" ); xTaskCreate(vTask4,"Task4",configMINIMAL_STACK_SIZE,NULL,4,&xTask4Handle); printf( "%s : %s \n", "Task3","xStatus = xQueueSendToBack(xQueue,&data,0)" ); xStatus = xQueueSendToBack(xQueue,&data,0); /* printf( "%s : %s \n", "Task3","xStatus = xQueueSendToBack(xQueue,&data,0)" ); xStatus = xQueueSendToBack(xQueue,&data,0); */ printf( "%s : %s \n", "Task3","vTaskDelete(xTask3Handle)" ); vTaskDelete(xTask3Handle); } static void vTask4( void *pvParameters ) { portBASE_TYPE xStatus1,xStatus2; // long lDataLocal = 30; /* Just to remove compiler warning. */ ( void ) pvParameters; printf( "%s : %s \n", "Task4","xStatus = xQueueTakeMutexRecursive( xMutex, portMAX_DELAY )" ); xStatus1 = xQueueTakeMutexRecursive( xMutex, portMAX_DELAY ); printf( "%s : %s \n", "Task4","xStatus2 = xQueueGiveMutexRecursive( xMutex )" ); xStatus2 = xQueueGiveMutexRecursive( xMutex ); printf( "%s : %s \n", "Task4","vTaskDelete(xTask4Handle)" ); vTaskDelete(xTask4Handle); } /*-----------------------------------------------------------*/ void vApplicationIdleHook( void ) { const unsigned long ulMSToSleep = 5; /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are tasks waiting to be terminated by the idle task. */ Sleep( ulMSToSleep ); } /*-----------------------------------------------------------*/ void vApplicationMallocFailedHook( void ) { /* Can be implemented if required, but probably not required in this environment and running this demo. */ } /*-----------------------------------------------------------*/ void vApplicationStackOverflowHook( void ) { /* Can be implemented if required, but not required in this environment and running this demo. */ }