utils

  • #include <posix/utils.h>

  • Define public interfaces

[中文]

Header File

Functions

size_t UTILS_strnlen(const char *const pcString, size_t xMaxLength)

Calculates the length of pcString, up to xMaxLength.

Parameters
  • pcString[in] The string to find the length of.

  • xMaxLength[in] 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.

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
  • pxAbsoluteTime[in] A time in the future, specified as seconds and nanoseconds since CLOCK_REALTIME’s 0.

  • pxCurrentTime[in] current time, specified as seconds and nanoseconds.

  • pxResult[out] 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.

int UTILS_TimespecToTicks(const struct timespec *const pxTimespec, TickType_t *const pxResult)

Converts a struct timespec to FreeRTOS ticks.

Parameters
  • pxTimespec[in] The timespec to convert.

  • Where[out] the result of the conversion is stored. The result is rounded up for fractional ticks.

Returns

0 on success. Otherwise, EINVAL for invalid parameters.

void UTILS_NanosecondsToTimespec(int64_t llSource, struct timespec *const pxDestination)

Converts an integer value to a timespec.

Parameters
  • llSource[in] The value to convert.

  • pxDestination[out] Where to store the converted value.

Returns

No return value.

int UTILS_TimespecAdd(const struct timespec *const x, const struct timespec *const y, struct timespec *const pxResult)

Calculates pxResult = x + y.

Parameters
  • x[in] The first argument for addition.

  • y[in] The second argument for addition.

  • pxResult[out] Where the result of the calculation is stored.

Returns

-1 if any argument was NULL; 1 if result is negative (overflow); otherwise, 0.

int UTILS_TimespecAddNanoseconds(const struct timespec *const x, int64_t llNanoseconds, struct timespec *const pxResult)

Calculates pxResult = x + ( struct timespec ) nanosec.

Parameters
  • x[in] The first argument for addition.

  • llNanoseconds[in] The second argument for addition.

  • pxResult[out] Where the result of the calculation is stored.

Returns

-1 if pxResult or x 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)

Calculates pxResult = x - y. If the result is negative contents of pResult are undefined.

Parameters
  • x[in] The first argument for subtraction.

  • y[in] The second argument for subtraction.

  • pxResult[out] Where the result of the calculation is stored.

Returns

-1 if any argument was NULL; 1 if result is negative; otherwise, 0.

int UTILS_TimespecCompare(const struct timespec *const x, const struct timespec *const y)

Compare x == y.

Parameters
  • x[in] The first argument for comparison.

  • y[in] The second argument for comparison.

Returns

0 if x == y; 1 if x > y; -1 if x < y or any argument was NULL

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

pxTimespec[in] The timespec to validate.

Returns

true if the pxTimespec is valid, false otherwise.