Skip to content

ARMmbed/mbed-time

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

POSIX time functions for mbed OS

This module provides simpler time functions for mbed OS, in the style of the POSIX time functions. All values returned from this module are derived from the realtime clock (RTC), so they return the time since the device started.

Installation

  • Install the module in your project via: yotta install mbed-time.
  • Add #include <sys/time.h> to the include list in your .cpp file.

Implemented functions

Example

Retrieving the time since startup, in milliseconds.

#include "mbed-drivers/mbed.h"
#include <sys/time.h>

static void read_time() {
    struct timeval tvp;
    gettimeofday(&tvp, NULL);
    printf("Time since startup %li ms.\r\n", (tvp.tv_sec * 1000L) + (tvp.tv_usec / 1000L));
}

void app_start(int, char**) {
    // on startup, set the time to 0.
    struct timeval tvp = { 0, 0 };
    settimeofday(&tvp, NULL);

    // every 500 ms. we call `read_time` function
    minar::Scheduler::postCallback(read_time).period(minar::milliseconds(500));
}

About

Module providing POSIX time using mbed HAL.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages