Add the Labs projects provided in the V10.2.1_191129 zip file.

This commit is contained in:
Richard Barry 2019-12-02 23:39:25 +00:00
parent 46e5937529
commit e5708b38e9
801 changed files with 356576 additions and 0 deletions

View file

@ -0,0 +1,310 @@
/*
* IoT Common V1.0.0
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file iot_taskpool.h
* @brief User-facing functions of the task pool library.
*/
#ifndef IOT_TASKPOOL_H_
#define IOT_TASKPOOL_H_
/* The config header is always included first. */
#include "iot_config.h"
/* Standard includes. */
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
/* Task pool types. */
#include "types/iot_taskpool_types_freertos.h"
/*------------------------- Task Pool library functions --------------------------*/
/**
* @functionspage{taskpool,task pool library}
* - @functionname{taskpool_function_createsystemtaskpool}
* - @functionname{taskpool_function_createjob}
* - @functionname{taskpool_function_schedule}
* - @functionname{taskpool_function_scheduledeferred}
* - @functionname{taskpool_function_getstatus}
* - @functionname{taskpool_function_trycancel}
* - @functionname{taskpool_function_getjobstoragefromhandle}
* - @functionname{taskpool_function_strerror}
*/
/**
* @functionpage{IotTaskPool_CreateSystemTaskPool,taskpool,createsystemtaskpool}
* @functionpage{IotTaskPool_CreateJob,taskpool,createjob}
* @functionpage{IotTaskPool_Schedule,taskpool,schedule}
* @functionpage{IotTaskPool_ScheduleDeferred,taskpool,scheduledeferred}
* @functionpage{IotTaskPool_GetStatus,taskpool,getstatus}
* @functionpage{IotTaskPool_TryCancel,taskpool,trycancel}
* @functionpage{IotTaskPool_GetJobStorageFromHandle,taskpool,getjobstoragefromhandle}
* @functionpage{IotTaskPool_strerror,taskpool,strerror}
*/
/**
* @brief Creates the one single instance of the system task pool.
*
* This function should be called once by the application to initialize the one single instance of the system task pool.
* An application should initialize the system task pool early in the boot sequence, before initializing any other library
* (e.g. MQTT) that uses the system task pool. An application should also initialize the system
* task pool before posting any jobs. Early initialization is typically easy to accomplish by creating the system task pool
* before the scheduler is started.
*
* The shortcut @ref IOT_SYSTEM_TASKPOOL contains the system task pool handle.
*
* @param[in] pInfo A pointer to the task pool initialization data.
*
* @return One of the following:
* - #IOT_TASKPOOL_SUCCESS
* - #IOT_TASKPOOL_BAD_PARAMETER
* - #IOT_TASKPOOL_NO_MEMORY
*
* @warning This function should be called only once. Calling this function more that once will result in
* undefined behavior.
*
*/
/* @[declare_taskpool_createsystemtaskpool] */
IotTaskPoolError_t IotTaskPool_CreateSystemTaskPool( const IotTaskPoolInfo_t * const pInfo );
/* @[declare_taskpool_createsystemtaskpool] */
/**
* @brief Creates a job for the task pool around a user-provided storage.
*
* @param[in] userCallback A user-specified callback for the job.
* @param[in] pUserContext A user-specified context for the callback.
* @param[in,out] pJobStorage The storage for the job data structure.
* @param[out] pJob A pointer to an instance of @ref IotTaskPoolJob_t that will be initialized when this
* function returns successfully. This handle can be used to inspect the job status with
* @ref IotTaskPool_GetStatus or cancel the job with @ref IotTaskPool_TryCancel, etc....
*
* @return One of the following:
* - #IOT_TASKPOOL_SUCCESS
* - #IOT_TASKPOOL_BAD_PARAMETER
*
*
*/
/* @[declare_taskpool_createjob] */
IotTaskPoolError_t IotTaskPool_CreateJob( IotTaskPoolRoutine_t userCallback,
void * pUserContext,
IotTaskPoolJobStorage_t * const pJobStorage,
IotTaskPoolJob_t * const pJob );
/* @[declare_taskpool_createjob] */
/**
* @brief This function schedules a job created with @ref IotTaskPool_CreateJob against the task pool pointed to by `taskPool`.
*
* @param[in] taskPool A handle to an initialized taskpool.
* @param[in] job A job to schedule for execution. This must be first initialized with a call to @ref IotTaskPool_CreateJob.
* @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.
*
* @return One of the following:
* - #IOT_TASKPOOL_SUCCESS
* - #IOT_TASKPOOL_BAD_PARAMETER
* - #IOT_TASKPOOL_ILLEGAL_OPERATION
* - #IOT_TASKPOOL_NO_MEMORY
* - #IOT_TASKPOOL_SHUTDOWN_IN_PROGRESS
*
* @note This function will not allocate memory, so it is guaranteed to succeed if the parameters are correct and the task pool
* was correctly initialized, and not yet destroyed.
*
* <b>Example</b>
* @code{c}
* // An example of a user context to pass to a callback through a task pool thread.
* typedef struct JobUserContext
* {
* uint32_t counter;
* } JobUserContext_t;
*
* // An example of a user callback to invoke through a task pool thread.
* static void ExecutionCb( IotTaskPool_t taskPool, IotTaskPoolJob_t job, void * context )
* {
* ( void )taskPool;
* ( void )job;
*
* JobUserContext_t * pUserContext = ( JobUserContext_t * )context;
*
* pUserContext->counter++;
* }
*
* void TaskPoolExample( )
* {
* JobUserContext_t userContext = { 0 };
* IotTaskPoolJob_t job;
* IotTaskPool_t taskPool;
*
* // Configure the task pool to hold one thread.
* // Provide proper stack size and priority per the application needs.
*
* const IotTaskPoolInfo_t tpInfo = { .minThreads = 1, .maxThreads = 1, .stackSize = 512, .priority = 0 };
*
* // Create a task pool.
* IotTaskPool_Create( &tpInfo, &taskPool );
*
* // Statically allocate one job, schedule it.
* IotTaskPool_CreateJob( &ExecutionCb, &userContext, &job );
*
* IotTaskPoolError_t errorSchedule = IotTaskPool_Schedule( taskPool, &job, 0 );
*
* switch ( errorSchedule )
* {
* case IOT_TASKPOOL_SUCCESS:
* break;
* case IOT_TASKPOOL_BAD_PARAMETER: // Invalid parameters, such as a NULL handle, can trigger this error.
* case IOT_TASKPOOL_ILLEGAL_OPERATION: // Scheduling a job that was previously scheduled or destroyed could trigger this error.
* case IOT_TASKPOOL_NO_MEMORY: // Scheduling a with flag #IOT_TASKPOOL_JOB_HIGH_PRIORITY could trigger this error.
* case IOT_TASKPOOL_SHUTDOWN_IN_PROGRESS: // Scheduling a job after trying to destroy the task pool could trigger this error.
* // ASSERT
* break;
* default:
* // ASSERT
* }
*
* //
* // ... Perform other operations ...
* //
*
* IotTaskPool_Destroy( taskPool );
* }
* @endcode
*/
/* @[declare_taskpool_schedule] */
IotTaskPoolError_t IotTaskPool_Schedule( IotTaskPool_t taskPool,
IotTaskPoolJob_t job,
uint32_t flags );
/* @[declare_taskpool_schedule] */
/**
* @brief This function schedules a job created with @ref IotTaskPool_CreateJob to be executed after a user-defined time interval.
*
* @param[in] taskPool A handle to an initialized taskpool.
* @param[in] job A job to schedule for execution. This must be first initialized with a call to @ref IotTaskPool_CreateJob.
* @param[in] timeMs The time in milliseconds to wait before scheduling the job.
*
* @return One of the following:
* - #IOT_TASKPOOL_SUCCESS
* - #IOT_TASKPOOL_BAD_PARAMETER
* - #IOT_TASKPOOL_ILLEGAL_OPERATION
* - #IOT_TASKPOOL_SHUTDOWN_IN_PROGRESS
*
*
* @note This function will not allocate memory.
*
* @warning The `taskPool` used in this function should be the same
* used to create the job pointed to by `job`, or the results will be undefined.
*
*/
/* @[declare_taskpool_scheduledeferred] */
IotTaskPoolError_t IotTaskPool_ScheduleDeferred( IotTaskPool_t taskPool,
IotTaskPoolJob_t job,
uint32_t timeMs );
/* @[declare_taskpool_scheduledeferred] */
/**
* @brief This function retrieves the current status of a job.
*
* @param[in] taskPool A handle to an initialized taskpool.
* @param[in] job The job to cancel.
* @param[out] pStatus The status of the job at the time of cancellation.
*
* @return One of the following:
* - #IOT_TASKPOOL_SUCCESS
* - #IOT_TASKPOOL_BAD_PARAMETER
* - #IOT_TASKPOOL_SHUTDOWN_IN_PROGRESS
*
* @warning This function is not thread safe and the job status returned in `pStatus` may be invalid by the time
* the calling thread has a chance to inspect it.
*/
/* @[declare_taskpool_getstatus] */
IotTaskPoolError_t IotTaskPool_GetStatus( IotTaskPool_t taskPool,
IotTaskPoolJob_t job,
IotTaskPoolJobStatus_t * const pStatus );
/* @[declare_taskpool_getstatus] */
/**
* @brief This function tries to cancel a job that was previously scheduled with @ref IotTaskPool_Schedule.
*
* A job can be canceled only if it is not yet executing, i.e. if its status is
* @ref IOT_TASKPOOL_STATUS_READY or @ref IOT_TASKPOOL_STATUS_SCHEDULED. Calling
* @ref IotTaskPool_TryCancel on a job whose status is @ref IOT_TASKPOOL_STATUS_COMPLETED,
* or #IOT_TASKPOOL_STATUS_CANCELED will yield a #IOT_TASKPOOL_CANCEL_FAILED return result.
*
* @param[in] taskPool A handle to an initialized taskpool.
* @param[in] job The job to cancel.
* @param[out] pStatus The status of the job at the time of cancellation.
*
* @return One of the following:
* - #IOT_TASKPOOL_SUCCESS
* - #IOT_TASKPOOL_BAD_PARAMETER
* - #IOT_TASKPOOL_SHUTDOWN_IN_PROGRESS
* - #IOT_TASKPOOL_CANCEL_FAILED
*
* @warning The `taskPool` used in this function should be the same
* used to create the job pointed to by `job`, or the results will be undefined.
*
*/
/* @[declare_taskpool_trycancel] */
IotTaskPoolError_t IotTaskPool_TryCancel( IotTaskPool_t taskPool,
IotTaskPoolJob_t job,
IotTaskPoolJobStatus_t * const pStatus );
/* @[declare_taskpool_trycancel] */
/**
* @brief Returns a pointer to the job storage from an instance of a job handle
* of type @ref IotTaskPoolJob_t. This function is guaranteed to succeed for a
* valid job handle.
*
* @param[in] job The job handle.
*
* @return A pointer to the storage associated with the job handle `job`.
*
* @warning If the `job` handle used is invalid, the results will be undefined.
*/
/* @[declare_taskpool_getjobstoragefromhandle] */
IotTaskPoolJobStorage_t * IotTaskPool_GetJobStorageFromHandle( IotTaskPoolJob_t job );
/* @[declare_taskpool_getjobstoragefromhandle] */
/**
* @brief Returns a string that describes an @ref IotTaskPoolError_t.
*
* Like the POSIX's `strerror`, this function returns a string describing a
* return code. In this case, the return code is a task pool library error code,
* `status`.
*
* The string returned by this function <b>MUST</b> be treated as read-only: any
* attempt to modify its contents may result in a crash. Therefore, this function
* is limited to usage in logging.
*
* @param[in] status The status to describe.
*
* @return A read-only string that describes `status`.
*
* @warning The string returned by this function must never be modified.
*/
/* @[declare_taskpool_strerror] */
const char * IotTaskPool_strerror( IotTaskPoolError_t status );
/* @[declare_taskpool_strerror] */
#endif /* ifndef IOT_TASKPOOL_H_ */

