2015-10-03 07:43:18 +08:00
|
|
|
/****************************************************************************
|
2014-08-09 04:43:02 +08:00
|
|
|
* sched/clock/clock_getres.c
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
2021-02-08 23:33:58 +08:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
2021-02-08 23:33:58 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
2021-02-08 23:33:58 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
2015-10-03 07:43:18 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2015-10-03 07:43:18 +08:00
|
|
|
/****************************************************************************
|
2007-02-18 07:21:28 +08:00
|
|
|
* Included Files
|
2015-10-03 07:43:18 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2009-12-15 02:39:29 +08:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2007-02-18 07:21:28 +08:00
|
|
|
#include <time.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
2009-12-15 02:39:29 +08:00
|
|
|
|
2014-08-09 04:43:02 +08:00
|
|
|
#include "clock/clock.h"
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2015-10-03 07:43:18 +08:00
|
|
|
/****************************************************************************
|
2007-02-18 07:21:28 +08:00
|
|
|
* Public Functions
|
2015-10-03 07:43:18 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2015-10-03 07:43:18 +08:00
|
|
|
/****************************************************************************
|
2012-07-15 03:30:31 +08:00
|
|
|
* Name: clock_getres
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Clock Functions based on POSIX APIs
|
|
|
|
*
|
2015-10-03 07:43:18 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
|
|
|
int clock_getres(clockid_t clock_id, struct timespec *res)
|
|
|
|
{
|
2009-12-15 02:39:29 +08:00
|
|
|
int ret = OK;
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2016-06-12 06:42:42 +08:00
|
|
|
sinfo("clock_id=%d\n", clock_id);
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2018-11-12 20:42:38 +08:00
|
|
|
switch (clock_id)
|
2007-02-18 07:21:28 +08:00
|
|
|
{
|
2018-11-12 20:42:38 +08:00
|
|
|
default:
|
|
|
|
serr("Returning ERROR\n");
|
|
|
|
set_errno(EINVAL);
|
|
|
|
ret = ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLOCK_MONOTONIC:
|
2020-12-05 16:40:48 +08:00
|
|
|
case CLOCK_BOOTTIME:
|
2018-11-12 20:42:38 +08:00
|
|
|
case CLOCK_REALTIME:
|
2019-12-02 03:01:16 +08:00
|
|
|
|
2018-11-12 20:42:38 +08:00
|
|
|
/* Form the timspec using clock resolution in nanoseconds */
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2018-11-12 20:42:38 +08:00
|
|
|
res->tv_sec = 0;
|
|
|
|
res->tv_nsec = NSEC_PER_TICK;
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2020-12-05 16:40:48 +08:00
|
|
|
sinfo("Returning res=(%d,%d)\n", (int)res->tv_sec,
|
|
|
|
(int)res->tv_nsec);
|
2018-11-12 20:42:38 +08:00
|
|
|
break;
|
2007-02-18 07:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|