d_time.h
Go to the documentation of this file.
1 /*
2 MIT LICENSE
3 
4 Copyright 2014-2019 Inertial Sense, Inc. - http://inertialsense.com
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
7 
8 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9 
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT, IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 */
12 
13 #ifndef _D_TIME_H_
14 #define _D_TIME_H_
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 #include <stdint.h>
21 
22 // defines
23 //#define ENABLE_TC_TIME
24 
25 // includes
26 // #include "user_board.h" // BOARD_FREQ_SLCK_XTAL
27 #ifdef ENABLE_TC_TIME
28 #include "d_timer.h"
29 #endif // ENABLE_TC_TIME
30 
31 // defines
32 #ifdef ENABLE_TC_TIME
33 #define RTPRES_SEC (CHIP_FREQ_MCK/8) // MCK/8
34 #define RTPRES 1
35 #else
36 #define RTPRES_SEC BOARD_FREQ_SLCK_XTAL
37 #define RTPRES 3 // finest allowed granularity
38 #endif // ENABLE_TC_TIME
39 
40 #define TIME_TICKS_PER_SEC (RTPRES_SEC/RTPRES)
41 #define TIME_TICKS_PER_MS (TIME_TICKS_PER_SEC/1000)
42 #define TIME_TICKS_PER_US (TIME_TICKS_PER_SEC/1000000)
43 
44 #define TIME_SECS_PER_TICK_LF (((double)RTPRES)/(double)RTPRES_SEC)
45 #define TIME_MS_PER_TICK_LF (TIME_SECS_PER_TICK_LF*1000.0)
46 #define TIME_US_PER_TICK_LF (TIME_SECS_PER_TICK_LF*1000000.0)
47 
48 #define TIME_SECS_PER_TICK_F (((float)RTPRES)/(float)RTPRES_SEC)
49 #define TIME_MS_PER_TICK_F (TIME_SECS_PER_TICK_F*1000.0f)
50 #define TIME_US_PER_TICK_F (TIME_SECS_PER_TICK_F*1000000.0f)
51 
52 // typedefs
53 typedef union
54 {
55  uint32_t u32[2];
56  uint64_t u64;
57 } ticks_t;
58 
59 // prototypes
60 void time_init(void);
61 volatile uint64_t time_ticks(void);
62 void time_delay(uint32_t ms);
63 uint32_t time_msec(void);
64 uint32_t time_usec(void);
65 float time_secf(void);
66 float time_msecf(void);
67 float time_usecf(void);
68 double time_seclf(void);
69 double time_mseclf(void);
70 double time_useclf(void);
71 
72 #ifdef __cplusplus
73 }
74 #endif
75 
76 #endif // _D_TIME_H_
void time_init(void)
Definition: d_time.c:40
double time_useclf(void)
Definition: d_time.c:155
void time_delay(uint32_t ms)
Definition: d_time.c:84
double time_mseclf(void)
Definition: d_time.c:149
Definition: d_time.h:53
float time_usecf(void)
Definition: d_time.c:137
uint64_t u64
Definition: d_time.h:56
uint32_t time_usec(void)
Definition: d_time.c:110
float time_secf(void)
Definition: d_time.c:125
double time_seclf(void)
Definition: d_time.c:143
volatile uint64_t time_ticks(void)
Definition: d_time.c:65
uint32_t time_msec(void)
Definition: d_time.c:95
float time_msecf(void)
Definition: d_time.c:131


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:57