View file

@ -0,0 +1,150 @@
/*
* Amazon FreeRTOS Platform V1.0.0
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/**
* @file iot_network_freertos.h
* @brief Declares the network stack functions specified in iot_network.h for
* FreeRTOS+TCP.
*/
#ifndef _IOT_NETWORK_FREERTOS_H_
#define _IOT_NETWORK_FREERTOS_H_
/* Standard includes. */
#include <stdbool.h>
/* Platform types include. */
#include "types/iot_platform_types.h"
/* Platform network include. */
#include "platform/iot_network.h"
/**
* @brief Provides a default value for an #IotNetworkConnectionFreeRTOS_t.
*
* All instances of #IotNetworkConnectionFreeRTOS_t should be initialized with
* this constant.
*
* @warning Failing to initialize an #IotNetworkConnectionFreeRTOS_t with this
* initializer may result in undefined behavior!
* @note This initializer may change at any time in future versions, but its
* name will remain the same.
*/
#define IOT_NETWORK_CONNECTION_FREERTOS_INITIALIZER { 0 }
/**
* @brief Generic initializer for an #IotNetworkServerInfo_t.
*
* @note This initializer may change at any time in future versions, but its
* name will remain the same.
*/
#define IOT_NETWORK_SERVER_INFO_FREERTOS_INITIALIZER { 0 }
/**
* @brief Generic initializer for an #IotNetworkCredentials_t.
*
* @note This initializer may change at any time in future versions, but its
* name will remain the same.
*/
#define IOT_NETWORK_CREDENTIALS_FREERTOS_INITIALIZER { 0 }
/**
* @brief Provides a pointer to an #IotNetworkInterface_t that uses the functions
* declared in this file.
*/
#define IOT_NETWORK_INTERFACE_FREERTOS ( &( IotNetworkFreeRTOS ) )
/**
* @brief One-time initialization function for this network stack.
*/
IotNetworkError_t IotNetworkFreeRTOS_Init( void );
/**
* @brief One-time cleanup function for this network stack.
*/
void IotNetworkFreeRTOS_Cleanup( void );
/**
* @brief An implementation of #IotNetworkInterface_t::create for FreeRTOS+TCP
* sockets.
*/
IotNetworkError_t IotNetworkFreeRTOS_Create( IotNetworkServerInfo_t pServerInfo,
IotNetworkCredentials_t pCredentialInfo,
IotNetworkConnection_t * pConnection );
/**
* @brief An implementation of #IotNetworkInterface_t::setReceiveCallback for
* FreeRTOS+TCP sockets.
*/
IotNetworkError_t IotNetworkFreeRTOS_SetReceiveCallback( IotNetworkConnection_t pConnection,
IotNetworkReceiveCallback_t receiveCallback,
void * pContext );
/**
* @brief An implementation of #IotNetworkInterface_t::send for FreeRTOS+TCP
* sockets.
*/
size_t IotNetworkFreeRTOS_Send( IotNetworkConnection_t pConnection,
const uint8_t * pMessage,
size_t messageLength );
/**
* @brief An implementation of #IotNetworkInterface_t::receive for FreeRTOS+TCP
* sockets.
*/
size_t IotNetworkFreeRTOS_Receive( IotNetworkConnection_t pConnection,
uint8_t * pBuffer,
size_t bytesRequested );
/**
* @brief An implementation of #IotNetworkInterface::receiveUpto for FreeRTOS+TCP
* sockets.
*/
size_t IotNetworkFreeRTOS_ReceiveUpto( IotNetworkConnection_t pConnection,
uint8_t * pBuffer,
size_t bufferSize );
/**
* @brief An implementation of #IotNetworkInterface_t::close for FreeRTOS+TCP
* sockets.
*/
IotNetworkError_t IotNetworkFreeRTOS_Close( IotNetworkConnection_t pConnection );
/**
* @brief An implementation of #IotNetworkInterface_t::destroy for FreeRTOS+TCP
* sockets.
*/
IotNetworkError_t IotNetworkFreeRTOS_Destroy( IotNetworkConnection_t pConnection );
/**
* @cond DOXYGEN_IGNORE
* Doxygen should ignore this section.
*
* Declaration of a network interface struct using the functions in this file.
*/
extern const IotNetworkInterface_t IotNetworkFreeRTOS;
/** @endcond */
#endif /* ifndef _IOT_NETWORK_FREERTOS_H_ */

