Init basesystem source codes.
[staging/basesystem.git] / otherservice / posix_based_os001_legacy_library / library / src / PosixBasedOS001TimeApi.c
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 // libraries for replacing PosixBasedOS001 to Linux
18 // PosixBasedOS001TimeApi.c
19
20 #include <other_service/PosixBasedOS001TimeApi.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include <unistd.h>                             // for using usleep()
26 #include <time.h>                               // for using clock()
27
28 // delay()
29 // NOTE: Control a device
30 // duration
31 //   The number of milliseconds for which to suspend the calling thread from execution.
32 //
33 // _CWORD72_ doesnot use return code of delay, and sets 1,100,and 1000.
34 unsigned int delay( unsigned int duration ){
35
36         int ret;
37         useconds_t duration_usec = duration * 1000;
38
39         ret = EOK;
40
41         if( duration_usec > 1000000 ){
42                 printf("delay():over flow!\n");
43         }else{
44
45                 // using usec order
46                 ret = usleep(duration_usec);
47
48                 // error of usleep() = 0(E_OK), -1(ERROR)
49                 // delay() cannot return error code. [data type unmatch]
50                 if(ret < 0){  // LCOV_EXCL_BR_LINE 5: fail safe for libc function usleep
51                         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
52                         printf("delay():error!\n");  // LCOV_EXCL_LINE 5: fail safe for libc function usleep
53                 }
54         }
55
56         return EOK;
57 }