Pico Libraries
Macros | Typedefs | Functions
pico_time.h File Reference

A simple time management library. More...

#include <stdint.h>
Include dependency graph for pico_time.h:

Go to the source code of this file.

Macros

#define _POSIX_C_SOURCE   199309L
 

Typedefs

typedef uint64_t ptime_t
 Time value expressed in microseconds. More...
 

Functions

ptime_t pt_now (void)
 Returns the present high-res clock time. More...
 
void pt_sleep (ptime_t duration)
 Sleeps for at least the specified duration. More...
 
int64_t pt_to_usec (ptime_t time)
 Converts time to microseconds. More...
 
int32_t pt_to_msec (ptime_t time)
 Converts time to milliseconds. More...
 
double pt_to_sec (ptime_t time)
 Converts time to seconds. More...
 
ptime_t pt_from_usec (int64_t usec)
 Make time from microseconds. More...
 
ptime_t pt_from_msec (int32_t msec)
 Make time from miliseconds. More...
 
ptime_t pt_from_sec (double sec)
 Make time from seconds. More...
 

Detailed Description

A simple time management library.


Licensing information at end of header

Features:

Summary:

This library provides high-res time and sleep functions, as well as unit conversions functions.

Even though ptime_t is expressed in microseconds, it is still recommended that you use the pt_to_usec and pt_from_usec functions should this ever change.

Usage:

To use this library in your project, add the following

#define PICO_TIME_IMPLEMENTATION #include "pico_time.h"

to a source file (once).

IMPORTANT: On POSIX systems, when defining PICO_TIME_IMPLEMENTATION, one of three conditions must hold:

1) #define _POSIX_C_SOURCE 199309L must precede any header include in the file 2) This library must be included before any other headers 3) The build system must define _POSIX_C_SOURCE 199309L

Macro Definition Documentation

◆ _POSIX_C_SOURCE

#define _POSIX_C_SOURCE   199309L

Typedef Documentation

◆ ptime_t

typedef uint64_t ptime_t

Time value expressed in microseconds.

Function Documentation

◆ pt_now()

ptime_t pt_now ( void  )

Returns the present high-res clock time.

◆ pt_sleep()

void pt_sleep ( ptime_t  duration)

Sleeps for at least the specified duration.

Note: On most platforms this function has microsecond resolution, except on Windows where it only has millisecond resoultion.

◆ pt_to_usec()

int64_t pt_to_usec ( ptime_t  time)

Converts time to microseconds.

◆ pt_to_msec()

int32_t pt_to_msec ( ptime_t  time)

Converts time to milliseconds.

◆ pt_to_sec()

double pt_to_sec ( ptime_t  time)

Converts time to seconds.

◆ pt_from_usec()

ptime_t pt_from_usec ( int64_t  usec)

Make time from microseconds.

◆ pt_from_msec()

ptime_t pt_from_msec ( int32_t  msec)

Make time from miliseconds.

◆ pt_from_sec()

ptime_t pt_from_sec ( double  sec)

Make time from seconds.