Implementation of utility functions in utils.h.
More...
#include <stddef.h>
#include <limits.h>
#include "FreeRTOS_POSIX.h"
#include "FreeRTOS_POSIX/errno.h"
#include "FreeRTOS_POSIX/utils.h"
|
size_t | UTILS_strnlen (const char *const pcString, size_t xMaxLength) |
| Calculates the length of pcString, up to xMaxLength. More...
|
|
int | UTILS_AbsoluteTimespecToDeltaTicks (const struct timespec *const pxAbsoluteTime, const struct timespec *const pxCurrentTime, TickType_t *const pxResult) |
| Calculates the number of ticks between now and a given timespec. More...
|
|
int | UTILS_TimespecToTicks (const struct timespec *const pxTimespec, TickType_t *const pxResult) |
| Converts a struct timespec to FreeRTOS ticks. More...
|
|
void | UTILS_NanosecondsToTimespec (int64_t llSource, struct timespec *const pxDestination) |
| Converts an integer value to a timespec. More...
|
|
int | UTILS_TimespecAdd (const struct timespec *const x, const struct timespec *const y, struct timespec *const pxResult) |
| Calculates pxResult = x + y. More...
|
|
int | UTILS_TimespecAddNanoseconds (const struct timespec *const x, int64_t llNanoseconds, struct timespec *const pxResult) |
| Calculates pxResult = x + ( struct timespec ) nanosec. More...
|
|
int | UTILS_TimespecSubtract (const struct timespec *const x, const struct timespec *const y, struct timespec *const pxResult) |
| Calculates pxResult = x - y. If the result is negative contents of pResult are undefined. More...
|
|
int | UTILS_TimespecCompare (const struct timespec *const x, const struct timespec *const y) |
| Compare x == y. More...
|
|
bool | UTILS_ValidateTimespec (const struct timespec *const pxTimespec) |
| Checks that a timespec conforms to POSIX. More...
|
|
Implementation of utility functions in utils.h.
◆ UTILS_strnlen()
size_t UTILS_strnlen |
( |
const char *const |
pcString, |
|
|
size_t |
xMaxLength |
|
) |
| |
Calculates the length of pcString, up to xMaxLength.
- Parameters
-
[in] | pcString | The string to find the length of. |
[in] | xMaxLength | The limit when searching for the end of pcString. |
- Returns
- 0 if pcString is NULL; otherwise, the length of pcString or xMaxLength, whichever is smaller.
◆ UTILS_AbsoluteTimespecToDeltaTicks()
int UTILS_AbsoluteTimespecToDeltaTicks |
( |
const struct timespec *const |
pxAbsoluteTime, |
|
|
const struct timespec *const |
pxCurrentTime, |
|
|
TickType_t *const |
pxResult |
|
) |
| |
Calculates the number of ticks between now and a given timespec.
- Parameters
-
[in] | pxAbsoluteTime | A time in the future, specified as seconds and nanoseconds since CLOCK_REALTIME's 0. |
[in] | pxCurrentTime | current time, specified as seconds and nanoseconds. |
[out] | pxResult | Where the result of the conversion is stored. The result is rounded up for fractional ticks. |
- Returns
- 0 on success. Otherwise, ETIMEDOUT if pxAbsoluteTime is in the past, or EINVAL for invalid parameters.
◆ UTILS_TimespecToTicks()
int UTILS_TimespecToTicks |
( |
const struct timespec *const |
pxTimespec, |
|
|
TickType_t *const |
pxResult |
|
) |
| |
Converts a struct timespec to FreeRTOS ticks.
- Parameters
-
[in] | pxTimespec | The timespec to convert. |
[out] | Where | the result of the conversion is stored. The result is rounded up for fractional ticks. |
- Returns
- 0 on success. Otherwise, EINVAL for invalid parameters.
◆ UTILS_NanosecondsToTimespec()
void UTILS_NanosecondsToTimespec |
( |
int64_t |
llSource, |
|
|
struct timespec *const |
pxDestination |
|
) |
| |
Converts an integer value to a timespec.
- Parameters
-
[in] | llSource | The value to convert. |
[out] | pxDestination | Where to store the converted value. |
- Returns
- No return value.
◆ UTILS_TimespecAdd()
int UTILS_TimespecAdd |
( |
const struct timespec *const |
x, |
|
|
const struct timespec *const |
y, |
|
|
struct timespec *const |
pxResult |
|
) |
| |
Calculates pxResult = x + y.
This function supports both signed and unsigned type definitions of the timespec.tv_sec member.
- Parameters
-
[in] | x | The first argument for addition. |
[in] | y | The second argument for addition. |
[out] | pxResult | Where the result of the calculation is stored. |
- Returns
- -1 if any argument is NULL or any of the input values is negative; 1 if there is an overflow in the result; otherwise, 0 for success.
◆ UTILS_TimespecAddNanoseconds()
int UTILS_TimespecAddNanoseconds |
( |
const struct timespec *const |
x, |
|
|
int64_t |
llNanoseconds, |
|
|
struct timespec *const |
pxResult |
|
) |
| |
Calculates pxResult = x + ( struct timespec ) nanosec.
- Parameters
-
[in] | x | The first argument for addition. |
[in] | llNanoseconds | The second argument for addition. |
[out] | pxResult | Where the result of the calculation is stored. |
- Returns
- -1 if pxResult or x was NULL; 1 if result is negative; otherwise, 0.
◆ UTILS_TimespecSubtract()
int UTILS_TimespecSubtract |
( |
const struct timespec *const |
x, |
|
|
const struct timespec *const |
y, |
|
|
struct timespec *const |
pxResult |
|
) |
| |
Calculates pxResult = x - y. If the result is negative contents of pResult are undefined.
- Parameters
-
[in] | x | The first argument for subtraction. |
[in] | y | The second argument for subtraction. |
[out] | pxResult | Where the result of the calculation is stored. |
- Returns
- -1 if any argument was NULL; 1 if result is negative; otherwise, 0.
◆ UTILS_TimespecCompare()
int UTILS_TimespecCompare |
( |
const struct timespec *const |
x, |
|
|
const struct timespec *const |
y |
|
) |
| |
Compare x == y.
- Parameters
-
[in] | x | The first argument for comparison. |
[in] | y | The second argument for comparison. |
- Returns
- 0 if x == y; 1 if x > y; -1 if x < y or any argument was NULL
◆ UTILS_ValidateTimespec()
bool UTILS_ValidateTimespec |
( |
const struct timespec *const |
pxTimespec | ) |
|
Checks that a timespec conforms to POSIX.
A valid timespec must have 0 <= tv_nsec < 1000000000.
- Parameters
-
[in] | pxTimespec | The timespec to validate. |
- Returns
- true if the pxTimespec is valid, false otherwise.