/**
 * \file tz_time.c
 * \brief helper function for time managing of trust zone
 * \author a.stafieiev@samsung.com
 * \version 0.1
 * \date Created 2016/01/22
 * \par In Samsung R&D Institute Ukraine (SRK) under a contract between
 * \par LLC Samsung Electronics Ukraine Company (Kiev, Ukraine) and
 * \par Samsung Electronics Co, Ltd (Seoul, Republic of Korea)
 * \par Copyright: (c) Samsung Electronics Co, Ltd 2016. All rights reserved.
 **/

#include <tz_time.h>
#include <qsee_timer.h>

uint64_t tz_get_timestamp(void)
{
    uint64_t time = 0;
    static uint64_t prev = 0;
    int i;

    /* qsee_get_uptime returns ms */
    for (i = 0 ; i < 10 ;i++)
    {
        time = qsee_get_uptime();
        if (time >= prev  && time != 0) break;
        TTY_LOG("qsee_get_uptime returned invalid value: prev(0x%x) current(0x%x)", prev, time);
    }

    if(i == 10) {
        TTY_LOG("tz_get_timestamp error prev(0x%x) current(0x%x)", prev, time);
    }
    else {
        prev = time;
    }

    return time;
}
