2015-10-03 01:43:18 +02:00
|
|
|
/****************************************************************************
|
2023-07-07 11:04:59 +02:00
|
|
|
* libs/libc/sched/clock_getres.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01: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 00:21:28 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01: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 00:21:28 +01:00
|
|
|
*
|
2015-10-03 01:43:18 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-10-03 01:43:18 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2015-10-03 01:43:18 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2009-12-14 19:39:29 +01:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <time.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
2009-12-14 19:39:29 +01:00
|
|
|
|
2023-07-07 11:04:59 +02:00
|
|
|
#include <nuttx/clock.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-10-03 01:43:18 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Public Functions
|
2015-10-03 01:43:18 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-10-03 01:43:18 +02:00
|
|
|
/****************************************************************************
|
2012-07-14 21:30:31 +02:00
|
|
|
* Name: clock_getres
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Clock Functions based on POSIX APIs
|
|
|
|
*
|
2015-10-03 01:43:18 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
int clock_getres(clockid_t clock_id, struct timespec *res)
|
|
|
|
{
|
2023-06-21 11:26:35 +02:00
|
|
|
clockid_t clock_type = clock_id & CLOCK_MASK;
|
|
|
|
int ret = OK;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2023-06-21 11:26:35 +02:00
|
|
|
sinfo("clock_id=%d, clock_type=%d\n", clock_id, clock_type);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2023-06-21 11:26:35 +02:00
|
|
|
switch (clock_type)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2018-11-12 13:42:38 +01:00
|
|
|
default:
|
|
|
|
serr("Returning ERROR\n");
|
|
|
|
set_errno(EINVAL);
|
|
|
|
ret = ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLOCK_MONOTONIC:
|
2020-12-05 09:40:48 +01:00
|
|
|
case CLOCK_BOOTTIME:
|
2018-11-12 13:42:38 +01:00
|
|
|
case CLOCK_REALTIME:
|
2023-06-19 16:11:16 +02:00
|
|
|
case CLOCK_PROCESS_CPUTIME_ID:
|
|
|
|
case CLOCK_THREAD_CPUTIME_ID:
|
2019-12-01 20:01:16 +01:00
|
|
|
|
2018-11-12 13:42:38 +01:00
|
|
|
/* Form the timspec using clock resolution in nanoseconds */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-11-12 13:42:38 +01:00
|
|
|
res->tv_sec = 0;
|
|
|
|
res->tv_nsec = NSEC_PER_TICK;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2020-12-05 09:40:48 +01:00
|
|
|
sinfo("Returning res=(%d,%d)\n", (int)res->tv_sec,
|
|
|
|
(int)res->tv_nsec);
|
2018-11-12 13:42:38 +01:00
|
|
|
break;
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|