upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
upm_utilities.h
1 /*
2  * Authors:
3  * Jon Trulson <jtrulson@ics.com>
4  * Contributions: Rex Tsai <rex.cc.tsai@gmail.com>
5  * Abhishek Malik <abhishek.malik@intel.com>
6  * Copyright (c) 2017 Intel Corporation.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27 #ifndef UPM_UTILITIES_H_
28 #define UPM_UTILITIES_H_
29 
30 #include <upm_platform.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #if defined(UPM_PLATFORM_LINUX)
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <stdint.h>
40 #include <unistd.h>
41 #include <sys/time.h>
42 
43 typedef struct timespec upm_clock_t;
44 #endif /* UPM_PLATFORM_LINUX */
45 
46 #if defined(UPM_PLATFORM_ZEPHYR)
47 #include <zephyr.h>
48 #include <device.h>
49 #include <sys_clock.h>
50 #include <version.h>
51 #include <kernel_version.h>
52 
53 #if defined(CONFIG_STDOUT_CONSOLE)
54 #include <stdio.h>
55 #define PRINT printf
56 #else
57 #include <misc/printk.h>
58 #define PRINT printk
59 #endif
60 
61 typedef uint64_t upm_clock_t;
62 
63 #endif /* UPM_PLATFORM_ZEPHYR */
64 
70 void upm_delay(uint32_t time);
71 
77 void upm_delay_ms(uint32_t time);
78 
84 void upm_delay_us(uint32_t time);
85 
94 void upm_delay_ns(uint64_t time);
95 
109 upm_clock_t upm_clock_init(void);
110 
119 uint64_t upm_elapsed_ms(const upm_clock_t *clock);
120 
129 uint64_t upm_elapsed_us(const upm_clock_t *clock);
130 
142 uint64_t upm_elapsed_ns(const upm_clock_t *clock);
143 
151 int upm_ugm3_to_aqi (double ugm3);
152 
153 #ifdef __cplusplus
154 }
155 #endif
156 
157 #endif /* UPM_UTILITIES_H_ */