125 lines
3.0 KiB
C
Executable File
125 lines
3.0 KiB
C
Executable File
/*------------------------------------------------------------------------------
|
|
Copyright 2016-2017 Sony Semiconductor Solutions Corporation
|
|
|
|
Last Updated : 2017/11/30
|
|
Modification ID : 253a4918e2da2cf28a9393596fa16f25024e504d
|
|
------------------------------------------------------------------------------*/
|
|
|
|
#include "sony_common.h"
|
|
|
|
#if defined(_WINDOWS)
|
|
|
|
#include <windows.h>
|
|
#include <mmsystem.h>
|
|
|
|
#pragma comment(lib, "winmm.lib")
|
|
|
|
sony_result_t sony_stopwatch_start (sony_stopwatch_t * pStopwatch)
|
|
{
|
|
SONY_TRACE_ENTER("sony_stopwatch_start");
|
|
|
|
if (!pStopwatch) {
|
|
SONY_TRACE_RETURN(SONY_RESULT_ERROR_ARG);
|
|
}
|
|
pStopwatch->startTime = timeGetTime ();
|
|
|
|
SONY_TRACE_RETURN(SONY_RESULT_OK);
|
|
}
|
|
|
|
sony_result_t sony_stopwatch_sleep (sony_stopwatch_t * pStopwatch, uint32_t ms)
|
|
{
|
|
SONY_TRACE_ENTER("sony_stopwatch_sleep");
|
|
if (!pStopwatch) {
|
|
SONY_TRACE_RETURN(SONY_RESULT_ERROR_ARG);
|
|
}
|
|
SONY_ARG_UNUSED(*pStopwatch);
|
|
SONY_SLEEP (ms);
|
|
|
|
SONY_TRACE_RETURN(SONY_RESULT_OK);
|
|
}
|
|
|
|
sony_result_t sony_stopwatch_elapsed (sony_stopwatch_t * pStopwatch, uint32_t* pElapsed)
|
|
{
|
|
SONY_TRACE_ENTER("sony_stopwatch_elapsed");
|
|
|
|
if (!pStopwatch || !pElapsed) {
|
|
SONY_TRACE_RETURN(SONY_RESULT_ERROR_ARG);
|
|
}
|
|
*pElapsed = timeGetTime () - pStopwatch->startTime;
|
|
|
|
SONY_TRACE_RETURN(SONY_RESULT_OK);
|
|
}
|
|
|
|
#elif defined(__linux__)
|
|
|
|
#include <time.h>
|
|
|
|
static uint32_t GetTimeCount (void)
|
|
{
|
|
struct timespec tp;
|
|
|
|
if (clock_gettime (CLOCK_MONOTONIC, &tp) != 0) {
|
|
SONY_TRACE_RETURN(SONY_RESULT_ERROR_OTHER);
|
|
}
|
|
|
|
/* In ms. Overflow is ignored, and upper value can be cut off. */
|
|
return (uint32_t) ((tp.tv_sec * 1000) + (tp.tv_nsec / 1000000));
|
|
}
|
|
|
|
sony_result_t sony_stopwatch_start (sony_stopwatch_t * pStopwatch)
|
|
{
|
|
SONY_TRACE_ENTER("sony_stopwatch_start");
|
|
|
|
if (!pStopwatch) {
|
|
SONY_TRACE_RETURN(SONY_RESULT_ERROR_ARG);
|
|
}
|
|
|
|
pStopwatch->startTime = GetTimeCount ();
|
|
|
|
SONY_TRACE_RETURN(SONY_RESULT_OK);
|
|
}
|
|
|
|
sony_result_t sony_stopwatch_sleep (sony_stopwatch_t * pStopwatch, uint32_t ms)
|
|
{
|
|
SONY_TRACE_ENTER("sony_stopwatch_sleep");
|
|
if (!pStopwatch) {
|
|
SONY_TRACE_RETURN(SONY_RESULT_ERROR_ARG);
|
|
}
|
|
SONY_ARG_UNUSED(*pStopwatch);
|
|
SONY_SLEEP (ms);
|
|
|
|
SONY_TRACE_RETURN(SONY_RESULT_OK);
|
|
}
|
|
|
|
sony_result_t sony_stopwatch_elapsed (sony_stopwatch_t * pStopwatch, uint32_t* pElapsed)
|
|
{
|
|
SONY_TRACE_ENTER("sony_stopwatch_elapsed");
|
|
|
|
if (!pStopwatch || !pElapsed) {
|
|
SONY_TRACE_RETURN(SONY_RESULT_ERROR_ARG);
|
|
}
|
|
*pElapsed = GetTimeCount () - pStopwatch->startTime;
|
|
|
|
SONY_TRACE_RETURN(SONY_RESULT_OK);
|
|
}
|
|
|
|
#else
|
|
|
|
sony_result_t sony_stopwatch_start (sony_stopwatch_t * pStopwatch)
|
|
{
|
|
#error sony_stopwatch_start is not implemented
|
|
}
|
|
|
|
sony_result_t sony_stopwatch_sleep (sony_stopwatch_t * pStopwatch, uint32_t ms)
|
|
{
|
|
#error sony_stopwatch_sleep is not implemented
|
|
}
|
|
|
|
sony_result_t sony_stopwatch_elapsed (sony_stopwatch_t * pStopwatch, uint32_t* pElapsed)
|
|
{
|
|
#error sony_stopwatch_elapsed is not implemented
|
|
return 0;
|
|
}
|
|
|
|
#endif
|