upiwin/src/time_func.c

45 lines
1.4 KiB
C

/*
* UPIWIN - Micro Pi Windowing Framework Kernel
* Copyright (C) 2019 Amy Bowersox/Erbosoft Metaverse Design Solutions
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*-------------------------------------------------------------------------
*/
#include <stddef.h>
#include <sys/time.h>
#include "time_func.h"
static TIMESTAMP start_timestamp = 0; /* time since epoch at start of run */
TIMESTAMP Time_since_epoch(void)
{
TIMESTAMP rc;
struct timeval tv;
gettimeofday(&tv, NULL);
rc = (tv.tv_sec * (TIMESTAMP)1000) + (tv.tv_usec / (TIMESTAMP)1000);
return rc;
}
TIMESTAMP Time_since_start(void)
{
return Time_since_epoch() - start_timestamp;
}
void Time_init(void)
{
start_timestamp = Time_since_epoch();
}