View file

@ -0,0 +1,92 @@
/*
* Amazon FreeRTOS Platform V1.0.0
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/**
* @file iot_platform_types_posix.h
* @brief Definitions of platform layer types on POSIX systems.
*/
#ifndef _IOT_PLATFORM_TYPES_AFR_H_
#define _IOT_PLATFORM_TYPES_AFR_H_
#include "timers.h"
typedef struct iot_mutex_internal
{
StaticSemaphore_t xMutex; /**< FreeRTOS mutex. */
BaseType_t recursive; /**< Type; used for indicating if this is reentrant or normal. */
} iot_mutex_internal_t;
/**
* @brief The native mutex type on AFR systems.
*/
typedef iot_mutex_internal_t _IotSystemMutex_t;
typedef struct iot_sem_internal
{
StaticSemaphore_t xSemaphore; /**< FreeRTOS semaphore. */
} iot_sem_internal_t;
/**
* @brief The native semaphore type on AFR systems.
*/
typedef iot_sem_internal_t _IotSystemSemaphore_t;
/**
* @brief Holds information about an active detached thread so that we can
* delete the FreeRTOS task when it completes
*/
typedef struct threadInfo
{
void * pArgument; /**< @brief Argument to `threadRoutine`. */
void ( * threadRoutine )( void * ); /**< @brief Thread function to run. */
} threadInfo_t;
/**
* @brief Holds information about an active timer.
*/
typedef struct timerInfo
{
TimerHandle_t timer; /**< @brief Underlying timer. */
void ( * threadRoutine )( void * ); /**< @brief Thread function to run on timer expiration. */
void * pArgument; /**< @brief First argument to threadRoutine. */
StaticTimer_t xTimerBuffer; /**< Memory that holds the FreeRTOS timer. */
TickType_t xTimerPeriod; /**< Period of this timer. */
} timerInfo_t;
/**
* @brief Represents an #IotTimer_t on AFR systems.
*/
typedef timerInfo_t _IotSystemTimer_t;
struct IotNetworkServerInfo;
struct IotNetworkCredentials;
struct _networkConnection;
typedef struct IotNetworkServerInfo const * _IotNetworkServerInfo_t;
typedef struct IotNetworkCredentials * _IotNetworkCredentials_t;
typedef struct _networkConnection * _IotNetworkConnection_t;
#endif /* ifndef _IOT_PLATFORM_TYPES_POSIX_H_ */

