1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** POSIX wrapper for THREADX */
16 /** */
17 /** */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 /* Include necessary system files. */
23
24 #include "tx_api.h" /* Threadx API */
25 #include "pthread.h" /* Posix API */
26 #include "px_int.h" /* Posix helper functions */
27
28
29 /**************************************************************************/
30 /* */
31 /* FUNCTION RELEASE */
32 /* */
33 /* clock_settime PORTABLE C */
34 /* 6.1.7 */
35 /* AUTHOR */
36 /* */
37 /* William E. Lamie, Microsoft Corporation */
38 /* */
39 /* DESCRIPTION */
40 /* */
41 /* This subroutine sets the internal Threadx timer tick variable */
42 /* to the time specificed in the tspec variable after conversion */
43 /* if tspec->tv_sec is 0 the clock with be set to the value of */
44 /* tspec->tv_nsec */
45 /* */
46 /* INPUT */
47 /* */
48 /* clockid_t, tspec */
49 /* */
50 /* OUTPUT */
51 /* */
52 /* error code */
53 /* */
54 /* CALLS */
55 /* */
56 /* tx_time_set ThreadX function */
57 /* */
58 /* CALLED BY */
59 /* */
60 /* Application Code */
61 /* */
62 /* RELEASE HISTORY */
63 /* */
64 /* DATE NAME DESCRIPTION */
65 /* */
66 /* 06-02-2021 William E. Lamie Initial Version 6.1.7 */
67 /* */
68 /**************************************************************************/
clock_settime(clockid_t t,const struct timespec * tspec)69 INT clock_settime(clockid_t t, const struct timespec * tspec)
70 {
71 ULONG tx_time;
72
73 if(t==CLOCK_REALTIME)
74 {
75 tx_time=(ULONG)((tspec->tv_sec * CPU_TICKS_PER_SECOND) + (tspec->tv_nsec / NANOSECONDS_IN_CPU_TICK));
76 tx_time_set( tx_time);
77 return(OK);
78 }
79 else return(EINVAL);
80 }
81