]> git.sur5r.net Git - freertos/commitdiff
Add the first and most basic task pool example.
authorrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Fri, 28 Jun 2019 23:20:52 +0000 (23:20 +0000)
committerrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Fri, 28 Jun 2019 23:20:52 +0000 (23:20 +0000)
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2667 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/TaskPool/.settings/language.settings.xml
FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/TaskPool/main.c
FreeRTOS-Plus/Source/FreeRTOS-Plus-IoT-SDK/c_sdk/standard/common/include/iot_taskpool.h

index a11d160d6d2df50cf5c0353b972e0be4793e00d4..782b97ca1286a77daf64968f4be5be18faef43fb 100644 (file)
@@ -5,7 +5,7 @@
                        <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>\r
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>\r
                        <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>\r
-                       <provider class="org.eclipse.cdt.managedbuilder.internal.language.settings.providers.GCCBuiltinSpecsDetectorMinGW" console="false" env-hash="-390853995593138292" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetectorMinGW" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings MinGW" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">\r
+                       <provider class="org.eclipse.cdt.managedbuilder.internal.language.settings.providers.GCCBuiltinSpecsDetectorMinGW" console="false" env-hash="-610351291490083443" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetectorMinGW" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings MinGW" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">\r
                                <language-scope id="org.eclipse.cdt.core.gcc"/>\r
                                <language-scope id="org.eclipse.cdt.core.g++"/>\r
                        </provider>\r
index bf6e538da80df8c4e75538ae6f92f215db6d2e74..c3181f570a437c26d0a7a2dae4c89f29f893d84c 100644 (file)
 #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
index 081e968dcb45e5385317717189f38a26cd324917..142c431efaea082c574e0082f1183e291e724d71 100644 (file)
@@ -411,6 +411,87 @@ IotTaskPoolError_t IotTaskPool_RecycleJob( IotTaskPool_t taskPool,
 IotTaskPoolError_t IotTaskPool_Schedule( IotTaskPool_t taskPool,\r
                                          IotTaskPoolJob_t job,\r
                                          uint32_t flags );\r
+\r
+/**\r
+ * @brief This function schedules a job created with @ref IotTaskPool_CreateJob or @ref IotTaskPool_CreateRecyclableJob\r
+ * against the system task pool.  The system task pool is the task pool created by @ref IotTaskPool_CreateSystemTaskPool.\r
+ *\r
+ * See @ref taskpool_design for a description of the jobs lifetime and interaction with the threads used in the task pool\r
+ * library.\r
+ *\r
+ * @param[in] job A job to schedule for execution. This must be first initialized with a call to @ref IotTaskPool_CreateJob.\r
+ * @param[in] flags Flags to be passed by the user, e.g. to identify the job as high priority by specifying #IOT_TASKPOOL_JOB_HIGH_PRIORITY.\r
+ *\r
+ * @return One of the following:\r
+ * - #IOT_TASKPOOL_SUCCESS\r
+ * - #IOT_TASKPOOL_BAD_PARAMETER\r
+ * - #IOT_TASKPOOL_ILLEGAL_OPERATION\r
+ * - #IOT_TASKPOOL_NO_MEMORY\r
+ * - #IOT_TASKPOOL_SHUTDOWN_IN_PROGRESS\r
+ *\r
+ *\r
+ * @note This function will not allocate memory, so it is guaranteed to succeed if the parameters are correct and the task pool\r
+ * was correctly initialized, and not yet destroyed.\r
+ *\r
+ * <b>Example</b>\r
+ * @code{c}\r
+ * // An example of a user context to pass to a callback through a task pool thread.\r
+ * typedef struct JobUserContext\r
+ * {\r
+ *     uint32_t counter;\r
+ * } JobUserContext_t;\r
+ *\r
+ * // An example of a user callback to invoke through a task pool thread.\r
+ * static void ExecutionCb( IotTaskPool_t taskPool, IotTaskPoolJob_t job, void * context )\r
+ * {\r
+ *     ( void )taskPool;\r
+ *     ( void )job;\r
+ *\r
+ *     JobUserContext_t * pUserContext = ( JobUserContext_t * )context;\r
+ *\r
+ *     pUserContext->counter++;\r
+ * }\r
+ *\r
+ * void TaskPoolExample( )\r
+ * {\r
+ *     JobUserContext_t userContext = { 0 };\r
+ *     IotTaskPoolJob_t job;\r
+ *\r
+ *     // Create the system task pool.  This example assumes the task pool is created successfully.\r
+ *     // It is recommended to test the function's return value in production code.\r
+ *     IotTaskPool_CreateSystemTaskPool( &xTaskPoolParameters );\r
+ *\r
+ *     // Statically allocate one job, schedule it.\r
+ *     IotTaskPool_CreateJob( &ExecutionCb, &userContext, &job );\r
+ *\r
+ *     IotTaskPoolError_t errorSchedule = IotTaskPool_ScheduleSystem( &job, 0 );\r
+ *\r
+ *     switch ( errorSchedule )\r
+ *     {\r
+ *     case IOT_TASKPOOL_SUCCESS:\r
+ *         break;\r
+ *     case IOT_TASKPOOL_BAD_PARAMETER:          // Invalid parameters, such as a NULL handle, can trigger this error.\r
+ *     case IOT_TASKPOOL_ILLEGAL_OPERATION:      // Scheduling a job that was previously scheduled or destroyed could trigger this error.\r
+ *     case IOT_TASKPOOL_NO_MEMORY:              // Scheduling a with flag #IOT_TASKPOOL_JOB_HIGH_PRIORITY could trigger this error.\r
+ *     case IOT_TASKPOOL_SHUTDOWN_IN_PROGRESS:   // Scheduling a job after trying to destroy the task pool could trigger this error.\r
+ *         // ASSERT\r
+ *         break;\r
+ *     default:\r
+ *         // ASSERT\r
+ *     }\r
+ *\r
+ *     //\r
+ *     // ... Perform other operations ...\r
+ *     //\r
+ *\r
+ *     IotTaskPool_Destroy( taskPool );\r
+ * }\r
+ * @endcode\r
+ */\r
+/* @[declare_taskpool_schedule] */\r
+IotTaskPoolError_t IotTaskPool_ScheduleSystem( IotTaskPoolJob_t pJob,\r
+                                               uint32_t flags );\r
+\r
 /* @[declare_taskpool_schedule] */\r
 \r
 /**\r