CARPLAY版本整理
This commit is contained in:
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Amazon FreeRTOS POSIX V1.1.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 errno.h
|
||||
* @brief System error numbers.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
|
||||
*
|
||||
* The values defined in this file may not be compatible with the strerror
|
||||
* function provided by this system.
|
||||
*/
|
||||
|
||||
#ifndef _FREERTOS_POSIX_ERRNO_H_
|
||||
#define _FREERTOS_POSIX_ERRNO_H_
|
||||
|
||||
/* Undefine all errnos to avoid redefinition errors with system errnos. */
|
||||
#undef EPERM
|
||||
#undef ENOENT
|
||||
#undef EBADF
|
||||
#undef EAGAIN
|
||||
#undef ENOMEM
|
||||
#undef EEXIST
|
||||
#undef EBUSY
|
||||
#undef EINVAL
|
||||
#undef ENOSPC
|
||||
#undef ERANGE
|
||||
#undef ENAMETOOLONG
|
||||
#undef EDEADLK
|
||||
#undef EOVERFLOW
|
||||
#undef ENOSYS
|
||||
#undef EMSGSIZE
|
||||
#undef ENOTSUP
|
||||
#undef ETIMEDOUT
|
||||
|
||||
/**
|
||||
* @name Definition of POSIX errnos.
|
||||
*/
|
||||
/**@{ */
|
||||
#define ENOERR 0 /**< No error */
|
||||
#define EPERM 1 /**< Operation not permitted. */
|
||||
#define ENOENT 2 /**< No such file or directory. */
|
||||
#define ESRCH 3 /* No such process */
|
||||
#define EIO 5 /* I/O error */
|
||||
#define ENXIO 6 /* No such device or address */
|
||||
#define EBADF 9 /**< Bad file descriptor. */
|
||||
#define EAGAIN 11 /**< Resource unavailable, try again. */
|
||||
#define ENOMEM 12 /**< Not enough space. */
|
||||
#define EACCES 13 /* Permission denied */
|
||||
#define EBUSY 16 /**< Device or resource busy. */
|
||||
#define EEXIST 17 /**< File exists. */
|
||||
#define ENODEV 19 /* No such device */
|
||||
#define EINVAL 22 /**< Invalid argument. */
|
||||
#define ENOSPC 28 /**< No space left on device. */
|
||||
#define ERANGE 34 /**< Result too large. */
|
||||
#define ENAMETOOLONG 36 /**< File name too long. */
|
||||
#define EDEADLK 45 /**< Resource deadlock would occur. */
|
||||
#define EPROTO 71 /* Protocol error */
|
||||
#define EOVERFLOW 75 /**< Value too large to be stored in data type. */
|
||||
#define EILSEQ 84 /* Illegal byte sequence */
|
||||
#define ENOSYS 88 /**< Function not supported. */
|
||||
#define EMSGSIZE 90 /**< Message too long. */
|
||||
#define ENOTSUP 95 /**< Operation not supported. */
|
||||
#define EINPROGRESS 115 /* Operation now in progress */
|
||||
#define ETIMEDOUT 116 /**< Connection timed out. */
|
||||
#define EREMOTEIO 121 /* Remote I/O error */
|
||||
#define ENOMEDIUM 123 /* No medium found */
|
||||
|
||||
|
||||
/**@} */
|
||||
|
||||
/**
|
||||
* @name System Variable
|
||||
*
|
||||
* @brief Define FreeRTOS+POSIX errno, if enabled.
|
||||
* Set configUSE_POSIX_ERRNO to enable, and clear to disable. See FreeRTOS.h.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#if ( configUSE_POSIX_ERRNO == 1 )
|
||||
extern int FreeRTOS_errno;
|
||||
#define errno FreeRTOS_errno
|
||||
#endif
|
||||
/**@} */
|
||||
|
||||
#endif /* ifndef _FREERTOS_POSIX_ERRNO_H_ */
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Amazon FreeRTOS POSIX V1.1.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 fcntl.h
|
||||
* @brief File control options.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/fcntl.h.html
|
||||
*/
|
||||
|
||||
#ifndef _FREERTOS_POSIX_FCNTL_H_
|
||||
#define _FREERTOS_POSIX_FCNTL_H_
|
||||
|
||||
/**
|
||||
* @name File creation flags for use in the oflag value to open() and openat().
|
||||
*/
|
||||
/**@{ */
|
||||
#define O_CLOEXEC 0x0001 /**< Close the file descriptor upon exec(). */
|
||||
#define O_CREAT 0x0002 /**< Create file if it does not exist. */
|
||||
#define O_DIRECTORY 0x0004 /**< Fail if file is a non-directory file. */
|
||||
#define O_EXCL 0x0008 /**< Exclusive use flag. */
|
||||
#define O_NOCTTY 0x0010 /**< Do not assign controlling terminal. */
|
||||
#define O_NOFOLLOW 0x0020 /**< Do not follow symbolic links. */
|
||||
#define O_TRUNC 0x0040 /**< Truncate flag. */
|
||||
#define O_TTY_INIT 0x0080 /**< termios structure provides conforming behavior. */
|
||||
/**@} */
|
||||
|
||||
/**
|
||||
* @name File status flags for open(), openat(), and fcntl().
|
||||
*/
|
||||
/**@{ */
|
||||
#define O_APPEND 0x0100 /**< Set append mode. */
|
||||
#define O_DSYNC 0x0200 /**< Write according to synchronized I/O data integrity completion. */
|
||||
#define O_NONBLOCK 0x0400 /**< Non-blocking mode. */
|
||||
#define O_RSYNC 0x0800 /**< Synchronized read I/O operations. */
|
||||
#define O_SYNC 0x0200 /**< Write according to synchronized I/O file integrity completion. */
|
||||
/**@} */
|
||||
|
||||
/**
|
||||
* @name Mask for file access modes.
|
||||
*/
|
||||
/**@{ */
|
||||
#define O_ACCMODE 0xF000
|
||||
/**@} */
|
||||
|
||||
/**
|
||||
* @name File access modes for open(), openat(), and fcntl().
|
||||
*/
|
||||
/**@{ */
|
||||
#define O_EXEC 0x1000 /**< Open for execute only (non-directory files). */
|
||||
#define O_RDONLY 0x2000 /**< Open for reading only. */
|
||||
#define O_RDWR 0xA000 /**< Open for reading and writing. */
|
||||
#define O_SEARCH 0x4000 /**< Open directory for search only. */
|
||||
#define O_WRONLY 0x8000 /**< Open for writing only. */
|
||||
/**@} */
|
||||
|
||||
#endif /* ifndef _FREERTOS_POSIX_FCNTL_H_ */
|
@ -0,0 +1,250 @@
|
||||
/*
|
||||
* Amazon FreeRTOS POSIX V1.1.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 mqueue.h
|
||||
* @brief Message queues.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/mqueue.h.html
|
||||
*/
|
||||
|
||||
#ifndef _FREERTOS_POSIX_MQUEUE_H_
|
||||
#define _FREERTOS_POSIX_MQUEUE_H_
|
||||
|
||||
/* FreeRTOS+POSIX includes. */
|
||||
#include "FreeRTOS_POSIX/time.h"
|
||||
|
||||
/**
|
||||
* @brief Message queue descriptor.
|
||||
*/
|
||||
typedef void * mqd_t;
|
||||
|
||||
/**
|
||||
* @brief Message queue attributes.
|
||||
*/
|
||||
struct mq_attr
|
||||
{
|
||||
long mq_flags; /**< Message queue flags. */
|
||||
long mq_maxmsg; /**< Maximum number of messages. */
|
||||
long mq_msgsize; /**< Maximum message size. */
|
||||
long mq_curmsgs; /**< Number of messages currently queued. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Close a message queue.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_close.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion
|
||||
* @retval -1 - A error occurred. errno is also set.
|
||||
*
|
||||
* @sideeffect Possible errno values
|
||||
* <br>
|
||||
* EBADF - The mqdes argument is not a valid message queue descriptor.
|
||||
*/
|
||||
int mq_close( mqd_t mqdes );
|
||||
|
||||
/**
|
||||
* @brief Get message queue attributes.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_getattr.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion
|
||||
* @retval -1 - A error occurred. errno is also set.
|
||||
*
|
||||
* @sideeffect Possible errno values
|
||||
* <br>
|
||||
* DBADF - The mqdes argument is not a valid message queue descriptor.
|
||||
*/
|
||||
int mq_getattr( mqd_t mqdes,
|
||||
struct mq_attr * mqstat );
|
||||
|
||||
/**
|
||||
* @brief Open a message queue.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_open.html
|
||||
*
|
||||
* @note Supported name pattern: leading <slash> character in name is always required;
|
||||
* the maximum length (excluding null-terminator) of the name argument can be NAME_MAX.
|
||||
* The default value of NAME_MAX in FreeRTOS_POSIX_portable_default.h is 64, which can be
|
||||
* overwritten by user.
|
||||
* @note mode argument is not supported.
|
||||
* @note Supported oflags: O_RDWR, O_CREAT, O_EXCL, and O_NONBLOCK.
|
||||
*
|
||||
* @retval Message queue descriptor -- Upon successful completion
|
||||
* @retval (mqd_t) - 1 -- An error occurred. errno is also set.
|
||||
*
|
||||
* @sideeffect Possible errno values
|
||||
* <br>
|
||||
* EINVAL - name argument is invalid (not following name pattern),
|
||||
* OR if O_CREAT is specified in oflag with attr argument not NULL and either mq_maxmsg or mq_msgsize is equal to or less than zero,
|
||||
* OR either O_CREAT or O_EXCL is not set and a queue with the same name is unlinked but pending to be removed.
|
||||
* <br>
|
||||
* EEXIST - O_CREAT and O_EXCL are set and the named message queue already exists.
|
||||
* <br>
|
||||
* ENOSPC - There is insufficient space for the creation of the new message queue.
|
||||
* <br>
|
||||
* ENOENT - O_CREAT is not set and the named message queue does not exist.
|
||||
*/
|
||||
mqd_t mq_open( const char * name,
|
||||
int oflag,
|
||||
mode_t mode,
|
||||
struct mq_attr * attr );
|
||||
|
||||
/**
|
||||
* @brief Receive a message from a message queue.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html
|
||||
*
|
||||
* @note msg_prio argument is not supported. Messages are not checked for corruption.
|
||||
*
|
||||
* @retval The length of the selected message in bytes - Upon successful completion.
|
||||
* The message is removed from the queue
|
||||
* @retval -1 - An error occurred. errno is also set.
|
||||
*
|
||||
* @sideeffect Possible errno values
|
||||
* <br>
|
||||
* EBADF - The mqdes argument is not a valid message queue descriptor open for reading.
|
||||
* <br>
|
||||
* EMSGSIZE - The specified message buffer size, msg_len, is less than the message size attribute of the message queue.
|
||||
* <br>
|
||||
* ETIMEDOUT - The O_NONBLOCK flag was not set when the message queue was opened,
|
||||
* but no message arrived on the queue before the specified timeout expired.
|
||||
* <br>
|
||||
* EAGAIN - O_NONBLOCK was set in the message description associated with mqdes, and the specified message queue is empty.
|
||||
*/
|
||||
ssize_t mq_receive( mqd_t mqdes,
|
||||
char * msg_ptr,
|
||||
size_t msg_len,
|
||||
unsigned int * msg_prio );
|
||||
|
||||
/**
|
||||
* @brief Send a message to a message queue.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html
|
||||
*
|
||||
* @note msg_prio argument is not supported.
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
* @retval -1 - An error occurred. errno is also set.
|
||||
*
|
||||
* @sideeffect Possible errno values
|
||||
* <br>
|
||||
* EBADF - The mqdes argument is not a valid message queue descriptor open for writing.
|
||||
* <br>
|
||||
* EMSGSIZE - The specified message length, msg_len, exceeds the message size attribute of the message queue,
|
||||
* OR insufficient memory for the message to be sent.
|
||||
* <br>
|
||||
* ETIMEDOUT - The O_NONBLOCK flag was not set when the message queue was opened,
|
||||
* but the timeout expired before the message could be added to the queue.
|
||||
* <br>
|
||||
* EAGAIN - The O_NONBLOCK flag is set in the message queue description associated with mqdes,
|
||||
* and the specified message queue is full.
|
||||
*/
|
||||
int mq_send( mqd_t mqdes,
|
||||
const char * msg_ptr,
|
||||
size_t msg_len,
|
||||
unsigned msg_prio );
|
||||
|
||||
/**
|
||||
* @brief Receive a message from a message queue with timeout.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_timedreceive.html
|
||||
*
|
||||
* @note msg_prio argument is not supported. Messages are not checked for corruption.
|
||||
*
|
||||
* @retval The length of the selected message in bytes - Upon successful completion.
|
||||
* The message is removed from the queue
|
||||
* @retval -1 - An error occurred. errno is also set.
|
||||
*
|
||||
* @sideeffect Possible errno values
|
||||
* <br>
|
||||
* EBADF - The mqdes argument is not a valid message queue descriptor open for reading.
|
||||
* <br>
|
||||
* EMSGSIZE - The specified message buffer size, msg_len, is less than the message size attribute of the message queue.
|
||||
* <br>
|
||||
* EINVAL - The process or thread would have blocked, and the abstime parameter specified a nanoseconds field value
|
||||
* less than zero or greater than or equal to 1000 million.
|
||||
* <br>
|
||||
* ETIMEDOUT - The O_NONBLOCK flag was not set when the message queue was opened,
|
||||
* but no message arrived on the queue before the specified timeout expired.
|
||||
* <br>
|
||||
* EAGAIN - O_NONBLOCK was set in the message description associated with mqdes, and the specified message queue is empty.
|
||||
*/
|
||||
ssize_t mq_timedreceive( mqd_t mqdes,
|
||||
char * msg_ptr,
|
||||
size_t msg_len,
|
||||
unsigned * msg_prio,
|
||||
const struct timespec * abstime );
|
||||
|
||||
/**
|
||||
* @brief Send a message to a message queue with timeout.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_timedsend.html
|
||||
*
|
||||
* @note msg_prio argument is not supported.
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
* @retval -1 - An error occurred. errno is also set.
|
||||
*
|
||||
* @sideeffect Possible errno values
|
||||
* <br>
|
||||
* EBADF - The mqdes argument is not a valid message queue descriptor open for writing.
|
||||
* <br>
|
||||
* EMSGSIZE - The specified message length, msg_len, exceeds the message size attribute of the message queue,
|
||||
* OR insufficient memory for the message to be sent.
|
||||
* <br>
|
||||
* EINVAL - The process or thread would have blocked, and the abstime parameter specified a nanoseconds field
|
||||
* value less than zero or greater than or equal to 1000 million.
|
||||
* <br>
|
||||
* ETIMEDOUT - The O_NONBLOCK flag was not set when the message queue was opened,
|
||||
* but the timeout expired before the message could be added to the queue.
|
||||
* <br>
|
||||
* EAGAIN - The O_NONBLOCK flag is set in the message queue description associated with mqdes,
|
||||
* and the specified message queue is full.
|
||||
*/
|
||||
int mq_timedsend( mqd_t mqdes,
|
||||
const char * msg_ptr,
|
||||
size_t msg_len,
|
||||
unsigned msg_prio,
|
||||
const struct timespec * abstime );
|
||||
|
||||
/**
|
||||
* @brief Remove a message queue.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_unlink.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
* @retval -1 - An error occurred. errno is also set.
|
||||
*
|
||||
* @sideeffect Possible errno values
|
||||
* <br>
|
||||
* EINVAL - name argument is invalid. Refer to requirements on name argument in mq_open().
|
||||
* <br>
|
||||
* ENOENT - The named message queue does not exist.
|
||||
*/
|
||||
int mq_unlink( const char * name );
|
||||
|
||||
#endif /* ifndef _FREERTOS_POSIX_MQUEUE_H_ */
|
@ -0,0 +1,513 @@
|
||||
/*
|
||||
* Amazon FreeRTOS POSIX V1.1.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 pthread.h
|
||||
* @brief Threads.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/pthread.h.html
|
||||
*/
|
||||
|
||||
#ifndef _FREERTOS_POSIX_PTHREAD_H_
|
||||
#define _FREERTOS_POSIX_PTHREAD_H_
|
||||
|
||||
/* FreeRTOS+POSIX includes. POSIX states that this header shall make symbols
|
||||
* defined in sched.h and time.h visible. */
|
||||
#include "FreeRTOS_POSIX/sched.h"
|
||||
#include "FreeRTOS_POSIX/time.h"
|
||||
|
||||
/**
|
||||
* @name pthread detach state.
|
||||
*/
|
||||
/**@{ */
|
||||
#define PTHREAD_CREATE_DETACHED 0 /**< Detached. */
|
||||
#define PTHREAD_CREATE_JOINABLE 1 /**< Joinable (default). */
|
||||
/**@} */
|
||||
|
||||
/**
|
||||
* @name Returned to a single thread after a successful pthread_barrier_wait.
|
||||
*
|
||||
* @brief POSIX specifies that "The constant PTHREAD_BARRIER_SERIAL_THREAD is defined in
|
||||
* <pthread.h> and its value shall be distinct from any other value returned by pthread_barrier_wait()."
|
||||
* So it's defined as negative to distinguish it from the errnos, which are positive.
|
||||
*/
|
||||
#define PTHREAD_BARRIER_SERIAL_THREAD ( -2 )
|
||||
|
||||
/**
|
||||
* @name Mutex types.
|
||||
*/
|
||||
/**@{ */
|
||||
#ifndef PTHREAD_MUTEX_NORMAL
|
||||
#define PTHREAD_MUTEX_NORMAL 0 /**< Non-robust, deadlock on relock, does not remember owner. */
|
||||
#endif
|
||||
#ifndef PTHREAD_MUTEX_ERRORCHECK
|
||||
#define PTHREAD_MUTEX_ERRORCHECK 1 /**< Non-robust, error on relock, remembers owner. */
|
||||
#endif
|
||||
#ifndef PTHREAD_MUTEX_RECURSIVE
|
||||
#define PTHREAD_MUTEX_RECURSIVE 2 /**< Non-robust, recursive relock, remembers owner. */
|
||||
#endif
|
||||
#ifndef PTHREAD_MUTEX_DEFAULT
|
||||
#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL /**< PTHREAD_MUTEX_NORMAL (default). */
|
||||
#endif
|
||||
/**@} */
|
||||
|
||||
/**
|
||||
* @name Compile-time initializers.
|
||||
*
|
||||
* @brief To use PTHREAD_COND_INITIALIZER, posixconfigENABLE_PTHREAD_COND_T needs to be set to 1
|
||||
* in port specific POSIX config file.
|
||||
*
|
||||
* To use PTHREAD_MUTEX_INITIALIZER, posixconfigENABLE_PTHREAD_MUTEX_T needs to be set to 1 in
|
||||
* port specific POSIX config file.
|
||||
*/
|
||||
/**@{ */
|
||||
#if posixconfigENABLE_PTHREAD_COND_T == 1
|
||||
#define PTHREAD_COND_INITIALIZER FREERTOS_POSIX_COND_INITIALIZER /**< pthread_cond_t. */
|
||||
#endif
|
||||
|
||||
#if posixconfigENABLE_PTHREAD_MUTEX_T == 1
|
||||
#define PTHREAD_MUTEX_INITIALIZER FREERTOS_POSIX_MUTEX_INITIALIZER /**< pthread_mutex_t. */
|
||||
#endif
|
||||
|
||||
/**@} */
|
||||
|
||||
/**
|
||||
* @brief Destroy the thread attributes object.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_destroy.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*/
|
||||
int pthread_attr_destroy( pthread_attr_t * attr );
|
||||
|
||||
/**
|
||||
* @brief Get detachstate attribute.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getdetachstate.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*/
|
||||
int pthread_attr_getdetachstate( const pthread_attr_t * attr,
|
||||
int * detachstate );
|
||||
|
||||
/**
|
||||
* @brief Get schedparam attribute.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getschedparam.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*/
|
||||
int pthread_attr_getschedparam( const pthread_attr_t * attr,
|
||||
struct sched_param * param );
|
||||
|
||||
/**
|
||||
* @brief Get stacksize attribute.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getstacksize.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*/
|
||||
int pthread_attr_getstacksize( const pthread_attr_t * attr,
|
||||
size_t * stacksize );
|
||||
|
||||
/**
|
||||
* @brief Initialize the thread attributes object.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_init.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*
|
||||
* @note Currently, only stack size, sched_param, and detach state attributes
|
||||
* are supported. Also see pthread_attr_get*() and pthread_attr_set*().
|
||||
*/
|
||||
int pthread_attr_init( pthread_attr_t * attr );
|
||||
|
||||
/**
|
||||
* @brief Set detachstate attribute.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setdetachstate.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion
|
||||
* @retval EINVAL - The value of detachstate is not valid. Currently, supported detach states are --
|
||||
* PTHREAD_CREATE_DETACHED and PTHREAD_CREATE_JOINABLE.
|
||||
*/
|
||||
int pthread_attr_setdetachstate( pthread_attr_t * attr,
|
||||
int detachstate );
|
||||
|
||||
/**
|
||||
* @brief Set schedparam attribute.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setschedparam.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
* @retval EINVAL - The value of param is not valid.
|
||||
* @retval ENOTSUP - An attempt was made to set the attribute to an unsupported value.
|
||||
*/
|
||||
int pthread_attr_setschedparam( pthread_attr_t * attr,
|
||||
const struct sched_param * param );
|
||||
|
||||
/**
|
||||
* @brief Set the schedpolicy attribute.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setschedpolicy.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*
|
||||
* @warning This function is a stub and always returns 0.
|
||||
*/
|
||||
int pthread_attr_setschedpolicy( pthread_attr_t * attr,
|
||||
int policy );
|
||||
|
||||
/**
|
||||
* @brief Set stacksize attribute.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setstacksize.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
* @retval EINVAL - The value of stacksize is less than {PTHREAD_STACK_MIN}.
|
||||
*/
|
||||
int pthread_attr_setstacksize( pthread_attr_t * attr,
|
||||
size_t stacksize );
|
||||
|
||||
/**
|
||||
* @brief Destroy a barrier object.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_barrier_destroy.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*
|
||||
* @note This function does not validate whether there is any thread blocking on the barrier before destroying.
|
||||
*/
|
||||
int pthread_barrier_destroy( pthread_barrier_t * barrier );
|
||||
|
||||
/**
|
||||
* @brief Initialize a barrier object.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_barrier_init.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
* @retval EINVAL - The value specified by count is equal to zero.
|
||||
* @retval ENOMEM - count cannot fit into FreeRTOS event group type OR insufficient memory exists to initialize the barrier.
|
||||
*
|
||||
* @note attr is ignored.
|
||||
*
|
||||
* @note pthread_barrier_init() is implemented with FreeRTOS event group.
|
||||
* To ensure count fits in event group, count may be at most 8 when configUSE_16_BIT_TICKS is 1;
|
||||
* it may be at most 24 otherwise. configUSE_16_BIT_TICKS is configured in application FreeRTOSConfig.h
|
||||
* file, which defines how many bits tick count type has. See further details and limitation about event
|
||||
* group and configUSE_16_BIT_TICKS in FreeRTOS site.
|
||||
*/
|
||||
int pthread_barrier_init( pthread_barrier_t * barrier,
|
||||
const pthread_barrierattr_t * attr,
|
||||
unsigned count );
|
||||
|
||||
/**
|
||||
* @brief Synchronize at a barrier.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_barrier_wait.html
|
||||
*
|
||||
* @retval PTHREAD_BARRIER_SERIAL_THREAD - Upon successful completion, the first thread.
|
||||
* @retval 0 - Upon successful completion, other thread(s).
|
||||
*/
|
||||
int pthread_barrier_wait( pthread_barrier_t * barrier );
|
||||
|
||||
/**
|
||||
* @brief Thread creation.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_create.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
* @retval EAGAIN - Insufficient memory for either thread structure or task creation.
|
||||
*/
|
||||
int pthread_create( pthread_t * thread,
|
||||
const pthread_attr_t * attr,
|
||||
void *( *startroutine )( void * ),
|
||||
void * arg );
|
||||
|
||||
/**
|
||||
* @brief Broadcast a condition.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_broadcast.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*/
|
||||
int pthread_cond_broadcast( pthread_cond_t * cond );
|
||||
|
||||
/**
|
||||
* @brief Destroy condition variables.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_destroy.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*/
|
||||
int pthread_cond_destroy( pthread_cond_t * cond );
|
||||
|
||||
/**
|
||||
* @brief Initialize condition variables.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_init.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
* @retval ENOMEM - Insufficient memory exists to initialize the condition variable.
|
||||
*
|
||||
* @note attr is ignored and treated as NULL. Default setting is always used.
|
||||
*/
|
||||
int pthread_cond_init( pthread_cond_t * cond,
|
||||
const pthread_condattr_t * attr );
|
||||
|
||||
/**
|
||||
* @brief Signal a condition.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_signal.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*/
|
||||
int pthread_cond_signal( pthread_cond_t * cond );
|
||||
|
||||
/**
|
||||
* @brief Wait on a condition with a timeout.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_timedwait.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
* @retval EINVAL - The abstime argument passed in does not refer to an initialized structure OR
|
||||
* the abstime parameter specified a nanoseconds field value less than zero or
|
||||
* greater than or equal to 1000 million.
|
||||
* @retval ETIMEDOUT - The time specified by abstime to pthread_cond_timedwait() has passed.
|
||||
*/
|
||||
int pthread_cond_timedwait( pthread_cond_t * cond,
|
||||
pthread_mutex_t * mutex,
|
||||
const struct timespec * abstime );
|
||||
|
||||
/**
|
||||
* @brief Wait on a condition.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_wait.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*/
|
||||
int pthread_cond_wait( pthread_cond_t * cond,
|
||||
pthread_mutex_t * mutex );
|
||||
|
||||
/**
|
||||
* @brief Compare thread IDs.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_equal.html
|
||||
*
|
||||
* @retval 0 - t1 and t2 are both not NULL && equal.
|
||||
* @retval non-zero - otherwise.
|
||||
*/
|
||||
int pthread_equal( pthread_t t1,
|
||||
pthread_t t2 );
|
||||
|
||||
/**
|
||||
* @brief Thread termination.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_exit.html
|
||||
*
|
||||
* @retval void - this function cannot return to its caller.
|
||||
*/
|
||||
void pthread_exit( void * value_ptr );
|
||||
|
||||
/**
|
||||
* @brief Dynamic thread scheduling parameters access.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getschedparam.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*
|
||||
* @note policy is always set to SCHED_OTHER by this function.
|
||||
*/
|
||||
int pthread_getschedparam( pthread_t thread,
|
||||
int * policy,
|
||||
struct sched_param * param );
|
||||
|
||||
/**
|
||||
* @brief Wait for thread termination.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_join.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
* @retval EDEADLK - The value specified by the thread argument to pthread_join() does not refer
|
||||
* to a joinable thread OR multiple simultaneous calls to pthread_join()
|
||||
* specifying the same target thread OR the value specified by the thread argument
|
||||
* to pthread_join() refers to the calling thread.
|
||||
*/
|
||||
int pthread_join( pthread_t thread,
|
||||
void ** retval );
|
||||
|
||||
/**
|
||||
* @brief Destroy a mutex.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_destroy.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*
|
||||
* @note If there exists a thread holding this mutex, this function returns 0 with mutex not being destroyed.
|
||||
*/
|
||||
int pthread_mutex_destroy( pthread_mutex_t * mutex );
|
||||
|
||||
/**
|
||||
* @brief Initialize a mutex.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_init.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
* @retval ENOMEM - Insufficient memory exists to initialize the mutex structure.
|
||||
* @retval EAGAIN - Unable to initialize the mutex structure member(s).
|
||||
*/
|
||||
int pthread_mutex_init( pthread_mutex_t * mutex,
|
||||
const pthread_mutexattr_t * attr );
|
||||
|
||||
/**
|
||||
* @brief Lock a mutex.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
* @retval EINVAL - the abstime parameter specified a nanoseconds field value less than zero
|
||||
* or greater than or equal to 1000 million.
|
||||
* @retval EDEADLK - The mutex type is PTHREAD_MUTEX_ERRORCHECK and the current thread already
|
||||
* owns the mutex.
|
||||
*/
|
||||
int pthread_mutex_lock( pthread_mutex_t * mutex );
|
||||
|
||||
/**
|
||||
* @brief Lock a mutex with timeout.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_timedlock.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
* @retval EINVAL - The abstime argument passed in does not refer to an initialized structure OR
|
||||
* the abstime parameter specified a nanoseconds field value less than zero or
|
||||
* greater than or equal to 1000 million.
|
||||
* @retval EDEADLK - The mutex type is PTHREAD_MUTEX_ERRORCHECK and the current thread already owns the mutex.
|
||||
* @retval ETIMEDOUT - The mutex could not be locked before the specified timeout expired.
|
||||
*/
|
||||
int pthread_mutex_timedlock( pthread_mutex_t * mutex,
|
||||
const struct timespec * abstime );
|
||||
|
||||
/**
|
||||
* @brief Attempt to lock a mutex. Fail immediately if mutex is already locked.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_trylock.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
* @retval EINVAL - the abstime parameter specified a nanoseconds field value less than zero
|
||||
* or greater than or equal to 1000 million.
|
||||
* @retval EDEADLK - The mutex type is PTHREAD_MUTEX_ERRORCHECK and the current thread already
|
||||
* owns the mutex.
|
||||
* @retval EBUSY - The mutex could not be acquired because it was already locked.
|
||||
*/
|
||||
int pthread_mutex_trylock( pthread_mutex_t * mutex );
|
||||
|
||||
/**
|
||||
* @brief Unlock a mutex.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_unlock.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
* @retval EPERM - The mutex type is PTHREAD_MUTEX_ERRORCHECK or PTHREAD_MUTEX_RECURSIVE, and
|
||||
* the current thread does not own the mutex.
|
||||
*/
|
||||
int pthread_mutex_unlock( pthread_mutex_t * mutex );
|
||||
|
||||
/**
|
||||
* @brief Destroy the mutex attributes object.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_destroy.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*/
|
||||
int pthread_mutexattr_destroy( pthread_mutexattr_t * attr );
|
||||
|
||||
/**
|
||||
* @brief Get the mutex type attribute.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_gettype.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*/
|
||||
int pthread_mutexattr_gettype( const pthread_mutexattr_t * attr,
|
||||
int * type );
|
||||
|
||||
/**
|
||||
* @brief Initialize the mutex attributes object.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_init.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*
|
||||
* @note Currently, only the type attribute is supported. Also see pthread_mutexattr_settype()
|
||||
* and pthread_mutexattr_gettype().
|
||||
*/
|
||||
int pthread_mutexattr_init( pthread_mutexattr_t * attr );
|
||||
|
||||
/**
|
||||
* @brief Set the mutex type attribute.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_settype.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
* @retval EINVAL - The value type is invalid.
|
||||
*/
|
||||
int pthread_mutexattr_settype( pthread_mutexattr_t * attr,
|
||||
int type );
|
||||
|
||||
/**
|
||||
* @brief Get the calling thread ID.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_self.html
|
||||
*
|
||||
* @retval the thread ID of the calling thread.
|
||||
*/
|
||||
pthread_t pthread_self( void );
|
||||
|
||||
/**
|
||||
* @brief Dynamic thread scheduling parameters access.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_setschedparam.html
|
||||
*
|
||||
* @note policy is ignored; only priority (param.sched_priority) may be changed.
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*/
|
||||
int pthread_setschedparam( pthread_t thread,
|
||||
int policy,
|
||||
const struct sched_param * param );
|
||||
|
||||
int pthread_key_create(pthread_key_t *, void (*)(void *));
|
||||
int pthread_key_delete(pthread_key_t);
|
||||
void *pthread_getspecific(pthread_key_t);
|
||||
int pthread_setspecific(pthread_key_t, const void *);
|
||||
|
||||
#define PTHREAD_ONCE_INIT 0
|
||||
|
||||
int pthread_once(pthread_once_t * once_control, void (*init_routine) (void));
|
||||
int pthread_once_ext(pthread_once_t *once_control, void (*init_routine)(void* arg), void* pargs);
|
||||
|
||||
|
||||
|
||||
#endif /* _FREERTOS_POSIX_PTHREAD_H_ */
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Amazon FreeRTOS POSIX V1.1.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 sched.h
|
||||
* @brief Execution scheduling.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sched.h.html
|
||||
*/
|
||||
|
||||
#ifndef _FREERTOS_POSIX_SCHED_H_
|
||||
#define _FREERTOS_POSIX_SCHED_H_
|
||||
|
||||
/**
|
||||
* @name Scheduling Policies
|
||||
*/
|
||||
/**@{ */
|
||||
#define SCHED_OTHER 0 /**< Another scheduling policy. */
|
||||
/**@} */
|
||||
|
||||
/**
|
||||
* @brief Scheduling parameters required for implementation of each supported
|
||||
* scheduling policy.
|
||||
*/
|
||||
struct sched_param
|
||||
{
|
||||
int sched_priority; /**< Process or thread execution scheduling priority. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Get priority limit (max).
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_get_priority_max.html
|
||||
*
|
||||
* @note policy is ignored.
|
||||
*
|
||||
* @return the maximum priority value (0-based) system configuration allows.
|
||||
* <br>
|
||||
* e.g. if configMAX_PRIORITIES == 7, this function returns (configMAX_PRIORITIES - 1).
|
||||
* configMAX_PRIORITIES is configured in application FreeRTOSConfig.h file.
|
||||
*/
|
||||
int sched_get_priority_max( int policy );
|
||||
|
||||
/**
|
||||
* @brief Get priority limit (min).
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_get_priority_min.html
|
||||
*
|
||||
* @note policy is ignored.
|
||||
*/
|
||||
int sched_get_priority_min( int policy );
|
||||
|
||||
/**
|
||||
* @brief Yield the processor.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_yield.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion
|
||||
*/
|
||||
int sched_yield( void );
|
||||
|
||||
#endif /* ifndef _FREERTOS_POSIX_SCHED_H_ */
|
@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Amazon FreeRTOS POSIX V1.1.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 semaphore.h
|
||||
* @brief Semaphores.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/semaphore.h.html
|
||||
*/
|
||||
|
||||
#ifndef _FREERTOS_POSIX_SEMAPHORE_H_
|
||||
#define _FREERTOS_POSIX_SEMAPHORE_H_
|
||||
|
||||
/* FreeRTOS+POSIX includes. */
|
||||
#include "FreeRTOS_POSIX/time.h"
|
||||
#include "FreeRTOS_POSIX_types.h"
|
||||
|
||||
/**
|
||||
* @brief Semaphore type.
|
||||
*/
|
||||
typedef PosixSemType_t sem_t;
|
||||
|
||||
/**
|
||||
* @brief Destroy an unnamed semaphore.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_destroy.html
|
||||
*
|
||||
* @retval 0 - upon successful completion
|
||||
*
|
||||
* @note Semaphore is destroyed regardless of whether there is any thread currently blocked on this semaphore.
|
||||
*/
|
||||
int sem_destroy( sem_t * sem );
|
||||
|
||||
/**
|
||||
* @brief Get the value of a semaphore.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_getvalue.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion
|
||||
*
|
||||
* @note If sem is locked, then the object to which sval points is set to zero.
|
||||
*/
|
||||
int sem_getvalue( sem_t * sem,
|
||||
int * sval );
|
||||
|
||||
/**
|
||||
* @brief Initialize an unnamed semaphore.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_init.html
|
||||
*
|
||||
* @note pshared is ignored. Semaphores will always be considered "shared".
|
||||
*
|
||||
* @retval 0 - upon successful completion
|
||||
* @retval -1 - otherwise. System error variable errno is also set in this case.
|
||||
*
|
||||
* @sideeffect Possible errno values
|
||||
* <br>
|
||||
* EINVAL - The value argument exceeds {SEM_VALUE_MAX}.
|
||||
* <br>
|
||||
* ENOSPC - A resource required to initialize the semaphore has been exhausted.
|
||||
*/
|
||||
int sem_init( sem_t * sem,
|
||||
int pshared,
|
||||
unsigned value );
|
||||
|
||||
/**
|
||||
* @brief Unlock a semaphore.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_post.html
|
||||
*
|
||||
* @retval 0 - upon successful completion
|
||||
*/
|
||||
int sem_post( sem_t * sem );
|
||||
|
||||
/**
|
||||
* @brief Lock a semaphore with timeout.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_timedwait.html
|
||||
*
|
||||
* @retval 0 - upon successful completion
|
||||
* @retval -1 - otherwise. System error variable errno is also set in this case.
|
||||
*
|
||||
* @sideeffect Possible errno values
|
||||
* <br>
|
||||
* EINVAL - parameter specified a nanoseconds field value less than zero or greater
|
||||
* than or equal to 1000 million
|
||||
* <br>
|
||||
* ETIMEDOUT - The semaphore could not be locked before the specified timeout expired.
|
||||
*
|
||||
* @note Deadlock detection is not implemented.
|
||||
*/
|
||||
int sem_timedwait( sem_t * sem,
|
||||
const struct timespec * abstime );
|
||||
|
||||
/**
|
||||
* @brief Lock a semaphore if available.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_trywait.html
|
||||
*
|
||||
* @retval 0 - upon successful completion
|
||||
* @retval -1 - otherwise. System error variable errno is also set in this case.
|
||||
*
|
||||
* @sideeffect Possible errno values
|
||||
* <br>
|
||||
* EAGAIN - The semaphore was already locked, so it cannot be immediately locked by the sem_trywait() operation.
|
||||
*/
|
||||
int sem_trywait( sem_t * sem );
|
||||
|
||||
/**
|
||||
* @brief Lock a semaphore.
|
||||
*
|
||||
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_wait.html
|
||||
*
|
||||
* @retval 0 - upon successful completion
|
||||
* @retval -1 - otherwise. System error variable errno is also set in this case.
|
||||
*
|
||||
* @note Deadlock detection is not implemented.
|
||||
*/
|
||||
int sem_wait( sem_t * sem );
|
||||
|
||||
#endif /* ifndef _FREERTOS_POSIX_SEMAPHORE_H_ */
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Amazon FreeRTOS POSIX V1.1.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 signal.h
|
||||
* @brief Signals.
|
||||
*
|
||||
* Signals are currently not implemented in FreeRTOS+POSIX. This header only
|
||||
* defines the signal data structures used elsewhere.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _FREERTOS_POSIX_SIGNAL_H_
|
||||
#define _FREERTOS_POSIX_SIGNAL_H_
|
||||
|
||||
/**
|
||||
* @name Values of sigev_notify.
|
||||
*/
|
||||
/**@{ */
|
||||
#define SIGEV_NONE 0 /**< No asynchronous notification is delivered when the event of interest occurs. */
|
||||
#define SIGEV_SIGNAL 1 /**< A queued signal, with an application-defined value, is generated when the event of interest occurs. Not supported. */
|
||||
#define SIGEV_THREAD 2 /**< A notification function is called to perform notification. */
|
||||
/**@} */
|
||||
|
||||
/**
|
||||
* @brief Signal value.
|
||||
*/
|
||||
union sigval
|
||||
{
|
||||
int sival_int; /**< Integer signal value. */
|
||||
void * sival_ptr; /**< Pointer signal value. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Signal event structure.
|
||||
*/
|
||||
struct sigevent
|
||||
{
|
||||
int sigev_notify; /**< Notification type. A value of SIGEV_SIGNAL is not supported. */
|
||||
int sigev_signo; /**< Signal number. This member is ignored. */
|
||||
union sigval sigev_value; /**< Signal value. Only the sival_ptr member is used. */
|
||||
void ( * sigev_notify_function )( union sigval ); /**< Notification function. */
|
||||
pthread_attr_t * sigev_notify_attributes; /**< Notification attributes. */
|
||||
};
|
||||
|
||||
#endif /* ifndef _FREERTOS_POSIX_SIGNAL_H_ */
|
@ -0,0 +1,575 @@
|
||||
/*
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)queue.h 8.5 (Berkeley) 8/20/94
|
||||
*/
|
||||
|
||||
#ifndef _SYS_QUEUE_H_
|
||||
#define _SYS_QUEUE_H_
|
||||
|
||||
/*
|
||||
* This file defines five types of data structures: singly-linked lists,
|
||||
* lists, simple queues, tail queues, and circular queues.
|
||||
*
|
||||
* A singly-linked list is headed by a single forward pointer. The
|
||||
* elements are singly linked for minimum space and pointer manipulation
|
||||
* overhead at the expense of O(n) removal for arbitrary elements. New
|
||||
* elements can be added to the list after an existing element or at the
|
||||
* head of the list. Elements being removed from the head of the list
|
||||
* should use the explicit macro for this purpose for optimum
|
||||
* efficiency. A singly-linked list may only be traversed in the forward
|
||||
* direction. Singly-linked lists are ideal for applications with large
|
||||
* datasets and few or no removals or for implementing a LIFO queue.
|
||||
*
|
||||
* A list is headed by a single forward pointer (or an array of forward
|
||||
* pointers for a hash table header). The elements are doubly linked
|
||||
* so that an arbitrary element can be removed without a need to
|
||||
* traverse the list. New elements can be added to the list before
|
||||
* or after an existing element or at the head of the list. A list
|
||||
* may only be traversed in the forward direction.
|
||||
*
|
||||
* A simple queue is headed by a pair of pointers, one the head of the
|
||||
* list and the other to the tail of the list. The elements are singly
|
||||
* linked to save space, so elements can only be removed from the
|
||||
* head of the list. New elements can be added to the list after
|
||||
* an existing element, at the head of the list, or at the end of the
|
||||
* list. A simple queue may only be traversed in the forward direction.
|
||||
*
|
||||
* A tail queue is headed by a pair of pointers, one to the head of the
|
||||
* list and the other to the tail of the list. The elements are doubly
|
||||
* linked so that an arbitrary element can be removed without a need to
|
||||
* traverse the list. New elements can be added to the list before or
|
||||
* after an existing element, at the head of the list, or at the end of
|
||||
* the list. A tail queue may be traversed in either direction.
|
||||
*
|
||||
* A circle queue is headed by a pair of pointers, one to the head of the
|
||||
* list and the other to the tail of the list. The elements are doubly
|
||||
* linked so that an arbitrary element can be removed without a need to
|
||||
* traverse the list. New elements can be added to the list before or after
|
||||
* an existing element, at the head of the list, or at the end of the list.
|
||||
* A circle queue may be traversed in either direction, but has a more
|
||||
* complex end of list detection.
|
||||
*
|
||||
* For details on the use of these macros, see the queue(3) manual page.
|
||||
*/
|
||||
|
||||
/*
|
||||
* List definitions.
|
||||
*/
|
||||
#define LIST_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *lh_first; /* first element */ \
|
||||
}
|
||||
|
||||
#define LIST_HEAD_INITIALIZER(head) \
|
||||
{ NULL }
|
||||
|
||||
#define LIST_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *le_next; /* next element */ \
|
||||
struct type **le_prev; /* address of previous next element */ \
|
||||
}
|
||||
|
||||
/*
|
||||
* List functions.
|
||||
*/
|
||||
#define LIST_INIT(head) do { \
|
||||
(head)->lh_first = NULL; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define LIST_INSERT_AFTER(listelm, elm, field) do { \
|
||||
if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
|
||||
(listelm)->field.le_next->field.le_prev = \
|
||||
&(elm)->field.le_next; \
|
||||
(listelm)->field.le_next = (elm); \
|
||||
(elm)->field.le_prev = &(listelm)->field.le_next; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
|
||||
(elm)->field.le_prev = (listelm)->field.le_prev; \
|
||||
(elm)->field.le_next = (listelm); \
|
||||
*(listelm)->field.le_prev = (elm); \
|
||||
(listelm)->field.le_prev = &(elm)->field.le_next; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define LIST_INSERT_HEAD(head, elm, field) do { \
|
||||
if (((elm)->field.le_next = (head)->lh_first) != NULL) \
|
||||
(head)->lh_first->field.le_prev = &(elm)->field.le_next;\
|
||||
(head)->lh_first = (elm); \
|
||||
(elm)->field.le_prev = &(head)->lh_first; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define LIST_REMOVE(elm, field) do { \
|
||||
if ((elm)->field.le_next != NULL) \
|
||||
(elm)->field.le_next->field.le_prev = \
|
||||
(elm)->field.le_prev; \
|
||||
*(elm)->field.le_prev = (elm)->field.le_next; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define LIST_FOREACH(var, head, field) \
|
||||
for ((var) = ((head)->lh_first); \
|
||||
(var); \
|
||||
(var) = ((var)->field.le_next))
|
||||
|
||||
/*
|
||||
* List access methods.
|
||||
*/
|
||||
#define LIST_EMPTY(head) ((head)->lh_first == NULL)
|
||||
#define LIST_FIRST(head) ((head)->lh_first)
|
||||
#define LIST_NEXT(elm, field) ((elm)->field.le_next)
|
||||
|
||||
|
||||
/*
|
||||
* Singly-linked List definitions.
|
||||
*/
|
||||
#define SLIST_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *slh_first; /* first element */ \
|
||||
}
|
||||
|
||||
#define SLIST_HEAD_INITIALIZER(head) \
|
||||
{ NULL }
|
||||
|
||||
#define SLIST_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *sle_next; /* next element */ \
|
||||
}
|
||||
|
||||
/*
|
||||
* Singly-linked List functions.
|
||||
*/
|
||||
#define SLIST_INIT(head) do { \
|
||||
(head)->slh_first = NULL; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
|
||||
(elm)->field.sle_next = (slistelm)->field.sle_next; \
|
||||
(slistelm)->field.sle_next = (elm); \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define SLIST_INSERT_HEAD(head, elm, field) do { \
|
||||
(elm)->field.sle_next = (head)->slh_first; \
|
||||
(head)->slh_first = (elm); \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define SLIST_REMOVE_HEAD(head, field) do { \
|
||||
(head)->slh_first = (head)->slh_first->field.sle_next; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define SLIST_REMOVE(head, elm, type, field) do { \
|
||||
if ((head)->slh_first == (elm)) { \
|
||||
SLIST_REMOVE_HEAD((head), field); \
|
||||
} \
|
||||
else { \
|
||||
struct type *curelm = (head)->slh_first; \
|
||||
while(curelm->field.sle_next != (elm)) \
|
||||
curelm = curelm->field.sle_next; \
|
||||
curelm->field.sle_next = \
|
||||
curelm->field.sle_next->field.sle_next; \
|
||||
} \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define SLIST_FOREACH(var, head, field) \
|
||||
for((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next)
|
||||
|
||||
/*
|
||||
* Singly-linked List access methods.
|
||||
*/
|
||||
#define SLIST_EMPTY(head) ((head)->slh_first == NULL)
|
||||
#define SLIST_FIRST(head) ((head)->slh_first)
|
||||
#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
|
||||
|
||||
|
||||
/*
|
||||
* Singly-linked Tail queue declarations.
|
||||
*/
|
||||
#define STAILQ_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *stqh_first; /* first element */ \
|
||||
struct type **stqh_last; /* addr of last next element */ \
|
||||
}
|
||||
|
||||
#define STAILQ_HEAD_INITIALIZER(head) \
|
||||
{ NULL, &(head).stqh_first }
|
||||
|
||||
#define STAILQ_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *stqe_next; /* next element */ \
|
||||
}
|
||||
|
||||
/*
|
||||
* Singly-linked Tail queue functions.
|
||||
*/
|
||||
#define STAILQ_INIT(head) do { \
|
||||
(head)->stqh_first = NULL; \
|
||||
(head)->stqh_last = &(head)->stqh_first; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define STAILQ_INSERT_HEAD(head, elm, field) do { \
|
||||
if (((elm)->field.stqe_next = (head)->stqh_first) == NULL) \
|
||||
(head)->stqh_last = &(elm)->field.stqe_next; \
|
||||
(head)->stqh_first = (elm); \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define STAILQ_INSERT_TAIL(head, elm, field) do { \
|
||||
(elm)->field.stqe_next = NULL; \
|
||||
*(head)->stqh_last = (elm); \
|
||||
(head)->stqh_last = &(elm)->field.stqe_next; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define STAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
|
||||
if (((elm)->field.stqe_next = (listelm)->field.stqe_next) == NULL)\
|
||||
(head)->stqh_last = &(elm)->field.stqe_next; \
|
||||
(listelm)->field.stqe_next = (elm); \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define STAILQ_REMOVE_HEAD(head, field) do { \
|
||||
if (((head)->stqh_first = (head)->stqh_first->field.stqe_next) == NULL) \
|
||||
(head)->stqh_last = &(head)->stqh_first; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define STAILQ_REMOVE(head, elm, type, field) do { \
|
||||
if ((head)->stqh_first == (elm)) { \
|
||||
STAILQ_REMOVE_HEAD((head), field); \
|
||||
} else { \
|
||||
struct type *curelm = (head)->stqh_first; \
|
||||
while (curelm->field.stqe_next != (elm)) \
|
||||
curelm = curelm->field.stqe_next; \
|
||||
if ((curelm->field.stqe_next = \
|
||||
curelm->field.stqe_next->field.stqe_next) == NULL) \
|
||||
(head)->stqh_last = &(curelm)->field.stqe_next; \
|
||||
} \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define STAILQ_FOREACH(var, head, field) \
|
||||
for ((var) = ((head)->stqh_first); \
|
||||
(var); \
|
||||
(var) = ((var)->field.stqe_next))
|
||||
|
||||
#define STAILQ_CONCAT(head1, head2) do { \
|
||||
if (!STAILQ_EMPTY((head2))) { \
|
||||
*(head1)->stqh_last = (head2)->stqh_first; \
|
||||
(head1)->stqh_last = (head2)->stqh_last; \
|
||||
STAILQ_INIT((head2)); \
|
||||
} \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
/*
|
||||
* Singly-linked Tail queue access methods.
|
||||
*/
|
||||
#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
|
||||
#define STAILQ_FIRST(head) ((head)->stqh_first)
|
||||
#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
|
||||
|
||||
|
||||
/*
|
||||
* Simple queue definitions.
|
||||
*/
|
||||
#define SIMPLEQ_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *sqh_first; /* first element */ \
|
||||
struct type **sqh_last; /* addr of last next element */ \
|
||||
}
|
||||
|
||||
#define SIMPLEQ_HEAD_INITIALIZER(head) \
|
||||
{ NULL, &(head).sqh_first }
|
||||
|
||||
#define SIMPLEQ_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *sqe_next; /* next element */ \
|
||||
}
|
||||
|
||||
/*
|
||||
* Simple queue functions.
|
||||
*/
|
||||
#define SIMPLEQ_INIT(head) do { \
|
||||
(head)->sqh_first = NULL; \
|
||||
(head)->sqh_last = &(head)->sqh_first; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
|
||||
if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
|
||||
(head)->sqh_last = &(elm)->field.sqe_next; \
|
||||
(head)->sqh_first = (elm); \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
|
||||
(elm)->field.sqe_next = NULL; \
|
||||
*(head)->sqh_last = (elm); \
|
||||
(head)->sqh_last = &(elm)->field.sqe_next; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
|
||||
if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
|
||||
(head)->sqh_last = &(elm)->field.sqe_next; \
|
||||
(listelm)->field.sqe_next = (elm); \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define SIMPLEQ_REMOVE_HEAD(head, field) do { \
|
||||
if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
|
||||
(head)->sqh_last = &(head)->sqh_first; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define SIMPLEQ_REMOVE(head, elm, type, field) do { \
|
||||
if ((head)->sqh_first == (elm)) { \
|
||||
SIMPLEQ_REMOVE_HEAD((head), field); \
|
||||
} else { \
|
||||
struct type *curelm = (head)->sqh_first; \
|
||||
while (curelm->field.sqe_next != (elm)) \
|
||||
curelm = curelm->field.sqe_next; \
|
||||
if ((curelm->field.sqe_next = \
|
||||
curelm->field.sqe_next->field.sqe_next) == NULL) \
|
||||
(head)->sqh_last = &(curelm)->field.sqe_next; \
|
||||
} \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define SIMPLEQ_FOREACH(var, head, field) \
|
||||
for ((var) = ((head)->sqh_first); \
|
||||
(var); \
|
||||
(var) = ((var)->field.sqe_next))
|
||||
|
||||
/*
|
||||
* Simple queue access methods.
|
||||
*/
|
||||
#define SIMPLEQ_EMPTY(head) ((head)->sqh_first == NULL)
|
||||
#define SIMPLEQ_FIRST(head) ((head)->sqh_first)
|
||||
#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
|
||||
|
||||
|
||||
/*
|
||||
* Tail queue definitions.
|
||||
*/
|
||||
#define _TAILQ_HEAD(name, type, qual) \
|
||||
struct name { \
|
||||
qual type *tqh_first; /* first element */ \
|
||||
qual type *qual *tqh_last; /* addr of last next element */ \
|
||||
}
|
||||
#define TAILQ_HEAD(name, type) _TAILQ_HEAD(name, struct type,)
|
||||
|
||||
#define TAILQ_HEAD_INITIALIZER(head) \
|
||||
{ NULL, &(head).tqh_first }
|
||||
|
||||
#define _TAILQ_ENTRY(type, qual) \
|
||||
struct { \
|
||||
qual type *tqe_next; /* next element */ \
|
||||
qual type *qual *tqe_prev; /* address of previous next element */\
|
||||
}
|
||||
#define TAILQ_ENTRY(type) _TAILQ_ENTRY(struct type,)
|
||||
|
||||
/*
|
||||
* Tail queue functions.
|
||||
*/
|
||||
#define TAILQ_INIT(head) do { \
|
||||
(head)->tqh_first = NULL; \
|
||||
(head)->tqh_last = &(head)->tqh_first; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define TAILQ_INSERT_HEAD(head, elm, field) do { \
|
||||
if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
|
||||
(head)->tqh_first->field.tqe_prev = \
|
||||
&(elm)->field.tqe_next; \
|
||||
else \
|
||||
(head)->tqh_last = &(elm)->field.tqe_next; \
|
||||
(head)->tqh_first = (elm); \
|
||||
(elm)->field.tqe_prev = &(head)->tqh_first; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define TAILQ_INSERT_TAIL(head, elm, field) do { \
|
||||
(elm)->field.tqe_next = NULL; \
|
||||
(elm)->field.tqe_prev = (head)->tqh_last; \
|
||||
*(head)->tqh_last = (elm); \
|
||||
(head)->tqh_last = &(elm)->field.tqe_next; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
|
||||
if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
|
||||
(elm)->field.tqe_next->field.tqe_prev = \
|
||||
&(elm)->field.tqe_next; \
|
||||
else \
|
||||
(head)->tqh_last = &(elm)->field.tqe_next; \
|
||||
(listelm)->field.tqe_next = (elm); \
|
||||
(elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
|
||||
(elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
|
||||
(elm)->field.tqe_next = (listelm); \
|
||||
*(listelm)->field.tqe_prev = (elm); \
|
||||
(listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define TAILQ_REMOVE(head, elm, field) do { \
|
||||
if (((elm)->field.tqe_next) != NULL) \
|
||||
(elm)->field.tqe_next->field.tqe_prev = \
|
||||
(elm)->field.tqe_prev; \
|
||||
else \
|
||||
(head)->tqh_last = (elm)->field.tqe_prev; \
|
||||
*(elm)->field.tqe_prev = (elm)->field.tqe_next; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define TAILQ_FOREACH(var, head, field) \
|
||||
for ((var) = ((head)->tqh_first); \
|
||||
(var); \
|
||||
(var) = ((var)->field.tqe_next))
|
||||
|
||||
#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
|
||||
for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last)); \
|
||||
(var); \
|
||||
(var) = (*(((struct headname *)((var)->field.tqe_prev))->tqh_last)))
|
||||
|
||||
#define TAILQ_CONCAT(head1, head2, field) do { \
|
||||
if (!TAILQ_EMPTY(head2)) { \
|
||||
*(head1)->tqh_last = (head2)->tqh_first; \
|
||||
(head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
|
||||
(head1)->tqh_last = (head2)->tqh_last; \
|
||||
TAILQ_INIT((head2)); \
|
||||
} \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
/*
|
||||
* Tail queue access methods.
|
||||
*/
|
||||
#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
|
||||
#define TAILQ_FIRST(head) ((head)->tqh_first)
|
||||
#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
|
||||
|
||||
#define TAILQ_LAST(head, headname) \
|
||||
(*(((struct headname *)((head)->tqh_last))->tqh_last))
|
||||
#define TAILQ_PREV(elm, headname, field) \
|
||||
(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
|
||||
|
||||
|
||||
/*
|
||||
* Circular queue definitions.
|
||||
*/
|
||||
#define CIRCLEQ_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *cqh_first; /* first element */ \
|
||||
struct type *cqh_last; /* last element */ \
|
||||
}
|
||||
|
||||
#define CIRCLEQ_HEAD_INITIALIZER(head) \
|
||||
{ (void *)&head, (void *)&head }
|
||||
|
||||
#define CIRCLEQ_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *cqe_next; /* next element */ \
|
||||
struct type *cqe_prev; /* previous element */ \
|
||||
}
|
||||
|
||||
/*
|
||||
* Circular queue functions.
|
||||
*/
|
||||
#define CIRCLEQ_INIT(head) do { \
|
||||
(head)->cqh_first = (void *)(head); \
|
||||
(head)->cqh_last = (void *)(head); \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
|
||||
(elm)->field.cqe_next = (listelm)->field.cqe_next; \
|
||||
(elm)->field.cqe_prev = (listelm); \
|
||||
if ((listelm)->field.cqe_next == (void *)(head)) \
|
||||
(head)->cqh_last = (elm); \
|
||||
else \
|
||||
(listelm)->field.cqe_next->field.cqe_prev = (elm); \
|
||||
(listelm)->field.cqe_next = (elm); \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
|
||||
(elm)->field.cqe_next = (listelm); \
|
||||
(elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
|
||||
if ((listelm)->field.cqe_prev == (void *)(head)) \
|
||||
(head)->cqh_first = (elm); \
|
||||
else \
|
||||
(listelm)->field.cqe_prev->field.cqe_next = (elm); \
|
||||
(listelm)->field.cqe_prev = (elm); \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
|
||||
(elm)->field.cqe_next = (head)->cqh_first; \
|
||||
(elm)->field.cqe_prev = (void *)(head); \
|
||||
if ((head)->cqh_last == (void *)(head)) \
|
||||
(head)->cqh_last = (elm); \
|
||||
else \
|
||||
(head)->cqh_first->field.cqe_prev = (elm); \
|
||||
(head)->cqh_first = (elm); \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
|
||||
(elm)->field.cqe_next = (void *)(head); \
|
||||
(elm)->field.cqe_prev = (head)->cqh_last; \
|
||||
if ((head)->cqh_first == (void *)(head)) \
|
||||
(head)->cqh_first = (elm); \
|
||||
else \
|
||||
(head)->cqh_last->field.cqe_next = (elm); \
|
||||
(head)->cqh_last = (elm); \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define CIRCLEQ_REMOVE(head, elm, field) do { \
|
||||
if ((elm)->field.cqe_next == (void *)(head)) \
|
||||
(head)->cqh_last = (elm)->field.cqe_prev; \
|
||||
else \
|
||||
(elm)->field.cqe_next->field.cqe_prev = \
|
||||
(elm)->field.cqe_prev; \
|
||||
if ((elm)->field.cqe_prev == (void *)(head)) \
|
||||
(head)->cqh_first = (elm)->field.cqe_next; \
|
||||
else \
|
||||
(elm)->field.cqe_prev->field.cqe_next = \
|
||||
(elm)->field.cqe_next; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
#define CIRCLEQ_FOREACH(var, head, field) \
|
||||
for ((var) = ((head)->cqh_first); \
|
||||
(var) != (const void *)(head); \
|
||||
(var) = ((var)->field.cqe_next))
|
||||
|
||||
#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
|
||||
for ((var) = ((head)->cqh_last); \
|
||||
(var) != (const void *)(head); \
|
||||
(var) = ((var)->field.cqe_prev))
|
||||
|
||||
/*
|
||||
* Circular queue access methods.
|
||||
*/
|
||||
#define CIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head))
|
||||
#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
|
||||
#define CIRCLEQ_LAST(head) ((head)->cqh_last)
|
||||
#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
|
||||
#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
|
||||
|
||||
#define CIRCLEQ_LOOP_NEXT(head, elm, field) \
|
||||
(((elm)->field.cqe_next == (void *)(head)) \
|
||||
? ((head)->cqh_first) \
|
||||
: (elm->field.cqe_next))
|
||||
#define CIRCLEQ_LOOP_PREV(head, elm, field) \
|
||||
(((elm)->field.cqe_prev == (void *)(head)) \
|
||||
? ((head)->cqh_last) \
|
||||
: (elm->field.cqe_prev))
|
||||
|
||||
#endif /* sys/queue.h */
|
||||
|
@ -0,0 +1,7 @@
|
||||
#ifndef _SYS_STAT_H
|
||||
#define _SYS_STAT_H 1
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,6 @@
|
||||
#ifndef _SYS_TIME_H
|
||||
#define _SYS_TIME_H 1
|
||||
#include "FreeRTOS_POSIX/time.h"
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,191 @@
|
||||
/*
|
||||
* Amazon FreeRTOS POSIX V1.1.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 sys/types.h
|
||||
* @brief Data types.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html
|
||||
*/
|
||||
|
||||
#ifndef _FREERTOS_POSIX_TYPES_H_
|
||||
#define _FREERTOS_POSIX_TYPES_H_
|
||||
|
||||
/* C standard library includes. */
|
||||
#include <stdint.h>
|
||||
|
||||
/* FreeRTOS types include */
|
||||
#include "FreeRTOS_POSIX_types.h"
|
||||
|
||||
/**
|
||||
* @brief Used for system times in clock ticks or CLOCKS_PER_SEC.
|
||||
*
|
||||
* Enabled/disabled by posixconfigENABLE_CLOCK_T.
|
||||
*/
|
||||
#if !defined( posixconfigENABLE_CLOCK_T ) || ( posixconfigENABLE_CLOCK_T == 1 )
|
||||
typedef uint32_t clock_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Used for clock ID type in the clock and timer functions.
|
||||
*
|
||||
* Enabled/disabled by posixconfigENABLE_CLOCKID_T.
|
||||
*/
|
||||
#if !defined( posixconfigENABLE_CLOCKID_T ) || ( posixconfigENABLE_CLOCKID_T == 1 )
|
||||
typedef int clockid_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Used for some file attributes.
|
||||
*
|
||||
* Enabled/disabled by posixconfigENABLE_MODE_T.
|
||||
*/
|
||||
#if !defined( posixconfigENABLE_MODE_T ) || ( posixconfigENABLE_MODE_T == 1 )
|
||||
typedef int mode_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Used for process IDs and process group IDs.
|
||||
*
|
||||
* Enabled/disabled by posixconfigENABLE_PID_T.
|
||||
*/
|
||||
#if !defined( posixconfigENABLE_PID_T ) || ( posixconfigENABLE_PID_T == 1 )
|
||||
typedef int pid_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Used to identify a thread attribute object.
|
||||
*
|
||||
* Enabled/disabled by posixconfigENABLE_PTHREAD_ATTR_T.
|
||||
*/
|
||||
#if !defined( posixconfigENABLE_PTHREAD_ATTR_T ) || ( posixconfigENABLE_PTHREAD_ATTR_T == 1 )
|
||||
typedef PthreadAttrType_t pthread_attr_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Used to identify a barrier.
|
||||
*
|
||||
* Enabled/disabled by posixconfigENABLE_PTHREAD_BARRIER_T.
|
||||
*/
|
||||
#if !defined( posixconfigENABLE_PTHREAD_BARRIER_T ) || ( posixconfigENABLE_PTHREAD_BARRIER_T == 1 )
|
||||
typedef PthreadBarrierType_t pthread_barrier_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Used to define a barrier attributes object.
|
||||
*/
|
||||
typedef void * pthread_barrierattr_t;
|
||||
|
||||
/**
|
||||
* @brief Used for condition variables.
|
||||
*
|
||||
* Enabled/disabled by posixconfigENABLE_PTHREAD_COND_T.
|
||||
*/
|
||||
#if !defined( posixconfigENABLE_PTHREAD_COND_T ) || ( posixconfigENABLE_PTHREAD_COND_T == 1 )
|
||||
typedef PthreadCondType_t pthread_cond_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Used to identify a condition attribute object.
|
||||
*
|
||||
* Enabled/disabled by posixconfigENABLE_PTHREAD_CONDATTR_T.
|
||||
*/
|
||||
#if !defined( posixconfigENABLE_PTHREAD_CONDATTR_T ) || ( posixconfigENABLE_PTHREAD_CONDATTR_T == 1 )
|
||||
typedef void * pthread_condattr_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Used for mutexes.
|
||||
*
|
||||
* Enabled/disabled by posixconfigENABLE_PTHREAD_MUTEX_T.
|
||||
*/
|
||||
#if !defined( posixconfigENABLE_PTHREAD_MUTEX_T ) || ( posixconfigENABLE_PTHREAD_MUTEX_T == 1 )
|
||||
typedef PthreadMutexType_t pthread_mutex_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Used to identify a mutex attribute object.
|
||||
*
|
||||
* Enabled/disabled by posixconfigENABLE_PTHREAD_MUTEXATTR_T.
|
||||
*/
|
||||
#if !defined( posixconfigENABLE_PTHREAD_MUTEXATTR_T ) || ( posixconfigENABLE_PTHREAD_MUTEXATTR_T == 1 )
|
||||
typedef PthreadMutexAttrType_t pthread_mutexattr_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Used to identify a thread.
|
||||
*
|
||||
* Enabled/disabled by posixconfigENABLE_PTHREAD_T.
|
||||
*/
|
||||
#if !defined( posixconfigENABLE_PTHREAD_T ) || ( posixconfigENABLE_PTHREAD_T == 1 )
|
||||
typedef void * pthread_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Used for a count of bytes or an error indication.
|
||||
*
|
||||
* Enabled/disabled by posixconfigENABLE_SSIZE_T.
|
||||
*/
|
||||
#if !defined( posixconfigENABLE_SSIZE_T ) || ( posixconfigENABLE_SSIZE_T == 1 )
|
||||
typedef int ssize_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Used for time in seconds.
|
||||
*
|
||||
* Enabled/disabled by posixconfigENABLE_TIME_T.
|
||||
*/
|
||||
#if !defined( posixconfigENABLE_TIME_T ) || ( posixconfigENABLE_TIME_T == 1 )
|
||||
typedef int64_t time_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Used for timer ID returned by timer_create().
|
||||
*
|
||||
* Enabled/disabled by posixconfigENABLE_TIMER_T.
|
||||
*/
|
||||
#if !defined( posixconfigENABLE_TIMER_T ) || ( posixconfigENABLE_TIMER_T == 1 )
|
||||
typedef void * timer_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Used for time in microseconds.
|
||||
*
|
||||
* Enabled/disabled by posixconfigENABLE_USECONDS_T.
|
||||
*/
|
||||
#if !defined( posixconfigENABLE_USECONDS_T ) || ( posixconfigENABLE_USECONDS_T == 1 )
|
||||
typedef unsigned long useconds_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Used for file sizes.
|
||||
*
|
||||
* Enabled/disabled by posixconfigENABLE_OFF_T.
|
||||
*/
|
||||
#if !defined( posixconfigENABLE_OFF_T ) || ( posixconfigENABLE_OFF_T == 1 )
|
||||
typedef long int off_t;
|
||||
#endif
|
||||
|
||||
#endif /* ifndef _FREERTOS_POSIX_TYPES_H_ */
|
@ -0,0 +1,5 @@
|
||||
#ifndef _SYS_SYSLOG_H
|
||||
#define _SYS_SYSLOG_H 1
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,669 @@
|
||||
/*
|
||||
* Amazon FreeRTOS POSIX V1.1.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 time.h
|
||||
* @brief Time types.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/time.h.html
|
||||
*/
|
||||
|
||||
#ifndef _FREERTOS_POSIX_TIME_H_
|
||||
#define _FREERTOS_POSIX_TIME_H_
|
||||
|
||||
/* FreeRTOS+POSIX includes. */
|
||||
#include "FreeRTOS_POSIX/sys/types.h"
|
||||
#include "FreeRTOS_POSIX/signal.h"
|
||||
|
||||
/**
|
||||
* @name Unit conversion constants.
|
||||
*/
|
||||
/**@{ */
|
||||
#define MICROSECONDS_PER_SECOND ( 1000000LL ) /**< Microseconds per second. */
|
||||
#define NANOSECONDS_PER_SECOND ( 1000000000LL ) /**< Nanoseconds per second. */
|
||||
#define NANOSECONDS_PER_TICK ( NANOSECONDS_PER_SECOND / configTICK_RATE_HZ ) /**< Nanoseconds per FreeRTOS tick. */
|
||||
/**@} */
|
||||
|
||||
/**
|
||||
* @name Clock identifiers.
|
||||
*/
|
||||
/**@{ */
|
||||
#define CLOCK_REALTIME 0 /**< The identifier of the system-wide clock measuring real time. */
|
||||
#define CLOCK_MONOTONIC 1 /**< The identifier for the system-wide monotonic clock.*/
|
||||
/**@} */
|
||||
|
||||
/**
|
||||
* @name A number used to convert the value returned by the clock() function into seconds.
|
||||
*/
|
||||
/**@{ */
|
||||
#define CLOCKS_PER_SEC ( ( clock_t ) configTICK_RATE_HZ )
|
||||
/**@} */
|
||||
|
||||
/**
|
||||
* @name Flag indicating time is absolute.
|
||||
*
|
||||
* For functions taking timer objects, this refers to the clock associated with the timer.
|
||||
*/
|
||||
/**@{ */
|
||||
#define TIMER_ABSTIME 0x01
|
||||
/**@} */
|
||||
|
||||
#if !defined( posixconfigENABLE_TIMESPEC ) || ( posixconfigENABLE_TIMESPEC == 1 )
|
||||
|
||||
/**
|
||||
* @brief represents an elapsed time
|
||||
*/
|
||||
struct timespec
|
||||
{
|
||||
time_t tv_sec; /**< Seconds. */
|
||||
long tv_nsec; /**< Nanoseconds. */
|
||||
};
|
||||
#endif
|
||||
|
||||
#if !defined( posixconfigENABLE_ITIMERSPEC ) || ( posixconfigENABLE_ITIMERSPEC == 1 )
|
||||
|
||||
/**
|
||||
* @brief timer
|
||||
*/
|
||||
struct itimerspec
|
||||
{
|
||||
struct timespec it_interval; /**< Timer period. */
|
||||
struct timespec it_value; /**< Timer expiration. */
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Report CPU time used.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock.html
|
||||
*
|
||||
* @return The number of FreeRTOS ticks since the scheduler
|
||||
* was started minus the ticks spent in the idle task.
|
||||
*
|
||||
* @note This function does NOT report the number of ticks spent by the calling thread.
|
||||
*/
|
||||
clock_t clock( void );
|
||||
|
||||
/**
|
||||
* @brief Access a process CPU-time clock.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getcpuclockid.html
|
||||
*
|
||||
* @retval EPERM
|
||||
*
|
||||
* @note This function is currently unsupported.
|
||||
*
|
||||
*/
|
||||
int clock_getcpuclockid( pid_t pid,
|
||||
clockid_t * clock_id );
|
||||
|
||||
/**
|
||||
* @brief Returns the resolution of a clock.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getres.html
|
||||
*
|
||||
* @note clock_id is ignored
|
||||
* @note This function stores the resolution of the FreeRTOS tick count in the object res points to.
|
||||
*
|
||||
* @retval 0 - Upon successful execution
|
||||
*/
|
||||
int clock_getres( clockid_t clock_id,
|
||||
struct timespec * res );
|
||||
|
||||
/**
|
||||
* @brief Returns the current value for the specified clock, clock_id.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_gettime.html
|
||||
*
|
||||
* @note clock_id is ignored
|
||||
* @note this function does not check for overflows of time_t.
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*/
|
||||
int clock_gettime( clockid_t clock_id,
|
||||
struct timespec * tp );
|
||||
|
||||
/**
|
||||
* @brief High resolution sleep with specifiable clock.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_nanosleep.html
|
||||
*
|
||||
* @note clock_id is ignored, as this function uses the FreeRTOS tick count as its clock.
|
||||
* @note flags is ignored, if INCLUDE_vTaskDelayUntil is 0. i.e. the FreeRTOS function vTaskDelayUntil isn't available.
|
||||
* @note rmtp is also ignored, as signals are not implemented.
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
* @retval EINVAL - The rqtp argument specified a nanosecond value less than zero or greater than or equal to 1000 million.
|
||||
*/
|
||||
int clock_nanosleep( clockid_t clock_id,
|
||||
int flags,
|
||||
const struct timespec * rqtp,
|
||||
struct timespec * rmtp );
|
||||
|
||||
/**
|
||||
* @brief Sets the time for the specified clock.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_settime.html
|
||||
*
|
||||
* @retval -1 with errno set to EPERM.
|
||||
*
|
||||
* @note This function is currently unsupported, as FreeRTOS does not provide a function to modify the tick count.
|
||||
*/
|
||||
int clock_settime( clockid_t clock_id,
|
||||
const struct timespec * tp );
|
||||
|
||||
/**
|
||||
* @brief High resolution sleep.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html
|
||||
*
|
||||
* @note rmtp is ignored, as signals are not implemented.
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
* @retval -1 - The rqtp argument is invalid OR the rqtp argument specified a nanosecond value less than zero or greater than or equal to 1000 million.
|
||||
*
|
||||
*/
|
||||
int nanosleep( const struct timespec * rqtp,
|
||||
struct timespec * rmtp );
|
||||
|
||||
/**
|
||||
* @brief Create a per-process timer.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_create.html
|
||||
*
|
||||
* @note clock_id is ignored, as this function used the FreeRTOS tick count as its clock.
|
||||
* @note evp.sigev_notify must be set to SIGEV_THREAD, since signals are currently not supported.
|
||||
*
|
||||
* @retval 0 - Upon successful completion, with location referenced by timerid updated.
|
||||
* @retval -1 - If an error occurs. errno is also set.
|
||||
*
|
||||
* @sideeffect Possible errno values
|
||||
* <br>
|
||||
* ENOTSUP - If evp is NULL OR evp->sigen_notify == SIGEV_SIGNAL.
|
||||
* <br>
|
||||
* EAGAIN - The system lacks sufficient signal queuing resources to honor the request.
|
||||
*/
|
||||
int timer_create( clockid_t clockid,
|
||||
struct sigevent * evp,
|
||||
timer_t * timerid );
|
||||
|
||||
/**
|
||||
* @brief Delete a per-process timer.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_delete.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*/
|
||||
int timer_delete( timer_t timerid );
|
||||
|
||||
/**
|
||||
* @brief Get the timer overrun count.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_getoverrun.html
|
||||
*
|
||||
* @retval 0 - Always return 0, since signals are not supported.
|
||||
*/
|
||||
int timer_getoverrun( timer_t timerid );
|
||||
|
||||
/**
|
||||
* @brief Get the amount of time until the timer expires.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_gettime.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*/
|
||||
int timer_gettime( timer_t timerid,
|
||||
struct itimerspec * value );
|
||||
|
||||
/**
|
||||
* @brief Set the time until the next expiration of the timer.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_settime.html
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
* @retval -1 - An error occurred, errno is also set.
|
||||
*
|
||||
* @sideeffect Possible errno values
|
||||
* <br>
|
||||
* EINVAL - A value structure specified a nanosecond value less than zero or greater than or equal to 1000 million,
|
||||
* AND the it_value member of that structure did not specify zero seconds and nanoseconds.
|
||||
*/
|
||||
int timer_settime( timer_t timerid,
|
||||
int flags,
|
||||
const struct itimerspec * value,
|
||||
struct itimerspec * ovalue );
|
||||
|
||||
/**
|
||||
The time function returns the systems current time stamp.
|
||||
If timer is not a null pointer, the return value is also assigned to the object it points to.
|
||||
*/
|
||||
|
||||
typedef int32_t __time32_t;
|
||||
|
||||
time_t time(time_t *timer);
|
||||
time_t __time32(time_t *timer);
|
||||
|
||||
/**
|
||||
The difftime function returns the difference between two binary time stamps,
|
||||
time1 - time0.
|
||||
*/
|
||||
int32_t difftime(time_t time1, time_t time0);
|
||||
int32_t __difftime32(time_t time1, time_t time0);
|
||||
|
||||
|
||||
/**
|
||||
The tm structure contains a representation of time 'broken down' into components of the
|
||||
Gregorian calendar.
|
||||
|
||||
The normal ranges of the elements are..
|
||||
|
||||
\code
|
||||
tm_sec seconds after the minute - [ 0 to 59 ]
|
||||
tm_min minutes after the hour - [ 0 to 59 ]
|
||||
tm_hour hours since midnight - [ 0 to 23 ]
|
||||
tm_mday day of the month - [ 1 to 31 ]
|
||||
tm_wday days since Sunday - [ 0 to 6 ]
|
||||
tm_mon months since January - [ 0 to 11 ]
|
||||
tm_year years since 1900
|
||||
tm_yday days since January 1 - [ 0 to 365 ]
|
||||
tm_isdst Daylight Saving Time flag *
|
||||
|
||||
\endcode
|
||||
|
||||
*The value of tm_isdst is zero if Daylight Saving Time is not in effect, and is negative if
|
||||
the information is not available.
|
||||
|
||||
When Daylight Saving Time is in effect, the value represents the number of
|
||||
seconds the clock is advanced.
|
||||
|
||||
See the set_dst() function for more information about Daylight Saving.
|
||||
|
||||
*/
|
||||
typedef struct tm {
|
||||
uint8_t tm_sec;
|
||||
uint8_t tm_min;
|
||||
uint8_t tm_hour;
|
||||
uint8_t tm_mday;
|
||||
uint8_t tm_wday;
|
||||
uint8_t tm_mon;
|
||||
uint16_t tm_year;
|
||||
uint16_t tm_yday;
|
||||
int16_t tm_isdst;
|
||||
} tm;
|
||||
|
||||
|
||||
/**
|
||||
This function 'compiles' the elements of a broken-down time structure, returning a binary time stamp.
|
||||
The elements of timeptr are interpreted as representing Local Time.
|
||||
|
||||
The original values of the tm_wday and tm_yday elements of the structure are ignored,
|
||||
and the original values of the other elements are not restricted to the ranges stated for struct tm.
|
||||
|
||||
On successful completion, the values of all elements of timeptr are set to the appropriate range.
|
||||
*/
|
||||
time_t mktime(struct tm * timeptr);
|
||||
time_t __mktime32(struct tm * timeptr);
|
||||
|
||||
|
||||
/**
|
||||
This function 'compiles' the elements of a broken-down time structure, returning a binary time stamp.
|
||||
The elements of timeptr are interpreted as representing UTC.
|
||||
|
||||
The original values of the tm_wday and tm_yday elements of the structure are ignored,
|
||||
and the original values of the other elements are not restricted to the ranges stated for struct tm.
|
||||
|
||||
Unlike mktime(), this function DOES NOT modify the elements of timeptr.
|
||||
*/
|
||||
time_t mk_gmtime(const struct tm * timeptr);
|
||||
|
||||
/**
|
||||
The gmtime function converts the time stamp pointed to by timer into broken-down time,
|
||||
expressed as UTC.
|
||||
*/
|
||||
struct tm *gmtime(const time_t * timer);
|
||||
struct tm *__gmtime32(const time_t * timeptr);
|
||||
|
||||
/**
|
||||
Re entrant version of gmtime().
|
||||
*/
|
||||
struct tm * gmtime_r(const time_t * timer, struct tm * timeptr);
|
||||
|
||||
/**
|
||||
The localtime function converts the time stamp pointed to by timer into broken-down time,
|
||||
expressed as Local time.
|
||||
*/
|
||||
struct tm *localtime(const time_t * timer);
|
||||
struct tm *__localtime32(const time_t * timer);
|
||||
|
||||
|
||||
/**
|
||||
Re entrant version of localtime().
|
||||
*/
|
||||
struct tm *localtime_r(const time_t *timep, struct tm *result);
|
||||
|
||||
/**
|
||||
The asctime function converts the broken-down time of timeptr, into an ascii string in the form
|
||||
|
||||
Sun Mar 23 01:03:52 2013
|
||||
*/
|
||||
char *asctime(const struct tm * timeptr);
|
||||
|
||||
/**
|
||||
Re entrant version of asctime().
|
||||
*/
|
||||
//void asctime_r(const struct tm * timeptr, char *buffer);
|
||||
char *asctime_r(const struct tm *timeptr, char *buffer);
|
||||
|
||||
|
||||
/**
|
||||
The ctime function is equivalent to asctime(localtime(timer))
|
||||
*/
|
||||
char *ctime(const time_t * timer);
|
||||
char *__ctime32(const time_t * timeptr);
|
||||
|
||||
/**
|
||||
Re entrant version of ctime().
|
||||
*/
|
||||
char *ctime_r(const time_t * timer, char *buf);
|
||||
|
||||
/**
|
||||
The isotime function constructs an ascii string in the form
|
||||
\code2013-03-23 01:03:52\endcode
|
||||
*/
|
||||
char *isotime(const struct tm * tmptr);
|
||||
|
||||
/**
|
||||
Re entrant version of isotime()
|
||||
*/
|
||||
void isotime_r(const struct tm *, char *);
|
||||
|
||||
/**
|
||||
A complete description of strftime() is beyond the pale of this document.
|
||||
Refer to ISO/IEC document 9899 for details.
|
||||
|
||||
All conversions are made using the 'C Locale', ignoring the E or O modifiers. Due to the lack of
|
||||
a time zone 'name', the 'Z' conversion is also ignored.
|
||||
*/
|
||||
size_t strftime(char *s, size_t maxsize, const char *format, const struct tm * timeptr);
|
||||
|
||||
/**
|
||||
Specify the Daylight Saving function.
|
||||
|
||||
The Daylight Saving function should examine its parameters to determine whether
|
||||
Daylight Saving is in effect, and return a value appropriate for tm_isdst.
|
||||
|
||||
Working examples for the USA and the EU are available..
|
||||
|
||||
\code #include <util/eu_dst.h>\endcode
|
||||
for the European Union, and
|
||||
\code #include <util/usa_dst.h>\endcode
|
||||
for the United States
|
||||
|
||||
If a Daylight Saving function is not specified, the system will ignore Daylight Saving.
|
||||
*/
|
||||
void set_dst(int16_t (*) (const time_t *, int32_t *));
|
||||
|
||||
/**
|
||||
Set the 'time zone'. The parameter is given in seconds East of the Prime Meridian.
|
||||
Example for New York City:
|
||||
\code set_zone(-5 * ONE_HOUR);\endcode
|
||||
|
||||
If the time zone is not set, the time system will operate in UTC only.
|
||||
*/
|
||||
void set_zone(int32_t);
|
||||
|
||||
/**
|
||||
Initialize the system time. Examples are...
|
||||
|
||||
From a Clock / Calendar type RTC:
|
||||
\code
|
||||
struct tm rtc_time;
|
||||
|
||||
read_rtc(&rtc_time);
|
||||
rtc_time.tm_isdst = 0;
|
||||
set_system_time( mktime(&rtc_time) );
|
||||
\endcode
|
||||
|
||||
From a Network Time Protocol time stamp:
|
||||
\code
|
||||
set_system_time(ntp_timestamp - NTP_OFFSET);
|
||||
\endcode
|
||||
|
||||
From a UNIX time stamp:
|
||||
\code
|
||||
set_system_time(unix_timestamp - UNIX_OFFSET);
|
||||
\endcode
|
||||
|
||||
*/
|
||||
void set_system_time(time_t timestamp);
|
||||
|
||||
/**
|
||||
Maintain the system time by calling this function at a rate of 1 Hertz.
|
||||
|
||||
It is anticipated that this function will typically be called from within an
|
||||
Interrupt Service Routine, (though that is not required). It therefore includes code which
|
||||
makes it simple to use from within a 'Naked' ISR, avoiding the cost of saving and restoring
|
||||
all the cpu registers.
|
||||
|
||||
Such an ISR may resemble the following example...
|
||||
\code
|
||||
ISR(RTC_OVF_vect, ISR_NAKED)
|
||||
{
|
||||
system_tick();
|
||||
reti();
|
||||
}
|
||||
\endcode
|
||||
*/
|
||||
void system_tick(void);
|
||||
|
||||
/**
|
||||
Enumerated labels for the days of the week.
|
||||
*/
|
||||
enum _WEEK_DAYS_ {
|
||||
SUNDAY,
|
||||
MONDAY,
|
||||
TUESDAY,
|
||||
WEDNESDAY,
|
||||
THURSDAY,
|
||||
FRIDAY,
|
||||
SATURDAY
|
||||
};
|
||||
|
||||
/**
|
||||
Enumerated labels for the months.
|
||||
*/
|
||||
enum _MONTHS_ {
|
||||
JANUARY,
|
||||
FEBRUARY,
|
||||
MARCH,
|
||||
APRIL,
|
||||
MAY,
|
||||
JUNE,
|
||||
JULY,
|
||||
AUGUST,
|
||||
SEPTEMBER,
|
||||
OCTOBER,
|
||||
NOVEMBER,
|
||||
DECEMBER
|
||||
};
|
||||
|
||||
/**
|
||||
Return 1 if year is a leap year, zero if it is not.
|
||||
*/
|
||||
//uint8_t is_leap_year(uint16_t year);
|
||||
|
||||
/**
|
||||
Return the length of month, given the year and month, where month is in the range 1 to 12.
|
||||
*/
|
||||
uint8_t month_length(uint16_t year, uint8_t month);
|
||||
|
||||
/**
|
||||
Return the calendar week of year, where week 1 is considered to begin on the
|
||||
day of week specified by 'start'. The returned value may range from zero to 52.
|
||||
*/
|
||||
uint8_t week_of_year(const struct tm * timeptr, uint8_t start);
|
||||
|
||||
/**
|
||||
Return the calendar week of month, where the first week is considered to begin on the
|
||||
day of week specified by 'start'. The returned value may range from zero to 5.
|
||||
*/
|
||||
uint8_t week_of_month(const struct tm * timeptr, uint8_t start);
|
||||
|
||||
/**
|
||||
Structure which represents a date as a year, week number of that year, and day of week.
|
||||
See http://en.wikipedia.org/wiki/ISO_week_date for more information.
|
||||
*/
|
||||
struct week_date{
|
||||
uint16_t year;
|
||||
uint8_t week;
|
||||
uint8_t day;
|
||||
};
|
||||
|
||||
/**
|
||||
Return a week_date structure with the ISO_8601 week based date corresponding to the given
|
||||
year and day of year. See http://en.wikipedia.org/wiki/ISO_week_date for more
|
||||
information.
|
||||
*/
|
||||
struct week_date * iso_week_date( uint16_t year, uint16_t yday);
|
||||
|
||||
/**
|
||||
Re-entrant version of iso-week_date.
|
||||
*/
|
||||
void iso_week_date_r( uint16_t year, uint16_t yday, struct week_date *);
|
||||
|
||||
/**
|
||||
Convert a Y2K time stamp into a FAT file system time stamp.
|
||||
*/
|
||||
uint32_t fatfs_time(const struct tm * timeptr);
|
||||
|
||||
/** One hour, expressed in seconds */
|
||||
#define ONE_HOUR 3600
|
||||
|
||||
/** Angular degree, expressed in arc seconds */
|
||||
#define ONE_DEGREE 3600
|
||||
|
||||
/** One day, expressed in seconds */
|
||||
#define ONE_DAY 86400
|
||||
|
||||
/** Difference between the Y2K and the UNIX epochs, in seconds. To convert a Y2K
|
||||
timestamp to UNIX...
|
||||
\code
|
||||
long unix;
|
||||
time_t y2k;
|
||||
|
||||
y2k = time(NULL);
|
||||
unix = y2k + UNIX_OFFSET;
|
||||
\endcode
|
||||
*/
|
||||
#define UNIX_OFFSET 946684800
|
||||
|
||||
/** Difference between the Y2K and the NTP epochs, in seconds. To convert a Y2K
|
||||
timestamp to NTP...
|
||||
\code
|
||||
unsigned long ntp;
|
||||
time_t y2k;
|
||||
|
||||
y2k = time(NULL);
|
||||
ntp = y2k + NTP_OFFSET;
|
||||
\endcode
|
||||
*/
|
||||
#define NTP_OFFSET 3155673600
|
||||
|
||||
/*
|
||||
* ===================================================================
|
||||
* Ephemera
|
||||
*/
|
||||
|
||||
/**
|
||||
Set the geographic coordinates of the 'observer', for use with several of the
|
||||
following functions. Parameters are passed as seconds of North Latitude, and seconds
|
||||
of East Longitude.
|
||||
|
||||
For New York City...
|
||||
\code set_position( 40.7142 * ONE_DEGREE, -74.0064 * ONE_DEGREE); \endcode
|
||||
*/
|
||||
void set_position(int32_t latitude, int32_t longitude);
|
||||
|
||||
/**
|
||||
Computes the difference between apparent solar time and mean solar time.
|
||||
The returned value is in seconds.
|
||||
*/
|
||||
int16_t equation_of_time(const time_t * timer);
|
||||
|
||||
/**
|
||||
Computes the amount of time the sun is above the horizon, at the location of the observer.
|
||||
|
||||
NOTE: At observer locations inside a polar circle, this value can be zero during the winter,
|
||||
and can exceed ONE_DAY during the summer.
|
||||
|
||||
The returned value is in seconds.
|
||||
*/
|
||||
int32_t daylight_seconds(const time_t * timer);
|
||||
|
||||
/**
|
||||
Computes the time of solar noon, at the location of the observer.
|
||||
*/
|
||||
time_t solar_noon(const time_t * timer);
|
||||
|
||||
/**
|
||||
Return the time of sunrise, at the location of the observer. See the note about daylight_seconds().
|
||||
*/
|
||||
time_t sun_rise(const time_t * timer);
|
||||
|
||||
/**
|
||||
Return the time of sunset, at the location of the observer. See the note about daylight_seconds().
|
||||
*/
|
||||
time_t sun_set(const time_t * timer);
|
||||
|
||||
/** Returns the declination of the sun in radians. */
|
||||
float solar_declination(const time_t * timer);
|
||||
|
||||
/**
|
||||
Returns an approximation to the phase of the moon.
|
||||
The sign of the returned value indicates a waning or waxing phase.
|
||||
The magnitude of the returned value indicates the percentage illumination.
|
||||
*/
|
||||
int8_t moon_phase(const time_t * timer);
|
||||
|
||||
/**
|
||||
Returns Greenwich Mean Sidereal Time, as seconds into the sidereal day.
|
||||
The returned value will range from 0 through 86399 seconds.
|
||||
*/
|
||||
uint32_t gm_sidereal(const time_t * timer);
|
||||
|
||||
/**
|
||||
Returns Local Mean Sidereal Time, as seconds into the sidereal day.
|
||||
The returned value will range from 0 through 86399 seconds.
|
||||
*/
|
||||
uint32_t lm_sidereal(const time_t * timer);
|
||||
|
||||
int timespec_get(struct timespec *ts, int base);
|
||||
|
||||
int __timespec_get32(struct timespec *ts, int base);
|
||||
//for c++ compile
|
||||
#define EDOM 33
|
||||
|
||||
|
||||
#endif /* ifndef _FREERTOS_POSIX_TIME_H_ */
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Amazon FreeRTOS POSIX V1.1.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 unistd.h
|
||||
* @brief Standard symbolic constants and types
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html
|
||||
*/
|
||||
|
||||
#ifndef _FREERTOS_POSIX_UNISTD_H_
|
||||
#define _FREERTOS_POSIX_UNISTD_H_
|
||||
|
||||
#include "FreeRTOS_POSIX/sys/types.h"
|
||||
|
||||
/**
|
||||
* @brief Suspend execution for an interval of time.
|
||||
*
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/sleep.html
|
||||
*
|
||||
* @param[in] seconds The number of seconds to suspend execution.
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*
|
||||
* @note Return value of a positive number is not yet supported.
|
||||
*/
|
||||
unsigned sleep( unsigned seconds );
|
||||
|
||||
/**
|
||||
* @brief Suspend execution for microsecond intervals.
|
||||
*
|
||||
* This is a useful, non-POSIX function.
|
||||
* @param[in] usec The number of microseconds to suspend execution.
|
||||
*
|
||||
* @retval 0 - Upon successful completion.
|
||||
*/
|
||||
int usleep( useconds_t usec );
|
||||
|
||||
int msleep( useconds_t msec );
|
||||
|
||||
#endif /* ifndef _FREERTOS_POSIX_UNISTD_H_ */
|
@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Amazon FreeRTOS POSIX V1.1.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 utils.h
|
||||
* @brief Utility functions used by FreeRTOS+POSIX.
|
||||
*/
|
||||
|
||||
#ifndef _FREERTOS_POSIX_UTILS_
|
||||
#define _FREERTOS_POSIX_UTILS_
|
||||
|
||||
/* C standard library includes. */
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* FreeRTOS+POSIX includes. */
|
||||
#include "FreeRTOS_POSIX/time.h"
|
||||
|
||||
/**
|
||||
* @brief Calculates the length of pcString, up to xMaxLength.
|
||||
*
|
||||
* @param[in] pcString The string to find the length of.
|
||||
* @param[in] xMaxLength The limit when searching for the end of pcString.
|
||||
*
|
||||
* @return 0 if pcString is NULL; otherwise, the length of pcString or xMaxLength,
|
||||
* whichever is smaller.
|
||||
*/
|
||||
size_t UTILS_strnlen( const char * const pcString,
|
||||
size_t xMaxLength );
|
||||
|
||||
/**
|
||||
* @brief Calculates the number of ticks between now and a given timespec.
|
||||
*
|
||||
* @param[in] pxAbsoluteTime A time in the future, specified as seconds and
|
||||
* nanoseconds since CLOCK_REALTIME's 0.
|
||||
* @param[in] pxCurrentTime current time, specified as seconds and
|
||||
* nanoseconds.
|
||||
* @param[out] pxResult Where the result of the conversion is stored. The result
|
||||
* is rounded up for fractional ticks.
|
||||
*
|
||||
* @return 0 on success. Otherwise, ETIMEDOUT if pxAbsoluteTime is in the past,
|
||||
* or EINVAL for invalid parameters.
|
||||
*/
|
||||
int UTILS_AbsoluteTimespecToDeltaTicks( const struct timespec * const pxAbsoluteTime,
|
||||
const struct timespec * const pxCurrentTime,
|
||||
TickType_t * const pxResult );
|
||||
|
||||
/**
|
||||
* @brief Converts a struct timespec to FreeRTOS ticks.
|
||||
*
|
||||
* @param[in] pxTimespec The timespec to convert.
|
||||
* @param[out] Where the result of the conversion is stored. The result is rounded
|
||||
* up for fractional ticks.
|
||||
*
|
||||
* @return 0 on success. Otherwise, EINVAL for invalid parameters.
|
||||
*/
|
||||
int UTILS_TimespecToTicks( const struct timespec * const pxTimespec,
|
||||
TickType_t * const pxResult );
|
||||
|
||||
/**
|
||||
* @brief Converts an integer value to a timespec.
|
||||
*
|
||||
* @param[in] llSource The value to convert.
|
||||
* @param[out] pxDestination Where to store the converted value.
|
||||
*
|
||||
* @return No return value.
|
||||
*/
|
||||
void UTILS_NanosecondsToTimespec( int64_t llSource,
|
||||
struct timespec * const pxDestination );
|
||||
|
||||
/**
|
||||
* @brief Calculates pxResult = x + y.
|
||||
*
|
||||
* @param[in] x The first argument for addition.
|
||||
* @param[in] y The second argument for addition.
|
||||
* @param[out] pxResult Where the result of the calculation is stored.
|
||||
*
|
||||
* @return -1 if any argument was NULL; 1 if result is negative (overflow); otherwise, 0.
|
||||
*/
|
||||
int UTILS_TimespecAdd( const struct timespec * const x,
|
||||
const struct timespec * const y,
|
||||
struct timespec * const pxResult );
|
||||
|
||||
/**
|
||||
* @brief Calculates pxResult = x + ( struct timespec ) nanosec.
|
||||
*
|
||||
* @param[in] x The first argument for addition.
|
||||
* @param[in] llNanoseconds The second argument for addition.
|
||||
* @param[out] pxResult Where the result of the calculation is stored.
|
||||
*
|
||||
* @return -1 if pxResult or x was NULL; 1 if result is negative; otherwise, 0.
|
||||
*/
|
||||
int UTILS_TimespecAddNanoseconds( const struct timespec * const x,
|
||||
int64_t llNanoseconds,
|
||||
struct timespec * const pxResult );
|
||||
|
||||
/**
|
||||
* @brief Calculates pxResult = x - y. If the result is negative contents of
|
||||
* pResult are undefined
|
||||
*
|
||||
* @param[in] x The first argument for subtraction.
|
||||
* @param[in] y The second argument for subtraction.
|
||||
* @param[out] pxResult Where the result of the calculation is stored.
|
||||
*
|
||||
* @return -1 if any argument was NULL; 1 if result is negative; otherwise, 0.
|
||||
*/
|
||||
int UTILS_TimespecSubtract( const struct timespec * const x,
|
||||
const struct timespec * const y,
|
||||
struct timespec * const pxResult );
|
||||
|
||||
/**
|
||||
* @brief Compare x == y.
|
||||
*
|
||||
* @param[in] x The first argument for comparison.
|
||||
* @param[in] y The second argument for comparison.
|
||||
*
|
||||
* @return 0 if x == y; 1 if x > y; -1 if x < y or any argument was NULL
|
||||
*/
|
||||
int UTILS_TimespecCompare( const struct timespec * const x,
|
||||
const struct timespec * const y );
|
||||
|
||||
/**
|
||||
* @brief Checks that a timespec conforms to POSIX.
|
||||
*
|
||||
* A valid timespec must have 0 <= tv_nsec < 1000000000.
|
||||
*
|
||||
* @param[in] pxTimespec The timespec to validate.
|
||||
*
|
||||
* @return true if the pxTimespec is valid, false otherwise.
|
||||
*/
|
||||
bool UTILS_ValidateTimespec( const struct timespec * const pxTimespec );
|
||||
|
||||
#endif /* ifndef _FREERTOS_POSIX_UTILS_ */
|
@ -0,0 +1,242 @@
|
||||
/*
|
||||
* Amazon FreeRTOS Common V1.0.0
|
||||
* Copyright (C) 2018 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_doubly_linked_list.h
|
||||
* @brief Doubly Linked List implementation.
|
||||
*
|
||||
* A generic implementation of circular Doubly Linked List which consists of a
|
||||
* list head and some list entries (zero in case of an empty list).
|
||||
*
|
||||
* To start with, a structure of type Link_t should be embedded in the structure
|
||||
* which is to be organized as doubly linked list.
|
||||
* @code
|
||||
* typedef struct UserStruct
|
||||
* {
|
||||
* uint32_t ulField1;
|
||||
* uint32_t ulField2;
|
||||
* Link_t xLink;
|
||||
* } UserStruct_t;
|
||||
* @endcode
|
||||
*
|
||||
* A List head should then be defined and initialized.
|
||||
* @code
|
||||
* Link_t xListHead;
|
||||
* listINIT_HEAD( &xListHead );
|
||||
* @endcode
|
||||
*
|
||||
* listADD can then be used to add nodes to the list.
|
||||
* @code
|
||||
* listADD( &( xListHead ), &( pxUserStruct->xLink ) );
|
||||
* @endcode
|
||||
*
|
||||
* listFOR_EACH can be used for traversing the list.
|
||||
* @code
|
||||
* Link_t *pxLink;
|
||||
* UserStruct_t *pxUserStruct;
|
||||
* listFOR_EACH( pxLink, &( xListHead ) )
|
||||
* {
|
||||
* pxUserStruct = listCONTAINER( pxLink, UserStruct_t, xLink );
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* listFOR_EACH_SAFE should be used if you want to perform destructive operations
|
||||
* (like free) on nodes while traversing the list.
|
||||
* @code
|
||||
* Link_t *pxLink, *pxTempLink;
|
||||
* UserStruct_t *pxUserStruct;
|
||||
* listFOR_EACH( pxLink, pxTempLink, &( xListHead ) )
|
||||
* {
|
||||
* pxUserStruct = listCONTAINER( pxLink, UserStruct_t, xLink );
|
||||
* free( pxUserStruct );
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
|
||||
#ifndef _AWS_DOUBLY_LINKED_LIST_H_
|
||||
#define _AWS_DOUBLY_LINKED_LIST_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief Struct embedded in any struct to make it a doubly linked
|
||||
* list.
|
||||
*
|
||||
* pxNext in the head points to the first node in the list and pxPrev
|
||||
* in the head points to the last node in the list. In case of empty
|
||||
* list, both pxPrev and pxNext in the head point to the head node itself.
|
||||
*/
|
||||
typedef struct Link
|
||||
{
|
||||
struct Link * pxPrev; /**< Pointer to the previous node. */
|
||||
struct Link * pxNext; /**< Pointer to the next node. */
|
||||
} Link_t;
|
||||
|
||||
/**
|
||||
* @brief Initializes the given list head to an empty list.
|
||||
*
|
||||
* @param[in] pxHead The given list head to initialize.
|
||||
*/
|
||||
#define listINIT_HEAD( pxHead ) \
|
||||
{ \
|
||||
( pxHead )->pxPrev = ( pxHead ); \
|
||||
( pxHead )->pxNext = ( pxHead ); \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adds the given new node to the given list.
|
||||
*
|
||||
* @param[in] pxHead The head of the given list.
|
||||
* @param[in] pxLink The given new node to be added to the given
|
||||
* list.
|
||||
*/
|
||||
#define listADD( pxHead, pxLink ) \
|
||||
{ \
|
||||
Link_t * pxPrevLink = ( pxHead ); \
|
||||
Link_t * pxNextLink = ( ( pxHead )->pxNext ); \
|
||||
\
|
||||
( pxLink )->pxNext = pxNextLink; \
|
||||
pxNextLink->pxPrev = ( pxLink ); \
|
||||
pxPrevLink->pxNext = ( pxLink ); \
|
||||
( pxLink )->pxPrev = ( pxPrevLink ); \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Removes the given node from the list it is part of.
|
||||
*
|
||||
* If the given node is not a part of any list (i.e. next and previous
|
||||
* nodes are NULL), nothing happens.
|
||||
*
|
||||
* @param[in] pxLink The given node to remove from the list.
|
||||
*/
|
||||
#define listREMOVE( pxLink ) \
|
||||
{ \
|
||||
/* If the link is part of a list, remove it from the list. */ \
|
||||
if( ( pxLink )->pxNext != NULL && ( pxLink )->pxPrev != NULL ) \
|
||||
{ \
|
||||
( pxLink )->pxPrev->pxNext = ( pxLink )->pxNext; \
|
||||
( pxLink )->pxNext->pxPrev = ( pxLink )->pxPrev; \
|
||||
} \
|
||||
\
|
||||
/* Make sure that this link is not part of any list anymore. */ \
|
||||
( pxLink )->pxPrev = NULL; \
|
||||
( pxLink )->pxNext = NULL; \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Given the head of a list, checks if the list is empty.
|
||||
*
|
||||
* @param[in] pxHead The head of the given list.
|
||||
*/
|
||||
#define listIS_EMPTY( pxHead ) ( ( ( pxHead ) == NULL ) || ( ( pxHead )->pxNext == ( pxHead ) ) )
|
||||
|
||||
/**
|
||||
* @brief Removes the first node from the given list and returns it.
|
||||
*
|
||||
* Removes the first node from the given list and assigns it to the
|
||||
* pxLink parameter. If the list is empty, it assigns NULL to the
|
||||
* pxLink.
|
||||
*
|
||||
* @param[in] pxHead The head of the list from which to remove the
|
||||
* first node.
|
||||
* @param[out] pxLink The output parameter to receive the removed
|
||||
* node.
|
||||
*/
|
||||
#define listPOP( pxHead, pxLink ) \
|
||||
{ \
|
||||
if( listIS_EMPTY( ( pxHead ) ) ) \
|
||||
{ \
|
||||
( pxLink ) = NULL; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
( pxLink ) = ( pxHead )->pxNext; \
|
||||
/* If the link is part of a list, remove it from the list. */ \
|
||||
if( ( pxLink )->pxNext != NULL && ( pxLink )->pxPrev != NULL ) \
|
||||
{ \
|
||||
( pxLink )->pxPrev->pxNext = ( pxLink )->pxNext; \
|
||||
( pxLink )->pxNext->pxPrev = ( pxLink )->pxPrev; \
|
||||
} \
|
||||
\
|
||||
/* Make sure that this link is not part of any list anymore. */ \
|
||||
( pxLink )->pxPrev = NULL; \
|
||||
( pxLink )->pxNext = NULL; \
|
||||
} \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Merges a list into a given list.
|
||||
*
|
||||
* @param[in] pxHeadResultList The head of the given list into which the
|
||||
* other list should be merged.
|
||||
* @param[in] pxHeadListToMerge The head of the list to be merged into the
|
||||
* given list.
|
||||
*/
|
||||
#define listMERGE( pxHeadResultList, pxHeadListToMerge ) \
|
||||
{ \
|
||||
if( !listIS_EMPTY( ( pxHeadListToMerge ) ) ) \
|
||||
{ \
|
||||
/* Setup links between last node of listToMerge and first node of resultList. */ \
|
||||
( pxHeadListToMerge )->pxPrev->pxNext = ( pxHeadResultList )->pxNext; \
|
||||
( pxHeadResultList )->pxNext->pxPrev = ( pxHeadListToMerge )->pxPrev; \
|
||||
\
|
||||
/* Setup links between first node of listToMerge and the head of resultList. */ \
|
||||
( pxHeadListToMerge )->pxNext->pxPrev = ( pxHeadResultList ); \
|
||||
( pxHeadResultList )->pxNext = ( pxHeadListToMerge )->pxNext; \
|
||||
/* Empty the merged list. */ \
|
||||
listINIT_HEAD( ( pxHeadListToMerge ) ); \
|
||||
} \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Helper macro to iterate over a list. pxLink contains the link node
|
||||
* in each iteration.
|
||||
*/
|
||||
#define listFOR_EACH( pxLink, pxHead ) \
|
||||
for( ( pxLink ) = ( pxHead )->pxNext; \
|
||||
( pxLink ) != ( pxHead ); \
|
||||
( pxLink ) = ( pxLink )->pxNext )
|
||||
|
||||
/**
|
||||
* @brief Helper macro to iterate over a list. It is safe to destroy/free the
|
||||
* nodes while iterating. pxLink contains the link node in each iteration.
|
||||
*/
|
||||
#define listFOR_EACH_SAFE( pxLink, pxTempLink, pxHead ) \
|
||||
for( ( pxLink ) = ( pxHead )->pxNext, ( pxTempLink ) = ( pxLink )->pxNext; \
|
||||
( pxLink ) != ( pxHead ); \
|
||||
( pxLink ) = ( pxTempLink ), ( pxTempLink ) = ( pxLink )->pxNext )
|
||||
|
||||
/**
|
||||
* @brief Given the pointer to the link member (of type Link_t) in a struct,
|
||||
* extracts the pointer to the containing struct.
|
||||
*
|
||||
* @param[in] pxLink The pointer to the link member.
|
||||
* @param[in] type The type of the containing struct.
|
||||
* @param[in] member Name of the link member in the containing struct.
|
||||
*/
|
||||
#define listCONTAINER( pxLink, type, member ) ( ( type * ) ( ( uint8_t * ) ( pxLink ) - ( uint8_t * ) ( &( ( type * ) 0 )->member ) ) )
|
||||
|
||||
#endif /* _AWS_DOUBLY_LINKED_LIST_H_ */
|
Reference in New Issue
Block a user