AWS IoT Device SDK C:
Platform
Platform portability layer
|
Return to main page ↑ |
Time-related functions used by libraries in this SDK. More...
#include "iot_config.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "types/iot_platform_types.h"
Go to the source code of this file.
Functions | |
bool | IotClock_GetTimestring (char *pBuffer, size_t bufferSize, size_t *pTimestringLength) |
Generates a human-readable timestring, such as "01 Jan 2018 12:00". More... | |
uint64_t | IotClock_GetTimeMs (void) |
Returns a nonzero, monotonically-increasing system time in milliseconds. More... | |
void | IotClock_SleepMs (uint32_t sleepTimeMs) |
Delay for the given number of milliseconds. More... | |
bool | IotClock_TimerCreate (IotTimer_t *pNewTimer, IotThreadRoutine_t expirationRoutine, void *pArgument) |
Create a new timer. More... | |
void | IotClock_TimerDestroy (IotTimer_t *pTimer) |
Free resources used by a timer. More... | |
bool | IotClock_TimerArm (IotTimer_t *pTimer, uint32_t relativeTimeoutMs, uint32_t periodMs) |
Arm a timer to expire at the given relative timeout. More... | |
Time-related functions used by libraries in this SDK.
bool IotClock_GetTimestring | ( | char * | pBuffer, |
size_t | bufferSize, | ||
size_t * | pTimestringLength | ||
) |
Generates a human-readable timestring, such as "01 Jan 2018 12:00".
This function uses the system clock to generate a human-readable timestring. This timestring is printed by the logging functions.
[out] | pBuffer | A buffer to store the timestring in. |
[in] | bufferSize | The size of pBuffer . |
[out] | pTimestringLength | The actual length of the timestring stored in pBuffer . |
true
if a timestring was successfully generated; false
otherwise.Example
uint64_t IotClock_GetTimeMs | ( | void | ) |
Returns a nonzero, monotonically-increasing system time in milliseconds.
This function reads a millisecond-resolution system clock. The clock should always be monotonically-increasing; therefore, real-time clocks that may be set by another process are not suitable for this function's implementation.
Example
void IotClock_SleepMs | ( | uint32_t | sleepTimeMs | ) |
Delay for the given number of milliseconds.
This function suspends its calling thread for at least sleepTimeMs
milliseconds.
[in] | sleepTimeMs | Sleep time (in milliseconds). |
bool IotClock_TimerCreate | ( | IotTimer_t * | pNewTimer, |
IotThreadRoutine_t | expirationRoutine, | ||
void * | pArgument | ||
) |
Create a new timer.
This function creates a new, unarmed timer. It must be called on an uninitialized IotTimer_t. This function must not be called on an already-initialized IotTimer_t.
[out] | pNewTimer | Set to a new timer handle on success. |
[in] | expirationRoutine | The function to run when this timer expires. This function should be called in its own detached thread. |
[in] | pArgument | The argument to pass to expirationRoutine . |
true
if the timer is successfully created; false
otherwise.void IotClock_TimerDestroy | ( | IotTimer_t * | pTimer | ) |
Free resources used by a timer.
This function frees resources used by a timer. It must be called on an initialized IotTimer_t. No other timer functions should be called on pTimer
after calling this function (unless the timer is re-created).
This function will stop the pTimer
if it is armed.
[in] | pTimer | The timer to destroy. |
bool IotClock_TimerArm | ( | IotTimer_t * | pTimer, |
uint32_t | relativeTimeoutMs, | ||
uint32_t | periodMs | ||
) |
Arm a timer to expire at the given relative timeout.
This function arms a timer to run its expiration routine at the given time.
If periodMs
is nonzero, the timer should expire periodically at intervals such as:
relativeTimeoutMs
relativeTimeoutMs + periodMs
relativeTimeoutMs + 2 * periodMs
Setting periodMs
to 0
arms a one-shot, non-periodic timer.
[in] | pTimer | The timer to arm. |
[in] | relativeTimeoutMs | When the timer should expire, relative to the time this function is called. |
[in] | periodMs | How often the timer should expire again after relativeTimerMs . |
true
if the timer was successfully armed; false
otherwise.Example