View file

@ -0,0 +1,306 @@
/*
* IoT Common V1.0.0
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file iot_taskpool_types.h
* @brief Types of the task pool.
*/
#ifndef IOT_TASKPOOL_TYPES_H_
#define IOT_TASKPOOL_TYPES_H_
/* The config header is always included first. */
#include "iot_config.h"
/* Standard includes. */
#include <stdbool.h>
#include <stdint.h>
/* Platform types includes. */
#include "types/iot_platform_types.h"
/* Linear containers (lists and queues) include. */
#include "iot_linear_containers.h"
/*-------------------------- Task pool enumerated types --------------------------*/
/**
* @ingroup taskpool_datatypes_enums
* @brief Return codes of [task pool functions](@ref taskpool_functions).
*/
typedef enum IotTaskPoolError
{
/**
* @brief Task pool operation completed successfully.
*/
IOT_TASKPOOL_SUCCESS = 0,
/**
* @brief Task pool operation failed because at least one parameter is invalid.
*/
IOT_TASKPOOL_BAD_PARAMETER,
/**
* @brief Task pool operation failed because it is illegal.
*/
IOT_TASKPOOL_ILLEGAL_OPERATION,
/**
* @brief Task pool operation failed because allocating memory failed.
*/
IOT_TASKPOOL_NO_MEMORY,
/**
* @brief Task pool operation failed because of an invalid parameter.
*/
IOT_TASKPOOL_SHUTDOWN_IN_PROGRESS,
/**
* @brief Task pool cancellation failed.
*/
IOT_TASKPOOL_CANCEL_FAILED,
/**
* @brief Task pool operation general failure.
*/
IOT_TASKPOOL_GENERAL_FAILURE,
} IotTaskPoolError_t;
/**
* @enums{taskpool,Task pool library}
*/
/**
* @ingroup taskpool_datatypes_enums
* @brief Status codes of [task pool Job](@ref IotTaskPoolJob_t).
*
*/
typedef enum IotTaskPoolJobStatus
{
/**
* @brief Job is ready to be scheduled.
*
*/
IOT_TASKPOOL_STATUS_READY = 0,
/**
* @brief Job has been queued for execution.
*
*/
IOT_TASKPOOL_STATUS_SCHEDULED,
/**
* @brief Job has been scheduled for deferred execution.
*
*/
IOT_TASKPOOL_STATUS_DEFERRED,
/**
* @brief Job is executing.
*
*/
IOT_TASKPOOL_STATUS_COMPLETED,
/**
* @brief Job has been canceled before executing.
*
*/
IOT_TASKPOOL_STATUS_CANCELED,
/**
* @brief Job status is undefined.
*
*/
IOT_TASKPOOL_STATUS_UNDEFINED,
} IotTaskPoolJobStatus_t;
/*------------------------- Task pool types and handles --------------------------*/
/**
* @ingroup taskpool_datatypes_handles
* @brief Opaque handle of a Task Pool instance.
*
* This type identifies a Task Pool instance, which is valid after a successful call
* to @ref taskpool_function_createsystemtaskpool.
*
* @initializer{IotTaskPool_t,IOT_TASKPOOL_INITIALIZER}
*/
typedef struct _taskPool * IotTaskPool_t;
/**
* @ingroup taskpool_datatypes_handles
* @brief A storage placeholder for TaskPool Jobs.
*
* This type provides a means to statically allocate an IoT TaskPool Job while
* hiding internal details.
*/
typedef struct IotTaskPoolJobStorage IotTaskPoolJobStorage_t;
/**
* @ingroup taskpool_datatypes_structs
* @brief A storage placeholder for private data in the IotTaskPoolJobStorage struct.
*
* @warning This is a system-level data type that should not be modified or used directly in any application.
* @warning This is a system-level data type that can and will change across different versions of the platform, with no regards for backward compatibility.
*/
struct PrivateMember
{
IotLink_t dummy1; /**< @brief Placeholder. */
TickType_t dummy2; /**< @brief Placeholder. */
};
/**
* @ingroup taskpool_datatypes_structs
* @brief The job storage data structure provides the storage for a statically allocated Task Pool Job instance.
*
* @warning This is a system-level data type that should not be modified or used directly in any application.
* @warning This is a system-level data type that can and will change across different versions of the platform, with no regards for backward compatibility.
*
*/
struct IotTaskPoolJobStorage
{
IotLink_t link; /**< @brief Placeholder. */
void * dummy2; /**< @brief Placeholder. */
void * dummy3; /**< @brief Placeholder. */
IotTaskPoolJobStatus_t status; /**< @brief Placeholder. */
struct PrivateMember dummy6; /**< @brief Placeholder. */
};
/**
* @ingroup taskpool_datatypes_handles
* @brief Opaque handle of a Task Pool Job.
*
* This type identifies a Task Pool Job instance, which is valid after a successful call
* to @ref taskpool_function_createjob.
*
* @initializer{IotTaskPoolJob_t,IOT_TASKPOOL_JOB_INITIALIZER}
*
*/
typedef struct _taskPoolJob * IotTaskPoolJob_t;
/*------------------------- Task pool parameter structs --------------------------*/
/**
* @ingroup taskpool_datatypes_functionpointers
* @brief Callback type for a user callback.
*
* This type identifies the user callback signature to execute a task pool job. This callback will be invoked
* by the task pool threads with the `pUserContext` parameter, as specified by the user when
* calling @ref IotTaskPool_Schedule.
*
*/
typedef void ( * IotTaskPoolRoutine_t )( IotTaskPool_t pTaskPool,
IotTaskPoolJob_t pJob,
void * pUserContext );
/**
* @ingroup taskpool_datatypes_paramstructs
* @brief Initialization information to create one task pool instance.
*
* @paramfor @ref taskpool_function_createsystemtaskpool
*
* @initializer{IotTaskPoolInfo_t,IOT_TASKPOOL_INFO_INITIALIZER}
*/
typedef struct IotTaskPoolInfo
{
/**
* @brief Specifies the operating parameters for a task pool.
*
* @attention #IotTaskPoolInfo_t.minThreads <b>MUST</b> be at least 1.
*/
uint32_t minThreads; /**< @brief Minimum number of threads in a task pool. These tasks will be statically allocated. */
uint32_t maxThreads; /**< @brief Maximum number of threads in a task pool. This is fixed for the lifetime of the taskpool. */
uint32_t stackSize; /**< @brief Stack size for every task pool thread. The stack size for each thread is fixed after the task pool is created and cannot be changed. */
int32_t priority; /**< @brief priority for every task pool thread. The priority for each thread is fixed after the task pool is created and cannot be changed. */
} IotTaskPoolInfo_t;
/*------------------------- TASKPOOL defined constants --------------------------*/
/**
* @constantspage{taskpool,task pool library}
*
* @section taskpool_constants_initializers Task pool Initializers
* @brief Provides default values for initializing the data types of the task pool library.
*
* @snippet this define_taskpool_initializers
*
* All user-facing data types of the task pool library can be initialized using
* one of the following.
*
* @warning Failure to initialize a task pool data type with the appropriate initializer
* may result in a runtime error!
* @note The initializers may change at any time in future versions, but their
* names will remain the same.
*
* <b>Example</b>
* @code{c}
*
* IotTaskPool_t * pTaskPool;
*
* const IotTaskPoolInfo_t tpInfo = IOT_TASKPOOL_INFO_INITIALIZER_LARGE;
*
* IotTaskPoolError_t error = IotTaskPool_Create( &tpInfo, &pTaskPool );
*
* // Use the task pool
* // ...
*
* @endcode
*
*/
/* @[define_taskpool_initializers] */
/** @brief Initializer for a small #IotTaskPoolInfo_t. */
#define IOT_TASKPOOL_INFO_INITIALIZER_SMALL { .minThreads = 1, .maxThreads = 1, .stackSize = IOT_THREAD_DEFAULT_STACK_SIZE, .priority = IOT_THREAD_DEFAULT_PRIORITY }
/** @brief Initializer for a medium #IotTaskPoolInfo_t. */
#define IOT_TASKPOOL_INFO_INITIALIZER_MEDIUM { .minThreads = 1, .maxThreads = 2, .stackSize = IOT_THREAD_DEFAULT_STACK_SIZE, .priority = IOT_THREAD_DEFAULT_PRIORITY }
/** @brief Initializer for a large #IotTaskPoolInfo_t. */
#define IOT_TASKPOOL_INFO_INITIALIZER_LARGE { .minThreads = 2, .maxThreads = 3, .stackSize = IOT_THREAD_DEFAULT_STACK_SIZE, .priority = IOT_THREAD_DEFAULT_PRIORITY }
/** @brief Initializer for a very large #IotTaskPoolInfo_t. */
#define IOT_TASKPOOL_INFO_INITIALIZER_XLARGE { .minThreads = 2, .maxThreads = 4, .stackSize = IOT_THREAD_DEFAULT_STACK_SIZE, .priority = IOT_THREAD_DEFAULT_PRIORITY }
/** @brief Initializer for a typical #IotTaskPoolInfo_t. */
#define IOT_TASKPOOL_INFO_INITIALIZER IOT_TASKPOOL_INFO_INITIALIZER_MEDIUM
/** @brief Initializer for a #IotTaskPool_t. */
#define IOT_TASKPOOL_INITIALIZER NULL
/** @brief Initializer for a #IotTaskPoolJobStorage_t. */
#define IOT_TASKPOOL_JOB_STORAGE_INITIALIZER { { NULL, NULL }, NULL, NULL, 0, IOT_TASKPOOL_STATUS_UNDEFINED }
/** @brief Initializer for a #IotTaskPoolJob_t. */
#define IOT_TASKPOOL_JOB_INITIALIZER NULL
/* @[define_taskpool_initializers] */
/**
* @brief Flag for scheduling a job to execute immediately, even if the maximum number of threads in the
* task pool was reached already.
*
* @warning This flag may cause the task pool to create a worker to serve the job immediately, and
* therefore using this flag may incur in additional memory usage and potentially fail scheduling the job.
*/
#define IOT_TASKPOOL_JOB_HIGH_PRIORITY ( ( uint32_t ) 0x00000001 )
/**
* @brief Allows the use of the handle to the system task pool.
*
* @warning The system task pool handle is not valid unless @ref IotTaskPool_CreateSystemTaskPool is
* called before the handle is used.
*/
#define IOT_SYSTEM_TASKPOOL ( NULL )
#endif /* ifndef IOT_TASKPOOL_TYPES_H_ */