#include "FreeRTOS.h"\r
#include "task.h"\r
\r
+/* IoT SDK includes. */\r
+#include "iot_taskpool.h"\r
+\r
+/*\r
+ * Prototypes for the functions that demonstrate the task pool API.\r
+ */\r
+static void prvExample_BasicSingleJob( void );\r
+\r
+/* Prototypes of the callback functions used in the examples. */\r
+static void prvSimpleTaskNotifyCallback( IotTaskPool_t pTaskPool, IotTaskPoolJob_t pJob, void *pUserContext );\r
+\r
+/*\r
+ * Prototypes for the standard FreeRTOS application hook (callback) functions\r
+ * implemented within this file. See http://www.freertos.org/a00016.html .\r
+ */\r
+void vApplicationMallocFailedHook( void );\r
+void vApplicationIdleHook( void );\r
+void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
+void vApplicationTickHook( void );\r
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize );\r
void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize );\r
\r
+/*\r
+ * The task used to demonstrate the task pool API.\r
+ */\r
+static void prvTaskPoolDemoTask( void *pvParameters );\r
+\r
+static const IotTaskPoolInfo_t xTaskPoolParameters = {\r
+ /* Minimum number of threads in a task pool. */\r
+ 2,\r
+ /* Maximum number of threads in a task pool. */\r
+ 2,\r
+ /* Stack size for every task pool thread - in words, not bytes. */\r
+ configMINIMAL_STACK_SIZE,\r
+ /* Priority for every task pool thread. */\r
+ tskIDLE_PRIORITY,\r
+ };\r
+\r
+/*-----------------------------------------------------------*/\r
\r
int main( void )\r
{\r
+ /* This example uses a single application task, which in turn is used to\r
+ create and send jobs to task pool tasks. */\r
+ xTaskCreate( prvTaskPoolDemoTask,\r
+ "PoolDemo",\r
+ configMINIMAL_STACK_SIZE,\r
+ NULL,\r
+ tskIDLE_PRIORITY,\r
+ NULL );\r
+\r
+ vTaskStartScheduler();\r
+\r
+ /* Should not reach here as vTaskStartScheduler() will only return if there\r
+ was insufficient FreeRTOS heap memory to create the Idle or Timer\r
+ Daemon task. */\r
return 0;\r
}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvSimpleTaskNotifyCallback( IotTaskPool_t pTaskPool, IotTaskPoolJob_t pJob, void *pUserContext )\r
+{\r
+TaskHandle_t xTaskToNotify = ( TaskHandle_t ) pUserContext;\r
+\r
+ /* Remove warnings about unused parameters. */\r
+ ( void ) pTaskPool;\r
+ ( void ) pJob;\r
+\r
+ /* Notify the task that created this job. */\r
+ xTaskNotifyGive( xTaskToNotify );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvExample_BasicSingleJob( void )\r
+{\r
+IotTaskPoolJobStorage_t xJobStorage;\r
+IotTaskPoolJob_t xJob;\r
+IotTaskPoolError_t xResult;\r
+\r
+ /* Ensure the notification count is 0 before scheduling the job. */\r
+ while( ulTaskNotifyTake( pdTRUE, 0 ) != 0 );\r
+\r
+ /* Create and schedule a job using the handle of this task as the job's\r
+ context and the function that sends a notification to the task handle as\r
+ the jobs callback function. */\r
+ xResult = IotTaskPool_CreateJob( prvSimpleTaskNotifyCallback, /* Callback function. */\r
+ ( void * ) xTaskGetCurrentTaskHandle(), /* Job context. */\r
+ &xJobStorage,\r
+ &xJob );\r
+ configASSERT( xResult == IOT_TASKPOOL_SUCCESS );\r
+ IotTaskPool_ScheduleSystem( xJob, 0 );\r
+\r
+ /* Wait for the notification coming from the job's callback function. */\r
+ ulTaskNotifyTake( pdTRUE, portMAX_DELAY );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvTaskPoolDemoTask( void *pvParameters )\r
+{\r
+IotTaskPoolError_t xResult;\r
\r
+ /* Remove compiler warnings about unused parameters. */\r
+ ( void ) pvParameters;\r
+\r
+ /* The task pool must be created before it can be used. */\r
+ xResult = IotTaskPool_CreateSystemTaskPool( &xTaskPoolParameters );\r
+ configASSERT( xResult == IOT_TASKPOOL_SUCCESS );\r
+\r
+ for( ;; )\r
+ {\r
+ /* Run through each task pool example in turn. See the comments in the\r
+ below functions for details of their behaviour. */\r
+ prvExample_BasicSingleJob();\r
+\r
+\r
+\r
+ vTaskDelete( NULL );\r
+ }\r
+}\r
/*-----------------------------------------------------------*/\r
\r
void vApplicationMallocFailedHook( void )\r